* c-decl.c (c_expand_body): Check TYPE_SIZE_UNIT (ret_type)
[official-gcc.git] / libio / dbz / fake.c
blob74f2ae682533ac0717a5e35367bfb5ea320840a7
1 /*
2 * fake - make up random lines resembling history-file entries, reproducibly
4 * -Log-
5 */
7 #include <stdio.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <string.h>
12 #define MAXSTR 500 /* For sizing strings -- DON'T use BUFSIZ! */
13 #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
15 int midonly = 0; /* just message ids, rest not realistic */
16 int tag = 0; /* tag lines with random digit for later use */
17 int expired = -1; /* percentage of lines to be expired */
19 int debug = 0;
20 char *progname;
22 char *inname; /* filename for messages etc. */
23 long lineno; /* line number for messages etc. */
25 void doline();
26 void addchars();
27 void seed();
30 - main - parse arguments and handle options
32 int
33 main(argc, argv)
34 int argc;
35 char *argv[];
37 int c;
38 int errflg = 0;
39 FILE *in;
40 struct stat statbuf;
41 extern int optind;
42 extern char *optarg;
43 void process();
44 register long no;
45 extern long atol();
46 char line[MAXSTR];
48 progname = argv[0];
50 while ((c = getopt(argc, argv, "ms:te:d")) != EOF)
51 switch (c) {
52 case 'm': /* message-ids only */
53 midonly = 1;
54 break;
55 case 's': /* seed */
56 seed(atol(optarg));
57 break;
58 case 't': /* tag lines with a random digit */
59 tag = 1;
60 break;
61 case 'e': /* percentage to be expired */
62 expired = atoi(optarg);
63 break;
64 case 'd': /* Debugging. */
65 debug++;
66 break;
67 case '?':
68 default:
69 errflg++;
70 break;
72 if (errflg || optind != argc - 1) {
73 fprintf(stderr, "usage: %s ", progname);
74 fprintf(stderr, "[-m] [-s seed] length\n");
75 exit(2);
78 for (no = atol(argv[optind]); no > 0; no--) {
79 doline(line);
80 puts(line);
82 #ifdef DBZ_FINISH
83 DBZ_FINISH;
84 #endif
85 exit(0);
89 - doline - generate random history pseudo-line
91 void
92 doline(buf)
93 char *buf;
95 char tagch[2];
97 (void) strcpy(buf, "<");
98 addchars(buf, range(4, 20));
99 (void) strcat(buf, "@");
100 addchars(buf, range(8, 20));
101 if (midonly)
102 (void) strcat(buf, ">\tx");
103 else {
104 if (tag) {
105 tagch[0] = "1234567890"[range(0,9)];
106 tagch[1] = '\0';
107 (void) strcat(buf, ">\t");
108 (void) strcat(buf, tagch);
109 (void) strcat(buf, "00000000~-");
110 } else
111 (void) strcat(buf, ">\t1234567890~-");
113 if (range(1, 100) > expired) {
114 if (midonly)
115 (void) strcat(buf, "\tx");
116 else {
117 (void) strcat(buf, "\t");
118 addchars(buf, range(10, 30));
124 - addchars - generate n random characters suitable for history file
126 void
127 addchars(buf, len)
128 char *buf;
129 int len;
131 register int i;
132 register char *p = buf + strlen(buf);
133 static char vocab[] = "1234567890.abcde.fghij.klmno.pqrst.uvwxyz.\
134 1234567890.ABCDE.FGHIJ.KLMNO.PQRST.UVWXYZ.1234567890.\
135 1234567890.abcde.fghij.klmno.pqrst.uvwxyz.1234567890";
137 for (i = len; i > 0; i--)
138 *p++ = vocab[range(0, sizeof(vocab)-2)];
139 *p++ = '\0';