|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T t
Length: 4063 (0xfdf) Types: TextFile Names: »testdbm.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦847972ed9⟧ »./gdbm0.9.tar.Z« └─⟦e41d67701⟧ └─⟦this⟧ »gdbm/testdbm.c«
/* testdbm.c - Driver program to test the dbm interface routines. */ /* GNU DBM - DataBase Manager (database subroutines) by Philip A. Nelson Copyright (C) 1989 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. You may contact the author by: e-mail: phil@wwu.edu us-mail: Philip A. Nelson Computer Science Department Western Washington University Bellingham, WA 98226 phone: (206) 676-3035 *************************************************************************/ #include <stdio.h> #include <sys/types.h> #include <sys/file.h> #include <sys/stat.h> #define TRUE 1 #define FALSE 0 typedef struct { char *dptr; int dsize; } datum; extern datum fetch (); extern datum firstkey (); extern datum nextkey (); /* The test program allows one to call all the routines plus the hash function. The commands are single letter commands. The user is prompted for all other information. The commands are q (quit), f (fetch), s (store), d (delete), 1 (firstkey), n (nextkey) and h (hash function). */ main () { char cmd_ch; datum key_data; datum data_data; datum return_data; char key_line[500]; char data_line[1000]; char done = FALSE; key_data.dptr = key_line; data_data.dptr = data_line; if (dbminit ("junkdbm") != 0) { printf("dbminit failed.\n"); exit(2); } /* Welcome message. */ printf ("\nWelcome to the dbm test program. Type ? for help.\n\n"); while (!done) { printf("com -> "); cmd_ch = getchar(); while (getchar() != '\n') /* Do nothing. */; switch (cmd_ch) { case 'q': done = TRUE; break; case 'f': printf ("key -> "); gets (key_line); key_data.dsize = strlen (key_line)+1; return_data = fetch (key_data); if (return_data.dptr != NULL) printf ("data is ->%s\n\n", return_data.dptr); else printf ("No such item found.\n\n"); break; case 's': printf ("key -> "); gets(key_line); key_data.dsize = strlen (key_line)+1; printf ("data -> "); gets(data_line); data_data.dsize = strlen (data_line)+1; if (store (key_data, data_data) != 0) printf("Item not inserted. \n"); printf("\n"); break; case 'd': printf ("key -> "); gets(key_line); key_data.dsize = strlen (key_line)+1; if (delete (key_data) != 0) printf("Item not found or deleted\n"); printf("\n"); break; case '1': return_data = firstkey (); if (return_data.dptr != NULL) printf ("data is ->%s\n\n", return_data.dptr); else printf ("No such item found.\n\n"); break; case '2': return_data = nextkey (return_data); if (return_data.dptr != NULL) printf ("data is ->%s\n\n", return_data.dptr); else printf ("No such item found.\n\n"); break; case 'c': { int temp; temp = 0; return_data = firstkey (); while (return_data.dptr != NULL) { temp++; return_data = nextkey (return_data); } printf ("There are %d items in the database.\n\n", temp); } break; case '?': printf ("c - count elements\n"); printf ("d - delete\n"); printf ("f - fetch\n"); printf ("q - quit\n"); printf ("s - store\n"); printf ("1 - firstkey\n"); printf ("2 - nextkey on last return value\n\n"); break; default: printf("What? \n\n"); break; } } /* Quit normally. */ exit(0); }