1
/* Copyright (C) 2004 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
20
typedef unsigned char uchar;
21
typedef unsigned short uint16;
30
#define MY_UCA_NPAGES 1024
31
#define MY_UCA_NCHARS 64
32
#define MY_UCA_CMASK 63
33
#define MY_UCA_PSHIFT 6
35
#define MY_UCA_NPAGES 256
36
#define MY_UCA_NCHARS 256
37
#define MY_UCA_CMASK 255
38
#define MY_UCA_PSHIFT 8
41
static char *pname[]= {"", "2", "3"};
43
int main(int ac, char **av)
47
struct uca_item_st uca[64*1024];
49
int pageloaded[MY_UCA_NPAGES];
51
bzero(uca, sizeof(uca));
52
bzero(pageloaded, sizeof(pageloaded));
54
while (fgets(str,sizeof(str),stdin))
61
code= strtol(str,NULL,16);
63
if (str[0]=='#' || (code > 0xFFFF))
65
if ((comment=strchr(str,'#')))
68
for ( ; *comment==' ' ; comment++);
72
if ((weight=strchr(str,';')))
75
for ( ; *weight==' ' ; weight++);
81
s= strtok(str, " \t");
84
s= strtok(NULL, " \t");
90
/* Multi-character weight,
98
s= strtok(weight, " []");
101
weights[uca[code].num]= s;
102
s= strtok(NULL, " []");
106
for (w=0; w < uca[code].num; w++)
116
part= strtol(s+1,&endptr,16);
117
uca[code].weight[partnum][w]= part;
122
/* Mark that a character from this page was loaded */
123
pageloaded[code >> MY_UCA_PSHIFT]++;
128
/* Now set implicit weights */
129
for (code=0; code <= 0xFFFF; code++)
131
size_t base, aaaa, bbbb;
137
3400;<CJK Ideograph Extension A, First>
138
4DB5;<CJK Ideograph Extension A, Last>
139
4E00;<CJK Ideograph, First>
140
9FA5;<CJK Ideograph, Last>
143
if (code >= 0x3400 && code <= 0x4DB5)
145
else if (code >= 0x4E00 && code <= 0x9FA5)
150
aaaa= base + (code >> 15);
151
bbbb= (code & 0x7FFF) | 0x8000;
152
uca[code].weight[0][0]= aaaa;
153
uca[code].weight[0][1]= bbbb;
155
uca[code].weight[1][0]= 0x0020;
156
uca[code].weight[1][1]= 0x0000;
158
uca[code].weight[2][0]= 0x0002;
159
uca[code].weight[2][1]= 0x0000;
161
uca[code].weight[3][0]= 0x0001;
162
uca[code].weight[3][2]= 0x0000;
167
printf("#include \"my_uca.h\"\n");
169
printf("#define MY_UCA_NPAGES %d\n",MY_UCA_NPAGES);
170
printf("#define MY_UCA_NCHARS %d\n",MY_UCA_NCHARS);
171
printf("#define MY_UCA_CMASK %d\n",MY_UCA_CMASK);
172
printf("#define MY_UCA_PSHIFT %d\n",MY_UCA_PSHIFT);
177
int pagemaxlen[MY_UCA_NPAGES];
179
for (page=0; page < MY_UCA_NPAGES; page++)
190
Skip this page if no weights were loaded
193
if (!pageloaded[page])
197
Calculate maximum weight
201
for (offs=0; offs < MY_UCA_NCHARS; offs++)
205
code= page*MY_UCA_NCHARS+offs;
207
/* Calculate only non-zero weights */
208
for (num=0, i=0; i < uca[code].num; i++)
209
if (uca[code].weight[w][i])
212
maxnum= maxnum < num ? num : maxnum;
214
/* Check if default weight */
215
if (w == 1 && num == 1)
218
if (uca[code].weight[w][0] == 0x0020)
221
else if (w == 2 && num == 1)
224
if (uca[code].weight[w][0] == 0x0002)
231
If the page have only default weights
232
then no needs to dump it, skip.
234
if (ndefs == MY_UCA_NCHARS)
240
case 0: mchars= 8; break;
241
case 1: mchars= 8; break;
242
case 2: mchars= 8; break;
243
case 3: mchars= 9; break;
244
case 4: mchars= 8; break;
245
default: mchars= uca[code].num;
248
pagemaxlen[page]= maxnum;
256
printf("uint16 page%03Xdata%s[]= { /* %04X (%d weights per char) */\n",
257
page, pname[w], page*MY_UCA_NCHARS, maxnum);
259
for (offs=0; offs < MY_UCA_NCHARS; offs++)
264
code= page*MY_UCA_NCHARS+offs;
266
bzero(weight,sizeof(weight));
268
/* Copy non-zero weights */
269
for (num=0, i=0; i < uca[code].num; i++)
271
if (uca[code].weight[w][i])
273
weight[num]= uca[code].weight[w][i];
278
for (i=0; i < maxnum; i++)
281
Invert weights for secondary level to
282
sort upper case letters before their
283
lower case counter part.
287
tmp= (int)(0x20 - weight[i]);
290
printf("0x%04X", tmp);
291
if ((offs+1 != MY_UCA_NCHARS) || (i+1!=maxnum))
308
printf("uchar uca_length%s[%d]={\n", pname[w], MY_UCA_NPAGES);
309
for (page=0; page < MY_UCA_NPAGES; page++)
311
printf("%d%s%s",pagemaxlen[page],page<MY_UCA_NPAGES-1?",":"",(page+1) % 16 ? "":"\n");
316
printf("uint16 *uca_weight%s[%d]={\n", pname[w], MY_UCA_NPAGES);
317
for (page=0; page < MY_UCA_NPAGES; page++)
319
const char *comma= page < MY_UCA_NPAGES-1 ? "," : "";
320
const char *nline= (page+1) % 4 ? "" : "\n";
321
if (!pagemaxlen[page])
322
printf("NULL %s%s%s", w ? " ": "", comma , nline);
324
printf("page%03Xdata%s%s%s", page, pname[w], comma, nline);
330
printf("int main(void){ return 0;};\n");