1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
83
79
#define NO_YACC_SYMBOLS
85
#include <mysys/my_sys.h>
86
#include <mystrings/m_string.h>
80
#include "my_global.h"
87
83
#ifndef __GNU_LIBRARY__
88
84
#define __GNU_LIBRARY__ // Skip warnings in getopt.h
90
#include <mysys/my_getopt.h>
91
#include <drizzled/version.h>
86
#include <my_getopt.h>
87
#include "mysql_version.h"
94
90
const char *default_dbug_option="d:t:o,/tmp/gen_lex_hash.trace";
96
92
struct my_option my_long_options[] =
95
{"debug", '#', "This is a non-debug version. Catch this and exit",
96
0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
98
{"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
99
(uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
98
101
{"help", '?', "Display help and exit",
99
102
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
100
103
{"version", 'V', "Output version information and exit",
144
147
int index2= root->iresult;
145
148
const char *name2= (index2 < 0 ? sql_functions[-index2-1] :
146
149
symbols[index2]).name + len_from_begin;
147
root->first_char= (int) (unsigned char) name2[0];
150
root->first_char= (int) (uchar) name2[0];
148
151
root->last_char= (char) root->first_char;
149
152
tails= (hash_lex_struct*)malloc(sizeof(hash_lex_struct));
150
153
root->char_tails= tails;
166
169
end= tails + new_size - real_size;
167
170
for (cur= tails; cur<end; cur++)
168
171
cur->first_char= 0;
169
root->first_char= (int) (unsigned char) *name;
172
root->first_char= (int) (uchar) *name;
172
175
if (root->last_char<(*name))
222
225
SYMBOL *cur, *end= symbols + array_elements(symbols);
223
226
for (cur= symbols; cur < end; cur++)
224
cur->length=(unsigned char) strlen(cur->name);
227
cur->length=(uchar) strlen(cur->name);
225
228
end= sql_functions + array_elements(sql_functions);
226
229
for (cur= sql_functions; cur<end; cur++)
227
cur->length=(unsigned char) strlen(cur->name);
230
cur->length=(uchar) strlen(cur->name);
230
233
void generate_find_structs()
265
268
st->first_char == 0 ? 0 : st->last_char);
266
269
if (st->first_char == -1)
268
hash_map[size_hash_map-2]= ((unsigned int)(int16_t)st->iresult)&255;
269
hash_map[size_hash_map-1]= ((unsigned int)(int16_t)st->iresult)>>8;
271
hash_map[size_hash_map-2]= ((unsigned int)(int16)st->iresult)&255;
272
hash_map[size_hash_map-1]= ((unsigned int)(int16)st->iresult)>>8;
271
274
else if (st->first_char == 0)
273
hash_map[size_hash_map-2]= ((unsigned int)(int16_t)array_elements_func(symbols))&255;
274
hash_map[size_hash_map-1]= ((unsigned int)(int16_t)array_elements(symbols))>>8;
276
hash_map[size_hash_map-2]= ((unsigned int)(int16)array_elements_func(symbols))&255;
277
hash_map[size_hash_map-1]= ((unsigned int)(int16)array_elements(symbols))>>8;
312
printf("static unsigned char %s[%d]= {\n",name,size_hash_map);
315
printf("static uchar %s[%d]= {\n",name,size_hash_map);
313
316
for (i=0, cur= hash_map; i<size_hash_map; i++, cur++)
320
323
printf("\'%c\', ",*cur);
322
case 2: printf("%u, ",(uint)(unsigned char)*cur); break;
323
case 3: printf("%u,\n",(uint)(unsigned char)*cur); break;
325
case 2: printf("%u, ",(uint)(uchar)*cur); break;
326
case 3: printf("%u,\n",(uint)(uchar)*cur); break;
347
350
static void usage(int version)
349
352
printf("%s Ver 3.6 Distrib %s, for %s (%s)\n",
350
my_progname, DRIZZLE_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
353
my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
353
puts("Copyright (C) 2008 Sun Microsystems, Inc.");
356
puts("Copyright (C) 2001 MySQL AB, by VVA and Monty");
354
357
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
355
358
and you are welcome to modify and redistribute it under the GPL license\n");
356
359
puts("This program generates a perfect hashing function for the sql_lex.cc");
450
457
/* Broken up to indicate that it's not advice to you, gentle reader. */
451
458
printf("/*\n\n Do " "not " "edit " "this " "file " "directly!\n\n*/\n");
453
printf("/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- \n"
454
" * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: \n"
456
" * Copyright (C) 2008 Sun Microsystems \n"
458
" * This program is free software; you can redistribute it and/or modify \n"
459
" * it under the terms of the GNU General Public License as published by \n"
460
" * the Free Software Foundation; version 2 of the License. \n"
462
" * This program is distributed in the hope that it will be useful, \n"
463
" * but WITHOUT ANY WARRANTY; without even the implied warranty of \n"
464
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n"
465
" * GNU General Public License for more details. \n"
467
" * You should have received a copy of the GNU General Public License \n"
468
" * along with this program; if not, write to the Free Software \n"
469
" * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \n"
461
/* Copyright (C) 2001-2004 MySQL AB\n\
463
This program is free software; you can redistribute it and/or modify\n\
464
it under the terms of the GNU General Public License as published by\n\
465
the Free Software Foundation; version 2 of the License.\n\
467
This program is distributed in the hope that it will be useful,\n\
468
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
469
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
470
GNU General Public License for more details.\n\
472
You should have received a copy of the GNU General Public License\n\
473
along with this program; see the file COPYING. If not, write to the\n\
474
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston\n\
475
MA 02110-1301 USA. */\n\
472
479
/* Broken up to indicate that it's not advice to you, gentle reader. */
473
480
printf("/* Do " "not " "edit " "this " "file! This is generated by "
489
496
static SYMBOL *get_hash_symbol(const char *s,\n\
490
497
unsigned int len,bool function)\n\
492
register unsigned char *hash_map;\n\
499
register uchar *hash_map;\n\
493
500
register const char *cur_str= s;\n\
495
502
if (len == 0) {\n\
503
DBUG_PRINT(\"warning\", (\"get_hash_symbol() received a request for a zero-length symbol, which is probably a mistake.\"));\
501
509
if (function){\n\
502
510
if (len>sql_functions_max_len) return 0;\n\
503
511
hash_map= sql_functions_map;\n\
504
register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
512
register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
507
register unsigned char first_char= (unsigned char)cur_struct;\n\
515
register uchar first_char= (uchar)cur_struct;\n\
509
517
if (first_char == 0)\n\
511
register int16_t ires= (int16_t)(cur_struct>>16);\n\
519
register int16 ires= (int16)(cur_struct>>16);\n\
512
520
if (ires==array_elements(symbols)) return 0;\n\
513
521
register SYMBOL *res;\n\
515
523
res= symbols+ires;\n\
517
525
res= sql_functions-ires-1;\n\
518
register uint32_t count= cur_str-s;\n\
526
register uint count= cur_str-s;\n\
519
527
return lex_casecmp(cur_str,res->name+count,len-count) ? 0 : res;\n\
522
register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
530
register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
523
531
if (cur_char<first_char) return 0;\n\
524
532
cur_struct>>=8;\n\
525
if (cur_char>(unsigned char)cur_struct) return 0;\n\
533
if (cur_char>(uchar)cur_struct) return 0;\n\
527
535
cur_struct>>=8;\n\
528
536
cur_struct= uint4korr(hash_map+\n\
529
(((uint16_t)cur_struct + cur_char - first_char)*4));\n\
537
(((uint16)cur_struct + cur_char - first_char)*4));\n\
536
544
if (len>symbols_max_len) return 0;\n\
537
545
hash_map= symbols_map;\n\
538
register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
546
register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
541
register unsigned char first_char= (unsigned char)cur_struct;\n\
549
register uchar first_char= (uchar)cur_struct;\n\
543
551
if (first_char==0){\n\
544
register int16_t ires= (int16_t)(cur_struct>>16);\n\
552
register int16 ires= (int16)(cur_struct>>16);\n\
545
553
if (ires==array_elements(symbols)) return 0;\n\
546
554
register SYMBOL *res= symbols+ires;\n\
547
register uint32_t count= cur_str-s;\n\
555
register uint count= cur_str-s;\n\
548
556
return lex_casecmp(cur_str,res->name+count,len-count)!=0 ? 0 : res;\n\
551
register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
559
register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
552
560
if (cur_char<first_char) return 0;\n\
553
561
cur_struct>>=8;\n\
554
if (cur_char>(unsigned char)cur_struct) return 0;\n\
562
if (cur_char>(uchar)cur_struct) return 0;\n\
556
564
cur_struct>>=8;\n\
557
565
cur_struct= uint4korr(hash_map+\n\
558
(((uint16_t)cur_struct + cur_char - first_char)*4));\n\
566
(((uint16)cur_struct + cur_char - first_char)*4));\n\