/* * Copyright (c) 2005 Teodor Sigaev * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include "tlog.h" static void usage() { puts( "Usage:\n" "tbtreetest -b [-r -c COUNT -f] | -s [ -c COUNT ]\n" ); exit(1); } extern char *optarg; extern int opterr; #define NO_MODE 0 #define MODE_BTREE 1 #define MODE_SFX 2 static char *symbols="qwertyuiopasdfghjklzxcvbnm1234567890"; static int symbolslen=0; int main(int argn, char *argv[]) { int mode=NO_MODE; int isrnd=0, count=10,i, isfind=0; opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL); symbolslen=strlen(symbols); while((i=getopt(argn,argv,"sbrc:f")) != EOF) { switch(i) { case 'f': isfind=1; break; case 'r': isrnd=1; break; case 'b': if ( mode ) usage(); mode = MODE_BTREE; break; case 's': if ( mode ) usage(); mode = MODE_SFX; break; case 'c': count=atoi(optarg); break; case 'h': default: usage(); } } if ( mode==MODE_BTREE ) { int cnt; if ( isfind ) for(i=0;i0) fputc( symbols[ random()%symbolslen ], stdout); fputc('\n', stdout); } } else if ( mode==MODE_SFX ) { int cnt; for(i=0;i0) fputc( tolower(symbols[ random()%symbolslen ]), stdout); fputc('\n', stdout); } } else { usage(); } return 0; }