1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* can't use -lmysys because this prog is used to create -lstrings */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <my_global.h>
#include <m_ctype.h>
#include <my_xml.h>
#define CHARSETS_SUBDIR "sql/share/charsets"
#define CTYPE_TABLE_SIZE 257
#define TO_LOWER_TABLE_SIZE 256
#define TO_UPPER_TABLE_SIZE 256
#define SORT_ORDER_TABLE_SIZE 256
#define ROW_LEN 16
char *prog;
char buf[1024], *p, *endptr;
void
print_array(FILE *f, const char *set, const char *name, int n)
{
int i;
char val[100];
printf("uchar %s_%s[] = {\n", name, set);
p = buf;
*buf = '\0';
for (i = 0; i < n; ++i)
{
/* get a word from f */
endptr = p;
for (;;)
{
while (isspace((* (unsigned char*) endptr)))
++endptr;
if (*endptr && *endptr != '#') /* not comment */
break;
if ((fgets(buf, sizeof(buf), f)) == NULL)
return; /* XXX: break silently */
endptr = buf;
}
p = val;
while (!isspace((* (unsigned char*) endptr)))
*p++ = *endptr++;
*p = '\0';
p = endptr;
/* write the value out */
if (i == 0 || i % ROW_LEN == n % ROW_LEN)
printf(" ");
printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16));
if (i < n - 1)
printf(",");
if ((i+1) % ROW_LEN == n % ROW_LEN)
printf("\n");
}
printf("};\n\n");
}
void
print_arrays_for(char *set)
{
FILE *f;
sprintf(buf, "%s.conf", set);
if ((f = fopen(buf, "r")) == NULL) {
fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set);
exit(EXIT_FAILURE);
}
printf("\
/* The %s character set. Generated automatically by\n\
* the %s program\n\
*/\n\n",
set, prog);
/* it would be nice if this used the code in mysys/charset.c, but... */
print_array(f, set, "ctype", CTYPE_TABLE_SIZE);
print_array(f, set, "to_lower", TO_LOWER_TABLE_SIZE);
print_array(f, set, "to_upper", TO_UPPER_TABLE_SIZE);
print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE);
printf("\n");
fclose(f);
return;
}
#define MAX_BUF 16*1024
static CHARSET_INFO all_charsets[256];
static int get_charset_number(const char *charset_name)
{
CHARSET_INFO *cs;
for (cs= all_charsets; cs < all_charsets+255; ++cs)
{
if ( cs->name && !strcmp(cs->name, charset_name))
return cs->number;
}
return 0;
}
static void simple_cs_copy_data()
{
}
static int add_collation(CHARSET_INFO *cs)
{
if (cs->name && (cs->number || (cs->number=get_charset_number(cs->name))))
{
#if 0
if (!(all_charsets[cs->number].state & MY_CS_COMPILED))
{
simple_cs_copy_data(all_charsets[cs->number],cs);
if (simple_cs_is_full(all_charsets[cs->number]))
{
simple_cs_init_functions(all_charsets[cs->number]);
all_charsets[cs->number]->state |= MY_CS_LOADED;
}
}
cs->number= 0;
cs->name= NULL;
cs->state= 0;
cs->sort_order= NULL;
cs->state= 0;
#endif
}
return MY_XML_OK;
}
static int my_read_charset_file(const char *filename)
{
char buf[MAX_BUF];
int fd;
uint len;
if ((fd=open(filename,O_RDONLY)) < 0)
return 1;
len=read(fd,buf,MAX_BUF);
close(fd);
if (my_parse_charset_xml(buf,len,add_collation))
{
#if 0
printf("ERROR at line %d pos %d '%s'\n",
my_xml_error_lineno(&p)+1,
my_xml_error_pos(&p),
my_xml_error_string(&p));
#endif
}
return FALSE;
}
int main()
{
bzero(&all_charsets,sizeof(all_charsets));
return 0;
}
|