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()
247
250
char *hash_map= 0;
248
251
int size_hash_map= 0;
250
/* Ok. I honestly don't know why this has no problem and
251
* array_elements macro doesn't. But it works.
253
static inline uint32_t array_elements_func(SYMBOL * symbols) {
254
return sizeof(symbols)/sizeof(symbols[0]);
257
253
void add_struct_to_map(hash_lex_struct *st)
259
255
st->ithis= size_hash_map/4;
260
256
size_hash_map+= 4;
261
257
hash_map= (char*)realloc((char*)hash_map,size_hash_map);
262
258
hash_map[size_hash_map-4]= (char) (st->first_char == -1 ? 0 :
264
260
hash_map[size_hash_map-3]= (char) (st->first_char == -1 ||
265
st->first_char == 0 ? 0 : st->last_char);
261
st->first_char == 0 ? 0 : st->last_char);
266
262
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;
264
hash_map[size_hash_map-2]= ((unsigned int)(int16)st->iresult)&255;
265
hash_map[size_hash_map-1]= ((unsigned int)(int16)st->iresult)>>8;
271
267
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;
269
hash_map[size_hash_map-2]= ((unsigned int)(int16)array_elements(symbols))&255;
270
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);
308
printf("static uchar %s[%d]= {\n",name,size_hash_map);
313
309
for (i=0, cur= hash_map; i<size_hash_map; i++, cur++)
320
316
printf("\'%c\', ",*cur);
322
case 2: printf("%u, ",(uint)(unsigned char)*cur); break;
323
case 3: printf("%u,\n",(uint)(unsigned char)*cur); break;
318
case 2: printf("%u, ",(uint)(uchar)*cur); break;
319
case 3: printf("%u,\n",(uint)(uchar)*cur); break;
347
343
static void usage(int version)
349
345
printf("%s Ver 3.6 Distrib %s, for %s (%s)\n",
350
my_progname, DRIZZLE_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
346
my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
353
puts("Copyright (C) 2008 Sun Microsystems, Inc.");
349
puts("Copyright (C) 2001 MySQL AB, by VVA and Monty");
354
350
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
355
351
and you are welcome to modify and redistribute it under the GPL license\n");
356
352
puts("This program generates a perfect hashing function for the sql_lex.cc");
450
450
/* Broken up to indicate that it's not advice to you, gentle reader. */
451
451
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"
454
/* Copyright (C) 2001-2004 MySQL AB\n\
456
This program is free software; you can redistribute it and/or modify\n\
457
it under the terms of the GNU General Public License as published by\n\
458
the Free Software Foundation; version 2 of the License.\n\
460
This program is distributed in the hope that it will be useful,\n\
461
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
462
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
463
GNU General Public License for more details.\n\
465
You should have received a copy of the GNU General Public License\n\
466
along with this program; see the file COPYING. If not, write to the\n\
467
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston\n\
468
MA 02110-1301 USA. */\n\
472
472
/* Broken up to indicate that it's not advice to you, gentle reader. */
473
473
printf("/* Do " "not " "edit " "this " "file! This is generated by "
489
489
static SYMBOL *get_hash_symbol(const char *s,\n\
490
490
unsigned int len,bool function)\n\
492
register unsigned char *hash_map;\n\
492
register uchar *hash_map;\n\
493
493
register const char *cur_str= s;\n\
495
495
if (len == 0) {\n\
496
DBUG_PRINT(\"warning\", (\"get_hash_symbol() received a request for a zero-length symbol, which is probably a mistake.\"));\
501
502
if (function){\n\
502
503
if (len>sql_functions_max_len) return 0;\n\
503
504
hash_map= sql_functions_map;\n\
504
register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
505
register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
507
register unsigned char first_char= (unsigned char)cur_struct;\n\
508
register uchar first_char= (uchar)cur_struct;\n\
509
510
if (first_char == 0)\n\
511
register int16_t ires= (int16_t)(cur_struct>>16);\n\
512
register int16 ires= (int16)(cur_struct>>16);\n\
512
513
if (ires==array_elements(symbols)) return 0;\n\
513
514
register SYMBOL *res;\n\
515
516
res= symbols+ires;\n\
517
518
res= sql_functions-ires-1;\n\
518
register uint32_t count= cur_str-s;\n\
519
register uint count= cur_str-s;\n\
519
520
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\
523
register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
523
524
if (cur_char<first_char) return 0;\n\
524
525
cur_struct>>=8;\n\
525
if (cur_char>(unsigned char)cur_struct) return 0;\n\
526
if (cur_char>(uchar)cur_struct) return 0;\n\
527
528
cur_struct>>=8;\n\
528
529
cur_struct= uint4korr(hash_map+\n\
529
(((uint16_t)cur_struct + cur_char - first_char)*4));\n\
530
(((uint16)cur_struct + cur_char - first_char)*4));\n\
536
537
if (len>symbols_max_len) return 0;\n\
537
538
hash_map= symbols_map;\n\
538
register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
539
register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
541
register unsigned char first_char= (unsigned char)cur_struct;\n\
542
register uchar first_char= (uchar)cur_struct;\n\
543
544
if (first_char==0){\n\
544
register int16_t ires= (int16_t)(cur_struct>>16);\n\
545
register int16 ires= (int16)(cur_struct>>16);\n\
545
546
if (ires==array_elements(symbols)) return 0;\n\
546
547
register SYMBOL *res= symbols+ires;\n\
547
register uint32_t count= cur_str-s;\n\
548
register uint count= cur_str-s;\n\
548
549
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\
552
register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
552
553
if (cur_char<first_char) return 0;\n\
553
554
cur_struct>>=8;\n\
554
if (cur_char>(unsigned char)cur_struct) return 0;\n\
555
if (cur_char>(uchar)cur_struct) return 0;\n\
556
557
cur_struct>>=8;\n\
557
558
cur_struct= uint4korr(hash_map+\n\
558
(((uint16_t)cur_struct + cur_char - first_char)*4));\n\
559
(((uint16)cur_struct + cur_char - first_char)*4));\n\