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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
|
--- inn-1.7.2.orig/dbz/dbz.c
+++ inn-1.7.2/dbz/dbz.c
@@ -1,6 +1,6 @@
/*
-dbz.c V3.2
+dbz.c V3.3
Copyright 1988 Jon Zeeff (zeeff@b-tech.ann-arbor.mi.us)
You can use this code in any manner, as long as you leave my name on it
@@ -19,6 +19,22 @@
Merged in MMAP code by David Robinson, formerly <david@elroy.jpl.nasa.gov>
now <david.robinson@sun.com> (January, 1993).
+Introduced "offset fuzzy", i.e., dropping several least significant bits
+of the offset value, to allocate more bits on hash and named as
+dbz v3.3 by Sang-yong Suh <sysuh@kigam.re.kr> (October, 1997)
+
+Increased the table size factor from 1.5 to 2.0, to make more holes
+in the table. The extra holes will speed up history lookup.
+The base file usage is added at the third .dir line.
+Sang-yong Suh <sysuh@kigam.re.kr> (October, 1997)
+
+Keeps from too many identical "can't tag" error messages which occurred
+some news servers started with fresh history. Also added more
+sofisticated prediction of the future history size hoping that no_tagging
+situation occur. If this succeeds, we have another bit for hash tagging!
+Currently, the bit is used to record the flag whether the offset is tagged
+or not. Sang-yong Suh <sysuh@kigam.re.kr> (December, 1997)
+
These routines replace dbm as used by the usenet news software
(it's not a full dbm replacement by any means). It's fast and
simple. It contains no AT&T code.
@@ -39,7 +55,7 @@
#ifndef __STDC__
extern int errno;
#endif
-#include <dbz.h>
+#include "dbz.h"
/*
* #ifdef index. "LIA" = "leave it alone unless you know what you're doing".
@@ -74,6 +90,26 @@
static int dbzversion = 3; /* for validating .dir file format */
+/*******************************************************************
+ Start of dbz version 3.3 specific definitions
+ ******************************************************************/
+
+/* MAXDROPBITS is the maximum number of bits in the offset value.
+ The least significant bits are dropped. The space is used to
+ store hash bits, thereby increasing the possibility of the
+ hash conflict */
+#define MAXDROPBITS 4 /* max # of bits to drop from the offset */
+
+/* MAXDROPBYTES must be derived from MAXDROPBITS as ((1 << MAXDROPBITS) - 1) */
+#define MAXDROPBYTES ((1 << MAXDROPBITS) - 1)
+
+/* START_OF_KEY is the last character of an entry, and it must be unique. */
+#define START_OF_KEY '<'
+
+/*******************************************************************
+ End of dbz version 3.3 sepecific definitions
+ ******************************************************************/
+
/*
* The dbz database exploits the fact that when news stores a <key,value>
* tuple, the `value' part is a seek offset into a text file, pointing to
@@ -147,6 +183,7 @@
static of_t tagbits; /* pre-shifted tag mask */
static of_t taghere; /* pre-shifted tag-enable bit */
static of_t tagboth; /* tagbits|taghere */
+static int notag_warned=0; /* a switch to keep from repeated err msges */
#define HASTAG(o) ((o)&taghere)
#define TAG(o) ((o)&tagbits)
#define NOTAG(o) ((o)&~tagboth)
@@ -159,7 +196,10 @@
* the user supplies this info, but there have to be defaults.
*/
#ifndef DEFSIZE
-#define DEFSIZE 120011 /* 300007 might be better */
+#define DEFSIZE 1000003 /* receiving 500K messsages in the 1st day. */
+#endif
+#ifndef DEFSIZE_BASE
+#define DEFSIZE_BASE 100000000 /* history will not grow this much 1st day */
#endif
#ifdef OLDBNEWS
#define DEFCASE '0' /* B2.10 -- no mapping */
@@ -199,6 +239,7 @@
# endif
# define NUSEDS (1+NMEMORY)
of_t used[NUSEDS]; /* entries used today, yesterday, ... */
+ of_t vused[NUSEDS]; /* max values used today, yesterday, ... */
int valuesize; /* size of table values, == SOF */
int bytemap[SOF]; /* byte-order map */
char casemap; /* case-mapping algorithm (see cipoint()) */
@@ -206,6 +247,8 @@
of_t tagenb; /* unshifted tag-enable bit */
of_t tagmask; /* unshifted tag mask */
int tagshift; /* shift count for tagmask and tagenb */
+ int dropbits; /* number of bits to discard from offset */
+ int offsetfuzzy; /* number of fuzzy bytes in offset */
};
static struct dbzconfig conf;
static int getconf();
@@ -355,7 +398,6 @@
extern void CloseOnExec();
/* misc. forwards */
-static long hash();
static void crcinit();
static char *cipoint();
static char *mapcase();
@@ -384,11 +426,78 @@
static int written; /* has a store() been done? */
/*
+ - dbzconfbase - reconfigure dbzconf from base file size.
+ */
+static void dbzconfbase(c, bsize)
+struct dbzconfig *c;
+of_t bsize; /* base file size */
+{
+ int i;
+ register of_t m;
+
+ /* if no tag requested, just return. */
+ if ((c->tagmask | c->tagenb) == 0)
+ return;
+
+ /*
+ * The base file will grow until the next dbz rebuild.
+ * Therefore the prediction of correct size is important.
+ * If the predicted size is too small, the "can't tag" occurs.
+ * If the prediction is too big, we'll waste tag bits.
+ */
+
+ /* History of a fresh news server will not grow this much in a day */
+ if (bsize < 1000)
+ bsize = DEFSIZE_BASE;
+
+ /* This must be a small server. It may grow 50% in a day. */
+ else if (bsize < DEFSIZE_BASE)
+ bsize += bsize / 2;
+
+ /* This is a midsize server. It can grow 20% in a day. */
+ else if (bsize < 2 * DEFSIZE_BASE)
+ bsize += bsize / 5;
+
+ /* This must be a big server. It can grow 10% in a day. */
+ else
+ bsize += bsize / 10;
+
+ /* calculate tagging from old file */
+ for (m = 1, i = 0; m < bsize; i++, m <<= 1)
+ continue;
+
+ /* if we had more tags than the default, use the new data */
+ c->dropbits = 0;
+ while (m > (1 << TAGSHIFT)) {
+ if (c->dropbits >= MAXDROPBITS)
+ break;
+ c->dropbits++;
+ m >>= 1;
+ i--;
+ }
+ c->tagenb = TAGENB;
+ c->tagmask = TAGMASK;
+ c->tagshift = TAGSHIFT;
+ if ((c->tagmask | c->tagenb) && m > (1 << TAGSHIFT)) {
+ c->tagshift = i;
+ c->tagmask = (~(unsigned long)0) >> (i + 1);
+ c->tagenb = (c->tagmask << 1) & ~c->tagmask;
+ }
+ c->offsetfuzzy = (int)(1 << c->dropbits) - 1;
+
+ m = (c->tagmask | c->tagenb) << c->tagshift;
+ if (m & (bsize >> c->dropbits)) {
+ fprintf(stderr, "m 0x%lx size 0x%lx\n", m, bsize);
+ exit(1);
+ }
+}
+
+/*
- dbzfresh - set up a new database, no historical info
*/
int /* 0 success, -1 failure */
dbzfresh(name, size, fs, cmap, tagmask)
-char *name; /* base name; .dir and .pag must exist */
+char *name; /* base name; base file must exist */
long size; /* table size (0 means default) */
int fs; /* field-separator character in base file */
int cmap; /* case-map algorithm (0 means default) */
@@ -398,6 +507,7 @@
struct dbzconfig c;
register of_t m;
register FILE *f;
+ struct stat sb;
if (pagf != NULL) {
DEBUG(("dbzfresh: database already open\n"));
@@ -443,6 +553,8 @@
c.tagshift = 0;
c.tagmask = 0;
c.tagenb = 0;
+ c.dropbits = 0;
+ c.offsetfuzzy = 0;
break;
default:
m = tagmask;
@@ -453,9 +565,16 @@
}
c.tagmask = m;
c.tagenb = (m << 1) & ~m;
+ c.dropbits = 0;
+ c.offsetfuzzy = 0;
break;
}
+ /* if big enough base file exists, update config */
+ if (stat(name, &sb) == -1)
+ sb.st_size = 0;
+ dbzconfbase(&c, sb.st_size);
+
/* write it out */
fn = enstring(name, dir);
if (fn == NULL)
@@ -504,7 +623,7 @@
DEBUG(("dbzsize: preposterous input (%ld)\n", contents));
return(DEFSIZE);
}
- n = (contents/2)*3; /* try to keep table at most 2/3 full */
+ n = contents*2; /* try to keep table at most 1/2 full */
if (!(n&01)) /* make it odd */
n++;
DEBUG(("dbzsize: tentative size %ld\n", n));
@@ -561,12 +680,11 @@
register char *fn;
struct dbzconfig c;
register int i;
- register long top;
+ register long top, vtop;
register FILE *f;
register int newtable;
register of_t newsize;
struct stat sb;
- register of_t m;
if (pagf != NULL) {
DEBUG(("dbzagain: database already open\n"));
@@ -590,35 +708,34 @@
return(-1);
}
- /* calculate tagging from old file */
- if (stat(oldname, &sb) != -1) {
- for (m = 1, i = 0; m < sb.st_size; i++, m <<= 1)
- continue;
-
- /* if we had more tags than the default, use the new data */
- if ((c.tagmask | c.tagenb) && m > (1 << TAGSHIFT)) {
- c.tagshift = i;
- c.tagmask = (~(unsigned long)0) >> (i + 1);
- c.tagenb = (c.tagmask << 1) & ~c.tagmask;
- }
- }
-
/* tinker with it */
top = 0;
+ vtop = 0;
newtable = 0;
for (i = 0; i < NUSEDS; i++) {
if (top < c.used[i])
top = c.used[i];
- if (c.used[i] == 0)
+ if (vtop < c.vused[i])
+ vtop = c.vused[i];
+ if (c.used[i] == 0 || c.vused[i] == 0)
newtable = 1; /* hasn't got full usage history yet */
}
- if (top == 0) {
+ if (top == 0 || vtop == 0) {
DEBUG(("dbzagain: old table has no contents!\n"));
newtable = 1;
}
- for (i = NUSEDS-1; i > 0; i--)
+ for (i = NUSEDS-1; i > 0; i--) {
c.used[i] = c.used[i-1];
+ c.vused[i] = c.vused[i-1];
+ }
c.used[0] = 0;
+ c.vused[0] = 0;
+
+ /* calculate tagging from old file */
+ if (stat(oldname, &sb) != -1 && vtop < sb.st_size)
+ vtop = sb.st_size;
+ dbzconfbase(&c, vtop);
+
newsize = dbzsize(top);
if (!newtable || newsize > c.tsize) /* don't shrink new table */
c.tsize = newsize;
@@ -790,6 +907,7 @@
/* misc. setup */
crcinit();
written = 0;
+ notag_warned = 0;
prevp = FRESH;
DEBUG(("dbminit: succeeded\n"));
return(0);
@@ -861,7 +979,6 @@
DEBUG(("dbmclose: fclose(dirf) failed\n"));
ret = -1;
}
-
DEBUG(("dbmclose: %s\n", (ret == 0) ? "succeeded" : "failed"));
return(ret);
}
@@ -953,12 +1070,13 @@
fetch(key)
datum key;
{
- char buffer[DBZMAXKEY + 1];
+ char buffer[DBZMAXKEY + MAXDROPBYTES + 1];
static of_t key_ptr; /* return value points here */
datum output;
register size_t keysize;
register size_t cmplen;
- register char *sepp;
+ int j, nb2r;
+ char *bp;
DEBUG(("fetch: (%s)\n", key.dptr));
output.dptr = NULL;
@@ -982,33 +1100,41 @@
}
cmplen = keysize;
- sepp = &conf.fieldsep;
if (key.dptr[keysize-1] == '\0') {
cmplen--;
- sepp = &buffer[keysize-1];
}
+ nb2r = keysize + conf.offsetfuzzy;
start(&srch, &key, FRESH);
while ((key_ptr = search(&srch)) != NOTFOUND) {
DEBUG(("got 0x%lx\n", key_ptr));
/* fetch the key */
+ key_ptr <<= conf.dropbits;
if (fseek(basef, key_ptr, SEEK_SET) != 0) {
DEBUG(("fetch: seek failed\n"));
return(output);
}
- if (fread((POINTER)buffer, 1, keysize, basef) != keysize) {
+ if (fread((POINTER)buffer, 1, nb2r, basef) < keysize) {
DEBUG(("fetch: read failed\n"));
return(output);
}
+ for (j=0,bp=buffer; j<conf.offsetfuzzy; j++,bp++)
+ if (*bp == START_OF_KEY)
+ break;
+ if (*bp != START_OF_KEY) {
+ DEBUG(("can't locate keystart\n"));
+ /* hash should be deleted, but I'm lazy... */
+ continue;
+ }
/* try it */
- buffer[keysize] = '\0'; /* terminated for DEBUG */
- (void) mapcase(buffer, buffer, keysize);
+ (void) mapcase(bp, bp, keysize);
+ bp[keysize] = '\0'; /* terminated for DEBUG */
DEBUG(("fetch: buffer (%s) looking for (%s) size = %d\n",
- buffer, key.dptr, keysize));
- if (memcmp((POINTER)key.dptr, (POINTER)buffer, cmplen) == 0 &&
- (*sepp == conf.fieldsep || *sepp == '\0')) {
+ bp, key.dptr, keysize));
+ if (memcmp((POINTER)key.dptr, (POINTER)bp, cmplen) == 0) {
/* we found it */
+ key_ptr += j;
output.dptr = (char *)&key_ptr;
output.dsize = SOF;
DEBUG(("fetch: successful\n"));
@@ -1111,6 +1237,9 @@
/* copy the value in to ensure alignment */
(void) memcpy((POINTER)&value, (POINTER)data.dptr, SOF);
+ if (value > conf.vused[0])
+ conf.vused[0] = value;
+ value >>= conf.dropbits;
DEBUG(("store: (%s, %ld)\n", key.dptr, (long)value));
if (!okayvalue(value)) {
DEBUG(("store: reserved bit or overflow in 0x%lx\n", value));
@@ -1166,7 +1295,7 @@
{
register long m;
register long tagmask;
- register int i;
+ register int i, j;
if (size <= 0)
return(0L); /* silly size */
@@ -1174,6 +1303,10 @@
for (m = 1, i = 0; m < size; i++, m <<= 1)
continue;
+ for (j=0; m < (1 << TAGSHIFT) && j<=MAXDROPBITS; j++) {
+ m <<= 1;
+ i--;
+ }
if (m < (1 << TAGSHIFT))
return(0L); /* not worth tagging */
@@ -1204,15 +1337,19 @@
cp->fieldsep = '\t';
for (i = 0; i < NUSEDS; i++)
cp->used[i] = 0;
+ for (i = 0; i < NUSEDS; i++)
+ cp->vused[i] = 0;
cp->valuesize = SOF;
mybytemap(cp->bytemap);
cp->casemap = DEFCASE;
cp->tagenb = TAGENB;
cp->tagmask = TAGMASK;
cp->tagshift = TAGSHIFT;
- DEBUG(("getconf: defaults (%ld, %c, (0x%lx/0x%lx<<%d))\n",
+ cp->dropbits = 0;
+ cp->offsetfuzzy = 0;
+ DEBUG(("getconf: defaults (%ld, %c, (0x%lx/0x%lx<<%d %d))\n",
cp->tsize, cp->casemap, cp->tagenb,
- cp->tagmask, cp->tagshift));
+ cp->tagmask, cp->tagshift, cp->dropbits));
return(0);
}
(void) ungetc(c, df);
@@ -1238,8 +1375,22 @@
}
for (i = 0; i < cp->valuesize; i++)
cp->bytemap[i] = getno(df, &err);
- if (getc(df) != '\n')
- err = -1;
+
+ /* dbz v3.3 has one more parameter, dropbits, at the end. */
+ cp->dropbits = 0;
+ if ((c = getc(df)) != '\n') {
+ (void) ungetc(c, df);
+ cp->dropbits = getno(df, &err);
+ if (cp->dropbits < 0 || cp->dropbits > MAXDROPBITS) {
+ DEBUG(("getconf: invalid dropbits (%d)\n", cp->dropbits));
+ err = -1;
+ cp->dropbits = 0;
+ }
+ if (getc(df) != '\n')
+ err = -1;
+ }
+ cp->offsetfuzzy = (1 << cp->dropbits) - 1;
+
#ifdef DBZDEBUG
DEBUG(("size %ld, sep %d, cmap %c, tags 0x%lx/0x%lx<<%d, ", cp->tsize,
cp->fieldsep, cp->casemap, cp->tagenb, cp->tagmask,
@@ -1248,16 +1399,32 @@
for (i = 0; i < cp->valuesize; i++) {
DEBUG((" %d", cp->bytemap[i]));
}
+ DEBUG((" dbit %d", cp->dropbits));
DEBUG(("\n"));
#endif
/* second line, the usages */
for (i = 0; i < NUSEDS; i++)
cp->used[i] = getno(df, &err);
- if (getc(df) != '\n')
+ if ((c = getc(df)) != '\n') {
+ DEBUG(("getconf: unexpected char %c detected on 2nd line\n", c));
err = -1;
+ }
DEBUG(("used %ld %ld %ld...\n", cp->used[0], cp->used[1], cp->used[2]));
+ /* third line, the base file sizes. handle earlier format as well */
+ if ((c = getc(df)) != EOF) {
+ (void) ungetc(c, df);
+ for (i = 0; i < NUSEDS; i++)
+ cp->vused[i] = getno(df, &err);
+ if (getc(df) != '\n')
+ err = -1;
+ DEBUG(("used %ld %ld %ld...\n", cp->vused[0], cp->vused[1], cp->vused[2]));
+ } else {
+ for (i = 0; i < NUSEDS; i++)
+ cp->vused[i] = 0;
+ }
+
if (err < 0) {
DEBUG(("getconf error\n"));
return(-1);
@@ -1324,9 +1491,12 @@
cp->tagmask, cp->tagshift, cp->valuesize);
for (i = 0; i < cp->valuesize; i++)
(void) fprintf(f, " %d", cp->bytemap[i]);
+ (void) fprintf(f, " %d", cp->dropbits);
(void) fprintf(f, "\n");
for (i = 0; i < NUSEDS; i++)
(void) fprintf(f, "%ld%c", cp->used[i], (i < NUSEDS-1) ? ' ' : '\n');
+ for (i = 0; i < NUSEDS; i++)
+ (void) fprintf(f, "%ld%c", cp->vused[i], (i < NUSEDS-1) ? ' ' : '\n');
(void) fflush(f);
if (ferror(f))
@@ -1343,13 +1513,16 @@
getcore(f)
FILE *f;
{
+ register char *it;
+#ifndef MMAP
register of_t *p;
register size_t i;
register size_t nread;
- register char *it;
-#ifdef MMAP
+#else
struct stat st;
+#endif
+#ifdef MMAP
if (fstat(fileno(f), &st) == -1) {
DEBUG(("getcore: fstat failed\n"));
return(NULL);
@@ -1368,7 +1541,7 @@
DEBUG(("getcore: mmap failed\n"));
return(NULL);
}
-#if defined (MADV_RANDOM)
+#if defined (MADV_RANDOM)
/* not present in all versions of mmap() */
madvise(it, (size_t)conf.tsize * SOF, MADV_RANDOM);
#endif
@@ -1426,7 +1599,7 @@
{
register long h;
- h = hash(kp->dptr, kp->dsize);
+ h = dbzhash(kp->dptr, kp->dsize);
if (osp != FRESH && osp->hash == h) {
if (sp != osp)
*sp = *osp;
@@ -1434,8 +1607,9 @@
} else {
sp->hash = h;
sp->tag = MKTAG(h / conf.tsize);
- DEBUG(("tag 0x%lx\n", sp->tag));
sp->place = h % conf.tsize;
+ DEBUG(("hash %8.8lx tag %8.8lx place %ld\n",
+ sp->hash, sp->tag, sp->place));
sp->tabno = 0;
sp->run = (conf.olddbz) ? conf.tsize : MAXRUN;
sp->aborted = 0;
@@ -1564,6 +1738,10 @@
if (v != LONG_MAX) /* and it won't overflow */
#endif
value = v;
+ } else if (notag_warned == 0) {
+ notag_warned = 1;
+ fprintf(stderr, "can't tag value 0x%lx", v);
+ fprintf(stderr, " tagboth = 0x%lx\n", tagboth);
}
DEBUG(("tagged value is 0x%lx\n", value));
value = BIAS(value);
@@ -1716,10 +1894,10 @@
}
/*
- - hash - Honeyman's nice hashing function
+ - dbzhash - Honeyman's nice hashing function
*/
-static long
-hash(name, size)
+long
+dbzhash(name, size)
register char *name;
register int size;
{
@@ -1728,11 +1906,44 @@
while (size--) {
sum = (sum >> 7) ^ CrcTable[(sum ^ (*name++)) & 0x7f];
}
- DEBUG(("hash: returns (%ld)\n", sum));
+ DEBUG(("hash: returns (%8.8lx)\n", sum));
return(sum);
}
/*
+ - dbzhash64 - 64-bit extended hashing function
+ */
+
+void
+dbzhash64(name_in, size_in, hash)
+register char *name_in;
+register int size_in;
+long hash[2];
+{
+ char *name;
+ int size;
+ long sum = 0L;
+ char buffer[DBZMAXKEY + 1];
+
+ if (size_in > DBZMAXKEY)
+ size_in = DBZMAXKEY;
+ name = mapcase(buffer, name_in, size_in);
+
+ size = size_in;
+ while (size--) {
+ sum = (sum >> 7) ^ CrcTable[(sum ^ (*name++)) & 0x7f];
+ }
+ hash[0] = sum;
+
+ size = size_in;
+ while (size--) {
+ sum = (sum >> 7) ^ CrcTable[(sum ^ (*--name)) & 0x7f];
+ }
+ /* set bit 31 from the number of characters in name */
+ hash[1] = sum;
+}
+
+/*
* case-mapping stuff
*
* Borrowed from C News, by permission of the authors. Somewhat modified.
@@ -1891,7 +2102,7 @@
/* crazy -- "postmaster" is case-insensitive */
return(s);
}
- return(p);
+ return(p);
case '=': /* 2.11, neither sensible nor conformant */
return(s); /* all case-insensitive */
}
@@ -1914,3 +2125,95 @@
return(old);
}
#endif
+
+#ifdef DBZTEST
+void CloseOnExec(int i, int j) {}
+
+usage()
+{
+ fprintf(stderr, "usage: dbztest [-r] [-s size] <history>\n");
+ fprintf(stderr, " -r rebuild history. deletes .dir .pag files\n");
+ fprintf(stderr, " -s size number of history lines[500000]\n");
+ fprintf(stderr, " history history text file\n");
+ exit(1);
+}
+
+int main(argc, argv)
+int argc;
+char *argv[];
+{
+ int i, line;
+ FILE *fpi;
+ char ibuf[2048], *p;
+ datum key, val, data;
+ long where;
+ int initialize = 0, size = 500000;
+ char *history = NULL;
+
+ for (i=1; i<argc; i++)
+ if (strcmp(argv[i], "-r") == 0)
+ initialize = 1;
+ else if (strcmp(argv[i], "-s") == 0)
+ size = atoi(argv[++i]);
+ else if (*argv[i] != '-' && history == NULL)
+ history = argv[i];
+ else
+ usage();
+
+ if (history == NULL)
+ usage();
+ if ((fpi = fopen(history, "r")) == NULL) {
+ fprintf(stderr, "can't open %s\n", history);
+ usage();
+ }
+
+ dbzincore(1);
+ dbzwritethrough(1);
+
+ if (initialize) {
+ sprintf(ibuf, "%s.%s", history, ".dir");
+ unlink(ibuf);
+ sprintf(ibuf, "%s.%s", history, ".pag");
+ unlink(ibuf);
+ if (dbzfresh(history, dbzsize(size), '\t', 'C', dbztagmask(size)) < 0) {
+ fprintf(stderr, "cant dbzfresh %s\n", history);
+ exit(1);
+ }
+ } else {
+#ifdef DBZDEBUG
+ dbzdebug(1);
+#endif
+ if (dbminit(history) < 0) {
+ fprintf(stderr, "cant dbminit %s\n", history);
+ exit(1);
+ }
+ }
+
+ key.dptr = (POINTER) ibuf;
+ where = ftell(fpi);
+ data.dptr = (char *)&where;
+
+ for (line=1; fgets(ibuf, sizeof(ibuf), fpi); line++, where=ftell(fpi)) {
+ if ((p = strchr(ibuf, '\t')) == NULL) {
+ fprintf(stderr, "ignoreing bad line: %s\n", ibuf);
+ continue;
+ }
+ *p = '\0';
+ key.dsize = p - ibuf + 1;
+ if (initialize) {
+ data.dsize = sizeof(where);
+ if (dbzstore(key, data) < 0) {
+ fprintf(stderr, "cant store %s\n", ibuf);
+ exit(1);
+ }
+ } else {
+ val = dbzfetch(key);
+ if (val.dptr == NULL) {
+ fprintf(stderr, "line %d can't fetch %s\n", line, key.dptr);
+ exit(1);
+ }
+ }
+ }
+ dbmclose();
+}
+#endif /* DBZTEST */
--- inn-1.7.2.orig/dbz/dbz.h
+++ inn-1.7.2/dbz/dbz.h
@@ -24,7 +24,9 @@
extern int dbzcancel();
extern int dbzdebug();
extern int dbzwritethrough();
-
+extern long dbzhash();
+extern void dbzhash64();
+
/*
* In principle we could handle unlimited-length keys by operating a chunk
* at a time, but it's not worth it in practice. Setting a nice large
|