|
1 diff -uNr cdb-0.75/FILES cdb-0.75-fefe/FILES |
|
2 --- cdb-0.75/FILES Sat Feb 19 21:42:05 2000 |
|
3 +++ cdb-0.75-fefe/FILES Wed Sep 27 21:54:44 2000 |
|
4 @@ -76,3 +76,21 @@ |
|
5 uint32.h2 |
|
6 uint32_pack.c |
|
7 uint32_unpack.c |
|
8 +traverse.c |
|
9 +cdbdump.1 |
|
10 +cdbget.1 |
|
11 +cdbmake.1 |
|
12 +cdbstats.1 |
|
13 +cdbtest.1 |
|
14 +cdbnext.c |
|
15 +cdb_datalen.3 |
|
16 +cdb_datapos.3 |
|
17 +cdb_find.3 |
|
18 +cdb_firstkey.3 |
|
19 +cdb_free.3 |
|
20 +cdb_init.3 |
|
21 +cdb_keylen.3 |
|
22 +cdb_keypos.3 |
|
23 +cdb_nextkey.3 |
|
24 +cdb_read.3 |
|
25 +cdb_successor.3 |
|
26 diff -uNr cdb-0.75/Makefile cdb-0.75-fefe/Makefile |
|
27 --- cdb-0.75/Makefile Sat Feb 19 21:42:05 2000 |
|
28 +++ cdb-0.75-fefe/Makefile Wed Sep 27 21:46:39 2000 |
|
29 @@ -87,13 +87,17 @@ |
|
30 ./compile byte_diff.c |
|
31 |
|
32 cdb.a: \ |
|
33 -makelib cdb.o cdb_hash.o cdb_make.o |
|
34 - ./makelib cdb.a cdb.o cdb_hash.o cdb_make.o |
|
35 +makelib cdb.o cdb_hash.o cdb_make.o cdb_traverse.o |
|
36 + ./makelib cdb.a cdb.o cdb_hash.o cdb_make.o cdb_traverse.o |
|
37 |
|
38 cdb.o: \ |
|
39 compile cdb.c readwrite.h error.h seek.h byte.h cdb.h uint32.h |
|
40 ./compile cdb.c |
|
41 |
|
42 +cdb_traverse.o: \ |
|
43 +compile cdb_traverse.c cdb.h uint32.h seek.h |
|
44 + ./compile cdb_traverse.c |
|
45 + |
|
46 cdb_hash.o: \ |
|
47 compile cdb_hash.c cdb.h uint32.h |
|
48 ./compile cdb_hash.c |
|
49 @@ -244,7 +248,7 @@ |
|
50 |
|
51 prog: \ |
|
52 cdbget cdbmake cdbdump cdbstats cdbtest cdbmake-12 cdbmake-sv rts \ |
|
53 -testzero |
|
54 +testzero traverse cdbnext |
|
55 |
|
56 rts: \ |
|
57 warn-auto.sh rts.sh conf-home |
|
58 @@ -318,3 +322,26 @@ |
|
59 seek_cur.o |
|
60 ./makelib unix.a error.o open_read.o open_trunc.o \ |
|
61 error_str.o seek_set.o seek_cur.o |
|
62 + |
|
63 +traverse: \ |
|
64 +load traverse.o cdb.a uint32_unpack.o byte_copy.o seek_set.o \ |
|
65 +error.o byte_diff.o fmt_ulong.o |
|
66 + ./load traverse cdb.a uint32_unpack.o byte_copy.o seek_set.o \ |
|
67 + error.o byte_diff.o fmt_ulong.o |
|
68 + |
|
69 +traverse.o: \ |
|
70 +compile traverse.c cdb.h uint32.h fmt.h |
|
71 + ./compile traverse.c |
|
72 + |
|
73 +cdbnext: \ |
|
74 +load cdbnext.o cdb.a buffer.a byte.a error.o error_str.o seek_set.o |
|
75 + ./load cdbnext cdb.a buffer.a byte.a error.o error_str.o \ |
|
76 + seek_set.o |
|
77 + |
|
78 +cdbnext.o: \ |
|
79 +compile cdbnext.c exit.h scan.h str.h buffer.h strerr.h cdb.h \ |
|
80 +uint32.h |
|
81 + ./compile cdbnext.c |
|
82 + |
|
83 +clean: |
|
84 + rm -f `cat TARGETS` |
|
85 diff -uNr cdb-0.75/TARGETS cdb-0.75-fefe/TARGETS |
|
86 --- cdb-0.75/TARGETS Sat Feb 19 21:42:05 2000 |
|
87 +++ cdb-0.75-fefe/TARGETS Wed Sep 27 21:35:15 2000 |
|
88 @@ -64,3 +64,8 @@ |
|
89 it |
|
90 setup |
|
91 check |
|
92 +traverse |
|
93 +traverse.o |
|
94 +cdb_traverse.o |
|
95 +cdbnext |
|
96 +cdbnext.o |
|
97 diff -uNr cdb-0.75/cdb.h cdb-0.75-fefe/cdb.h |
|
98 --- cdb-0.75/cdb.h Sat Feb 19 21:42:05 2000 |
|
99 +++ cdb-0.75-fefe/cdb.h Wed Sep 27 21:02:59 2000 |
|
100 @@ -31,7 +31,14 @@ |
|
101 extern int cdb_findnext(struct cdb *,char *,unsigned int); |
|
102 extern int cdb_find(struct cdb *,char *,unsigned int); |
|
103 |
|
104 +extern int cdb_firstkey(struct cdb *c,uint32 *kpos); |
|
105 +extern int cdb_nextkey(struct cdb *c,uint32 *kpos); |
|
106 + |
|
107 +extern int cdb_successor(struct cdb *c,char *,unsigned int); |
|
108 + |
|
109 #define cdb_datapos(c) ((c)->dpos) |
|
110 #define cdb_datalen(c) ((c)->dlen) |
|
111 +#define cdb_keypos(c) ((c)->kpos) |
|
112 +#define cdb_keylen(c) ((c)->dpos-(c)->kpos) |
|
113 |
|
114 #endif |
|
115 diff -uNr cdb-0.75/cdb_datalen.3 cdb-0.75-fefe/cdb_datalen.3 |
|
116 --- cdb-0.75/cdb_datalen.3 Thu Jan 1 01:00:00 1970 |
|
117 +++ cdb-0.75-fefe/cdb_datalen.3 Wed Sep 27 21:52:34 2000 |
|
118 @@ -0,0 +1,17 @@ |
|
119 +.TH cdb_datalen 3 |
|
120 +.SH NAME |
|
121 +cdb_datalen \- get length of data |
|
122 +.SH SYNTAX |
|
123 +.B #include <cdb.h> |
|
124 + |
|
125 +unsigned int cdb_datalen(struct cdb *\fIc\fR); |
|
126 + |
|
127 +.SH DESCRIPTION |
|
128 +.B cdb_datalen |
|
129 +returns the length of the data associated with the last key you looked |
|
130 +up with cdb_find or cdb_findnext. |
|
131 + |
|
132 +Use cdb_datapos to get the position of the data. |
|
133 + |
|
134 +.SH "SEE ALSO" |
|
135 +cdb_datapos(3), cdb_keylen(3), cdb_keypos(3) |
|
136 diff -uNr cdb-0.75/cdb_datapos.3 cdb-0.75-fefe/cdb_datapos.3 |
|
137 --- cdb-0.75/cdb_datapos.3 Thu Jan 1 01:00:00 1970 |
|
138 +++ cdb-0.75-fefe/cdb_datapos.3 Wed Sep 27 21:52:37 2000 |
|
139 @@ -0,0 +1,17 @@ |
|
140 +.TH cdb_datapos 3 |
|
141 +.SH NAME |
|
142 +cdb_datapos \- get position of data |
|
143 +.SH SYNTAX |
|
144 +.B #include <cdb.h> |
|
145 + |
|
146 +uint32 cdb_datapos(struct cdb *\fIc\fR); |
|
147 + |
|
148 +.SH DESCRIPTION |
|
149 +.B cdb_datapos |
|
150 +returns the position of the data associated with the last key you looked |
|
151 +up using cdb_find or cdb_findnext. |
|
152 + |
|
153 +Use cdb_datalen to get the length of the data. |
|
154 + |
|
155 +.SH "SEE ALSO" |
|
156 +cdb_datalen(3), cdb_keypos(3), cdb_keylen(3) |
|
157 diff -uNr cdb-0.75/cdb_find.3 cdb-0.75-fefe/cdb_find.3 |
|
158 --- cdb-0.75/cdb_find.3 Thu Jan 1 01:00:00 1970 |
|
159 +++ cdb-0.75-fefe/cdb_find.3 Wed Sep 27 21:53:03 2000 |
|
160 @@ -0,0 +1,42 @@ |
|
161 +.TH cdb_find 3 |
|
162 +.SH NAME |
|
163 +cdb_find \- look up a key in a constant database |
|
164 +.SH SYNTAX |
|
165 +.B #include <cdb.h> |
|
166 +.br |
|
167 +.B #include <uint32.h> |
|
168 + |
|
169 +int cdb_find(struct cdb *\fIc\fR,char *\fIkey\fR,unsigned int \fIkeylen\fR); |
|
170 +.br |
|
171 +int cdb_datalen(struct cdb *\fIc\fR); |
|
172 +.br |
|
173 +int cdb_datapos(struct cdb *\fIc\fR); |
|
174 +.br |
|
175 +int cdb_findnext(struct cdb *\fIc\fR,char *\fIkey\fR,unsigned int \fIkeylen\fR); |
|
176 + |
|
177 +.SH DESCRIPTION |
|
178 +\fBcdb_find\fR looks for \fIkey\fR. If cdb_find returns 0, the database |
|
179 +does not contain that key; stop. If cdb_find returns -1, there was a |
|
180 +read error; abort. |
|
181 + |
|
182 +\fBcdb_datalen\fR returns the length of the data associated with the |
|
183 +\fIkey\fR. Use it to allocate a pointer \fIp\fR with enough space to |
|
184 +hold the data. |
|
185 + |
|
186 +\fBcdb_datapos\fR returns the position of the data inside the file. Use |
|
187 +it as argument to cdb_read to retrieve the data. |
|
188 + |
|
189 +There may be several records under a single key. You can use |
|
190 +\fBcdb_findnext\fR to find the next record under this key. |
|
191 + |
|
192 +.SH EXAMPLE |
|
193 +static struct cdb; |
|
194 + |
|
195 +if (cdb_find(&c,key,strlen(key)>0) { |
|
196 + char *buf=alloca(cdb_datalen(&c)); |
|
197 + cdb_read(&c,buf,cdb_datalen(&c),cdb_datapos(&c)); |
|
198 + write(1,buf,cdb_datalen(&c)); |
|
199 +.br |
|
200 +} |
|
201 +.SH "SEE ALSO" |
|
202 +cdb_read(3), cdb_init(3), cdb_free(3), cdbmake(1) |
|
203 diff -uNr cdb-0.75/cdb_firstkey.3 cdb-0.75-fefe/cdb_firstkey.3 |
|
204 --- cdb-0.75/cdb_firstkey.3 Thu Jan 1 01:00:00 1970 |
|
205 +++ cdb-0.75-fefe/cdb_firstkey.3 Wed Sep 27 21:53:07 2000 |
|
206 @@ -0,0 +1,19 @@ |
|
207 +.TH cdb_firstkey 3 |
|
208 +.SH NAME |
|
209 +cdb_firstkey \- find first physical record in constant database |
|
210 +.SH SYNTAX |
|
211 +.B #include <cdb.h> |
|
212 +.br |
|
213 +.B #include <uint32.h> |
|
214 + |
|
215 +int cdb_firstkey(struct cdb *\fIc\fR,uint32 *\fIkpos\fR); |
|
216 + |
|
217 +.SH DESCRIPTION |
|
218 +\fBcdb_firstkey\fR finds the physically first record in the constant |
|
219 +database. |
|
220 + |
|
221 +You can use cdb_datapos or cdb_keypos to get \fIposition\fR and |
|
222 +cdb_datalen and cdb_keylen to get \fIlen\fR. |
|
223 + |
|
224 +.SH "SEE ALSO" |
|
225 +cdb_nextkey(3), cdb_successor(3) |
|
226 diff -uNr cdb-0.75/cdb_free.3 cdb-0.75-fefe/cdb_free.3 |
|
227 --- cdb-0.75/cdb_free.3 Thu Jan 1 01:00:00 1970 |
|
228 +++ cdb-0.75-fefe/cdb_free.3 Wed Sep 27 21:53:10 2000 |
|
229 @@ -0,0 +1,17 @@ |
|
230 +.TH cdb_free 3 |
|
231 +.SH NAME |
|
232 +cdb_free \- close a constant databased |
|
233 +.SH SYNTAX |
|
234 +.B #include <cdb.h> |
|
235 + |
|
236 +int cdb_free(struct cdb *\fIc\fR); |
|
237 + |
|
238 +.SH DESCRIPTION |
|
239 +.B cdb_free |
|
240 +removes any memory mapping that cdb_init might have established. |
|
241 + |
|
242 +It will not close the file descriptor that you passed to cdb_init or |
|
243 +attempt to call free() on the struct cdb pointer. |
|
244 + |
|
245 +.SH "SEE ALSO" |
|
246 +cdb_free(3), cdb_read(3), cdb_find(3), cdbmake(1) |
|
247 diff -uNr cdb-0.75/cdb_init.3 cdb-0.75-fefe/cdb_init.3 |
|
248 --- cdb-0.75/cdb_init.3 Thu Jan 1 01:00:00 1970 |
|
249 +++ cdb-0.75-fefe/cdb_init.3 Wed Sep 27 21:53:12 2000 |
|
250 @@ -0,0 +1,20 @@ |
|
251 +.TH cdb_init 3 |
|
252 +.SH NAME |
|
253 +cdb_init \- open a constant database |
|
254 +.SH SYNTAX |
|
255 +.B #include <cdb.h> |
|
256 + |
|
257 +int cdb_init(struct cdb *\fIc\fR,int \fIfd\fR); |
|
258 + |
|
259 +.SH DESCRIPTION |
|
260 +.B cdb_init |
|
261 +places information about \fIfd\fR into a struct cdb variable \fIc\fR. |
|
262 +\fIfd\fR has to be a seekable file previously opened for reading. |
|
263 + |
|
264 +On systems that support mmap, cdb_init will try to map the whole |
|
265 +constant database into memory. |
|
266 + |
|
267 +The inverse operation to cdb_init is cdb_free. |
|
268 + |
|
269 +.SH "SEE ALSO" |
|
270 +cdb_free(3), cdb_read(3), cdb_find(3), cdbmake(1) |
|
271 diff -uNr cdb-0.75/cdb_keylen.3 cdb-0.75-fefe/cdb_keylen.3 |
|
272 --- cdb-0.75/cdb_keylen.3 Thu Jan 1 01:00:00 1970 |
|
273 +++ cdb-0.75-fefe/cdb_keylen.3 Wed Sep 27 21:53:14 2000 |
|
274 @@ -0,0 +1,16 @@ |
|
275 +.TH cdb_keylen 3 |
|
276 +.SH NAME |
|
277 +cdb_keylen \- get length of key |
|
278 +.SH SYNTAX |
|
279 +.B #include <cdb.h> |
|
280 + |
|
281 +unsigned int cdb_keylen(struct cdb *\fIc\fR); |
|
282 + |
|
283 +.SH DESCRIPTION |
|
284 +.B cdb_keylen |
|
285 +returns the length of the key cdb_firstkey or cdb_nextkey found. |
|
286 + |
|
287 +Use cdb_keypos to get the position of the key. |
|
288 + |
|
289 +.SH "SEE ALSO" |
|
290 +cdb_keypos(3), cdb_datalen(3), cdb_datapos(3) |
|
291 diff -uNr cdb-0.75/cdb_keypos.3 cdb-0.75-fefe/cdb_keypos.3 |
|
292 --- cdb-0.75/cdb_keypos.3 Thu Jan 1 01:00:00 1970 |
|
293 +++ cdb-0.75-fefe/cdb_keypos.3 Wed Sep 27 21:53:16 2000 |
|
294 @@ -0,0 +1,16 @@ |
|
295 +.TH cdb_keypos 3 |
|
296 +.SH NAME |
|
297 +cdb_keypos \- get position of key |
|
298 +.SH SYNTAX |
|
299 +.B #include <cdb.h> |
|
300 + |
|
301 +uint32 cdb_keypos(struct cdb *\fIc\fR); |
|
302 + |
|
303 +.SH DESCRIPTION |
|
304 +.B cdb_keypos |
|
305 +returns the position of the key cdb_firstkey or cdb_nextkey found. |
|
306 + |
|
307 +Use cdb_keylen to get the length of the key. |
|
308 + |
|
309 +.SH "SEE ALSO" |
|
310 +cdb_keylen(3), cdb_datapos(3), cdb_datalen(3) |
|
311 diff -uNr cdb-0.75/cdb_nextkey.3 cdb-0.75-fefe/cdb_nextkey.3 |
|
312 --- cdb-0.75/cdb_nextkey.3 Thu Jan 1 01:00:00 1970 |
|
313 +++ cdb-0.75-fefe/cdb_nextkey.3 Wed Sep 27 21:52:17 2000 |
|
314 @@ -0,0 +1,19 @@ |
|
315 +.TH cdb_nextkey 3 |
|
316 +.SH NAME |
|
317 +cdb_nextkey \- find next physical record in constant database |
|
318 +.SH SYNTAX |
|
319 +.B #include <cdb.h> |
|
320 +.br |
|
321 +.B #include <uint32.h> |
|
322 + |
|
323 +int cdb_nextkey(struct cdb *\fIc\fR,uint32 *\fIkpos\fR); |
|
324 + |
|
325 +.SH DESCRIPTION |
|
326 +\fBcdb_nextkey\fR finds the next physical record in the constant |
|
327 +database. |
|
328 + |
|
329 +You can use cdb_datapos or cdb_keypos to get \fIposition\fR and |
|
330 +cdb_datalen and cdb_keylen to get \fIlen\fR. |
|
331 + |
|
332 +.SH "SEE ALSO" |
|
333 +cdb_firstkey(3), cdb_successor(3) |
|
334 diff -uNr cdb-0.75/cdb_read.3 cdb-0.75-fefe/cdb_read.3 |
|
335 --- cdb-0.75/cdb_read.3 Thu Jan 1 01:00:00 1970 |
|
336 +++ cdb-0.75-fefe/cdb_read.3 Wed Sep 27 21:53:22 2000 |
|
337 @@ -0,0 +1,20 @@ |
|
338 +.TH cdb_read 3 |
|
339 +.SH NAME |
|
340 +cdb_read \- read bytes from a constant database |
|
341 +.SH SYNTAX |
|
342 +.B #include <cdb.h> |
|
343 +.br |
|
344 +.B #include <uint32.h> |
|
345 + |
|
346 +int cdb_read(struct cdb *\fIc\fR,char *\fIbuf\fR,unsigned int \fIlen\fR,uint32 \fIposition\fR); |
|
347 + |
|
348 +.SH DESCRIPTION |
|
349 +\fBcdb_read\fR reads \fIlen\fR bytes starting at \fIposition\fR from |
|
350 +\fIc\fR to buf. You can use cdb_datapos or cdb_keypos to get |
|
351 +\fIposition\fR and cdb_datalen and cdb_keylen to get \fIlen\fR. |
|
352 + |
|
353 +\fIbuf\fR needs to point to a memory region large enough to hold |
|
354 +\fIlen\fR bytes. |
|
355 + |
|
356 +.SH "SEE ALSO" |
|
357 +cdb_find(3), cdb_init(3), cdb_free(3), cdbmake(1) |
|
358 diff -uNr cdb-0.75/cdb_successor.3 cdb-0.75-fefe/cdb_successor.3 |
|
359 --- cdb-0.75/cdb_successor.3 Thu Jan 1 01:00:00 1970 |
|
360 +++ cdb-0.75-fefe/cdb_successor.3 Wed Sep 27 21:53:23 2000 |
|
361 @@ -0,0 +1,21 @@ |
|
362 +.TH cdb_successor 3 |
|
363 +.SH NAME |
|
364 +cdb_successor \- find next record |
|
365 +.SH SYNTAX |
|
366 +.B #include <cdb.h> |
|
367 + |
|
368 +int cdb_successor(struct cdb *\fIc\fR,char *\fIkey\fR,unsigned int \fIklen\fR); |
|
369 + |
|
370 +.SH DESCRIPTION |
|
371 +\fBcdb_successor\fR finds the record that follows \fIkey\fR. If |
|
372 +\fIkey\fR is NULL, cdb_successor finds the first record. |
|
373 + |
|
374 +\fBNOTE!\fR The database must not contain keys with more than one |
|
375 +associated record or this API will lead to infinite loops! Use |
|
376 +cdb_firstkey and cdb_nextkey instead. |
|
377 + |
|
378 +You can use cdb_datapos or cdb_keypos to get \fIposition\fR and |
|
379 +cdb_datalen and cdb_keylen to get \fIlen\fR. |
|
380 + |
|
381 +.SH "SEE ALSO" |
|
382 +cdb_firstkey(3), cdb_nextkey(3) |
|
383 diff -uNr cdb-0.75/cdb_traverse.c cdb-0.75-fefe/cdb_traverse.c |
|
384 --- cdb-0.75/cdb_traverse.c Thu Jan 1 01:00:00 1970 |
|
385 +++ cdb-0.75-fefe/cdb_traverse.c Wed Sep 27 21:39:18 2000 |
|
386 @@ -0,0 +1,41 @@ |
|
387 +#include "cdb.h" |
|
388 +#include "seek.h" |
|
389 + |
|
390 +static int doit(struct cdb *c,uint32 *kpos) { |
|
391 + char buf[8]; |
|
392 + uint32 eod,klen; |
|
393 + if (cdb_read(c,buf,4,0)) return -1; |
|
394 + uint32_unpack(buf,&eod); |
|
395 + if (eod<8 || eod-8<*kpos) return 0; |
|
396 + c->kpos=*kpos+8; |
|
397 + if (c->kpos<*kpos) return -1; /* wraparound */ |
|
398 + cdb_findstart(c); |
|
399 + c->hslots=1; |
|
400 + if (cdb_read(c,buf,8,*kpos) == -1) return -1; |
|
401 + uint32_unpack(buf,&klen); |
|
402 + uint32_unpack(buf+4,&c->dlen); |
|
403 + c->dpos=c->kpos+klen; |
|
404 + *kpos+=8+klen+c->dlen; |
|
405 + return 1; |
|
406 +} |
|
407 + |
|
408 +int cdb_firstkey(struct cdb *c,uint32 *kpos) { |
|
409 + *kpos=2048; |
|
410 + return doit(c,kpos); |
|
411 +} |
|
412 + |
|
413 +int cdb_nextkey(struct cdb *c,uint32 *kpos) { |
|
414 + return doit(c,kpos); |
|
415 +} |
|
416 + |
|
417 +int cdb_successor(struct cdb *c,char *key,unsigned int klen) { |
|
418 + int r; |
|
419 + uint32 kpos; |
|
420 + if (key) { |
|
421 + r=cdb_find(c,key,klen); |
|
422 + if (r<1) return r; |
|
423 + kpos=c->dpos+c->dlen; |
|
424 + } else |
|
425 + kpos=2048; |
|
426 + return doit(c,&kpos); |
|
427 +} |
|
428 diff -uNr cdb-0.75/cdbdump.1 cdb-0.75-fefe/cdbdump.1 |
|
429 --- cdb-0.75/cdbdump.1 Thu Jan 1 01:00:00 1970 |
|
430 +++ cdb-0.75-fefe/cdbdump.1 Wed Sep 27 20:27:54 2000 |
|
431 @@ -0,0 +1,17 @@ |
|
432 +.TH cdbdump 1 |
|
433 +.SH NAME |
|
434 +cdbdump \- print the contents of a constant database |
|
435 +.SH SYNOPSIS |
|
436 +.B cdbdump |
|
437 +.SH DESCRIPTION |
|
438 +.B cbddump |
|
439 +reads a constant database from its standard input |
|
440 +and prints its contents, in |
|
441 +.B cbdmake |
|
442 +format, |
|
443 +on standard output. |
|
444 +.SH "SEE ALSO" |
|
445 +cdbget(1), |
|
446 +cdbmake(1), |
|
447 +cdb_firstkey(3), |
|
448 +cdb_nextkey(3) |
|
449 diff -uNr cdb-0.75/cdbget.1 cdb-0.75-fefe/cdbget.1 |
|
450 --- cdb-0.75/cdbget.1 Thu Jan 1 01:00:00 1970 |
|
451 +++ cdb-0.75-fefe/cdbget.1 Sun Apr 30 14:31:33 2000 |
|
452 @@ -0,0 +1,38 @@ |
|
453 +.TH cdbget 1 |
|
454 +.SH NAME |
|
455 +cdbget \- look up one key in a constant database |
|
456 +.SH SYNOPSIS |
|
457 +.B cdbget |
|
458 +.I key |
|
459 +.SH DESCRIPTION |
|
460 +.B cdbget |
|
461 +searches for a record indexed by |
|
462 +.I key |
|
463 +in a constant database. |
|
464 +The constant database must be readable (and seekable) |
|
465 +on |
|
466 +.BR cdbget 's |
|
467 +standard input. |
|
468 + |
|
469 +.B cdbget |
|
470 +normally (1) prints the data in the first matching record |
|
471 +and (2) exits 0. |
|
472 +Note that |
|
473 +.B cdbget |
|
474 +does not check for write errors, |
|
475 +so it should be used only inside a pipe. |
|
476 + |
|
477 +If |
|
478 +.I key |
|
479 +is not in the database, |
|
480 +.B cdbget |
|
481 +exits 1 without printing anything. |
|
482 + |
|
483 +If |
|
484 +.B cdbget |
|
485 +encounters a read error, |
|
486 +it complains and exits 111. |
|
487 +.SH "SEE ALSO" |
|
488 +cdbdump(1), |
|
489 +cdbmake(1), |
|
490 +cdb(3) |
|
491 diff -uNr cdb-0.75/cdbmake.1 cdb-0.75-fefe/cdbmake.1 |
|
492 --- cdb-0.75/cdbmake.1 Thu Jan 1 01:00:00 1970 |
|
493 +++ cdb-0.75-fefe/cdbmake.1 Sun Apr 30 14:31:33 2000 |
|
494 @@ -0,0 +1,113 @@ |
|
495 +.TH cdbmake 1 |
|
496 +.SH NAME |
|
497 +cdbmake \- create a constant database |
|
498 +.SH SYNOPSIS |
|
499 +.B cdbmake |
|
500 +.I file |
|
501 +.I temp |
|
502 +.SH DESCRIPTION |
|
503 +.B cdbmake |
|
504 +reads a series of encoded records from its standard input |
|
505 +and writes a constant database to |
|
506 +.IR file . |
|
507 + |
|
508 +Records are indexed by |
|
509 +.BR keys . |
|
510 +A key is a string. |
|
511 +.I file |
|
512 +is structured so that another program, starting from a key, |
|
513 +can quickly find the relevant record. |
|
514 +.B cdbmake |
|
515 +allows several records with the same key, |
|
516 +although (1) most readers only take the first record |
|
517 +and (2) |
|
518 +.B cdbmake |
|
519 +slows down somewhat if there are many records with the same key. |
|
520 +Note that |
|
521 +.B cdbmake |
|
522 +preserves the order of records in |
|
523 +.IR file . |
|
524 + |
|
525 +A record is encoded for |
|
526 +.B cdbmake |
|
527 +as |
|
528 +.B +\fIklen\fB,\fIdlen\fB:\fIkey\fB->\fIdata |
|
529 +followed by a newline. |
|
530 +Here |
|
531 +.I klen |
|
532 +is the number of bytes in |
|
533 +.IR key |
|
534 +and |
|
535 +.I dlen |
|
536 +is the number of bytes in |
|
537 +.IR data . |
|
538 +The end of data is indicated by an extra newline. |
|
539 +For example: |
|
540 + |
|
541 +.EX |
|
542 + +3,5:one->Hello |
|
543 +.br |
|
544 + +3,7:two->Goodbye |
|
545 +.br |
|
546 + |
|
547 +.EE |
|
548 + |
|
549 +.I key |
|
550 +and |
|
551 +.I data |
|
552 +may contain any characters, including colons, dashes, newlines, and nulls. |
|
553 + |
|
554 +.B cdbmake |
|
555 +ensures that |
|
556 +.I file |
|
557 +is updated atomically, |
|
558 +so programs reading |
|
559 +.I file |
|
560 +never have to wait for |
|
561 +.B cdbmake |
|
562 +to finish. |
|
563 +It does this by first writing the database to |
|
564 +.I temp |
|
565 +and then moving |
|
566 +.I temp |
|
567 +on top of |
|
568 +.IR file . |
|
569 +If |
|
570 +.I temp |
|
571 +already exists, |
|
572 +it is destroyed. |
|
573 +The directories containing |
|
574 +.I temp |
|
575 +and |
|
576 +.I file |
|
577 +must be writable to |
|
578 +.BR cdbmake ; |
|
579 +they must also be on the same filesystem. |
|
580 + |
|
581 +.B cdbmake |
|
582 +always makes sure that |
|
583 +.I temp |
|
584 +is safely written to disk before it replaces |
|
585 +.IR file . |
|
586 +If the input is in a bad format or if |
|
587 +.B cdbmake |
|
588 +has any trouble writing |
|
589 +.I temp |
|
590 +to disk, |
|
591 +.B cdbmake |
|
592 +complains and leaves |
|
593 +.I file |
|
594 +alone. |
|
595 + |
|
596 +Keys and data do not have to fit into memory, |
|
597 +but |
|
598 +.B cdbmake |
|
599 +needs roughly 16 bytes of memory per record. |
|
600 +A database cannot exceed 4 gigabytes. |
|
601 + |
|
602 +.I file |
|
603 +is portable across machines. |
|
604 +.SH "SEE ALSO" |
|
605 +cdbdump(1), |
|
606 +cdbget(1), |
|
607 +cdbstats(1) |
|
608 diff -uNr cdb-0.75/cdbnext.c cdb-0.75-fefe/cdbnext.c |
|
609 --- cdb-0.75/cdbnext.c Thu Jan 1 01:00:00 1970 |
|
610 +++ cdb-0.75-fefe/cdbnext.c Wed Sep 27 21:43:32 2000 |
|
611 @@ -0,0 +1,51 @@ |
|
612 +#include "exit.h" |
|
613 +#include "scan.h" |
|
614 +#include "str.h" |
|
615 +#include "buffer.h" |
|
616 +#include "strerr.h" |
|
617 +#include "cdb.h" |
|
618 + |
|
619 +#define FATAL "cdbnext: fatal: " |
|
620 + |
|
621 +void die_read(void) |
|
622 +{ |
|
623 + strerr_die2sys(111,FATAL,"unable to read input: "); |
|
624 +} |
|
625 +void die_write(void) |
|
626 +{ |
|
627 + strerr_die2sys(111,FATAL,"unable to write output: "); |
|
628 +} |
|
629 + |
|
630 +static struct cdb c; |
|
631 +char buf[1024]; |
|
632 + |
|
633 +main(int argc,char **argv) |
|
634 +{ |
|
635 + char *key; |
|
636 + int r; |
|
637 + uint32 pos; |
|
638 + uint32 len; |
|
639 + unsigned long u = 0; |
|
640 + |
|
641 + key = argv[1]; |
|
642 + |
|
643 + cdb_init(&c,0); |
|
644 + |
|
645 + r=cdb_successor(&c,key,key?str_len(key):0); |
|
646 + if (r == -1) die_read(); |
|
647 + if (!r) _exit(100); |
|
648 + |
|
649 + pos = cdb_keypos(&c); |
|
650 + len = cdb_keylen(&c); |
|
651 + |
|
652 + while (len > 0) { |
|
653 + r = sizeof buf; |
|
654 + if (r > len) r = len; |
|
655 + if (cdb_read(&c,buf,r,pos) == -1) die_read(); |
|
656 + if (buffer_put(buffer_1small,buf,r) == -1) die_write(); |
|
657 + pos += r; |
|
658 + len -= r; |
|
659 + } |
|
660 + if (buffer_flush(buffer_1small) == -1) die_write(); |
|
661 + _exit(0); |
|
662 +} |
|
663 diff -uNr cdb-0.75/cdbstats.1 cdb-0.75-fefe/cdbstats.1 |
|
664 --- cdb-0.75/cdbstats.1 Thu Jan 1 01:00:00 1970 |
|
665 +++ cdb-0.75-fefe/cdbstats.1 Sun Apr 30 14:31:33 2000 |
|
666 @@ -0,0 +1,18 @@ |
|
667 +.TH cdbstats 1 |
|
668 +.SH NAME |
|
669 +cdbstats \- summarize the contents of a constant database |
|
670 +.SH SYNOPSIS |
|
671 +.B cdbstats |
|
672 +.SH DESCRIPTION |
|
673 +.B cdbstats |
|
674 +reads a (seekable) constant database from its standard input |
|
675 +and prints a few statistics: |
|
676 +.B slots |
|
677 +is the number of hash positions; |
|
678 +.B records |
|
679 +is the number of records in the database; |
|
680 +.B d0 |
|
681 +is the number of records at distance 0 from their hash. |
|
682 +.SH "SEE ALSO" |
|
683 +cdbdump(1), |
|
684 +cdbmake(1) |
|
685 diff -uNr cdb-0.75/cdbtest.1 cdb-0.75-fefe/cdbtest.1 |
|
686 --- cdb-0.75/cdbtest.1 Thu Jan 1 01:00:00 1970 |
|
687 +++ cdb-0.75-fefe/cdbtest.1 Sun Apr 30 14:31:33 2000 |
|
688 @@ -0,0 +1,36 @@ |
|
689 +.TH cdbtest 1 |
|
690 +.SH NAME |
|
691 +cdbtest \- check retrieval from a constant database |
|
692 +.SH SYNOPSIS |
|
693 +.B cdbtest |
|
694 +.SH DESCRIPTION |
|
695 +.B cdbtest |
|
696 +reads a (seekable) constant database from its standard input. |
|
697 +For each record in the database, it feeds the record's key to |
|
698 +.B cdb_seek() |
|
699 +and checks the result. |
|
700 +It prints tallies in several categories: |
|
701 +.TP 5 |
|
702 +.B found |
|
703 +is the number of records found correctly by their keys. |
|
704 +.TP |
|
705 +.B different record |
|
706 +is the number of records where a different record was found |
|
707 +with the same key. This should not happen unless the database |
|
708 +has multiple records with the same key. |
|
709 +.TP |
|
710 +.B bad length |
|
711 +is the number of records found but with the wrong data length. |
|
712 +This should never happen. |
|
713 +.TP |
|
714 +.B not found |
|
715 +is the number of records not found. |
|
716 +This should never happen. |
|
717 +.TP |
|
718 +.B too long to test |
|
719 +is the number of records with keys longer than 1024 bytes. |
|
720 +.B cdbtest |
|
721 +doesn't bother testing these records. |
|
722 +.SH "SEE ALSO" |
|
723 +cdbget(1), |
|
724 +cdb(3) |
|
725 Binary files cdb-0.75/foo.cdb and cdb-0.75-fefe/foo.cdb differ |
|
726 diff -uNr cdb-0.75/hier.c cdb-0.75-fefe/hier.c |
|
727 --- cdb-0.75/hier.c Sat Feb 19 21:42:05 2000 |
|
728 +++ cdb-0.75-fefe/hier.c Wed Sep 27 22:05:11 2000 |
|
729 @@ -4,6 +4,10 @@ |
|
730 { |
|
731 h(auto_home,-1,-1,02755); |
|
732 d(auto_home,"bin",-1,-1,02755); |
|
733 + d(auto_home,"man",-1,-1,0755); |
|
734 + d(auto_home,"man/man1",-1,-1,0755); |
|
735 + d(auto_home,"man/man3",-1,-1,0755); |
|
736 + |
|
737 |
|
738 c(auto_home,"bin","cdbget",-1,-1,0755); |
|
739 c(auto_home,"bin","cdbmake",-1,-1,0755); |
|
740 @@ -12,4 +16,22 @@ |
|
741 c(auto_home,"bin","cdbtest",-1,-1,0755); |
|
742 c(auto_home,"bin","cdbmake-12",-1,-1,0755); |
|
743 c(auto_home,"bin","cdbmake-sv",-1,-1,0755); |
|
744 + |
|
745 + c(auto_home,"man/man1","cdbdump.1",-1,-1,0755); |
|
746 + c(auto_home,"man/man1","cdbget.1",-1,-1,0755); |
|
747 + c(auto_home,"man/man1","cdbmake.1",-1,-1,0755); |
|
748 + c(auto_home,"man/man1","cdbstats.1",-1,-1,0755); |
|
749 + c(auto_home,"man/man1","cdbtest.1",-1,-1,0755); |
|
750 + |
|
751 + c(auto_home,"man/man3","cdb_datalen.3",-1,-1,0644); |
|
752 + c(auto_home,"man/man3","cdb_datapos.3",-1,-1,0644); |
|
753 + c(auto_home,"man/man3","cdb_find.3",-1,-1,0644); |
|
754 + c(auto_home,"man/man3","cdb_firstkey.3",-1,-1,0644); |
|
755 + c(auto_home,"man/man3","cdb_free.3",-1,-1,0644); |
|
756 + c(auto_home,"man/man3","cdb_init.3",-1,-1,0644); |
|
757 + c(auto_home,"man/man3","cdb_keylen.3",-1,-1,0644); |
|
758 + c(auto_home,"man/man3","cdb_keypos.3",-1,-1,0644); |
|
759 + c(auto_home,"man/man3","cdb_nextkey.3",-1,-1,0644); |
|
760 + c(auto_home,"man/man3","cdb_read.3",-1,-1,0644); |
|
761 + c(auto_home,"man/man3","cdb_successor.3",-1,-1,0644); |
|
762 } |
|
763 diff -uNr cdb-0.75/traverse.c cdb-0.75-fefe/traverse.c |
|
764 --- cdb-0.75/traverse.c Thu Jan 1 01:00:00 1970 |
|
765 +++ cdb-0.75-fefe/traverse.c Wed Sep 27 18:41:38 2000 |
|
766 @@ -0,0 +1,43 @@ |
|
767 +#include <unistd.h> |
|
768 +#include <sys/fcntl.h> |
|
769 +#include <stdlib.h> |
|
770 +#include <assert.h> |
|
771 +#include "cdb.h" |
|
772 +#include "fmt.h" |
|
773 + |
|
774 +main(int argc,char *argv[]) { |
|
775 + int fd; |
|
776 + struct cdb c; |
|
777 + char strnum[FMT_ULONG]; |
|
778 + uint32 kpos; |
|
779 + fd=open(argc>1?argv[1]:"foo.cdb",O_RDONLY); |
|
780 + assert(fd>=0); |
|
781 + cdb_init(&c,fd); |
|
782 + if (cdb_firstkey(&c,&kpos)==1) { |
|
783 + do { |
|
784 + uint32 kp,klen,dp,dlen; |
|
785 + char *key,*data; |
|
786 + kp=cdb_keypos(&c); |
|
787 + klen=cdb_keylen(&c); |
|
788 + dp=cdb_datapos(&c); |
|
789 + dlen=cdb_datalen(&c); |
|
790 + { |
|
791 + key=alloca(klen); |
|
792 + data=alloca(dlen); |
|
793 +/* printf("%lu %lu; %lu %lu\n",kp,klen,dp,dlen); */ |
|
794 + assert(cdb_read(&c,key,klen,kp)==0); |
|
795 + assert(cdb_read(&c,data,dlen,dp)==0); |
|
796 + write(1,"+",1); |
|
797 + write(1,strnum,fmt_ulong(strnum,klen)); |
|
798 + write(1,",",1); |
|
799 + write(1,strnum,fmt_ulong(strnum,dlen)); |
|
800 + write(1,":",1); |
|
801 + write(1,key,klen); |
|
802 + write(1,"->",2); |
|
803 + write(1,data,dlen); |
|
804 + write(1,"\n",1); |
|
805 + } |
|
806 + } while (cdb_nextkey(&c,&kpos)==1); |
|
807 + write(1,"\n",1); |
|
808 + } |
|
809 +} |