puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB, by Sinisa and Monty");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
puts("This program generates a perfect hashing function for the sql_lex.cc");
printf("Usage: %s [OPTIONS]\n", my_progname);
printf("\n\
-c, --count=# Try count times to find a optimal hash table\n\
-r, --rnd1=# Set 1 part of rnd value for hash generator\n\
-R, --rnd2=# Set 2 part of rnd value for hash generator\n\
-t, --type=# Set type of char table to generate\n\
-S, --search Search after good rnd1 and rnd2 values\n\
-v, --verbose Write some information while the program executes\n\
-V, --version Output version information and exit\n");
}
static uint best_type;
static ulong best_t1,best_t2;
static int get_options(int argc, char **argv)
{
int c,option_index=0;
while ((c=getopt_long(argc,argv,"?SvVc:r:R:t:",
long_options, &option_index)) != EOF)
{
switch(c) {
case 'c':
opt_count=atol(optarg);
break;
case 'r':
best_t1=atol(optarg);
break;
case 'R':
best_t2=atol(optarg);
break;
case 't':
best_type=atoi(optarg);
break;
case 'S':
opt_search=1;
break;
case 'v':
opt_verbose=1;
break;
case 'V': usage(1); exit(0);
case 'I':
case '?':
usage(0);
exit(0);
default:
fprintf(stderr,"illegal option: -%c\n",opterr);
usage(0);
exit(1);
}
}
argc-=optind;
argv+=optind;
if (argc >= 1)
{
usage(0);
exit(1);
}
return(0);
}
static uint max_prefix(const char *name)
{
uint i;
uint max_length=1;
for (i=0 ; i < sizeof(symbols)/sizeof(SYMBOL) ; i++)
{
const char *str=symbols[i].name;
if (str != name)
{
const char *str2=name;
uint length;
while (*str && *str == *str2)
{
str++;
str2++;
}
length=(uint) (str2 - name)+1;
if (length > max_length)
max_length=length;
}
}
for (i=0 ; i < sizeof(sql_functions)/sizeof(SYMBOL) ; i++)
{
const char *str=sql_functions[i].name;
if (str != name)
{
const char *str2=name;
uint length;
while (*str && *str == *str2)
{
str++;
str2++;
}
length=(uint) (str2 - name)+1;
if (length > max_length)
max_length=length;
}
}
return max_length;
}
static void make_max_length_table(void)
{
uint i;
for (i=0 ; i < sizeof(symbols)/sizeof(SYMBOL) ; i++)
{
uint length=max_prefix(symbols[i].name);
if (length > unique_length[(uchar) symbols[i].name[0]])