]>
Commit | Line | Data |
---|---|---|
6599da04 JM |
1 | /* |
2 | * fake - make up random lines resembling history-file entries, reproducibly | |
3 | * | |
4 | * -Log- | |
5 | */ | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <sys/types.h> | |
9 | #include <sys/stat.h> | |
10 | #include <string.h> | |
11 | ||
12 | #define MAXSTR 500 /* For sizing strings -- DON'T use BUFSIZ! */ | |
13 | #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) | |
14 | ||
15 | #ifndef lint | |
16 | static char RCSid[] = "$Header: /rel/cvsfiles/devo/libio/dbz/fake.c,v 1.2 1993/10/25 20:02:42 bothner Exp $"; | |
17 | #endif | |
18 | ||
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 */ | |
22 | ||
23 | int debug = 0; | |
24 | char *progname; | |
25 | ||
26 | char *inname; /* filename for messages etc. */ | |
27 | long lineno; /* line number for messages etc. */ | |
28 | ||
29 | void doline(); | |
30 | void addchars(); | |
31 | void seed(); | |
32 | ||
33 | /* | |
34 | - main - parse arguments and handle options | |
35 | */ | |
36 | int | |
37 | main(argc, argv) | |
38 | int argc; | |
39 | char *argv[]; | |
40 | { | |
41 | int c; | |
42 | int errflg = 0; | |
43 | FILE *in; | |
44 | struct stat statbuf; | |
45 | extern int optind; | |
46 | extern char *optarg; | |
47 | void process(); | |
48 | register long no; | |
49 | extern long atol(); | |
50 | char line[MAXSTR]; | |
51 | ||
52 | progname = argv[0]; | |
53 | ||
54 | while ((c = getopt(argc, argv, "ms:te:d")) != EOF) | |
55 | switch (c) { | |
56 | case 'm': /* message-ids only */ | |
57 | midonly = 1; | |
58 | break; | |
59 | case 's': /* seed */ | |
60 | seed(atol(optarg)); | |
61 | break; | |
62 | case 't': /* tag lines with a random digit */ | |
63 | tag = 1; | |
64 | break; | |
65 | case 'e': /* percentage to be expired */ | |
66 | expired = atoi(optarg); | |
67 | break; | |
68 | case 'd': /* Debugging. */ | |
69 | debug++; | |
70 | break; | |
71 | case '?': | |
72 | default: | |
73 | errflg++; | |
74 | break; | |
75 | } | |
76 | if (errflg || optind != argc - 1) { | |
77 | fprintf(stderr, "usage: %s ", progname); | |
78 | fprintf(stderr, "[-m] [-s seed] length\n"); | |
79 | exit(2); | |
80 | } | |
81 | ||
82 | for (no = atol(argv[optind]); no > 0; no--) { | |
83 | doline(line); | |
84 | puts(line); | |
85 | } | |
86 | #ifdef DBZ_FINISH | |
87 | DBZ_FINISH; | |
88 | #endif | |
89 | exit(0); | |
90 | } | |
91 | ||
92 | /* | |
93 | - doline - generate random history pseudo-line | |
94 | */ | |
95 | void | |
96 | doline(buf) | |
97 | char *buf; | |
98 | { | |
99 | char tagch[2]; | |
100 | ||
101 | (void) strcpy(buf, "<"); | |
102 | addchars(buf, range(4, 20)); | |
103 | (void) strcat(buf, "@"); | |
104 | addchars(buf, range(8, 20)); | |
105 | if (midonly) | |
106 | (void) strcat(buf, ">\tx"); | |
107 | else { | |
108 | if (tag) { | |
109 | tagch[0] = "1234567890"[range(0,9)]; | |
110 | tagch[1] = '\0'; | |
111 | (void) strcat(buf, ">\t"); | |
112 | (void) strcat(buf, tagch); | |
113 | (void) strcat(buf, "00000000~-"); | |
114 | } else | |
115 | (void) strcat(buf, ">\t1234567890~-"); | |
116 | } | |
117 | if (range(1, 100) > expired) { | |
118 | if (midonly) | |
119 | (void) strcat(buf, "\tx"); | |
120 | else { | |
121 | (void) strcat(buf, "\t"); | |
122 | addchars(buf, range(10, 30)); | |
123 | } | |
124 | } | |
125 | } | |
126 | ||
127 | /* | |
128 | - addchars - generate n random characters suitable for history file | |
129 | */ | |
130 | void | |
131 | addchars(buf, len) | |
132 | char *buf; | |
133 | int len; | |
134 | { | |
135 | register int i; | |
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"; | |
140 | ||
141 | for (i = len; i > 0; i--) | |
142 | *p++ = vocab[range(0, sizeof(vocab)-2)]; | |
143 | *p++ = '\0'; | |
144 | } |