add .gitignore
[tedtools.git] / gendata.c
1 /*
2  * Copyright (c) 2005 Teodor Sigaev <teodor@sigaev.ru>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *      notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *      notice, this list of conditions and the following disclaimer in the
12  *      documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of any co-contributors
14  *      may be used to endorse or promote products derived from this software
15  *      without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <ctype.h>
35
36 #include "tlog.h"
37
38 static void
39 usage() {
40         puts(
41         "Usage:\n"
42         "tbtreetest  -b [-r -c COUNT -f] | -s [ -c COUNT ]\n"
43         );
44         exit(1);
45 }
46
47 extern char *optarg;
48 extern int opterr;
49
50 #define NO_MODE         0
51 #define MODE_BTREE      1
52 #define MODE_SFX        2
53
54 static char *symbols="qwertyuiopasdfghjklzxcvbnm1234567890";
55 static int symbolslen=0;
56
57 int
58 main(int argn, char *argv[]) {
59         int mode=NO_MODE;
60         int isrnd=0, count=10,i, isfind=0; 
61
62         opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
63         symbolslen=strlen(symbols);
64         
65           
66         while((i=getopt(argn,argv,"sbrc:f")) != EOF) {
67                 switch(i) {
68                         case 'f':
69                                 isfind=1;
70                                 break;
71                         case 'r':
72                                 isrnd=1;
73                                 break;
74                         case 'b':
75                                 if ( mode ) usage();
76                                 mode = MODE_BTREE;
77                                 break;
78                         case 's':
79                                 if ( mode ) usage();
80                                 mode = MODE_SFX;
81                                 break;
82                         case 'c':
83                                 count=atoi(optarg);
84                                 break;
85                         case 'h':
86                         default:
87                                 usage();
88                 }
89         }
90
91         if ( mode==MODE_BTREE ) {
92                 int cnt;
93                 if ( isfind ) 
94                         for(i=0;i<count;i++)
95                                 printf("S\t%d\n", (int)( (isrnd) ? random()%count : i )); 
96                 else    
97                         for(i=0;i<count;i++) {
98                                 printf("I\t%d\t", (int)( (isrnd) ? random()%count : i ));
99                                 cnt=1+random()%512;
100                                 while(cnt-->0)
101                                         fputc( symbols[ random()%symbolslen ], stdout);
102                                 fputc('\n', stdout);
103                         }
104         } else if ( mode==MODE_SFX ) {
105                 int cnt;
106                 for(i=0;i<count;i++) {
107                         cnt=1+random()%10;
108                         while(cnt-->0)
109                                 fputc( tolower(symbols[ random()%symbolslen ]), stdout);
110                         fputc('\n', stdout);
111                 }
112         } else {
113                 usage();
114         }
115         return 0;
116 }