Annotation of loncom/debugging_tools/dump_db.c, revision 1.1
1.1 ! albertel 1: #include <stdio.h>
! 2: #include <stdlib.h>
! 3: #include <unistd.h>
! 4: #include <gdbm.h>
! 5: #include <errno.h>
! 6: #include <string.h>
! 7:
! 8: void usage()
! 9: {
! 10: printf("\nUsage:\ngdbm_convertor -f <gdbm file to convert>\n");
! 11: }
! 12:
! 13: void read_db(char *filename)
! 14: {
! 15: GDBM_FILE db;
! 16: datum key, nextkey, content;
! 17: db = gdbm_open(filename, 0, GDBM_READER, 0, 0);
! 18:
! 19: if (db == NULL) {
! 20: printf("Unable to open db %s beacsue of %s (%d) -- %s (%d)\n",filename,
! 21: gdbm_strerror(gdbm_errno),gdbm_errno,strerror(errno),errno);
! 22: return;
! 23: }
! 24: key = gdbm_firstkey(db);
! 25:
! 26: while ( key.dptr ) {
! 27: content = gdbm_fetch(db, key);
! 28: fwrite(key.dptr, key.dsize, sizeof(char), stdout);
! 29: printf(" -> ");
! 30: fwrite(content.dptr, content.dsize, sizeof(char), stdout);
! 31: printf("\n");
! 32: free(content.dptr);
! 33: nextkey = gdbm_nextkey(db, key);
! 34: free(key.dptr);
! 35: key = nextkey;
! 36: }
! 37: }
! 38:
! 39: int main(int argc, char **argv)
! 40: {
! 41:
! 42: int c;
! 43: char *filename=NULL;
! 44: while (1) {
! 45: c = getopt(argc,argv,"f:");
! 46: if (c == -1)
! 47: break;
! 48: switch (c) {
! 49: case 'f':
! 50: filename = optarg;
! 51: }
! 52: }
! 53:
! 54: if (filename == NULL) {
! 55: usage();
! 56: return 1;
! 57: }
! 58:
! 59: read_db(filename);
! 60:
! 61: return 0;
! 62: }
! 63:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>