2 * fake - make up random lines resembling history-file entries, reproducibly
12 #define MAXSTR 500 /* For sizing strings -- DON'T use BUFSIZ! */
13 #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
16 static char RCSid[] = "$Header: /rel/cvsfiles/devo/libio/dbz/fake.c,v 1.2 1993/10/25 20:02:42 bothner Exp $";
19 int midonly = 0; /* just message ids, rest not realistic */
20 int tag = 0; /* tag lines with random digit for later use */
21 int expired = -1; /* percentage of lines to be expired */
26 char *inname; /* filename for messages etc. */
27 long lineno; /* line number for messages etc. */
34 - main - parse arguments and handle options
54 while ((c = getopt(argc, argv, "ms:te:d")) != EOF)
56 case 'm': /* message-ids only */
62 case 't': /* tag lines with a random digit */
65 case 'e': /* percentage to be expired */
66 expired = atoi(optarg);
68 case 'd': /* Debugging. */
76 if (errflg || optind != argc - 1) {
77 fprintf(stderr, "usage: %s ", progname);
78 fprintf(stderr, "[-m] [-s seed] length\n");
82 for (no = atol(argv[optind]); no > 0; no--) {
93 - doline - generate random history pseudo-line
101 (void) strcpy(buf, "<");
102 addchars(buf, range(4, 20));
103 (void) strcat(buf, "@");
104 addchars(buf, range(8, 20));
106 (void) strcat(buf, ">\tx");
109 tagch[0] = "1234567890"[range(0,9)];
111 (void) strcat(buf, ">\t");
112 (void) strcat(buf, tagch);
113 (void) strcat(buf, "00000000~-");
115 (void) strcat(buf, ">\t1234567890~-");
117 if (range(1, 100) > expired) {
119 (void) strcat(buf, "\tx");
121 (void) strcat(buf, "\t");
122 addchars(buf, range(10, 30));
128 - addchars - generate n random characters suitable for history file
136 register char *p = buf + strlen(buf);
137 static char vocab[] = "1234567890.abcde.fghij.klmno.pqrst.uvwxyz.\
138 1234567890.ABCDE.FGHIJ.KLMNO.PQRST.UVWXYZ.1234567890.\
139 1234567890.abcde.fghij.klmno.pqrst.uvwxyz.1234567890";
141 for (i = len; i > 0; i--)
142 *p++ = vocab[range(0, sizeof(vocab)-2)];