adding check for duplicated symbols

parent 558ee89e
......@@ -90,6 +90,7 @@ tonu@x153.internalnet
tonu@x3.internalnet
venu@myvenu.com
venu@work.mysql.com
vva@eagle.mysql.r18.ru
vva@genie.(none)
walrus@mysql.com
wax@mysql.com
......
......@@ -200,19 +200,21 @@ void insert_sql_functions()
}
}
void generate_find_structs()
void calc_length()
{
root_by_len= 0;
max_len=0;
size_t i;
SYMBOL *cur, *end= symbols + array_elements(symbols);
for (cur= symbols; cur < end; cur++)
cur->length=(uchar) strlen(cur->name);
end= sql_functions + array_elements(sql_functions);
for (cur= sql_functions; cur<end; cur++)
cur->length=(uchar) strlen(cur->name);
}
void generate_find_structs()
{
root_by_len= 0;
max_len=0;
insert_symbols();
root_by_len2= root_by_len;
......@@ -351,6 +353,45 @@ static int get_options(int argc, char **argv)
return(0);
}
int check_dup_symbols(SYMBOL *s1, SYMBOL *s2)
{
if (s1->length!=s2->length || strncmp(s1->name,s2->name,s1->length))
return 0;
const char *err_tmpl= "\ngen_lex_hash fatal error : \
Unfortunately gen_lex_hash can not generate a hash,\n since \
your lex.h has duplicate definition for a symbol \"%s\"\n\n";
printf (err_tmpl,s1->name);
fprintf (stderr,err_tmpl,s1->name);
return 1;
}
int check_duplicates()
{
SYMBOL *cur1, *cur2, *s_end, *f_end;
s_end= symbols + array_elements(symbols);
f_end= sql_functions + array_elements(sql_functions);
for (cur1= symbols; cur1<s_end; cur1++)
{
for (cur2= cur1+1; cur2<s_end; cur2++)
if (check_dup_symbols(cur1,cur2))
return 1;
for (cur2= sql_functions; cur2<f_end; cur2++)
if (check_dup_symbols(cur1,cur2))
return 1;
}
for (cur1= sql_functions; cur1<f_end; cur1++)
for (cur2= cur1+1; cur2< f_end; cur2++)
if (check_dup_symbols(cur1,cur2))
return 1;
return 0;
}
int main(int argc,char **argv)
{
MY_INIT(argv[0]);
......@@ -376,6 +417,11 @@ int main(int argc,char **argv)
a perfect\nhash function */\n\n");
printf("#include \"lex.h\"\n\n");
calc_length();
if (check_duplicates())
exit(1);
generate_find_structs();
print_find_structs();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment