OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [extra/] [locale/] [gen_wc8bit.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#define _GNU_SOURCE
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
#include <locale.h>
6
#include <stddef.h>
7
#include <wctype.h>
8
#include <limits.h>
9
 
10
#ifndef _CTYPE_H
11
#define _CTYPE_H
12
#endif
13
#ifndef _WCTYPE_H
14
#define _WCTYPE_H
15
#endif
16
#include "../../libc/sysdeps/linux/common/bits/uClibc_ctype.h"
17
 
18
 
19
/*  #define CTYPE_PACKED */
20
#define UPLOW_IDX_SHIFT         3
21
/* best if 2 unpacked or 3 packed */
22
#define CTYPE_IDX_SHIFT         3
23
/* 3 or 4 are very similar */
24
#define C2WC_IDX_SHIFT          3
25
 
26
#define CTYPE_IDX_LEN           (128 >> (CTYPE_IDX_SHIFT))
27
#define UPLOW_IDX_LEN           (128 >> (UPLOW_IDX_SHIFT))
28
#define C2WC_IDX_LEN            (128 >> (C2WC_IDX_SHIFT))
29
 
30
/*  #ifdef CTYPE_PACKED */
31
/*  #define CTYPE_ROW_LEN               (1 << ((CTYPE_IDX_SHIFT)-1)) */
32
/*  #else */
33
#define CTYPE_ROW_LEN           (1 << (CTYPE_IDX_SHIFT))
34
/*  #endif */
35
#define UPLOW_ROW_LEN           (1 << (UPLOW_IDX_SHIFT))
36
#define C2WC_ROW_LEN            (1 << (C2WC_IDX_SHIFT))
37
 
38
 
39
 
40
#define MAX_WCHAR       (0x2600-1)
41
 
42
static unsigned char ctype_tbl[256 * CTYPE_ROW_LEN];
43
static unsigned char uplow_tbl[256 * UPLOW_ROW_LEN];
44
#ifdef DO_WIDE_CHAR
45
static unsigned short c2wc_tbl[256 * C2WC_ROW_LEN];
46
#endif
47
static unsigned char tt[MAX_WCHAR+1];
48
static unsigned char ti[MAX_WCHAR+1];
49
static unsigned char xi[MAX_WCHAR+1];
50
 
51
static int n_ctype_rows;
52
static int n_uplow_rows;
53
#ifdef DO_WIDE_CHAR
54
static int n_c2wc_rows;
55
#endif
56
static int tt_num;
57
static int ti_num;
58
 
59
#define RANGE MAX_WCHAR
60
 
61
#define TT_SHIFT 4
62
#define TI_SHIFT 4
63
 
64
#define II_LEN          ((MAX_WCHAR+1) >> (TT_SHIFT+TI_SHIFT))
65
 
66
typedef struct {
67
        unsigned long c2w[256];
68
        unsigned char w2c[MAX_WCHAR];
69
        unsigned char ii[II_LEN];
70
        unsigned char ctype_idx[CTYPE_IDX_LEN];
71
        unsigned char uplow_idx[UPLOW_IDX_LEN];
72
        unsigned char c2wc_idx[C2WC_IDX_LEN];
73
} charset_data;
74
 
75
int main(int argc, char **argv)
76
{
77
        FILE *fp;
78
        FILE *out;
79
        charset_data csd[30];
80
        unsigned long max_wchar;
81
        unsigned char *p;
82
        int numsets;
83
        int i;
84
        int j;
85
        char buf[80];
86
        unsigned char row[256];
87
#ifdef DO_WIDE_CHAR
88
        unsigned short wrow[256];
89
#endif
90
        char codeset_list[500];
91
        char codeset_index[30];
92
        int codeset_list_end = 0;
93
        int total_size = 0;
94
 
95
        if (!setlocale(LC_CTYPE, "en_US.UTF-8")) {
96
                printf("setlocale(LC_CTYPE,\"en_US.UTF-8\") failed!\n");
97
                return EXIT_FAILURE;
98
        }
99
 
100
        if (!(out = fopen("c8tables.h","w"))) {
101
                printf("error: couldn't open file \"c8tables.h\"\n");
102
                return EXIT_FAILURE;
103
        }
104
 
105
#if 0
106
        if (argc == 1) {
107
                /* User requested 8-bit codesets, but didn't list any... */
108
                /* Allow to build, just so this feature can be left on in config. */
109
                fprintf(out, "#ifdef __CTYPE_HAS_8_BIT_LOCALES\n");
110
                fprintf(out, "#warning ignoring 8 bit codesets request"
111
                                " as no codesets specified.\n");
112
                fprintf(out, "#endif\n");
113
                fprintf(out, "#undef __CTYPE_HAS_8_BIT_LOCALES\n\n");
114
 
115
                fprintf(out, "#define __LOCALE_DATA_NUM_CODESETS\t\t0\n");
116
                fprintf(out, "#define __LOCALE_DATA_CODESET_LIST\t\t\"\"\n");
117
                fclose(out);
118
                return EXIT_SUCCESS;
119
        }
120
 
121
/*      fprintf(out, "#define __CTYPE_HAS_8_BIT_LOCALES\t1\n\n"); */
122
        fprintf(out, "#ifdef __CTYPE_HAS_8_BIT_LOCALES\n\n");
123
#endif
124
 
125
        if (argc == 1) {
126
                fprintf(out, "#undef __CTYPE_HAS_8_BIT_LOCALES\n\n");
127
 
128
                fprintf(out, "#define __LOCALE_DATA_NUM_CODESETS\t\t0\n");
129
                fprintf(out, "#define __LOCALE_DATA_CODESET_LIST\t\t\"\"\n");
130
        } else {
131
                fprintf(out, "#define __CTYPE_HAS_8_BIT_LOCALES\t\t1\n\n");
132
        }
133
 
134
        fprintf(out, "#define __LOCALE_DATA_Cctype_IDX_SHIFT\t%d\n", CTYPE_IDX_SHIFT);
135
        fprintf(out, "#define __LOCALE_DATA_Cctype_IDX_LEN\t\t%d\n", CTYPE_IDX_LEN);
136
#ifdef CTYPE_PACKED
137
        fprintf(out, "#define __LOCALE_DATA_Cctype_ROW_LEN\t\t%d\n", CTYPE_ROW_LEN >> 1);
138
        fprintf(out, "#define __LOCALE_DATA_Cctype_PACKED\t\t1\n");
139
#else
140
        fprintf(out, "#define __LOCALE_DATA_Cctype_ROW_LEN\t\t%d\n", CTYPE_ROW_LEN);
141
        fprintf(out, "#undef __LOCALE_DATA_Cctype_PACKED\n");
142
#endif
143
 
144
        fprintf(out, "\n#define __LOCALE_DATA_Cuplow_IDX_SHIFT\t%d\n", UPLOW_IDX_SHIFT);
145
        fprintf(out, "#define __LOCALE_DATA_Cuplow_IDX_LEN\t\t%d\n", UPLOW_IDX_LEN);
146
        fprintf(out, "#define __LOCALE_DATA_Cuplow_ROW_LEN\t\t%d\n", UPLOW_ROW_LEN);
147
 
148
#ifdef DO_WIDE_CHAR
149
        fprintf(out, "\n#define __LOCALE_DATA_Cc2wc_IDX_LEN\t\t%d\n", C2WC_IDX_LEN);
150
        fprintf(out, "#define __LOCALE_DATA_Cc2wc_IDX_SHIFT\t\t%d\n", C2WC_IDX_SHIFT);
151
        fprintf(out, "#define __LOCALE_DATA_Cc2wc_ROW_LEN\t\t%d\n", C2WC_ROW_LEN);
152
#endif
153
 
154
        fprintf(out, "\ntypedef struct {\n");
155
        fprintf(out, "\tunsigned char idx8ctype[%d];\n", CTYPE_IDX_LEN);
156
        fprintf(out, "\tunsigned char idx8uplow[%d];\n", UPLOW_IDX_LEN);
157
#ifdef DO_WIDE_CHAR
158
        fprintf(out, "\tunsigned char idx8c2wc[%d];\n", C2WC_IDX_LEN);
159
        fprintf(out, "\tunsigned char idx8wc2c[%d];\n", II_LEN);
160
#endif
161
        fprintf(out, "} __codeset_8_bit_t;\n\n");
162
 
163
        fprintf(out, "#ifdef WANT_DATA\n\n");
164
        fprintf(out, "static const __codeset_8_bit_t codeset_8_bit[%d] = {\n", argc-1);
165
 
166
        max_wchar = 0x7f;
167
        numsets = 0;
168
        codeset_index[0] = 0;
169
        while (--argc) {
170
                if (!(fp = fopen(*++argv,"r"))) {
171
                        printf("error: couldn't open file \"%s\"\n", *argv);
172
                        return EXIT_FAILURE;
173
                }
174
                printf("processing %s... ", *argv);
175
 
176
                {
177
                        char *s0;
178
                        char *s1;
179
                        int n;
180
 
181
                        s0 = strrchr(*argv, '/');
182
                        if (!s0) {
183
                                s0 = *argv;
184
                        } else {
185
                                ++s0;
186
                        }
187
                        s1 = strchr(s0, '.');
188
                        if (!s1) {
189
                                n = strlen(s0);
190
                        } else {
191
                                n = s1 - s0;
192
                        }
193
 
194
/*                      if ((numsets == 0) && strncmp("ASCII", s0, n)) { */
195
/*                              printf("error - first codeset isn't ASCII!\n"); */
196
/*                              return EXIT_FAILURE; */
197
/*                      } */
198
 
199
                        if (numsets >= sizeof(codeset_index)) {
200
                                printf("error - too many codesets!\n");
201
                                return EXIT_FAILURE;
202
                        }
203
 
204
                        if (codeset_list_end + n + 1 + numsets + 1 + 1 >= 256) {
205
                                printf("error - codeset list to big!\n");
206
                                return EXIT_FAILURE;
207
                        }
208
 
209
                        codeset_index[numsets+1] = codeset_index[numsets] + n+1;
210
                        strncpy(codeset_list + codeset_list_end, s0, n);
211
                        codeset_list_end += (n+1);
212
                        codeset_list[codeset_list_end - 1] = 0;
213
 
214
                        fprintf(out, "\t{ /* %.*s */", n, s0);
215
                }
216
 
217
                memset(&csd[numsets],sizeof(charset_data),0);
218
                memset(xi, sizeof(xi), 0);
219
                {
220
                        unsigned long c, wc;
221
                        int lines;
222
                        lines = 0;
223
                        while (fgets(buf,sizeof(buf),fp)) {
224
                                if ((2 != sscanf(buf, "{ %lx , %lx", &c, &wc))
225
                                        || (c >= 256) || (wc > MAX_WCHAR)) {
226
                                        printf("error: scanf failure! \"%s\"\n", buf);
227
                                        return EXIT_FAILURE;
228
                                }
229
 
230
                                /* don't put in w2c... dynamicly build tt instead. */
231
 
232
                                if (c <= 0x7f) { /* check the 7bit entries but don't store */
233
                                        if (c != wc) {
234
                                                printf("error: c != wc in %s\n", buf);
235
                                                return EXIT_FAILURE;
236
                                        }
237
                                        csd[numsets].c2w[c] = wc;
238
                                        csd[numsets].w2c[wc] = 0; /* ignore */
239
                                        if (wc > max_wchar) {
240
                                                max_wchar = wc;
241
                                        }
242
                                } else {
243
                                        csd[numsets].c2w[c] = wc;
244
                                        csd[numsets].w2c[wc] = c;
245
                                        if (wc > max_wchar) {
246
                                                max_wchar = wc;
247
                                        }
248
                                }
249
                                ++lines;
250
                        }
251
                        printf("%d lines  ", lines);
252
 
253
                        for (i = 0 ; i <= MAX_WCHAR ; i += (1 << TT_SHIFT)) {
254
                                p = &csd[numsets].w2c[i];
255
                                for (j = 0 ; j < tt_num ; j++) {
256
                                        if (!memcmp(p, &tt[j << TT_SHIFT], (1 << TT_SHIFT))) {
257
                                                break;
258
                                        }
259
                                }
260
                                if (j == tt_num) { /* new entry */
261
                                        memcpy(&tt[j << TT_SHIFT], p, (1 << TT_SHIFT));
262
                                        ++tt_num;
263
                                }
264
                                xi[i >> TT_SHIFT] = j;
265
                        }
266
 
267
                        for (i = 0 ; i <= (MAX_WCHAR >> TT_SHIFT)  ; i += (1 << TI_SHIFT)) {
268
                                p = &xi[i];
269
                                for (j = 0 ; j < ti_num ; j++) {
270
                                        if (!memcmp(p, &ti[j << TI_SHIFT], (1 << TI_SHIFT))) {
271
                                                break;
272
                                        }
273
                                }
274
                                if (j == ti_num) { /* new entry */
275
                                        memcpy(&ti[j << TI_SHIFT], p, (1 << TI_SHIFT));
276
                                        ++ti_num;
277
                                }
278
                                csd[numsets].ii[i >> TI_SHIFT] = j;
279
/*                              printf("%d ", i >> TI_SHIFT); */
280
                        }
281
 
282
#if 1
283
                        fprintf(out, "\n\t\t/* idx8ctype data */\n\t\t{");
284
                        for (i = 128 ; i < 256 ; i++) {
285
                                wchar_t c;
286
                                unsigned int d;
287
 
288
/*                              if (!(i & 0x7)) { */
289
/*                                      fprintf(out, "\n"); */
290
/*                              } */
291
 
292
                                c = csd[numsets].c2w[i];
293
 
294
                                if (c == 0) {    /* non-existant char in codeset */
295
                                        d = __CTYPE_unclassified;
296
                                } else if (iswdigit(c)) {
297
                                        d = __CTYPE_digit;
298
                                } else if (iswalpha(c)) {
299
                                        d = __CTYPE_alpha_nonupper_nonlower;
300
                                        if (iswlower(c)) {
301
                                                d = __CTYPE_alpha_lower;
302
                                                if (iswupper(c)) {
303
                                                        d = __CTYPE_alpha_upper_lower;
304
                                                }
305
                                        } else if (iswupper(c)) {
306
                                                d = __CTYPE_alpha_upper;
307
                                        }
308
                                } else if (iswpunct(c)) {
309
                                        d = __CTYPE_punct;
310
                                } else if (iswgraph(c)) {
311
                                        d = __CTYPE_graph;
312
                                } else if (iswprint(c)) {
313
                                        d = __CTYPE_print_space_nonblank;
314
                                        if (iswblank(c)) {
315
                                                d = __CTYPE_print_space_blank;
316
                                        }
317
                                } else if (iswspace(c) && !iswcntrl(c)) {
318
                                        d = __CTYPE_space_nonblank_noncntrl;
319
                                        if (iswblank(c)) {
320
                                                d = __CTYPE_space_blank_noncntrl;
321
                                        }
322
                                } else if (iswcntrl(c)) {
323
                                        d = __CTYPE_cntrl_nonspace;
324
                                        if (iswspace(c)) {
325
                                                d = __CTYPE_cntrl_space_nonblank;
326
                                                if (iswblank(c)) {
327
                                                        d = __CTYPE_cntrl_space_blank;
328
                                                }
329
                                        }
330
                                } else {
331
                                        d = __CTYPE_unclassified;
332
                                }
333
 
334
#if 1
335
                                row[i & (CTYPE_ROW_LEN-1)] = d;
336
                                if ((i & (CTYPE_ROW_LEN-1)) == (CTYPE_ROW_LEN-1)) {
337
                                        p = ctype_tbl;
338
                                        for (j=0 ; j < n_ctype_rows ; j++) {
339
                                                if (!memcmp(p, row, CTYPE_ROW_LEN)) {
340
                                                        break;
341
                                                }
342
                                                p += CTYPE_ROW_LEN;
343
                                        }
344
                                        if (j == n_ctype_rows) { /* new entry */
345
                                                if (++n_ctype_rows > 256) {
346
                                                        printf("error -- to many ctype rows!\n");
347
                                                        return EXIT_FAILURE;
348
                                                }
349
                                                memcpy(p, row, CTYPE_ROW_LEN);
350
                                        }
351
                                        csd[numsets].ctype_idx[i >> CTYPE_IDX_SHIFT] = j;
352
                                        if (!((i >> CTYPE_IDX_SHIFT) & 0x7)
353
                                                && (i != (127 + CTYPE_ROW_LEN))
354
                                                ) {
355
                                                fprintf(out, "\n\t\t ");
356
                                        }
357
                                        fprintf(out, " %#4x,", j);
358
                                }
359
#else
360
                                fprintf(out, " %#4x,", d);
361
#endif
362
                        }
363
#endif
364
                        fprintf(out, " }");
365
 
366
#if 1
367
                        fprintf(out, ",\n\t\t/* idx8uplow data */\n\t\t{");
368
                        for (i = 128 ; i < 256 ; i++) {
369
                                wchar_t c, u, l;
370
/*                              if (!(i & 0x7)) { */
371
/*                                      fprintf(out, "\n"); */
372
/*                              } */
373
                                c = csd[numsets].c2w[i];
374
                                if ((c != 0) || 1) {
375
                                        u = towupper(c);
376
                                        l = towlower(c);
377
 
378
                                        if (u >= 0x80) u = csd[numsets].w2c[u];
379
                                        if (l >= 0x80) l = csd[numsets].w2c[l];
380
 
381
                                        if (u == 0) u = i; /* upper is missing, so ignore */
382
                                        if (l == 0) l = i; /* lower is missing, so ignore */
383
 
384
#if 1
385
                                        /* store as unsigned char and let overflow handle it. */
386
/*                                      if ((((u-i) < CHAR_MIN) || ((u-i) > CHAR_MAX)) */
387
/*                                              || (((i-l) < CHAR_MIN) || ((i-l) > CHAR_MAX)) */
388
/*                                              ) { */
389
/*                                              printf("error - uplow diff out of range! %d %ld %ld\n", */
390
/*                                                         i, u, l); */
391
/*                                              return EXIT_FAILURE; */
392
/*                                      } */
393
 
394
                                        row[i & (UPLOW_ROW_LEN-1)] = ((l==i) ? (u-i) : (i-l));
395
                                        if ((i & (UPLOW_ROW_LEN-1)) == (UPLOW_ROW_LEN-1)) {
396
                                                p = uplow_tbl;
397
                                                for (j=0 ; j < n_uplow_rows ; j++) {
398
                                                        if (!memcmp(p, row, UPLOW_ROW_LEN)) {
399
                                                                break;
400
                                                        }
401
                                                        p += UPLOW_ROW_LEN;
402
                                                }
403
                                                if (j == n_uplow_rows) { /* new entry */
404
                                                        if (++n_uplow_rows > 256) {
405
                                                                printf("error -- to many uplow rows!\n");
406
                                                                return EXIT_FAILURE;
407
                                                        }
408
                                                        memcpy(p, row, UPLOW_ROW_LEN);
409
                                                }
410
                                                csd[numsets].uplow_idx[i >> UPLOW_IDX_SHIFT] = j;
411
                                                if (!((i >> UPLOW_IDX_SHIFT) & 0x7)
412
                                                        && (i != (127 + UPLOW_ROW_LEN))
413
                                                        ) {
414
                                                        fprintf(out, "\n\t\t ");
415
                                                }
416
                                                fprintf(out, " %#4x,", j);
417
                                        }
418
 
419
#elif 0
420
                                        if (!(i & 0x7) && i) {
421
                                                fprintf(out, "\n");
422
                                        }
423
                                        fprintf(out, " %4ld,", (l==i) ? (u-i) : (i-l));
424
/*                                      fprintf(out, " %4ld,", (l==i) ? u : l); */
425
#else
426
                                        if ((u != i) || (l != i)) {
427
#if 0
428
                                                fprintf(out, " %#08lx, %#08lx, %#08lx, %#08lx, %#08lx, %#08lx, \n",
429
                                                                (unsigned long) i,
430
                                                                (unsigned long) c,
431
                                                                (unsigned long) l,
432
                                                                (unsigned long) towlower(c),
433
                                                                (unsigned long) u,
434
                                                                (unsigned long) towupper(c));
435
 
436
#else
437
                                                fprintf(out, " %#08lx, %8ld, %d, %8ld, %d, %#08lx\n",
438
                                                                (unsigned long) i,
439
                                                                (long) (l - i),
440
                                                                iswupper(c),
441
                                                                (long) (i - u),
442
                                                                iswlower(c),
443
                                                                (unsigned long) c);
444
#endif
445
                                        }
446
#endif
447
                                }
448
                        }
449
                        fprintf(out, " }");
450
#endif
451
 
452
#ifndef DO_WIDE_CHAR
453
                        fprintf(out,"\n");
454
#else  /* DO_WIDE_CHAR */
455
 
456
#if 1
457
                        fprintf(out, ",\n\t\t/* idx8c2wc data */\n\t\t{");
458
                        for (i = 128 ; i < 256 ; i++) {
459
#if 1
460
                                wrow[i & (C2WC_ROW_LEN-1)] = csd[numsets].c2w[i];
461
                                if ((i & (C2WC_ROW_LEN-1)) == (C2WC_ROW_LEN-1)) {
462
                                        p = (char *) c2wc_tbl;
463
                                        for (j=0 ; j < n_c2wc_rows ; j++) {
464
                                                if (!memcmp(p, (char *) wrow, 2*C2WC_ROW_LEN)) {
465
                                                        break;
466
                                                }
467
                                                p += 2*C2WC_ROW_LEN;
468
                                        }
469
                                        if (j == n_c2wc_rows) { /* new entry */
470
                                                if (++n_c2wc_rows > 256) {
471
                                                        printf("error -- to many c2wc rows!\n");
472
                                                        return EXIT_FAILURE;
473
                                                }
474
                                                memcpy(p, (char *) wrow, 2*C2WC_ROW_LEN);
475
                                        }
476
                                        csd[numsets].c2wc_idx[i >> C2WC_IDX_SHIFT] = j;
477
                                        if (!((i >> C2WC_IDX_SHIFT) & 0x7)
478
                                                && (i != (127 + C2WC_ROW_LEN))
479
                                                ) {
480
                                                fprintf(out, "\n\t\t ");
481
                                        }
482
                                        fprintf(out, " %#4x,", j);
483
                                }
484
#else
485
                                if (!(i & 0x7) && i) {
486
                                        fprintf(out, "\n");
487
                                }
488
                                fprintf(out, " %#6lx,", csd[numsets].c2w[i]);
489
#endif
490
                        }
491
                        fprintf(out, " },\n");
492
#endif
493
 
494
#if 1
495
/*                      fprintf(out, "\nII_LEN = %d\n", II_LEN); */
496
                        fprintf(out, "\t\t/* idx8wc2c data */\n\t\t{");
497
                        for (i = 0 ; i < II_LEN ; i++) {
498
                                if (!(i & 0x7) && i) {
499
                                        fprintf(out, "\n\t\t ");
500
                                }
501
                                fprintf(out, " %#4x,", csd[numsets].ii[i]);
502
                        }
503
                        fprintf(out, " }\n");
504
#endif
505
 
506
#endif /* DO_WIDE_CHAR */
507
                        fprintf(out, "\t},\n");
508
 
509
                }
510
                ++numsets;
511
                printf("done\n");
512
        }
513
        fprintf(out, "};\n");
514
        fprintf(out, "\n#endif /* WANT_DATA */\n");
515
 
516
#ifdef DO_WIDE_CHAR
517
        fprintf(out, "\n");
518
        fprintf(out, "#define __LOCALE_DATA_Cwc2c_DOMAIN_MAX\t%#x\n", RANGE);
519
        fprintf(out, "#define __LOCALE_DATA_Cwc2c_TI_SHIFT\t\t%d\n", TI_SHIFT);
520
        fprintf(out, "#define __LOCALE_DATA_Cwc2c_TT_SHIFT\t\t%d\n", TT_SHIFT);
521
        fprintf(out, "#define __LOCALE_DATA_Cwc2c_II_LEN\t\t%d\n", II_LEN);
522
        fprintf(out, "#define __LOCALE_DATA_Cwc2c_TI_LEN\t\t%d\n", ti_num << TI_SHIFT);
523
        fprintf(out, "#define __LOCALE_DATA_Cwc2c_TT_LEN\t\t%d\n", tt_num << TT_SHIFT);
524
        fprintf(out, "\n");
525
 
526
        fprintf(out, "\n#define __LOCALE_DATA_Cwc2c_TBL_LEN\t\t%d\n",
527
                        (ti_num << TI_SHIFT) + (tt_num << TT_SHIFT));
528
 
529
        fprintf(out, "#ifdef WANT_DATA\n\n");
530
        fprintf(out, "static const unsigned char __LOCALE_DATA_Cwc2c_data[%d] = {\n",
531
                        (ti_num << TI_SHIFT) + (tt_num << TT_SHIFT));
532
        fprintf(out, "\t/* ti_table */\n\t");
533
        for (i=0 ; i < ti_num << TI_SHIFT ; i++) {
534
                if (!(i & 7) && i) {
535
                        fprintf(out, "\n\t");
536
                }
537
                fprintf(out, " %#4x,", ti[i]);
538
        }
539
        fprintf(out, "\n");
540
        fprintf(out, "\t/* tt_table */\n\t");
541
        for (i=0 ; i < tt_num << TT_SHIFT ; i++) {
542
                if (!(i & 7) && i) {
543
                        fprintf(out, "\n\t");
544
                }
545
                fprintf(out, " %#4x,", tt[i]);
546
        }
547
        fprintf(out, "\n};\n");
548
 
549
        fprintf(out, "\n#endif /* WANT_DATA */\n");
550
#endif /* DO_WIDE_CHAR */
551
 
552
        fprintf(out, "\n#define __LOCALE_DATA_Cuplow_TBL_LEN\t\t%d\n",
553
                        n_uplow_rows * UPLOW_ROW_LEN);
554
        fprintf(out, "\n#ifdef WANT_DATA\n\n");
555
 
556
        fprintf(out, "\nstatic const unsigned char __LOCALE_DATA_Cuplow_data[%d] = {\n",
557
                        n_uplow_rows * UPLOW_ROW_LEN);
558
        p = uplow_tbl;
559
        for (j=0 ; j < n_uplow_rows ; j++) {
560
                fprintf(out, "\t");
561
                for (i=0 ; i < UPLOW_ROW_LEN ; i++) {
562
                        fprintf(out, " %#4x,", (unsigned int)((unsigned char) p[i]));
563
                }
564
                fprintf(out, "\n");
565
                p += UPLOW_ROW_LEN;
566
        }
567
        fprintf(out, "};\n");
568
 
569
        fprintf(out, "\n#endif /* WANT_DATA */\n");
570
        fprintf(out, "\n#define __LOCALE_DATA_Cctype_TBL_LEN\t\t%d\n",
571
#ifdef CTYPE_PACKED
572
                        n_ctype_rows * CTYPE_ROW_LEN / 2
573
#else
574
                        n_ctype_rows * CTYPE_ROW_LEN
575
#endif
576
                        );
577
        fprintf(out, "\n#ifdef WANT_DATA\n\n");
578
 
579
 
580
        fprintf(out, "\nstatic const unsigned char __LOCALE_DATA_Cctype_data[%d] = {\n",
581
#ifdef CTYPE_PACKED
582
                        n_ctype_rows * CTYPE_ROW_LEN / 2
583
#else
584
                        n_ctype_rows * CTYPE_ROW_LEN
585
#endif
586
                        );
587
        p = ctype_tbl;
588
        for (j=0 ; j < n_ctype_rows ; j++) {
589
                fprintf(out, "\t");
590
                for (i=0 ; i < CTYPE_ROW_LEN ; i++) {
591
#ifdef CTYPE_PACKED
592
                        fprintf(out, " %#4x,", (unsigned int)(p[i] + (p[i+1] << 4)));
593
                        ++i;
594
#else
595
                        fprintf(out, " %#4x,", (unsigned int)p[i]);
596
#endif
597
                }
598
                fprintf(out, "\n");
599
                p += CTYPE_ROW_LEN;
600
        }
601
        fprintf(out, "};\n");
602
 
603
        fprintf(out, "\n#endif /* WANT_DATA */\n");
604
 
605
#ifdef DO_WIDE_CHAR
606
 
607
        fprintf(out, "\n#define __LOCALE_DATA_Cc2wc_TBL_LEN\t\t%d\n",
608
                        n_c2wc_rows * C2WC_ROW_LEN);
609
        fprintf(out, "\n#ifdef WANT_DATA\n\n");
610
 
611
        fprintf(out, "\nstatic const unsigned short __LOCALE_DATA_Cc2wc_data[%d] = {\n",
612
                        n_c2wc_rows * C2WC_ROW_LEN);
613
        p = (char *) c2wc_tbl;
614
        for (j=0 ; j < n_c2wc_rows ; j++) {
615
                fprintf(out, "\t");
616
                for (i=0 ; i < C2WC_ROW_LEN ; i++) {
617
                        fprintf(out, " %#6x,", (unsigned int)(((unsigned short *)p)[i]));
618
                }
619
                fprintf(out, "\n");
620
                p += 2*C2WC_ROW_LEN;
621
        }
622
        fprintf(out, "};\n");
623
        fprintf(out, "\n#endif /* WANT_DATA */\n");
624
#endif /* DO_WIDE_CHAR */
625
        fprintf(out, "\n\n");
626
 
627
        fprintf(out, "#define __LOCALE_DATA_NUM_CODESETS\t\t%d\n", numsets);
628
        fprintf(out, "#define __LOCALE_DATA_CODESET_LIST \\\n\t\"");
629
        for (i=0 ; i < numsets ; i++) {
630
                fprintf(out, "\\x%02x", numsets + 1 + (unsigned char) codeset_index[i]);
631
                if (((i & 7) == 7) && (i + 1 < numsets)) {
632
                        fprintf(out, "\" \\\n\t\"");
633
                }
634
        }
635
        fprintf(out, "\" \\\n\t\"\\0\"");
636
        for (i=0 ; i < numsets ; i++) {
637
                fprintf(out, " \\\n\t\"%s\\0\"",
638
                                codeset_list + ((unsigned char)codeset_index[i]));
639
        }
640
 
641
        fprintf(out, "\n\n");
642
        for (i=0 ; i < numsets ; i++) {
643
                char buf[30];
644
                char *z;
645
                strcpy(buf, codeset_list + ((unsigned char)codeset_index[i]));
646
                for (z=buf ; *z ; z++) {
647
                        if (*z == '-') {
648
                                *z = '_';
649
                        }
650
                }
651
                fprintf(out, "#define __CTYPE_HAS_CODESET_%s\n", buf);
652
        }
653
#ifdef DO_WIDE_CHAR
654
        fprintf(out, "#define __CTYPE_HAS_CODESET_UTF_8\n");
655
#endif /* DO_WIDE_CHAR */
656
 
657
#if 0
658
        fprintf(out, "\n#endif /* __CTYPE_HAS_8_BIT_LOCALES */\n\n");
659
#endif
660
 
661
        fclose(out);
662
 
663
        total_size = 0;
664
#ifdef DO_WIDE_CHAR
665
        printf("tt_num = %d   ti_num = %d\n", tt_num, ti_num);
666
        printf("max_wchar = %#lx\n", max_wchar);
667
 
668
        printf("size is %d * %d  +  %d * %d  + %d * %d  =  %d\n",
669
                   tt_num, 1 << TT_SHIFT, ti_num, 1 << TI_SHIFT,
670
                   ((MAX_WCHAR >> (TT_SHIFT + TI_SHIFT)) + 1), numsets,
671
                   j = tt_num * (1 << TT_SHIFT) + ti_num * (1 << TI_SHIFT)
672
                   + ((MAX_WCHAR >> (TT_SHIFT + TI_SHIFT)) + 1) * numsets);
673
        total_size += j;
674
#endif /* DO_WIDE_CHAR */
675
 
676
#ifdef CTYPE_PACKED
677
        i = 2;
678
#else
679
        i = 1;
680
#endif
681
 
682
        printf("ctype - CTYPE_IDX_SHIFT = %d -- %d * %d + %d * %d = %d\n",
683
                   CTYPE_IDX_SHIFT, numsets, CTYPE_IDX_LEN, n_ctype_rows, CTYPE_ROW_LEN / i,
684
                   j = numsets * CTYPE_IDX_LEN +  n_ctype_rows * CTYPE_ROW_LEN / i);
685
        total_size += j;
686
 
687
        printf("uplow - UPLOW_IDX_SHIFT = %d -- %d * %d + %d * %d = %d\n",
688
                   UPLOW_IDX_SHIFT, numsets, UPLOW_IDX_LEN, n_uplow_rows, UPLOW_ROW_LEN,
689
                   j = numsets * UPLOW_IDX_LEN +  n_uplow_rows * UPLOW_ROW_LEN);
690
        total_size += j;
691
 
692
#ifdef DO_WIDE_CHAR
693
 
694
        printf("c2wc - C2WC_IDX_SHIFT = %d -- %d * %d + 2 * %d * %d = %d\n",
695
                   C2WC_IDX_SHIFT, numsets, C2WC_IDX_LEN, n_c2wc_rows, C2WC_ROW_LEN,
696
                   j = numsets * C2WC_IDX_LEN +  2 * n_c2wc_rows * C2WC_ROW_LEN);
697
        total_size += j;
698
 
699
#endif /* DO_WIDE_CHAR */
700
 
701
        printf("total size = %d\n", total_size);
702
 
703
/*      for (i=0 ; i < numsets ; i++) { */
704
/*              printf("codeset_index[i] = %d  codeset_list[ci[i]] = \"%s\"\n", */
705
/*                         (unsigned char) codeset_index[i], */
706
/*                         codeset_list + ((unsigned char)codeset_index[i])); */
707
/*      } */
708
 
709
        return EXIT_SUCCESS;
710
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.