1
/* Copyright (C) 2000 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 */
16
#include <my_global.h>
24
#define MAX_BUF 64*1024
26
static CHARSET_INFO all_charsets[256];
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; cs < all_charsets+255; ++cs)
68
if ( cs->name && !strcmp(cs->name, charset_name))
74
char *mdup(const char *src, uint len)
76
char *dst=(char*)malloc(len);
83
static void simple_cs_copy_data(CHARSET_INFO *to, CHARSET_INFO *from)
85
to->number= from->number ? from->number : to->number;
86
to->state|= from->state;
89
to->csname= strdup(from->csname);
92
to->name= strdup(from->name);
95
to->ctype= (uchar*) mdup((char*) from->ctype, MY_CS_CTYPE_TABLE_SIZE);
97
to->to_lower= (uchar*) mdup((char*) from->to_lower, MY_CS_TO_LOWER_TABLE_SIZE);
99
to->to_upper= (uchar*) mdup((char*) from->to_upper, MY_CS_TO_UPPER_TABLE_SIZE);
100
if (from->sort_order)
102
to->sort_order= (uchar*) mdup((char*) from->sort_order, MY_CS_SORT_ORDER_TABLE_SIZE);
104
set_max_sort_char(to);
107
if (from->tab_to_uni)
109
uint sz= MY_CS_TO_UNI_TABLE_SIZE*sizeof(uint16);
110
to->tab_to_uni= (uint16*) mdup((char*)from->tab_to_uni, sz);
117
static my_bool simple_cs_is_full(CHARSET_INFO *cs)
119
return ((cs->csname && cs->tab_to_uni && cs->ctype && cs->to_upper &&
121
(cs->number && cs->name &&
122
(cs->sort_order || (cs->state & MY_CS_BINSORT))));
125
static int add_collation(CHARSET_INFO *cs)
127
if (cs->name && (cs->number || (cs->number=get_charset_number(cs->name))))
129
if (!(all_charsets[cs->number].state & MY_CS_COMPILED))
131
simple_cs_copy_data(&all_charsets[cs->number],cs);
138
cs->sort_order= NULL;
145
static int my_read_charset_file(const char *filename)
151
if ((fd=open(filename,O_RDONLY)) < 0)
153
fprintf(stderr,"Can't open '%s'\n",filename);
157
len=read(fd,buf,MAX_BUF);
158
DBUG_ASSERT(len < MAX_BUF);
161
if (my_parse_charset_xml(buf,len,add_collation))
164
printf("ERROR at line %d pos %d '%s'\n",
165
my_xml_error_lineno(&p)+1,
166
my_xml_error_pos(&p),
167
my_xml_error_string(&p));
175
is_case_sensitive(CHARSET_INFO *cs)
177
return (cs->sort_order &&
178
cs->sort_order['A'] < cs->sort_order['a'] &&
179
cs->sort_order['a'] < cs->sort_order['B']) ? 1 : 0;
183
void dispcset(FILE *f,CHARSET_INFO *cs)
186
fprintf(f," %d,%d,%d,\n",cs->number,0,0);
187
fprintf(f," MY_CS_COMPILED%s%s%s%s%s,\n",
188
cs->state & MY_CS_BINSORT ? "|MY_CS_BINSORT" : "",
189
cs->state & MY_CS_PRIMARY ? "|MY_CS_PRIMARY" : "",
190
is_case_sensitive(cs) ? "|MY_CS_CSSORT" : "",
191
my_charset_is_8bit_pure_ascii(cs) ? "|MY_CS_PUREASCII" : "",
192
!my_charset_is_ascii_compatible(cs) ? "|MY_CS_NONASCII": "");
196
fprintf(f," \"%s\", /* cset name */\n",cs->csname);
197
fprintf(f," \"%s\", /* coll name */\n",cs->name);
198
fprintf(f," \"\", /* comment */\n");
199
fprintf(f," NULL, /* tailoring */\n");
200
fprintf(f," ctype_%s, /* ctype */\n",cs->name);
201
fprintf(f," to_lower_%s, /* lower */\n",cs->name);
202
fprintf(f," to_upper_%s, /* upper */\n",cs->name);
204
fprintf(f," sort_order_%s, /* sort_order */\n",cs->name);
206
fprintf(f," NULL, /* sort_order */\n");
207
fprintf(f," NULL, /* contractions */\n");
208
fprintf(f," NULL, /* sort_order_big*/\n");
209
fprintf(f," to_uni_%s, /* to_uni */\n",cs->name);
213
fprintf(f," NULL, /* cset name */\n");
214
fprintf(f," NULL, /* coll name */\n");
215
fprintf(f," NULL, /* comment */\n");
216
fprintf(f," NULL, /* tailoging */\n");
217
fprintf(f," NULL, /* ctype */\n");
218
fprintf(f," NULL, /* lower */\n");
219
fprintf(f," NULL, /* upper */\n");
220
fprintf(f," NULL, /* sort order */\n");
221
fprintf(f," NULL, /* contractions */\n");
222
fprintf(f," NULL, /* sort_order_big*/\n");
223
fprintf(f," NULL, /* to_uni */\n");
226
fprintf(f," NULL, /* from_uni */\n");
227
fprintf(f," my_unicase_default, /* caseinfo */\n");
228
fprintf(f," NULL, /* state map */\n");
229
fprintf(f," NULL, /* ident map */\n");
230
fprintf(f," 1, /* strxfrm_multiply*/\n");
231
fprintf(f," 1, /* caseup_multiply*/\n");
232
fprintf(f," 1, /* casedn_multiply*/\n");
233
fprintf(f," 1, /* mbminlen */\n");
234
fprintf(f," 1, /* mbmaxlen */\n");
235
fprintf(f," 0, /* min_sort_char */\n");
236
fprintf(f," 255, /* max_sort_char */\n");
237
fprintf(f," ' ', /* pad_char */\n");
238
fprintf(f," 0, /* escape_with_backslash_is_dangerous */\n");
239
fprintf(f," 1, /* levels_for_compare */\n");
240
fprintf(f," 1, /* levels_for_order */\n");
242
fprintf(f," &my_charset_8bit_handler,\n");
243
if (cs->state & MY_CS_BINSORT)
244
fprintf(f," &my_collation_8bit_bin_handler,\n");
246
fprintf(f," &my_collation_8bit_simple_ci_handler,\n");
252
fprint_copyright(FILE *file)
255
"/* Copyright (C) 2000-2007 MySQL AB\n"
257
" This program is free software; you can redistribute it and/or modify\n"
258
" it under the terms of the GNU General Public License as published by\n"
259
" the Free Software Foundation; version 2 of the License.\n"
261
" This program is distributed in the hope that it will be useful,\n"
262
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
263
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
264
" GNU General Public License for more details.\n"
266
" You should have received a copy of the GNU General Public License\n"
267
" along with this program; if not, write to the Free Software\n"
268
" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */\n"
274
main(int argc, char **argv __attribute__((unused)))
283
fprintf(stderr, "usage: %s source-dir\n", argv[0]);
287
bzero((void*)&ncs,sizeof(ncs));
288
bzero((void*)&all_charsets,sizeof(all_charsets));
290
sprintf(filename,"%s/%s",argv[1],"Index.xml");
291
my_read_charset_file(filename);
293
for (cs=all_charsets; cs < all_charsets+256; cs++)
295
if (cs->number && !(cs->state & MY_CS_COMPILED))
297
if ( (!simple_cs_is_full(cs)) && (cs->csname))
299
sprintf(filename,"%s/%s.xml",argv[1],cs->csname);
300
my_read_charset_file(filename);
306
fprintf(f, " This file was generated by the conf_to_src utility. "
307
"Do not edit it directly,\n");
308
fprintf(f, " edit the XML definitions in sql/share/charsets/ instead.\n\n");
309
fprintf(f, " To re-generate, run the following in the strings/ "
311
fprintf(f, " ./conf_to_src ../sql/share/charsets/ > FILE\n");
312
fprintf(f, "*/\n\n");
314
fprintf(f,"#include <my_global.h>\n");
315
fprintf(f,"#include <m_ctype.h>\n\n");
318
for (cs=all_charsets; cs < all_charsets+256; cs++)
320
if (simple_cs_is_full(cs))
322
fprintf(f,"#ifdef HAVE_CHARSET_%s\n",cs->csname);
323
print_array(f, cs->name, "ctype", cs->ctype, MY_CS_CTYPE_TABLE_SIZE);
324
print_array(f, cs->name, "to_lower", cs->to_lower, MY_CS_TO_LOWER_TABLE_SIZE);
325
print_array(f, cs->name, "to_upper", cs->to_upper, MY_CS_TO_UPPER_TABLE_SIZE);
327
print_array(f, cs->name, "sort_order", cs->sort_order, MY_CS_SORT_ORDER_TABLE_SIZE);
328
print_array16(f, cs->name, "to_uni", cs->tab_to_uni, MY_CS_TO_UNI_TABLE_SIZE);
329
fprintf(f,"#endif\n");
334
fprintf(f,"CHARSET_INFO compiled_charsets[] = {\n");
335
for (cs=all_charsets; cs < all_charsets+256; cs++)
337
if (simple_cs_is_full(cs))
339
fprintf(f,"#ifdef HAVE_CHARSET_%s\n",cs->csname);
342
fprintf(f,"#endif\n");