Revision 13853,
1.8 KB
checked in by tb, 25 years ago
(diff) |
Check for <db.h> and <nbdm.h> in configure.in; use lert.h to select the right
db header file. Change .c files not to include <ndbm.h> anymore.
|
Line | |
---|
1 | /* |
---|
2 | file: lertstop.c |
---|
3 | basic use: lertstop type |
---|
4 | remove a single letter category from db |
---|
5 | |
---|
6 | ndbm apparently fails in traversing the data if you delete or |
---|
7 | change keys while traversing. |
---|
8 | options--restart traversing or build a linked list of changes... |
---|
9 | |
---|
10 | q&d program...restart traverse! |
---|
11 | |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <sys/types.h> |
---|
16 | #include <sys/stat.h> |
---|
17 | #include <fcntl.h> |
---|
18 | #include <sys/file.h> |
---|
19 | |
---|
20 | #include "lert.h" |
---|
21 | |
---|
22 | main(argc, argv) |
---|
23 | int argc; |
---|
24 | char ** argv; |
---|
25 | { |
---|
26 | char buffer[512]; |
---|
27 | DBM *db; |
---|
28 | datum key; |
---|
29 | datum new; |
---|
30 | datum data; |
---|
31 | register char *cp; |
---|
32 | register char *nd_p; |
---|
33 | int nd_c; |
---|
34 | int count = 0; |
---|
35 | int changed; |
---|
36 | int new_char; |
---|
37 | char * name_p; |
---|
38 | int name_c; |
---|
39 | char categ[128]; |
---|
40 | |
---|
41 | if (argc != 2) { |
---|
42 | fprintf(stderr, "usage: %s type\n", argv[0]); |
---|
43 | fprintf(stderr, " type is a single character category\n"); |
---|
44 | fprintf(stderr, " to be removed from the lertdata file\n"); |
---|
45 | exit(1); |
---|
46 | } |
---|
47 | |
---|
48 | db = dbm_open(LERTS_DATA, O_RDWR, 0600); |
---|
49 | if (db == NULL) { |
---|
50 | fprintf(stderr, "Unable to open database file %s.\n", LERTS_DATA); |
---|
51 | exit (1); |
---|
52 | } |
---|
53 | key = dbm_firstkey(db); |
---|
54 | while (key.dptr != NULL) { |
---|
55 | data = dbm_fetch(db, key); |
---|
56 | if (!dbm_error(db)) { |
---|
57 | cp = categ; |
---|
58 | changed = FALSE; |
---|
59 | for(name_c = data.dsize, name_p = data.dptr; name_c > 0; name_c--) { |
---|
60 | if (*name_p != argv[1][0]) { |
---|
61 | *cp = *name_p; |
---|
62 | cp++; |
---|
63 | } else { |
---|
64 | changed = TRUE; |
---|
65 | } |
---|
66 | name_p++; |
---|
67 | } |
---|
68 | |
---|
69 | if (changed) { |
---|
70 | if (data.dsize == 1) { |
---|
71 | if (dbm_delete(db, key) < 0) { |
---|
72 | fprintf(stderr, "dbm_delete() failed\n"); |
---|
73 | (void) dbm_clearerr(db); |
---|
74 | } |
---|
75 | } else { |
---|
76 | new.dsize = data.dsize - 1; |
---|
77 | new.dptr = categ; |
---|
78 | if (dbm_store(db, key, new, DBM_REPLACE) < 0) { |
---|
79 | fprintf(stderr, "dbm_store() failed\n"); |
---|
80 | (void) dbm_clearerr(db); |
---|
81 | } |
---|
82 | } |
---|
83 | key = dbm_firstkey(db); |
---|
84 | } else { |
---|
85 | key = dbm_nextkey(db); |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | return (0); |
---|
90 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.