BTree realization
[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] \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
53
54 int
55 main(int argn, char *argv[]) {
56         int mode=NO_MODE;
57         int isrnd=0, count=10,i; 
58
59         opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
60           
61         while((i=getopt(argn,argv,"brc:")) != EOF) {
62                 switch(i) {
63                         case 'r':
64                                 isrnd=1;
65                                 break;
66                         case 'b':
67                                 if ( mode ) usage();
68                                 mode = MODE_BTREE;
69                                 break;
70                         case 'c':
71                                 count=atoi(optarg);
72                                 break;
73                         case 'h':
74                         default:
75                                 usage();
76                 }
77         }
78
79         if ( mode==MODE_BTREE ) {
80                 int j, cnt,c;
81                 for(i=0;i<count;i++) {
82                         printf("I\t%d\t", (int)( (isrnd) ? random()%count : i ));
83                         cnt=1+random()%512;
84                         for(j=0;j<cnt;j++) {
85                                 do { c=random()%128; } while ( !isalnum(c) );   
86                                 fputc(c, stdout);
87                         }
88                         fputc('\n', stdout);
89                 }
90         } else {
91                 usage();
92         }
93         return 0;
94 }