home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_08
/
ramey.exe
/
STEST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-14
|
2KB
|
105 lines
/*
Copyright (c) Robert Ramey 1991. All Rights Reserved
*/
/* program to generate a test file file for sort program */
#define TMAX 512
#define FMAX 8
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include "arg.h"
char umsg[] =
"usage: stest -n <number of records> [-s <size range>] -k <char table> ...\n\
<char table> := <character>\n\
| <character range>\n\
<character range> := <character>-<character>\n\
<character> := '<ascii character>'\n\
| <decimal number>\n\
| 0x<hexidecimal number>\n";
main(argc, argv)
int argc;
char **argv;
{
long int l;
char c, byte[TMAX], *bptr;
RANGE r, size;
int fcount, i, length;
struct {
int size;
char *bptr;
} field[FMAX];
size.start = 2;
size.end = 512;
fcount = 0;
bptr = byte;
while(--argc > 0){
++argv;
if(!strcmp(*argv, "-n")){
if(--argc == 0)
error(umsg);
l = atol(*++argv);
continue;
}
else
if(!strcmp(*argv, "-k")){
if(fcount == FMAX)
error("Too many fields");
bptr = byte;
while(--argc){
if(*(argv+1)[0] == '-'){
++argc;
break;
}
arg_range(*++argv,&r);
if(r.start > 0xff || r.end > 0xff)
error("character larger than 8 bits");
do{
*bptr++ = r.start++;
}while(r.start <= r.end);
}
i =
field[fcount].size = bptr - byte;
if(i){
bptr =
field[fcount].bptr = malloc(i);
memcpy(bptr, byte, i);
++fcount;
}
}
else
if(!strcmp(*argv, "-s")){
--argc;
arg_range(*++argv, &size);
}
else
error(umsg);
}
size.start -= 2;
size.end -= 2;
length =
i = 0;
for(;;){
c = field[i].bptr[rand() % field[i].size];
if(c == '\n' && length < size.start)
continue;
if(length++ == size.end){
c = '\n';
}
putchar(c);
if(c == '\n'){
length = 0;
if(--l == 0)
break;
i = 0;
}
if(c == '\t' && i < fcount-1)
++i;
}
}