source: trunk/athena/bin/lert/lertdump.c @ 7779

Revision 7779, 1.2 KB checked in by cfields, 29 years ago (diff)
Initial revision
Line 
1/*
2   file: lertdump.c
3   dump the dbm data file
4
5 */
6
7#include <stdio.h>
8#include <sys/types.h>
9#include <sys/stat.h>
10#include <fcntl.h>
11#include <ndbm.h>
12#include <sys/file.h>
13
14#include "lert.h"     
15
16main(argc, argv)
17int argc;
18char ** argv;
19{
20  char buffer[512];
21  DBM *db;
22  datum key;
23  datum old;
24  datum data;
25  register char *cp;
26  register char *name_p;
27  int name_c;
28  char name[128];
29  char categ[128];
30
31  if (argc != 1) {
32     fprintf(stderr, "usage: %s\n", argv[0]);
33     fprintf(stderr, "   dumps the file of lert entries\n");
34     exit(1);
35  }
36   
37  db = dbm_open(LERTS_DATA, O_RDONLY, 0600);
38  if (db == NULL) {
39    fprintf(stderr, "Unable to open database file %s.\n", LERTS_DATA);
40    exit (1);
41  }
42
43  for (key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db)) {
44    data = dbm_fetch(db, key);
45    if (!dbm_error(db)) {
46      cp = name;
47      for(name_c = key.dsize, name_p = key.dptr; name_c > 0; name_c--) {
48        *cp = *name_p;
49        cp++;
50        name_p++;
51      }
52      cp = categ;
53      for(name_c = data.dsize, name_p = data.dptr; name_c > 0; name_c--) {
54        *cp = *name_p;
55        cp++;
56        name_p++;
57      }
58      *cp = '\0';
59      printf("name: %s  categories: %s\n", name, categ);
60    }
61  }
62  return (0);
63}
64   
Note: See TracBrowser for help on using the repository browser.