-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlertsaid.c
64 lines (56 loc) · 1.24 KB
/
lertsaid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
file: lertsaid.c
dump the dbm data file where I'm keeping records
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/file.h>
#include "lert.h"
int main(argc, argv)
int argc;
char ** argv;
{
char buffer[512];
DBM *db;
datum key;
datum old;
datum data;
register char *cp;
register char *name_p;
int name_c;
char name[128];
char categ[128];
if (argc != 1) {
fprintf(stderr, "usage: %s\n", argv[0]);
fprintf(stderr, " dumps the file of people who have responded -n\n");
exit(1);
}
db = dbm_open(LERTS_LOG, O_RDONLY, 0600);
if (db == NULL) {
fprintf(stderr, "Unable to open database file %s.\n", LERTS_LOG);
exit (1);
}
for (key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db)) {
data = dbm_fetch(db, key);
if (!dbm_error(db)) {
cp = name;
for(name_c = key.dsize, name_p = key.dptr; name_c > 0; name_c--) {
*cp = *name_p;
cp++;
name_p++;
}
cp = categ;
for(name_c = data.dsize, name_p = data.dptr; name_c > 0; name_c--) {
*cp = *name_p;
cp++;
name_p++;
}
*cp = '\0';
printf("name: %s categories: %s\n", name, categ);
}
}
return (0);
}