16 #include <my_global.h>
24 #define MAX_BUF 64*1024
30 print_array(FILE *f,
const char *
set,
const char *
name, uchar *a,
int n)
34 fprintf(f,
"uchar %s_%s[] = {\n", name,
set);
38 fprintf(f,
"0x%02X",a[i]);
39 fprintf(f, (i+1<n) ?
"," :
"" );
40 fprintf(f, ((i+1) % ROW_LEN == n % ROW_LEN) ?
"\n" :
"" );
47 print_array16(FILE *f,
const char *
set,
const char *name, uint16 *a,
int n)
51 fprintf(f,
"uint16 %s_%s[] = {\n", name,
set);
55 fprintf(f,
"0x%04X",a[i]);
56 fprintf(f, (i+1<n) ?
"," :
"" );
57 fprintf(f, ((i+1) % ROW16_LEN == n % ROW16_LEN) ?
"\n" :
"" );
63 static int get_charset_number(
const char *charset_name)
66 for (cs= all_charsets;
67 cs < all_charsets + array_elements(all_charsets);
70 if ( cs->name && !strcmp(cs->name, charset_name))
76 char *mdup(
const char *src, uint len)
78 char *dst=(
char*)malloc(len);
87 to->number= from->number ? from->number : to->number;
88 to->state|= from->state;
91 to->csname= strdup(from->csname);
94 to->name= strdup(from->name);
97 to->ctype= (uchar*) mdup((
char*) from->ctype, MY_CS_CTYPE_TABLE_SIZE);
99 to->to_lower= (uchar*) mdup((
char*) from->to_lower, MY_CS_TO_LOWER_TABLE_SIZE);
101 to->to_upper= (uchar*) mdup((
char*) from->to_upper, MY_CS_TO_UPPER_TABLE_SIZE);
102 if (from->sort_order)
104 to->sort_order= (uchar*) mdup((
char*) from->sort_order, MY_CS_SORT_ORDER_TABLE_SIZE);
109 if (from->tab_to_uni)
111 uint sz= MY_CS_TO_UNI_TABLE_SIZE*
sizeof(uint16);
112 to->tab_to_uni= (uint16*) mdup((
char*)from->tab_to_uni, sz);
121 return ((cs->csname && cs->tab_to_uni && cs->ctype && cs->to_upper &&
123 (cs->number && cs->name &&
124 (cs->sort_order || (cs->state & MY_CS_BINSORT))));
129 if (cs->name && (cs->number || (cs->number=get_charset_number(cs->name))))
131 if (!(all_charsets[cs->number].state & MY_CS_COMPILED))
133 simple_cs_copy_data(&all_charsets[cs->number],cs);
140 cs->sort_order= NULL;
148 default_reporter(
enum loglevel
level __attribute__ ((unused)),
149 const char *format __attribute__ ((unused)),
158 loader->error[0]=
'\0';
159 loader->once_alloc= malloc;
160 loader->malloc= malloc;
161 loader->realloc= realloc;
163 loader->reporter= default_reporter;
164 loader->add_collation= add_collation;
168 static int my_read_charset_file(
const char *filename)
175 my_charset_loader_init(&loader);
176 if ((fd=open(filename,O_RDONLY)) < 0)
178 fprintf(stderr,
"Can't open '%s'\n",filename);
182 len=read(fd,buf,MAX_BUF);
183 DBUG_ASSERT(len < MAX_BUF);
186 if (my_parse_charset_xml(&loader, buf, len))
188 fprintf(stderr,
"Error while parsing '%s': %s\n", filename, loader.error);
198 return (cs->sort_order &&
199 cs->sort_order[
'A'] < cs->sort_order[
'a'] &&
200 cs->sort_order[
'a'] < cs->sort_order[
'B']) ? 1 : 0;
207 fprintf(f,
" %d,%d,%d,\n",cs->number,0,0);
208 fprintf(f,
" MY_CS_COMPILED%s%s%s%s%s,\n",
209 cs->state & MY_CS_BINSORT ?
"|MY_CS_BINSORT" :
"",
210 cs->state & MY_CS_PRIMARY ?
"|MY_CS_PRIMARY" :
"",
211 is_case_sensitive(cs) ?
"|MY_CS_CSSORT" :
"",
212 my_charset_is_8bit_pure_ascii(cs) ?
"|MY_CS_PUREASCII" :
"",
213 !my_charset_is_ascii_compatible(cs) ?
"|MY_CS_NONASCII":
"");
217 fprintf(f,
" \"%s\", /* cset name */\n",cs->csname);
218 fprintf(f,
" \"%s\", /* coll name */\n",cs->name);
219 fprintf(f,
" \"\", /* comment */\n");
220 fprintf(f,
" NULL, /* tailoring */\n");
221 fprintf(f,
" ctype_%s, /* ctype */\n",cs->name);
222 fprintf(f,
" to_lower_%s, /* lower */\n",cs->name);
223 fprintf(f,
" to_upper_%s, /* upper */\n",cs->name);
225 fprintf(f,
" sort_order_%s, /* sort_order */\n",cs->name);
227 fprintf(f,
" NULL, /* sort_order */\n");
228 fprintf(f,
" NULL, /* uca */\n");
229 fprintf(f,
" to_uni_%s, /* to_uni */\n",cs->name);
233 fprintf(f,
" NULL, /* cset name */\n");
234 fprintf(f,
" NULL, /* coll name */\n");
235 fprintf(f,
" NULL, /* comment */\n");
236 fprintf(f,
" NULL, /* tailoging */\n");
237 fprintf(f,
" NULL, /* ctype */\n");
238 fprintf(f,
" NULL, /* lower */\n");
239 fprintf(f,
" NULL, /* upper */\n");
240 fprintf(f,
" NULL, /* sort order */\n");
241 fprintf(f,
" NULL, /* uca */\n");
242 fprintf(f,
" NULL, /* to_uni */\n");
245 fprintf(f,
" NULL, /* from_uni */\n");
246 fprintf(f,
" &my_unicase_default, /* caseinfo */\n");
247 fprintf(f,
" NULL, /* state map */\n");
248 fprintf(f,
" NULL, /* ident map */\n");
249 fprintf(f,
" 1, /* strxfrm_multiply*/\n");
250 fprintf(f,
" 1, /* caseup_multiply*/\n");
251 fprintf(f,
" 1, /* casedn_multiply*/\n");
252 fprintf(f,
" 1, /* mbminlen */\n");
253 fprintf(f,
" 1, /* mbmaxlen */\n");
254 fprintf(f,
" 0, /* min_sort_char */\n");
255 fprintf(f,
" 255, /* max_sort_char */\n");
256 fprintf(f,
" ' ', /* pad_char */\n");
257 fprintf(f,
" 0, /* escape_with_backslash_is_dangerous */\n");
258 fprintf(f,
" 1, /* levels_for_compare */\n");
259 fprintf(f,
" 1, /* levels_for_order */\n");
261 fprintf(f,
" &my_charset_8bit_handler,\n");
262 if (cs->state & MY_CS_BINSORT)
263 fprintf(f,
" &my_collation_8bit_bin_handler,\n");
265 fprintf(f,
" &my_collation_8bit_simple_ci_handler,\n");
271 fprint_copyright(FILE *
file)
274 "/* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.\n"
276 " This program is free software; you can redistribute it and/or modify\n"
277 " it under the terms of the GNU General Public License as published by\n"
278 " the Free Software Foundation; version 2 of the License.\n"
280 " This program is distributed in the hope that it will be useful,\n"
281 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
282 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
283 " GNU General Public License for more details.\n"
285 " You should have received a copy of the GNU General Public License\n"
286 " along with this program; if not, write to the Free Software\n"
287 " Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */\n"
293 main(
int argc,
char **argv __attribute__((unused)))
302 fprintf(stderr,
"usage: %s source-dir\n", argv[0]);
306 memset(&ncs, 0,
sizeof(ncs));
307 memset(&all_charsets, 0,
sizeof(all_charsets));
309 sprintf(filename,
"%s/%s",argv[1],
"Index.xml");
310 my_read_charset_file(filename);
312 for (cs= all_charsets;
313 cs < all_charsets + array_elements(all_charsets);
316 if (cs->number && !(cs->state & MY_CS_COMPILED))
318 if ( (!simple_cs_is_full(cs)) && (cs->csname))
320 sprintf(filename,
"%s/%s.xml",argv[1],cs->csname);
321 my_read_charset_file(filename);
327 fprintf(f,
" This file was generated by the conf_to_src utility. "
328 "Do not edit it directly,\n");
329 fprintf(f,
" edit the XML definitions in sql/share/charsets/ instead.\n\n");
330 fprintf(f,
" To re-generate, run the following in the strings/ "
332 fprintf(f,
" ./conf_to_src ../sql/share/charsets/ > FILE\n");
333 fprintf(f,
"*/\n\n");
335 fprintf(f,
"#include <my_global.h>\n");
336 fprintf(f,
"#include <m_ctype.h>\n\n");
339 for (cs= all_charsets;
340 cs < all_charsets + array_elements(all_charsets);
343 if (simple_cs_is_full(cs))
345 fprintf(f,
"#ifdef HAVE_CHARSET_%s\n",cs->csname);
346 print_array(f, cs->name,
"ctype", cs->ctype, MY_CS_CTYPE_TABLE_SIZE);
347 print_array(f, cs->name,
"to_lower", cs->to_lower, MY_CS_TO_LOWER_TABLE_SIZE);
348 print_array(f, cs->name,
"to_upper", cs->to_upper, MY_CS_TO_UPPER_TABLE_SIZE);
350 print_array(f, cs->name,
"sort_order", cs->sort_order, MY_CS_SORT_ORDER_TABLE_SIZE);
351 print_array16(f, cs->name,
"to_uni", cs->tab_to_uni, MY_CS_TO_UNI_TABLE_SIZE);
352 fprintf(f,
"#endif\n");
357 fprintf(f,
"CHARSET_INFO compiled_charsets[] = {\n");
358 for (cs= all_charsets;
359 cs < all_charsets + array_elements(all_charsets);
362 if (simple_cs_is_full(cs))
364 fprintf(f,
"#ifdef HAVE_CHARSET_%s\n",cs->csname);
367 fprintf(f,
"#endif\n");