home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume19 / cnews2 / pch16apr90 < prev    next >
Internet Message Format  |  1990-06-07  |  25KB

  1. From @BBN.COM,@uunet.uu.net.uucp:henry@zoo.toronto.edu Wed Apr 18 19:49:40 1990
  2. Received: from BBN.COM by pineapple.bbn.com id <AA15387@pineapple.bbn.com>; Wed, 18 Apr 90 19:49:28 -0400
  3. Received: from uunet.UU.NET by BBN.COM id aa26305; 18 Apr 90 19:22 EDT
  4. Received: from zoo.utoronto.ca by uunet.uu.net (5.61/1.14) with SMTP 
  5.     id AA15474; Wed, 18 Apr 90 16:50:21 -0400
  6. Message-Id: <9004182050.AA15474@uunet.uu.net>
  7. From: henry@zoo.toronto.edu
  8. Date: Wed, 18 Apr 90 14:17:51 EDT
  9. To: uunet!source-patches@uunet.uu.net
  10. Newsgroups: news.software.b,comp.sources.bugs
  11. Subject: C News patch of 16-Apr-1990
  12. Status: R
  13.  
  14. This is the third of three (!) patches mostly constituting the new dbz.
  15.  
  16. start of patch 16-Apr-1990
  17. (suggested archive name: `pch16Apr90.Z')
  18. this should be run with   patch -p0 <thisfile
  19.  
  20. The following is a complete list of patches to date.
  21.  
  22. Prereq: 23-Jun-1989
  23. Prereq: 7-Jul-1989
  24. Prereq: 23-Jul-1989
  25. Prereq: 22-Aug-1989
  26. Prereq: 24-Aug-1989
  27. Prereq: 14-Sep-1989
  28. Prereq: 13-Nov-1989
  29. Prereq: 10-Jan-1990
  30. Prereq: 16-Jan-1990
  31. Prereq: 17-Jan-1990
  32. Prereq: 18-Jan-1990
  33. Prereq: 12-Mar-1990
  34. Prereq: 14-Apr-1990
  35. Prereq: 15-Apr-1990
  36. *** PATCHDATES.old    Sat Apr 14 20:24:28 1990
  37. --- PATCHDATES    Sat Apr 14 20:24:28 1990
  38. ***************
  39. *** 1,14 ****
  40. --- 1,15 ----
  41.   23-Jun-1989
  42.   7-Jul-1989
  43.   23-Jul-1989
  44.   22-Aug-1989
  45.   24-Aug-1989
  46.   14-Sep-1989
  47.   13-Nov-1989
  48.   10-Jan-1990
  49.   16-Jan-1990
  50.   17-Jan-1990
  51.   18-Jan-1990
  52.   12-Mar-1990
  53.   14-Apr-1990
  54.   15-Apr-1990
  55. + 16-Apr-1990
  56.  
  57. new dbz/dbz.h (patch can't create, so diff against null):
  58. Index: dbz/dbz.h
  59. *** cnpatch/old/dbz/dbz.h    Sat Apr 14 20:29:10 1990
  60. --- dbz/dbz.h    Wed Apr 11 17:14:10 1990
  61. ***************
  62. *** 0 ****
  63. --- 1,31 ----
  64. + /* for dbm and dbz */
  65. + typedef struct {
  66. +     char *dptr;
  67. +     int dsize;
  68. + } datum;
  69. + /* standard dbm functions */
  70. + extern int dbminit();
  71. + extern datum fetch();
  72. + extern int store();
  73. + extern int delete();        /* not in dbz */
  74. + extern datum firstkey();    /* not in dbz */
  75. + extern datum nextkey();        /* not in dbz */
  76. + extern int dbmclose();        /* in dbz, but not in old dbm */
  77. + /* new stuff for dbz */
  78. + extern int dbzfresh();
  79. + extern int dbzagain();
  80. + extern datum dbzfetch();
  81. + extern int dbzstore();
  82. + extern int dbzsync();
  83. + extern long dbzsize();
  84. + extern int dbzincore();
  85. + extern int dbzdebug();
  86. + /*
  87. +  * In principle we could handle unlimited-length keys by operating a chunk
  88. +  * at a time, but it's not worth it in practice.  Setting a nice large
  89. +  * bound on them simplifies the code and doesn't hurt anything.
  90. +  */
  91. + #define DBZMAXKEY    255
  92.  
  93. new dbz/dbzmain.c (patch can't create, so diff against null):
  94. Index: dbz/dbzmain.c
  95. *** cnpatch/old/dbz/dbzmain.c    Sat Apr 14 20:29:10 1990
  96. --- dbz/dbzmain.c    Thu Apr 12 16:52:59 1990
  97. ***************
  98. *** 0 ****
  99. --- 1,500 ----
  100. + /*
  101. +  * dbz - use and test dbz in various ways
  102. +  *
  103. +  * $Log$
  104. +  */
  105. + #include <stdio.h>
  106. + #include <sys/types.h>
  107. + #include <sys/stat.h>
  108. + #include <string.h>
  109. + #include <dbz.h>
  110. + #ifdef FUNNYSEEKS
  111. + #include <unistd.h>
  112. + #else
  113. + #define    SEEK_SET    0
  114. + #endif
  115. + #define    STREQ(a, b)    (*(a) == *(b) && strcmp((a), (b)) == 0)
  116. + #ifndef lint
  117. + static char RCSid[] = "$Header$";
  118. + #endif
  119. + char *progname;
  120. + char *inname = "(no file)";        /* filename for messages etc. */
  121. + long lineno;                /* line number for messages etc. */
  122. + char *basename;
  123. + char *pagname;
  124. + char *dirname;
  125. + char *str2dup();
  126. + FILE *base;
  127. + int op = 'b';            /* what to do, default build a new table */
  128. + int baseinput = 1;        /* is the base file also the input? */
  129. + char *from = NULL;        /* old table to use for dbzagain() */
  130. + int omitzero = 0;        /* omit lines tagged with 0 */
  131. + long every = 0;            /* report every n lines */
  132. + int syncs = 0;            /* dbzsync() on each report */
  133. + int quick = 0;            /* quick checking, not too thorough */
  134. + int sweep = 0;            /* sweep file checking all offsets */
  135. + int useincore = 1;        /* should we use incore facility? */
  136. + long xxx = 0;            /* debugging variable */
  137. + int printx = 0;            /* print xxx after all is done */
  138. + int unique = 1;            /* before store(), check with fetch() */
  139. + int usefresh = 0;        /* use dbzfresh? */
  140. + long siz = 0;            /* -p size */
  141. + char map = 'C';            /* -p map */
  142. + long tag = 0;            /* -p tag mask */
  143. + int exact = 0;            /* do not run dbzsize(siz) */
  144. + int dbzint = 1;            /* use new interface? */
  145. + char fs = '\t';            /* field separator, default tab */
  146. + int unopen = 0;            /* make base unopenable during dbminit? */
  147. + char *change = NULL;        /* chdir here before dbmclose */
  148. + #define    DEFBUF    1024        /* default line-buffer size */
  149. + int buflen = DEFBUF;        /* line length limit */
  150. + char lbuf[DEFBUF];
  151. + char *line = lbuf;
  152. + char cbuf[DEFBUF];
  153. + char *cmp = cbuf;
  154. + void fail();
  155. + void dofile();
  156. + void runs();
  157. + void dosweep();
  158. + void mkfiles();
  159. + void crfile();
  160. + void doline();
  161. + #ifdef HAVERFCIZE
  162. + extern char *rfc822ize();
  163. + #else
  164. + #define    rfc822ize(n)    (n)
  165. + #endif
  166. + /*
  167. +  - main - parse arguments and handle options
  168. +  */
  169. + main(argc, argv)
  170. + int argc;
  171. + char *argv[];
  172. + {
  173. +     int c;
  174. +     int errflg = 0;
  175. +     extern int optind;
  176. +     extern char *optarg;
  177. +     void process();
  178. +     int doruns = 0;
  179. +     extern long atol();
  180. +     extern char *malloc();
  181. +     progname = argv[0];
  182. +     while ((c = getopt(argc, argv, "axct:l:R0E:SqOiX:Yuf:p:eMUC:d")) != EOF)
  183. +         switch (c) {
  184. +         case 'a':    /* append to existing table */
  185. +             if (op != 'b')
  186. +                 fail("only one of -a -x -c can be given", "");
  187. +             op = 'a';
  188. +             baseinput = 0;
  189. +             break;
  190. +         case 'x':    /* extract from existing table */
  191. +             if (op != 'b')
  192. +                 fail("only one of -a -x -c can be given", "");
  193. +             op = 'x';
  194. +             baseinput = 0;
  195. +             break;
  196. +         case 'c':    /* check existing table */
  197. +             if (op != 'b')
  198. +                 fail("only one of -a -x -c can be given", "");
  199. +             op = 'c';
  200. +             break;
  201. +         case 't':    /* set field separator */
  202. +             if (strlen(optarg) > 1)
  203. +                 fail("only one field separator allowed", "");
  204. +             fs = *optarg;
  205. +             break;
  206. +         case 'l':    /* override line-length limit */
  207. +             buflen = atoi(optarg) + 1;
  208. +             if (buflen <= 2)
  209. +                 fail("bad -l value `%s'", optarg);
  210. +             line = malloc(buflen);
  211. +             cmp = malloc(buflen);
  212. +             if (line == NULL || cmp == NULL)
  213. +                 fail("cannot allocate %s-byte buffers", optarg);
  214. +             break;
  215. +         case 'R':    /* print run statistics */
  216. +             doruns = 1;
  217. +             break;
  218. +         case '0':    /* omit lines tagged (by fake -t) with 0 */
  219. +             omitzero = 1;
  220. +             break;
  221. +         case 'E':    /* report every n items */
  222. +             every = atol(optarg);
  223. +             break;
  224. +         case 'S':    /* dbzsync() on each -E report */
  225. +             syncs = 1;
  226. +             break;
  227. +         case 'q':    /* quick check, not too thorough */
  228. +             quick = 1;
  229. +             break;
  230. +         case 'O':    /* sweep file checking all offsets */
  231. +             sweep = 1;
  232. +             break;
  233. +         case 'i':    /* don't use incore */
  234. +             useincore = 0;
  235. +             break;
  236. +         case 'X':    /* set xxx */
  237. +             xxx = atoi(optarg);
  238. +             break;
  239. +         case 'Y':    /* print xxx afterward */
  240. +             printx = 1;
  241. +             break;
  242. +         case 'u':    /* don't check uniqueness */
  243. +             unique = 0;
  244. +             break;
  245. +         case 'f':    /* init from existing table's parameters */
  246. +             from = optarg;
  247. +             break;
  248. +         case 'p':    /* parameters for dbzfresh */
  249. +             if (sscanf(optarg, "%ld %1s %lx", &siz, &map, &tag) != 3) {
  250. +                 map = '?';
  251. +                 tag = 0;
  252. +                 if (sscanf(optarg, "%ld", &siz) != 1)
  253. +                     fail("bad -n value `%s'", optarg);
  254. +             }
  255. +             usefresh = 1;
  256. +             break;
  257. +         case 'e':    /* -p size is exact, don't dbzsize() it */
  258. +             exact = 1;
  259. +             break;
  260. +         case 'M':    /* use old dbm interface + rfc822ize */
  261. +             dbzint = 0;
  262. +             break;
  263. +         case 'U':    /* make base unopenable during init */
  264. +             unopen = 1;
  265. +             break;
  266. +         case 'C':    /* change directories before dbmclose */
  267. +             change = optarg;
  268. +             break;
  269. +         case 'd':    /* Debugging. */
  270. +             if (dbzdebug(1) < 0)
  271. +                 fail("dbz debugging not available", "");
  272. +             break;
  273. +         case '?':
  274. +         default:
  275. +             errflg++;
  276. +             break;
  277. +         }
  278. +     if (errflg || optind >= argc || (optind+1 < argc && baseinput)) {
  279. +         fprintf(stderr, "usage: %s ", progname);
  280. +         fprintf(stderr, "[-a] [-x] [-c] database [file] ...\n");
  281. +         exit(2);
  282. +     }
  283. +     (void) dbzincore(useincore);
  284. +     basename = argv[optind];
  285. +     pagname = str2dup(basename, ".pag");
  286. +     dirname = str2dup(basename, ".dir");
  287. +     mkfiles();
  288. +     optind++;
  289. +     if (baseinput)        /* implies no further arguments */
  290. +         process(base, basename);
  291. +     else if (optind >= argc)
  292. +         process(stdin, "stdin");
  293. +     else
  294. +         for (; optind < argc; optind++)
  295. +             dofile(argv[optind]);
  296. +     if (change != NULL)
  297. +         (void) chdir(change);
  298. +     if (dbmclose() < 0)
  299. +         fail("dbmclose failed", "");
  300. +     if (doruns)
  301. +         runs(pagname);
  302. +     if (sweep)
  303. +         dosweep(basename, pagname);
  304. +     if (printx)
  305. +         printf("%ld\n", xxx);
  306. +     exit(0);
  307. + }
  308. + /*
  309. +  - dofile - open a file and invoke process()
  310. +  */
  311. + void
  312. + dofile(name)
  313. + char *name;
  314. + {
  315. +     register FILE *in;
  316. +     if (STREQ(name, "-"))
  317. +         process(stdin, "-");
  318. +     else {
  319. +         in = fopen(name, "r");
  320. +         if (in == NULL)
  321. +             fail("cannot open `%s'", name);
  322. +         process(in, name);
  323. +         (void) fclose(in);
  324. +     }
  325. + }
  326. + /*
  327. +  - mkfiles - create empty files and open them up
  328. +  */
  329. + void
  330. + mkfiles()
  331. + {
  332. +     if (op == 'b' && !dbzint) {
  333. +         crfile(dirname);
  334. +         crfile(pagname);
  335. +     }
  336. +     base = fopen(basename, (op == 'a') ? "a" : "r");
  337. +     if (base == NULL)
  338. +         fail("cannot open `%s'", basename);
  339. +     if (unopen)
  340. +         (void) chmod(basename, 0);
  341. +     if (from != NULL) {
  342. +         if (dbzagain(basename, from) < 0)
  343. +             fail("dbzagain(`%s'...) failed", basename);
  344. +     } else if (op == 'b' && dbzint) {
  345. +         if (!exact)
  346. +             siz = dbzsize(siz);
  347. +         if (dbzfresh(basename, siz, (int)fs, map, tag) < 0)
  348. +             fail("dbzfresh(`%s'...) failed", basename);
  349. +     } else if (dbminit(basename) < 0)
  350. +         fail("dbminit(`%s') failed", basename);
  351. +     if (unopen)
  352. +         (void) chmod(basename, 0600);    /* hard to restore original */
  353. + }
  354. + /*
  355. +  - crfile - create a file
  356. +  */
  357. + void
  358. + crfile(name)
  359. + char *name;
  360. + {
  361. +     register int f;
  362. +     f = creat(name, 0666);
  363. +     if (f < 0)
  364. +         fail("cannot create `%s'", name);
  365. +     (void) close(f);
  366. + }
  367. + /*
  368. +  - process - process input file
  369. +  */
  370. + void
  371. + process(in, name)
  372. + FILE *in;
  373. + char *name;
  374. + {
  375. +     register off_t place;
  376. +     inname = name;
  377. +     lineno = 0;
  378. +     for (;;) {
  379. +         place = ftell(in);
  380. +         if (fgets(line, buflen, in) == NULL)
  381. +             return;
  382. +         lineno++;
  383. +         if (every > 0 && lineno%every == 0) {
  384. +             fprintf(stderr, "%ld\n", lineno);
  385. +             if (dbzsync() < 0)
  386. +                 fail("dbzsync failed", "");
  387. +         }
  388. +         doline(line, place);
  389. +     }
  390. +     /* NOTREACHED */
  391. + }
  392. + /*
  393. +  - doline - process input line
  394. +  */
  395. + void
  396. + doline(lp, inoffset)
  397. + char *lp;
  398. + off_t inoffset;
  399. + {
  400. +     register char *p;
  401. +     register char pc;
  402. +     datum key, value;
  403. +     off_t place = inoffset;
  404. +     register int shouldfind;
  405. +     register int llen;
  406. +     char keytext[DBZMAXKEY+1];
  407. +     p = NULL;
  408. +     if (fs != '\0')
  409. +         p = strchr(lp, fs);
  410. +     if (p == NULL)
  411. +         p = lp + strlen(lp);
  412. +     if (p > lp && *(p-1) == '\n')
  413. +         p--;
  414. +     if (p - lp > DBZMAXKEY)
  415. +         fail("key of `%.40s...' too long", lp);
  416. +     pc = *p;
  417. +     *p = '\0';
  418. +     (void) strcpy(keytext, lp);
  419. +     *p = pc;
  420. +     key.dptr = (dbzint) ? keytext : rfc822ize(keytext);
  421. +     key.dsize = strlen(keytext)+1;
  422. +     switch (op) {
  423. +     case 'a':
  424. +         place = ftell(base);
  425. +         llen = strlen(lp);
  426. +         if (fwrite(lp, 1, llen, base) != llen)
  427. +             fail("write error in `%s'", basename);
  428. +         /* FALLTHROUGH */
  429. +     case 'b':
  430. +         if (omitzero && p != NULL && *(p+1) == '0')
  431. +             return;
  432. +         if (unique) {
  433. +             value = (dbzint) ? dbzfetch(key) : fetch(key);
  434. +             if (value.dptr != NULL)
  435. +                 fail("`%.40s...' already present", lp);
  436. +         }
  437. +         value.dptr = (char *)&place;
  438. +         value.dsize = (int)sizeof(off_t);
  439. +         if (((dbzint) ? dbzstore(key, value) : store(key, value)) < 0)
  440. +             fail("store failed on `%.40s...'", lp);
  441. +         break;
  442. +     case 'c':
  443. +         value = (dbzint) ? dbzfetch(key) : fetch(key);
  444. +         shouldfind = (omitzero && p != NULL && *(p+1) == '0') ? 0 : 1;
  445. +         if (!shouldfind && (value.dptr != NULL || value.dsize != 0))
  446. +             fail("`%.40s...' found, shouldn't be", lp);
  447. +         if (shouldfind && (value.dptr == NULL ||
  448. +                     value.dsize != sizeof(off_t)))
  449. +             fail("can't find `%.40s...'", lp);
  450. +         if (shouldfind && !quick) {
  451. +             (void) memcpy((char *)&place, value.dptr, sizeof(off_t));
  452. +             if (place != inoffset)
  453. +                 fail("offset mismatch on `%.40s...'", lp);
  454. +             if (fseek(base, place, SEEK_SET) == -1)
  455. +                 fail("fseek failed on `%.40s...'", lp);
  456. +             if (fgets(cmp, buflen, base) == NULL)
  457. +                 fail("can't read line for `%.40s...'", lp);
  458. +             if (!STREQ(lp, cmp))
  459. +                 fail("compare failed on `%.40s...'", lp);
  460. +         }
  461. +         break;
  462. +     case 'x':
  463. +         value = (dbzint) ? dbzfetch(key) : fetch(key);
  464. +         if (value.dptr != NULL) {
  465. +             (void) memcpy((char *)&place, value.dptr, sizeof(off_t));
  466. +             if (fseek(base, place, SEEK_SET) == -1)
  467. +                 fail("fseek failed on `%.40s...'", lp);
  468. +             if (fgets(cmp, buflen, base) == NULL)
  469. +                 fail("can't read line for `%.40s...'", lp);
  470. +             fputs(cmp, stdout);
  471. +         }
  472. +         break;
  473. +     default:
  474. +         fail("unknown operator -- can't happen", "");
  475. +         break;
  476. +     }
  477. + }
  478. + /*
  479. +  - runs - print run statistics
  480. +  */
  481. + void
  482. + runs(file)
  483. + char *file;
  484. + {
  485. +     register FILE *fd;
  486. +     off_t it;
  487. +     register long run;
  488. +     fd = fopen(file, "r");
  489. +     if (fd == NULL)
  490. +         fail("cannot reopen `%s'", file);
  491. +     run = 0;
  492. +     while (fread((char *)&it, sizeof(off_t), 1, fd) == 1) {
  493. +         if (it != 0)
  494. +             run++;
  495. +         else if (run > 0) {
  496. +             printf("%ld\n", run);
  497. +             run = 0;
  498. +         }
  499. +     }
  500. +     (void) fclose(fd);
  501. + }
  502. + /*
  503. +  - dosweep - sweep pag file checking for valid offsets
  504. +  */
  505. + void
  506. + dosweep(fn, pn)
  507. + char *fn;
  508. + char *pn;
  509. + {
  510. +     register FILE *pf;
  511. +     off_t it;
  512. +     char nl;
  513. +     register FILE *hf;
  514. +     hf = fopen(fn, "r");
  515. +     if (hf == NULL)
  516. +         fail("cannot reopen `%s'", fn);
  517. +     pf = fopen(pn, "r");
  518. +     if (pf == NULL)
  519. +         fail("cannot reopen `%s'", pn);
  520. +     while (fread((char *)&it, sizeof(off_t), 1, pf) == 1) {
  521. +         it = (it & (0x80<<24)) ? (it&~(0xff<<24)) : it;
  522. +         if (it != 0 && it != 1) {    /* 0 empty, 1 known okay */
  523. +             it--;        /* get rid of bias */
  524. +             (void) fseek(hf, it-1, SEEK_SET);
  525. +             nl = getc(hf);
  526. +             if (nl != '\n')
  527. +                 fprintf(stderr, "offset 0%lo does not point to line\n",
  528. +                                 (long)it);
  529. +         }
  530. +     }
  531. +     (void) fclose(hf);
  532. +     (void) fclose(pf);
  533. + }
  534. + /*
  535. +  - fail - complain and die
  536. +  */
  537. + void
  538. + fail(s1, s2)
  539. + char *s1;
  540. + char *s2;
  541. + {
  542. +     fprintf(stderr, "%s: (file `%s', line %ld) ", progname, inname, lineno);
  543. +     fprintf(stderr, s1, s2);
  544. +     fprintf(stderr, "\n");
  545. +     exit(1);
  546. + }
  547. + /*
  548. +  - str2dup - concatenate strings and malloc result
  549. +  */
  550. + char *
  551. + str2dup(s1, s2)
  552. + char *s1;
  553. + char *s2;
  554. + {
  555. +     register char *p;
  556. +     p = malloc((size_t)strlen(s1) + strlen(s2) + 1);
  557. +     if (p == NULL)
  558. +         fail("can't allocate space for strings", "");
  559. +     (void) strcpy(p, s1);
  560. +     (void) strcat(p, s2);
  561. +     return(p);
  562. + }
  563.  
  564. new dbz/fake.c (patch can't create, so diff against null):
  565. Index: dbz/fake.c
  566. *** cnpatch/old/dbz/fake.c    Sat Apr 14 20:29:12 1990
  567. --- dbz/fake.c    Sat Mar 31 19:24:20 1990
  568. ***************
  569. *** 0 ****
  570. --- 1,142 ----
  571. + /*
  572. +  * fake - make up random lines resembling history-file entries, reproducibly
  573. +  *
  574. +  * $Log$
  575. +  */
  576. + #include <stdio.h>
  577. + #include <sys/types.h>
  578. + #include <sys/stat.h>
  579. + #include <string.h>
  580. + #define    MAXSTR    500        /* For sizing strings -- DON'T use BUFSIZ! */
  581. + #define    STREQ(a, b)    (*(a) == *(b) && strcmp((a), (b)) == 0)
  582. + #ifndef lint
  583. + static char RCSid[] = "$Header$";
  584. + #endif
  585. + int midonly = 0;        /* just message ids, rest not realistic */
  586. + int tag = 0;            /* tag lines with random digit for later use */
  587. + int expired = -1;        /* percentage of lines to be expired */
  588. + int debug = 0;
  589. + char *progname;
  590. + char *inname;                /* filename for messages etc. */
  591. + long lineno;                /* line number for messages etc. */
  592. + void fail();
  593. + void doline();
  594. + void addchars();
  595. + void seed();
  596. + /*
  597. +  - main - parse arguments and handle options
  598. +  */
  599. + main(argc, argv)
  600. + int argc;
  601. + char *argv[];
  602. + {
  603. +     int c;
  604. +     int errflg = 0;
  605. +     FILE *in;
  606. +     struct stat statbuf;
  607. +     extern int optind;
  608. +     extern char *optarg;
  609. +     extern FILE *efopen();
  610. +     void process();
  611. +     register long no;
  612. +     extern long atol();
  613. +     char line[MAXSTR];
  614. +     progname = argv[0];
  615. +     while ((c = getopt(argc, argv, "ms:te:d")) != EOF)
  616. +         switch (c) {
  617. +         case 'm':    /* message-ids only */
  618. +             midonly = 1;
  619. +             break;
  620. +         case 's':    /* seed */
  621. +             seed(atol(optarg));
  622. +             break;
  623. +         case 't':    /* tag lines with a random digit */
  624. +             tag = 1;
  625. +             break;
  626. +         case 'e':    /* percentage to be expired */
  627. +             expired = atoi(optarg);
  628. +             break;
  629. +         case 'd':    /* Debugging. */
  630. +             debug++;
  631. +             break;
  632. +         case '?':
  633. +         default:
  634. +             errflg++;
  635. +             break;
  636. +         }
  637. +     if (errflg || optind != argc - 1) {
  638. +         fprintf(stderr, "usage: %s ", progname);
  639. +         fprintf(stderr, "[-m] [-s seed] length\n");
  640. +         exit(2);
  641. +     }
  642. +     for (no = atol(argv[optind]); no > 0; no--) {
  643. +         doline(line);
  644. +         puts(line);
  645. +     }
  646. +     exit(0);
  647. + }
  648. + /*
  649. +  - doline - generate random history pseudo-line
  650. +  */
  651. + void
  652. + doline(buf)
  653. + char *buf;
  654. + {
  655. +     char tagch[2];
  656. +     (void) strcpy(buf, "<");
  657. +     addchars(buf, range(4, 20));
  658. +     (void) strcat(buf, "@");
  659. +     addchars(buf, range(8, 20));
  660. +     if (midonly)
  661. +         (void) strcat(buf, ">\tx");
  662. +     else {
  663. +         if (tag) {
  664. +             tagch[0] = "1234567890"[range(0,9)];
  665. +             tagch[1] = '\0';
  666. +             (void) strcat(buf, ">\t");
  667. +             (void) strcat(buf, tagch);
  668. +             (void) strcat(buf, "00000000~-");
  669. +         } else
  670. +             (void) strcat(buf, ">\t1234567890~-");
  671. +     }
  672. +     if (range(1, 100) > expired) {
  673. +         if (midonly)
  674. +             (void) strcat(buf, "\tx");
  675. +         else {
  676. +             (void) strcat(buf, "\t");
  677. +             addchars(buf, range(10, 30));
  678. +         }
  679. +     }
  680. + }
  681. + /*
  682. +  - addchars - generate n random characters suitable for history file
  683. +  */
  684. + void
  685. + addchars(buf, len)
  686. + char *buf;
  687. + int len;
  688. + {
  689. +     register int i;
  690. +     register char *p = buf + strlen(buf);
  691. +     static char vocab[] = "1234567890.abcde.fghij.klmno.pqrst.uvwxyz.\
  692. + 1234567890.ABCDE.FGHIJ.KLMNO.PQRST.UVWXYZ.1234567890.\
  693. + 1234567890.abcde.fghij.klmno.pqrst.uvwxyz.1234567890";
  694. +     for (i = len; i > 0; i--)
  695. +         *p++ = vocab[range(0, sizeof(vocab)-2)];
  696. +     *p++ = '\0';
  697. + }
  698.  
  699. new dbz/firstlast25 (patch can't create, so diff against null):
  700. Index: dbz/firstlast25
  701. *** cnpatch/old/dbz/firstlast25    Sat Apr 14 20:29:12 1990
  702. --- dbz/firstlast25    Sat Mar 31 19:24:20 1990
  703. ***************
  704. *** 0 ****
  705. --- 1,50 ----
  706. + <m....VO1.9q.@s95e1zKsIj7LrIwa1>    600000000~-    90fz0706yo.1Env21x8b
  707. + <H5.i.R6ZQ2@Vg6.5mqj8..z>    200000000~-
  708. + <1Hy.ufmjqe371x5.o@HEEl0tAp4>    700000000~-
  709. + <T6.c9.xM4i@943..7z.c..3h>    600000000~-
  710. + <Exus7LsME4fPL9v8@2.ouu97O25z9cdft>    700000000~-
  711. + <6kUzkf.v74@iC1iGj882RQ0zli>    400000000~-
  712. + <J.7YT7dV.Kkul8Bh0fc@Rar.EnMx2lm0.6Yeob>    600000000~-
  713. + <.wVJi1DX42@5.4i6.jaZ6qw9Ln1.>    500000000~-
  714. + <uUd9e18vxzevae7uY@33a480208l0.4p2q>    300000000~-
  715. + <43hQ.5shbE7@912400.ajES6x0sXl.M>    400000000~-
  716. + <g25r..2r.0WOZ6k3@tb3.U9xrR.uw61a2y0>    600000000~-
  717. + <923s5e67d5Oq085Y.1@6Pik68584>    900000000~-
  718. + <.5.n5cx5aD62i9q8@Ai60Sc.4x>    200000000~-
  719. + <9N9n@3.1ql87.yj2xFs.zLqI>    700000000~-    Q2.kni8kZps7kF5uiEv32B38y4z.p
  720. + <.X.fw.6LtoT.0@pp6bp.5s6yh74.>    400000000~-
  721. + <54c1w@7..u1.99m9T4j.BNGBiK>    600000000~-    .F3hb.OFh06V..p
  722. + <j12Mtn6q9@m2.m1X1s>    500000000~-
  723. + <o1WJV9G4H.zf0BX44w@W7.76xn33>    000000000~-
  724. + <0C605s6plaAgfM.ap40@e6d66n.uv01W.j.8ph.>    100000000~-    m.x7TY8.8DQ5
  725. + <.2.14xdn.@D0g.W.uZ.75gyyg.q1G>    100000000~-
  726. + <.A..03.@5v..64.5v3.3tbjUo.>    500000000~-
  727. + <72..c19ms65.WCf0G3.@83seEG9nnhM.O.j22>    900000000~-
  728. + <D..xX.kti9@u739li.xvy2>    000000000~-    NPLL42XVfM
  729. + <6HO.nFal1ufl3.8b@3.n0k7a.IDgNy>    700000000~-    Wv4j3Itccnh0Zp3
  730. + <x5RjUnIpd03xBBnuN@z0puc82Q26Ou.0T6>    400000000~-    k67.hvXwv6X745R4rh2ybuFN3n.
  731. + <62dIeg.fW92.ov375@x76mf5c6.37.v>    000000000~-
  732. + <chdpqs.0mgZOp.@Dxl9v..94e7ar2>    900000000~-
  733. + <.9Xr.7V91..oe5CG.hX@p5x3jos3s27R6O3yj1>    400000000~-
  734. + <Mm6dr.231dH35ua@SE1u0za3V1M43lRn9>    100000000~-
  735. + <JIhw2@.Qdf.8v28Tnf1M>    200000000~-
  736. + <z4FCa.q4MF..EE0.2@W9U63e33h9w3lcFFl>    400000000~-
  737. + <87.W3r6is4.@svVqQCBiNqz400A.qwj>    200000000~-
  738. + <0liI7Lu0Mx435m7M99@87Xw.8j63.9.>    500000000~-
  739. + <tRtht5M.6d0@06gj.qm3.s9>    200000000~-    e27S.BKVD70P.o
  740. + <Jpga8@m68yvw.b4b>    200000000~-
  741. + <.2.69hy3JT1@Aq3.r83o.9>    700000000~-
  742. + <.W7EurYppo4fhzs.I@8651m2W7v>    700000000~-
  743. + <3m02.@22074.a5ct2j3>    900000000~-
  744. + <.fy9Epa@.1.kNGCNokFwB8ezo1WM>    800000000~-
  745. + <c758d64.FS4yY7L5@43sw.kI6>    900000000~-
  746. + <vLd0.t@.kq70oHl96ixdnXd.GVv>    100000000~-    9A6Ejq5t55I4VJ6.q1
  747. + <d3.4@n17p4N.77N7W..7.8>    300000000~-
  748. + <f2lv064.8@4jokk3e07>    400000000~-
  749. + <rr7hoxA.U7.JXxnpvd@1rbMO437vHnakx>    000000000~-
  750. + <.0p3G7novlrYz9kjI@Sx.2w.yqzerZl12781.k>    700000000~-
  751. + <51ny.pQ7ay4@nfU2l1f0ixG09584.m>    000000000~-    38K5bhK7cr6.bg.5MlC2Fxq06Ziuw.
  752. + <2.cau.9s@.n4Pk0Jd9g>    300000000~-
  753. + <bEH1Bwa.662i@zm.3g.gx4.lp3>    300000000~-    c8.t4Q0.8t0.m50
  754. + <.t13789u5AqM4m3.z0T@P17e.ypf>    200000000~-    q17z.fZ3.FyD533WthqZs8q7
  755. + <M4r1I@Ovaev.dp>    100000000~-
  756.  
  757. new dbz/getmap (patch can't create, so diff against null):
  758. Index: dbz/getmap
  759. *** cnpatch/old/dbz/getmap    Sat Apr 14 20:29:13 1990
  760. --- dbz/getmap    Thu Apr 12 16:29:25 1990
  761. ***************
  762. *** 0 ****
  763. --- 1,5 ----
  764. + awk 'NR == 1 {
  765. +     for (i = 9; i <= NF; i++)
  766. +         printf "%s ", $i
  767. +     printf "\n"
  768. + }' $*
  769.  
  770. new dbz/random.c (patch can't create, so diff against null):
  771. Index: dbz/random.c
  772. *** cnpatch/old/dbz/random.c    Sat Apr 14 20:29:13 1990
  773. --- dbz/random.c    Sat Mar 31 19:24:21 1990
  774. ***************
  775. *** 0 ****
  776. --- 1,31 ----
  777. + /*
  778. +  * random-number generator for testing
  779. +  */
  780. + static unsigned long next = 1;
  781. + /*
  782. +  - range - generate a random number within an inclusive range
  783. +  *
  784. +  * Algorithm from ANSI C standard.  Limitation:  max-min <= 32767.
  785. +  */
  786. + int
  787. + range(min, max)
  788. + int min;
  789. + int max;
  790. + {
  791. +     register int temp;
  792. +     next = next * 1103515245 + 12345;
  793. +     temp = (int)((next/65536)%32768);
  794. +     return(temp%(max - min + 1) + min);
  795. + }
  796. + /*
  797. +  - seed - seed random number generator
  798. +  */
  799. + void
  800. + seed(n)
  801. + long n;
  802. + {
  803. +     next = (unsigned long)n;
  804. + }
  805.  
  806. new dbz/revbytes (patch can't create, so diff against null):
  807. Index: dbz/revbytes
  808. *** cnpatch/old/dbz/revbytes    Sat Apr 14 20:29:13 1990
  809. --- dbz/revbytes    Thu Apr 12 16:34:45 1990
  810. ***************
  811. *** 0 ****
  812. --- 1,7 ----
  813. + NR == 1 {
  814. +     printf "%s %s %s %s %s %s %s %s %s", $1, $2, $3, $4, $5, $6, $7, $8, $9
  815. +     for (i = NF; i > 9; i--)
  816. +         printf " %s", $i
  817. +     printf "\n"
  818. + }
  819. + NR > 1 { print }
  820.  
  821. new h/dbz.h (patch can't create, so diff against null):
  822. Index: h/dbz.h
  823. *** cnpatch/old/h/dbz.h    Sat Apr 14 20:29:14 1990
  824. --- h/dbz.h    Thu Apr 12 16:18:34 1990
  825. ***************
  826. *** 0 ****
  827. --- 1,31 ----
  828. + /* for dbm and dbz */
  829. + typedef struct {
  830. +     char *dptr;
  831. +     int dsize;
  832. + } datum;
  833. + /* standard dbm functions */
  834. + extern int dbminit();
  835. + extern datum fetch();
  836. + extern int store();
  837. + extern int delete();        /* not in dbz */
  838. + extern datum firstkey();    /* not in dbz */
  839. + extern datum nextkey();        /* not in dbz */
  840. + extern int dbmclose();        /* in dbz, but not in old dbm */
  841. + /* new stuff for dbz */
  842. + extern int dbzfresh();
  843. + extern int dbzagain();
  844. + extern datum dbzfetch();
  845. + extern int dbzstore();
  846. + extern int dbzsync();
  847. + extern long dbzsize();
  848. + extern int dbzincore();
  849. + extern int dbzdebug();
  850. + /*
  851. +  * In principle we could handle unlimited-length keys by operating a chunk
  852. +  * at a time, but it's not worth it in practice.  Setting a nice large
  853. +  * bound on them simplifies the code and doesn't hurt anything.
  854. +  */
  855. + #define DBZMAXKEY    255
  856.  
  857. new libfake/dbz.c (patch can't create, so diff against null):
  858. Index: libfake/dbz.c
  859. *** cnpatch/old/libfake/dbz.c    Sat Apr 14 20:29:15 1990
  860. --- libfake/dbz.c    Thu Apr 12 17:43:54 1990
  861. ***************
  862. *** 0 ****
  863. --- 1,82 ----
  864. + /*
  865. +  * fakes for using dbm (or old dbz) as if it were dbz
  866. +  */
  867. + #include <stdio.h>
  868. + #include <sys/types.h>
  869. + #include <dbz.h>
  870. + /* the simple stuff */
  871. + dbzfresh(a,b,c,d,e) char *a; long b; { return(dbzagain(a,a)); }
  872. + long dbzsize(a) long a; { return(a); }
  873. + dbzincore(n) int n; { return(0); }
  874. + dbzdebug(n) int n; { return(0); }
  875. + long dbztrim(a) long a; { return(a); }
  876. + int dbzsync() { return(0); }
  877. + /*
  878. +  - dbzagain - like dbminit but creates files
  879. +  */
  880. + int
  881. + dbzagain(a, b)
  882. + char *a;
  883. + char *b;
  884. + {
  885. +     char dirname[200];
  886. +     char pagname[200];
  887. +     FILE *p;
  888. +     FILE *d;
  889. +     sprintf(dirname, "%s.dir", a);
  890. +     sprintf(pagname, "%s.pag", a);
  891. +     p = fopen(dirname, "w");
  892. +     d = fopen(pagname, "w");
  893. +     if (p != NULL)
  894. +         (void) fclose(p);
  895. +     if (d != NULL)
  896. +         (void) fclose(d);
  897. +     if (p == NULL || d == NULL)
  898. +         return(-1);
  899. +     return(dbminit(a));
  900. + }
  901. + /*
  902. +  - dbzfetch - fetch() with case mapping built in
  903. +  *
  904. +  * Uses C News rfc822ize().  Assumes keys are strings.
  905. +  */
  906. + datum
  907. + dbzfetch(key)
  908. + datum key;
  909. + {
  910. +     char buffer[DBZMAXKEY + 1];
  911. +     datum mappedkey;
  912. +     (void) strcpy(buffer, key.dptr);
  913. +     (void) rfc822ize(buffer);
  914. +     mappedkey.dptr = buffer;
  915. +     mappedkey.dsize = key.dsize;
  916. +     return(fetch(mappedkey));
  917. + }
  918. + /*
  919. +  - dbzstore - store() with case mapping built in
  920. +  *
  921. +  * Uses C News rfc822ize().  Assumes keys are strings.
  922. +  */
  923. + int
  924. + dbzstore(key, data)
  925. + datum key;
  926. + datum data;
  927. + {
  928. +     char buffer[DBZMAXKEY + 1];
  929. +     datum mappedkey;
  930. +     (void) strcpy(buffer, key.dptr);
  931. +     (void) rfc822ize(buffer);
  932. +     mappedkey.dptr = buffer;
  933. +     mappedkey.dsize = key.dsize;
  934. +     return(store(mappedkey, data));
  935. + }
  936.  
  937.  
  938. end of patch 16-Apr-1990
  939.  
  940.