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
|
/*
* fake - make up random lines resembling history-file entries, reproducibly
*
* -Log-
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#define MAXSTR 500 /* For sizing strings -- DON'T use BUFSIZ! */
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
#ifndef lint
static char RCSid[] = "$Header$";
#endif
int midonly = 0; /* just message ids, rest not realistic */
int tag = 0; /* tag lines with random digit for later use */
int expired = -1; /* percentage of lines to be expired */
int debug = 0;
char *progname;
char *inname; /* filename for messages etc. */
long lineno; /* line number for messages etc. */
void doline();
void addchars();
void seed();
/*
- main - parse arguments and handle options
*/
main(argc, argv)
int argc;
char *argv[];
{
int c;
int errflg = 0;
FILE *in;
struct stat statbuf;
extern int optind;
extern char *optarg;
void process();
register long no;
char line[MAXSTR];
progname = argv[0];
while ((c = getopt(argc, argv, "ms:te:d")) != EOF)
switch (c) {
case 'm': /* message-ids only */
midonly = 1;
break;
case 's': /* seed */
seed(atol(optarg));
break;
case 't': /* tag lines with a random digit */
tag = 1;
break;
case 'e': /* percentage to be expired */
expired = atoi(optarg);
break;
case 'd': /* Debugging. */
debug++;
break;
case '?':
default:
errflg++;
break;
}
if (errflg || optind != argc - 1) {
fprintf(stderr, "usage: %s ", progname);
fprintf(stderr, "[-m] [-s seed] length\n");
exit(2);
}
for (no = atol(argv[optind]); no > 0; no--) {
doline(line);
puts(line);
}
exit(0);
}
/*
- doline - generate random history pseudo-line
*/
void
doline(buf)
char *buf;
{
char tagch[2];
(void) strcpy(buf, "<");
addchars(buf, range(4, 20));
(void) strcat(buf, "@");
addchars(buf, range(8, 20));
if (midonly)
(void) strcat(buf, ">\tx");
else {
if (tag) {
tagch[0] = "1234567890"[range(0,9)];
tagch[1] = '\0';
(void) strcat(buf, ">\t");
(void) strcat(buf, tagch);
(void) strcat(buf, "00000000~-");
} else
(void) strcat(buf, ">\t1234567890~-");
}
if (range(1, 100) > expired) {
if (midonly)
(void) strcat(buf, "\tx");
else {
(void) strcat(buf, "\t");
addchars(buf, range(10, 30));
}
}
}
/*
- addchars - generate n random characters suitable for history file
*/
void
addchars(buf, len)
char *buf;
int len;
{
register int i;
register char *p = buf + strlen(buf);
static char vocab[] = "1234567890.abcde.fghij.klmno.pqrst.uvwxyz.\
1234567890.ABCDE.FGHIJ.KLMNO.PQRST.UVWXYZ.1234567890.\
1234567890.abcde.fghij.klmno.pqrst.uvwxyz.1234567890";
for (i = len; i > 0; i--)
*p++ = vocab[range(0, sizeof(vocab)-2)];
*p++ = '\0';
}
|