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

Subversion Repositories or1k

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

Go to most recent revision | 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 <ctype.h>
6
#include <limits.h>
7
#include <assert.h>
8
#include <locale.h>
9
#include <langinfo.h>
10
#include <nl_types.h>
11
#include <stdint.h>
12
 
13
#include "c8tables.h"
14
 
15
 
16
#define __LOCALE_DATA_CATEGORIES 6
17
 
18
/* must agree with ordering of gen_mmap! */
19
static const unsigned char *lc_names[] = {
20
        "LC_CTYPE",
21
        "LC_NUMERIC",
22
        "LC_MONETARY",
23
        "LC_TIME",
24
        "LC_COLLATE",
25
        "LC_MESSAGES",
26
#if __LOCALE_DATA_CATEGORIES == 12
27
        "LC_PAPER",
28
        "LC_NAME",
29
        "LC_ADDRESS",
30
        "LC_TELEPHONE",
31
        "LC_MEASUREMENT",
32
        "LC_IDENTIFICATION",
33
#elif __LOCALE_DATA_CATEGORIES != 6
34
#error unsupported __LOCALE_DATA_CATEGORIES value!
35
#endif
36
};
37
 
38
 
39
 
40
typedef struct {
41
        char *glibc_name;
42
        char name[5];
43
        char dot_cs;                            /* 0 if no codeset specified */
44
        char cs;
45
        unsigned char idx_name;
46
        unsigned char lc_time_row;
47
        unsigned char lc_numeric_row;
48
        unsigned char lc_monetary_row;
49
        unsigned char lc_messages_row;
50
        unsigned char lc_ctype_row;
51
#if __LOCALE_DATA_CATEGORIES != 6
52
#error unsupported __LOCALE_DATA_CATEGORIES value
53
#endif
54
} locale_entry;
55
 
56
static void read_at_mappings(void);
57
static void read_enable_disable(void);
58
static void read_locale_list(void);
59
 
60
static int find_codeset_num(const char *cs);
61
static int find_at_string_num(const char *as);
62
static int le_cmp(const void *, const void *);
63
static void dump_table8(const char *name, const char *tbl, int len);
64
static void dump_table8c(const char *name, const char *tbl, int len);
65
static void dump_table16(const char *name, const int *tbl, int len);
66
 
67
static void do_lc_time(void);
68
static void do_lc_numeric(void);
69
static void do_lc_monetary(void);
70
 
71
static void do_lc_messages(void);
72
static void do_lc_ctype(void);
73
 
74
 
75
static FILE *fp;
76
static FILE *ofp;
77
static char line_buf[80];
78
static char at_mappings[256];
79
static char at_mapto[256];
80
static char at_strings[1024];
81
static char *at_strings_end;
82
static locale_entry locales[700];
83
static char glibc_locale_names[60000];
84
 
85
static int num_locales;
86
 
87
static int default_utf8;
88
static int default_8bit;
89
 
90
static int total_size;
91
static int null_count;
92
 
93
static void do_locale_names(void)
94
{
95
        /* "C" locale name is handled specially by the setlocale code. */
96
        int uniq = 0;
97
        int i;
98
 
99
        if (num_locales <= 1) {
100
/*              printf("error - only C locale?\n"); */
101
/*              exit(EXIT_FAILURE); */
102
                fprintf(ofp, "static const unsigned char __locales[%d];\n", (3 + __LOCALE_DATA_CATEGORIES));
103
                fprintf(ofp, "static const unsigned char __locale_names5[5];\n");
104
        } else {
105
                if (default_utf8) {
106
                        fprintf(ofp, "#define __CTYPE_HAS_UTF_8_LOCALES\t\t\t1\n");
107
                }
108
                fprintf(ofp, "#define __LOCALE_DATA_CATEGORIES\t\t\t%d\n", __LOCALE_DATA_CATEGORIES);
109
                fprintf(ofp, "#define __LOCALE_DATA_WIDTH_LOCALES\t\t\t%d\n", 3+__LOCALE_DATA_CATEGORIES);
110
                fprintf(ofp, "#define __LOCALE_DATA_NUM_LOCALES\t\t\t%d\n", num_locales);
111
                fprintf(ofp, "static const unsigned char __locales[%d] = {\n",
112
                                (num_locales) * (3 + __LOCALE_DATA_CATEGORIES));
113
                for (i=0 ; i < num_locales ; i++) {
114
                        if (memcmp(locales[i].name, locales[i-1].name, 5) != 0) {
115
                                locales[i].idx_name = uniq;
116
                                ++uniq;
117
                        } else {
118
                                locales[i].idx_name = uniq - 1;
119
                        }
120
                        fprintf(ofp, "\t%#4x, ", (int)((unsigned char) locales[i].idx_name));
121
                        fprintf(ofp, "\t%#4x, ", (int)((unsigned char) locales[i].dot_cs));
122
                        fprintf(ofp, "\t%#4x, ", (int)((unsigned char) locales[i].cs));
123
                        /* lc_ctype would store translit flags and turkish up/low flag. */
124
                        fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_ctype_row));
125
                        fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_numeric_row));
126
                        fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_monetary_row));
127
                        fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_time_row));
128
#if 1
129
                        /* lc_collate */
130
                        if (strlen(locales[i].glibc_name) >= 5) {
131
                            fprintf(ofp, "COL_IDX_%.2s_%.2s, ", locales[i].glibc_name, locales[i].glibc_name+3);
132
                        } else if (!strcmp(locales[i].glibc_name, "C")) {
133
                            fprintf(ofp, "COL_IDX_C    , ");
134
                        } else {
135
                            printf("don't know how to handle COL_IDX_ for %s\n", locales[i].glibc_name);
136
                            exit(EXIT_FAILURE);
137
                        }
138
#else
139
                        fprintf(ofp, "%#4x, ", 0); /* place holder for lc_collate */
140
#endif
141
                        fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_messages_row));
142
                        fprintf(ofp, "\t/* %s */\n", locales[i].glibc_name);
143
                }
144
                fprintf(ofp, "};\n\n");
145
 
146
                fprintf(ofp, "#define __LOCALE_DATA_NUM_LOCALE_NAMES\t\t%d\n", uniq );
147
                fprintf(ofp, "static const unsigned char __locale_names5[%d] = \n\t", uniq * 5);
148
                uniq = 0;
149
                for (i=1 ; i < num_locales ; i++) {
150
                        if (memcmp(locales[i].name, locales[i-1].name, 5) != 0) {
151
                                fprintf(ofp, "\"%5.5s\" ", locales[i].name);
152
                                ++uniq;
153
                                if ((uniq % 8) == 0) {
154
                                        fprintf(ofp, "\n\t");
155
                                }
156
                        }
157
                }
158
                fprintf(ofp,";\n\n");
159
 
160
                if (at_strings_end > at_strings) {
161
                        int i, j;
162
                        char *p;
163
                        i = 0;
164
                        p = at_strings;
165
                        while (*p) {
166
                                ++i;
167
                                p += 1 + (unsigned char) *p;
168
                        }
169
                        /* len, char, string\0 */
170
                        fprintf(ofp, "#define __LOCALE_DATA_AT_MODIFIERS_LENGTH\t\t%d\n",
171
                                        i + (at_strings_end - at_strings));
172
                        fprintf(ofp, "static const unsigned char __locale_at_modifiers[%d] = {",
173
                                        i + (at_strings_end - at_strings));
174
                        i = 0;
175
                        p = at_strings;
176
                        while (*p) {
177
                                fprintf(ofp, "\n\t%4d, '%c',",
178
                                                (unsigned char) *p, /* len of string\0 */
179
                                                at_mapto[i]);
180
                                for (j=1 ; j < ((unsigned char) *p) ; j++) {
181
                                        fprintf(ofp, " '%c',", p[j]);
182
                                }
183
                                fprintf(ofp, " 0,");
184
                                ++i;
185
                                p += 1 + (unsigned char) *p;
186
                        }
187
                        fprintf(ofp, "\n};\n\n");
188
                }
189
 
190
                {
191
                        int pos[__LOCALE_DATA_CATEGORIES];
192
                        pos[0] = __LOCALE_DATA_CATEGORIES;
193
                        for (i=0 ; i < __LOCALE_DATA_CATEGORIES ; i++) {
194
                                fprintf(ofp, "#define __%s\t\t%d\n", lc_names[i], i);
195
                                if (i + 1 < __LOCALE_DATA_CATEGORIES) {
196
                                        pos[i+1] = 1 + strlen(lc_names[i]) + pos[i];
197
                                }
198
                        }
199
                        if (pos[__LOCALE_DATA_CATEGORIES-1] > 255) {
200
                                printf("error - lc_names is too big (%d)\n", pos[__LOCALE_DATA_CATEGORIES-1]);
201
                                exit(EXIT_FAILURE);
202
                        }
203
                        fprintf(ofp, "#define __LC_ALL\t\t%d\n\n", i);
204
 
205
                        fprintf(ofp, "#define __lc_names_LEN\t\t%d\n",
206
                                        pos[__LOCALE_DATA_CATEGORIES-1] + strlen(lc_names[__LOCALE_DATA_CATEGORIES-1]) + 1);
207
                        total_size += pos[__LOCALE_DATA_CATEGORIES-1] + strlen(lc_names[__LOCALE_DATA_CATEGORIES-1]) + 1;
208
 
209
                        fprintf(ofp, "static unsigned const char lc_names[%d] =\n",
210
                                        pos[__LOCALE_DATA_CATEGORIES-1] + strlen(lc_names[__LOCALE_DATA_CATEGORIES-1]) + 1);
211
                        fprintf(ofp, "\t\"");
212
                        for (i=0 ; i < __LOCALE_DATA_CATEGORIES ; i++) {
213
                                fprintf(ofp, "\\x%02x", (unsigned char) pos[i]);
214
                        }
215
                        fprintf(ofp, "\"");
216
                        for (i=0 ; i < __LOCALE_DATA_CATEGORIES ; i++) {
217
                                fprintf(ofp, "\n\t\"%s\\0\"", lc_names[i]);
218
                        }
219
                        fprintf(ofp, ";\n\n");
220
                }
221
 
222
                printf("locale data = %d  name data = %d for %d uniq\n",
223
                           num_locales * (3 + __LOCALE_DATA_CATEGORIES), uniq * 5, uniq);
224
 
225
                total_size += num_locales * (3 + __LOCALE_DATA_CATEGORIES) + uniq * 5;
226
        }
227
 
228
}
229
 
230
static void read_at_mappings(void)
231
{
232
        char *p;
233
        char *m;
234
        int mc = 0;
235
 
236
        do {
237
                if (!(p = strtok(line_buf, " \t\n")) || (*p == '#')) {
238
                        if (!fgets(line_buf, sizeof(line_buf), fp)) {
239
                                if (ferror(fp)) {
240
                                        printf("error reading file\n");
241
                                        exit(EXIT_FAILURE);
242
                                }
243
                                return;                 /* EOF */
244
                        }
245
                        if ((*line_buf == '#') && (line_buf[1] == '-')) {
246
                                break;
247
                        }
248
                        continue;
249
                }
250
                if (*p == '@') {
251
                        if (p[1] == 0) {
252
                                printf("error: missing @modifier name\n");
253
                                exit(EXIT_FAILURE);
254
                        }
255
                        m = p;                          /* save the modifier name */
256
                        if (!(p = strtok(NULL, " \t\n")) || p[1] || (((unsigned char) *p) > 0x7f)) {
257
                                printf("error: missing or illegal @modifier mapping char\n");
258
                                exit(EXIT_FAILURE);
259
                        }
260
                        if (at_mappings[(int)((unsigned char) *p)]) {
261
                                printf("error: reused @modifier mapping char\n");
262
                                exit(EXIT_FAILURE);
263
                        }
264
                        at_mappings[(int)((unsigned char) *p)] = 1;
265
                        at_mapto[mc] = *p;
266
                        ++mc;
267
                        *at_strings_end = (char)( (unsigned char) (strlen(m)) );
268
                        strcpy(++at_strings_end, m+1);
269
                        at_strings_end += (unsigned char) at_strings_end[-1];
270
 
271
                        printf("@mapping: \"%s\" to '%c'\n", m, *p);
272
 
273
                        if (((p = strtok(NULL, " \t\n")) != NULL) && (*p != '#')) {
274
                                printf("ignoring trailing text: %s...\n", p);
275
                        }
276
                        *line_buf = 0;
277
                        continue;
278
                }
279
                break;
280
        } while (1);
281
 
282
#if 0
283
        {
284
                p = at_strings;
285
 
286
                if (!*p) {
287
                        printf("no @ strings\n");
288
                        return;
289
                }
290
 
291
                do {
292
                        printf("%s\n", p+1);
293
                        p += 1 + (unsigned char) *p;
294
                } while (*p);
295
        }
296
#endif
297
}
298
 
299
static void read_enable_disable(void)
300
{
301
        char *p;
302
 
303
        do {
304
                if (!(p = strtok(line_buf, " =\t\n")) || (*p == '#')) {
305
                        if (!fgets(line_buf, sizeof(line_buf), fp)) {
306
                                if (ferror(fp)) {
307
                                        printf("error reading file\n");
308
                                        exit(EXIT_FAILURE);
309
                                }
310
                                return;                 /* EOF */
311
                        }
312
                        if ((*line_buf == '#') && (line_buf[1] == '-')) {
313
                                break;
314
                        }
315
                        continue;
316
                }
317
                if (!strcmp(p, "UTF-8")) {
318
                        if (!(p = strtok(NULL, " =\t\n"))
319
                                || ((toupper(*p) != 'Y') && (toupper(*p) != 'N'))) {
320
                                printf("error: missing or illegal UTF-8 setting\n");
321
                                exit(EXIT_FAILURE);
322
                        }
323
                        default_utf8 = (toupper(*p) == 'Y');
324
                        printf("UTF-8 locales are %sabled\n", "dis\0en"+ (default_utf8 << 2));
325
                } else if (!strcmp(p, "8-BIT")) {
326
                        if (!(p = strtok(NULL, " =\t\n"))
327
                                || ((toupper(*p) != 'Y') && (toupper(*p) != 'N'))) {
328
                                printf("error: missing or illegal 8-BIT setting\n");
329
                                exit(EXIT_FAILURE);
330
                        }
331
                        default_8bit = (toupper(*p) == 'Y');
332
                        printf("8-BIT locales are %sabled\n", "dis\0en" + (default_8bit << 2));
333
                } else {
334
                        break;
335
                }
336
 
337
                if (((p = strtok(NULL, " \t\n")) != NULL) && (*p != '#')) {
338
                        printf("ignoring trailing text: %s...\n", p);
339
                }
340
                *line_buf = 0;
341
                continue;
342
 
343
        } while (1);
344
}
345
 
346
#ifdef __LOCALE_DATA_CODESET_LIST
347
 
348
static int find_codeset_num(const char *cs)
349
{
350
        int r = 2;
351
        char *s = __LOCALE_DATA_CODESET_LIST;
352
 
353
        /* 7-bit is 1, UTF-8 is 2, 8-bits are > 2 */
354
 
355
        if (strcmp(cs, "UTF-8") != 0) {
356
                ++r;
357
                while (*s && strcmp(__LOCALE_DATA_CODESET_LIST+ ((unsigned char) *s), cs)) {
358
/*                      printf("tried %s\n", __LOCALE_DATA_CODESET_LIST + ((unsigned char) *s)); */
359
                        ++r;
360
                        ++s;
361
                }
362
                if (!*s) {
363
                        printf("error: unsupported codeset %s\n", cs);
364
                        exit(EXIT_FAILURE);
365
                }
366
        }
367
        return r;
368
}
369
 
370
#else
371
 
372
static int find_codeset_num(const char *cs)
373
{
374
        int r = 2;
375
 
376
        /* 7-bit is 1, UTF-8 is 2, 8-bits are > 2 */
377
 
378
        if (strcmp(cs, "UTF-8") != 0) {
379
                printf("error: unsupported codeset %s\n", cs);
380
                exit(EXIT_FAILURE);
381
        }
382
        return r;
383
}
384
 
385
#endif
386
 
387
static int find_at_string_num(const char *as)
388
{
389
        int i = 0;
390
        char *p = at_strings;
391
 
392
        while (*p) {
393
                if (!strcmp(p+1, as)) {
394
                        return i;
395
                }
396
                ++i;
397
                p += 1 + (unsigned char) *p;
398
        }
399
 
400
        printf("error: unmapped @string %s\n", as);
401
        exit(EXIT_FAILURE);
402
}
403
 
404
static void read_locale_list(void)
405
{
406
        char *p;
407
        char *s;
408
        char *ln;                                       /* locale name */
409
        char *ls;                                       /* locale name ll_CC */
410
        char *as;                                       /* at string */
411
        char *ds;                                       /* dot string */
412
        char *cs;                                       /* codeset */
413
        int i;
414
 
415
        typedef struct {
416
                char *glibc_name;
417
                char name[5];
418
                char dot_cs;                            /* 0 if no codeset specified */
419
                char cs;
420
        } locale_entry;
421
 
422
        /* First the C locale. */
423
        locales[0].glibc_name = locales[0].name;
424
        strncpy(locales[0].name,"C",5);
425
        locales[0].dot_cs = 0;
426
        locales[0].cs = 1;                       /* 7-bit encoding */
427
        ++num_locales;
428
 
429
        do {
430
                if (!(p = strtok(line_buf, " \t\n")) || (*p == '#')) {
431
                        if (!fgets(line_buf, sizeof(line_buf), fp)) {
432
                                if (ferror(fp)) {
433
                                        printf("error reading file\n");
434
                                        exit(EXIT_FAILURE);
435
                                }
436
                                return;                 /* EOF */
437
                        }
438
                        if ((*line_buf == '#') && (line_buf[1] == '-')) {
439
                                break;
440
                        }
441
                        continue;
442
                }
443
 
444
                s = glibc_locale_names;
445
                for (i=0 ; i < num_locales ; i++) {
446
                        if (!strcmp(s+1, p)) {
447
                                break;
448
                        }
449
                        s += 1 + ((unsigned char) *s);
450
                }
451
                if (i < num_locales) {
452
                        printf("ignoring dulplicate locale name: %s", p);
453
                        *line_buf = 0;
454
                        continue;
455
                }
456
 
457
                /* New locale, but don't increment num until codeset verified! */
458
                *s = (char)((unsigned char) (strlen(p) + 1));
459
                strcpy(s+1, p);
460
                locales[num_locales].glibc_name = s+1;
461
                ln = p;                                 /* save locale name */
462
 
463
                if (!(p = strtok(NULL, " \t\n"))) {
464
                        printf("error: missing codeset for locale %s\n", ln);
465
                        exit(EXIT_FAILURE);
466
                }
467
                cs = p;
468
                i = find_codeset_num(p);
469
                if ((i == 2) && !default_utf8) {
470
                        printf("ignoring UTF-8 locale %s\n", ln);
471
                        *line_buf = 0;
472
                        continue;
473
                } else if ((i > 2) && !default_8bit) {
474
                        printf("ignoring 8-bit codeset locale %s\n", ln);
475
                        *line_buf = 0;
476
                        continue;
477
                }
478
                locales[num_locales].cs = (char)((unsigned char) i);
479
 
480
                if (((p = strtok(NULL, " \t\n")) != NULL) && (*p != '#')) {
481
                        printf("ignoring trailing text: %s...\n", p);
482
                }
483
 
484
                /* Now go back to locale string for .codeset and @modifier */
485
                as = strtok(ln, "@");
486
                if (as) {
487
                        as = strtok(NULL, "@");
488
                }
489
                ds = strtok(ln, ".");
490
                if (ds) {
491
                        ds = strtok(NULL, ".");
492
                }
493
                ls = ln;
494
 
495
                if ((strlen(ls) != 5) || (ls[2] != '_')) {
496
                        printf("error: illegal locale name %s\n", ls);
497
                        exit(EXIT_FAILURE);
498
                }
499
 
500
                i = 0;                                   /* value for unspecified codeset */
501
                if (ds) {
502
                        i = find_codeset_num(ds);
503
                        if ((i == 2) && !default_utf8) {
504
                                printf("ignoring UTF-8 locale %s\n", ln);
505
                                *line_buf = 0;
506
                                continue;
507
                        } else if ((i > 2) && !default_8bit) {
508
                                printf("ignoring 8-bit codeset locale %s\n", ln);
509
                                *line_buf = 0;
510
                                continue;
511
                        }
512
                }
513
                locales[num_locales].dot_cs = (char)((unsigned char) i);
514
 
515
                if (as) {
516
                        i = find_at_string_num(as);
517
                        ls[2] = at_mapto[i];
518
                }
519
                memcpy(locales[num_locales].name, ls, 5);
520
/*              printf("locale: %5.5s %2d %2d %s\n", */
521
/*                         locales[num_locales].name, */
522
/*                         locales[num_locales].cs, */
523
/*                         locales[num_locales].dot_cs, */
524
/*                         locales[num_locales].glibc_name */
525
/*                         ); */
526
                ++num_locales;
527
                *line_buf = 0;
528
        } while (1);
529
}
530
 
531
static int le_cmp(const void *a, const void *b)
532
{
533
        const locale_entry *p;
534
        const locale_entry *q;
535
        int r;
536
 
537
        p = (const locale_entry *) a;
538
        q = (const locale_entry *) b;
539
 
540
        if (!(r = p->name[0] - q->name[0])
541
                && !(r = p->name[1] - q->name[1])
542
                && !(r = p->name[3] - q->name[3])
543
                && !(r = p->name[4] - q->name[4])
544
                && !(r = p->name[2] - q->name[2])
545
                && !(r = -(p->cs - q->cs))
546
                ) {
547
                r = -(p->dot_cs - q->dot_cs);
548
                /* Reverse the ordering of the codesets so UTF-8 comes last.
549
                 * Work-around (hopefully) for glibc bug affecting at least
550
                 * the euro currency symbol. */
551
        }
552
 
553
        return r;
554
}
555
 
556
int main(int argc, char **argv)
557
{
558
        if ((argc != 2) || (!(fp = fopen(*++argv, "r")))) {
559
                printf("error: missing filename or file!\n");
560
                return EXIT_FAILURE;
561
        }
562
 
563
        at_strings_end = at_strings;
564
 
565
        read_at_mappings();
566
        read_enable_disable();
567
        read_locale_list();
568
 
569
        fclose(fp);
570
 
571
        /* handle C locale specially */
572
        qsort(locales+1, num_locales-1, sizeof(locale_entry), le_cmp);
573
 
574
#if 0
575
        for (i=0 ; i < num_locales ; i++) {
576
                printf("locale: %5.5s %2d %2d %s\n",
577
                           locales[i].name,
578
                           locales[i].cs,
579
                           locales[i].dot_cs,
580
                           locales[i].glibc_name
581
                           );
582
        }
583
#endif
584
 
585
        if (!(ofp = fopen("locale_tables.h", "w"))) {
586
                printf("error: can not open locale_tables.h for writing!\n");
587
                return EXIT_FAILURE;
588
        }
589
 
590
        do_lc_time();
591
        do_lc_numeric();
592
        do_lc_monetary();
593
        do_lc_messages();
594
        do_lc_ctype();
595
 
596
        do_locale_names();
597
 
598
        fclose(ofp);
599
 
600
        printf("total data size = %d\n", total_size);
601
        printf("null count = %d\n", null_count);
602
 
603
        return EXIT_SUCCESS;
604
}
605
 
606
static char *idx[10000];
607
static char buf[100000];
608
static char *last;
609
static int uniq;
610
 
611
static int addblock(const char *s, size_t n) /* l includes nul terminator */
612
{
613
        int j;
614
 
615
        if (!s) {
616
                ++null_count;
617
                return 0;
618
        }
619
 
620
        for (j=0 ; (j < uniq) && (idx[j] + n < last) ; j++) {
621
                if (!memcmp(s, idx[j], n)) {
622
                        return idx[j] - buf;
623
                }
624
        }
625
        if (uniq >= sizeof(idx)) {
626
                printf("too many uniq strings!\n");
627
                exit(EXIT_FAILURE);
628
        }
629
        if (last + n >= buf + sizeof(buf)) {
630
                printf("need to increase size of buf!\n");
631
                exit(EXIT_FAILURE);
632
        }
633
 
634
        idx[uniq] = last;
635
        ++uniq;
636
        memcpy(last, s, n);
637
        last += n;
638
        return idx[uniq - 1] - buf;
639
}
640
 
641
static int addstring(const char *s)
642
{
643
        int j;
644
        size_t l;
645
 
646
        if (!s) {
647
                ++null_count;
648
                return 0;
649
        }
650
 
651
        for (j=0 ; j < uniq ; j++) {
652
                if (!strcmp(s, idx[j])) {
653
                        return idx[j] - buf;
654
                }
655
        }
656
        if (uniq >= sizeof(idx)) {
657
                printf("too many uniq strings!\n");
658
                exit(EXIT_FAILURE);
659
        }
660
        l = strlen(s) + 1;
661
        if (last + l >= buf + sizeof(buf)) {
662
                printf("need to increase size of buf!\n");
663
                exit(EXIT_FAILURE);
664
        }
665
 
666
        idx[uniq] = last;
667
        ++uniq;
668
        strcpy(last, s);
669
        last += l;
670
        return idx[uniq - 1] - buf;
671
}
672
 
673
#define DO_LC_COMMON(CATEGORY) \
674
        printf("buf-size=%d  uniq=%d  rows=%d\n", \
675
                   (int)(last - buf), uniq, lc_##CATEGORY##_uniq); \
676
        printf("total = %d + %d * %d + %d = %d\n", \
677
                   num_locales, lc_##CATEGORY##_uniq, NUM_NL_##CATEGORY, (int)(last - buf), \
678
                   i = num_locales + lc_##CATEGORY##_uniq*NUM_NL_##CATEGORY + (int)(last - buf)); \
679
        total_size += i; \
680
        dump_table8c("__lc_" #CATEGORY "_data", buf, (int)(last - buf)); \
681
        for (i=0 ; i < lc_##CATEGORY##_uniq ; i++) { \
682
                m = locales[i].lc_##CATEGORY##_row; \
683
                for (k=0 ; k < NUM_NL_##CATEGORY ; k++) { \
684
                        buf[NUM_NL_##CATEGORY*i + k] = (char)((unsigned char) lc_##CATEGORY##_uniq_X[i][k]); \
685
                } \
686
        } \
687
        dump_table8("__lc_" #CATEGORY "_rows", buf, lc_##CATEGORY##_uniq * NUM_NL_##CATEGORY); \
688
        buf16[0] =0; \
689
        for (i=0 ; i < NUM_NL_##CATEGORY - 1 ; i++) { \
690
                buf16[i+1] = buf16[i] + lc_##CATEGORY##_count[i]; \
691
        } \
692
        dump_table16("__lc_" #CATEGORY "_item_offsets", buf16, NUM_NL_##CATEGORY); \
693
        m = 0; \
694
        for (k=0 ; k < NUM_NL_##CATEGORY ; k++) { \
695
                for (i=0 ; i < lc_##CATEGORY##_count[k] ; i++) { \
696
                        buf16[m] = lc_##CATEGORY##_item[k][i]; \
697
                        ++m; \
698
                } \
699
        } \
700
        dump_table16("__lc_" #CATEGORY "_item_idx", buf16, m);
701
 
702
 
703
#define DL_LC_LOOPTAIL(CATEGORY) \
704
                if (k > NUM_NL_##CATEGORY) { \
705
                        printf("error -- lc_" #CATEGORY " nl_item count > %d!\n", NUM_NL_##CATEGORY); \
706
                        exit(EXIT_FAILURE); \
707
                } \
708
                { \
709
                        int r; \
710
                        for (r=0 ; r < lc_##CATEGORY##_uniq ; r++) { \
711
                                if (!memcmp(lc_##CATEGORY##_uniq_X[lc_##CATEGORY##_uniq], \
712
                                                        lc_##CATEGORY##_uniq_X[r], NUM_NL_##CATEGORY)) { \
713
                                        break; \
714
                                } \
715
                        } \
716
                        if (r == lc_##CATEGORY##_uniq) { /* new locale row */ \
717
                                ++lc_##CATEGORY##_uniq; \
718
                                if (lc_##CATEGORY##_uniq > 255) { \
719
                                        printf("too many unique lc_" #CATEGORY " rows!\n"); \
720
                                        exit(EXIT_FAILURE); \
721
                                } \
722
                        } \
723
                        locales[i].lc_##CATEGORY##_row = r; \
724
                }
725
 
726
 
727
 
728
static int buf16[100*256];
729
 
730
static void dump_table8(const char *name, const char *tbl, int len)
731
{
732
        int i;
733
 
734
        fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);
735
        fprintf(ofp, "static const unsigned char %s[%d] = {", name, len);
736
        for (i=0 ; i < len ; i++) {
737
                if ((i % 12) == 0) {
738
                        fprintf(ofp, "\n\t");
739
                }
740
                fprintf(ofp, "%#4x, ", (int)((unsigned char) tbl[i]));
741
        }
742
        fprintf(ofp, "\n};\n\n");
743
}
744
 
745
#define __C_isdigit(c) \
746
        ((sizeof(c) == sizeof(char)) \
747
         ? (((unsigned char)((c) - '0')) < 10) \
748
         : (((unsigned int)((c) - '0')) < 10))
749
#define __C_isalpha(c) \
750
        ((sizeof(c) == sizeof(char)) \
751
         ? (((unsigned char)(((c) | 0x20) - 'a')) < 26) \
752
         : (((unsigned int)(((c) | 0x20) - 'a')) < 26))
753
#define __C_isalnum(c) (__C_isalpha(c) || __C_isdigit(c))
754
 
755
static void dump_table8c(const char *name, const char *tbl, int len)
756
{
757
        int i;
758
 
759
        fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);
760
        fprintf(ofp, "static const unsigned char %s[%d] = {", name, len);
761
        for (i=0 ; i < len ; i++) {
762
                if ((i % 12) == 0) {
763
                        fprintf(ofp, "\n\t");
764
                }
765
                if (__C_isalnum(tbl[i]) || (tbl[i] == ' ')) {
766
                        fprintf(ofp, " '%c', ", (int)((unsigned char) tbl[i]));
767
                } else {
768
                        fprintf(ofp, "%#4x, ", (int)((unsigned char) tbl[i]));
769
                }
770
        }
771
        fprintf(ofp, "\n};\n\n");
772
}
773
 
774
static void dump_table16(const char *name, const int *tbl, int len)
775
{
776
        int i;
777
 
778
        fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);
779
        fprintf(ofp, "static const uint16_t %s[%d] = {", name, len);
780
        for (i=0 ; i < len ; i++) {
781
                if ((i % 8) == 0) {
782
                        fprintf(ofp, "\n\t");
783
                }
784
                if (tbl[i] != (uint16_t) tbl[i]) {
785
                        printf("error - falls outside uint16 range!\n");
786
                        exit(EXIT_FAILURE);
787
                }
788
                fprintf(ofp, "%#6x, ", tbl[i]);
789
        }
790
        fprintf(ofp, "\n};\n\n");
791
}
792
 
793
 
794
#define NUM_NL_time 50
795
 
796
static int lc_time_item[NUM_NL_time][256];
797
static int lc_time_count[NUM_NL_time];
798
static unsigned char lc_time_uniq_X[700][NUM_NL_time];
799
static int lc_time_uniq;
800
 
801
#define DO_NL_S(X)      lc_time_S(X, k++)
802
 
803
static void lc_time_S(int X, int k)
804
{
805
        size_t len;
806
        int j, m;
807
        const char *s = nl_langinfo(X);
808
        const char *p;
809
        static const char nulbuf[] = "";
810
 
811
        if (X == ALT_DIGITS) {
812
                len = 1;
813
                if (!s) {
814
                        s = nulbuf;
815
                }
816
                if (*s) {
817
                        p = s;
818
                        for (j = 0 ; j < 100 ; j++) {
819
                                while (*p) {
820
                                        ++p;
821
                                }
822
                                ++p;
823
                        }
824
                        len = p - s;
825
                }
826
                j = addblock(s, len);
827
/*              if (len > 1) fprintf(stderr, "alt_digit: called addblock with len %zd\n", len); */
828
        } else if (X == ERA) {
829
                if (!s) {
830
                        s = nulbuf;
831
                }
832
                p = s;
833
                while (*p) {
834
                        while (*p) {
835
                                ++p;
836
                        }
837
                        ++p;
838
                }
839
                ++p;
840
                j = addblock(s, p - s);
841
/*              if (p-s > 1) fprintf(stderr, "era: called addblock with len %d\n", p-s); */
842
        } else {
843
                j = addstring(s);
844
        }
845
        for (m=0 ; m < lc_time_count[k] ; m++) {
846
                if (lc_time_item[k][m] == j) {
847
                        break;
848
                }
849
        }
850
        if (m == lc_time_count[k]) { /* new for this nl_item */
851
                if (m > 255) {
852
                        printf("too many nl_item %d entries in lc_time\n", k);
853
                        exit(EXIT_FAILURE);
854
                }
855
                lc_time_item[k][m] = j;
856
                ++lc_time_count[k];
857
        }
858
        lc_time_uniq_X[lc_time_uniq][k] = m;
859
}
860
 
861
static void do_lc_time(void)
862
{
863
        int i, k, m;
864
 
865
        last = buf+1;
866
        uniq = 1;
867
        *buf = 0;
868
        *idx = buf;
869
 
870
        for (i=0 ; i < num_locales ; i++) {
871
                k = 0;
872
 
873
                if (!setlocale(LC_ALL, locales[i].glibc_name)) {
874
                        printf("setlocale(LC_ALL,%s) failed!\n",
875
                                   locales[i].glibc_name);
876
                }
877
 
878
                DO_NL_S(ABDAY_1);
879
                DO_NL_S(ABDAY_2);
880
                DO_NL_S(ABDAY_3);
881
                DO_NL_S(ABDAY_4);
882
                DO_NL_S(ABDAY_5);
883
                DO_NL_S(ABDAY_6);
884
                DO_NL_S(ABDAY_7);
885
 
886
                DO_NL_S(DAY_1);
887
                DO_NL_S(DAY_2);
888
                DO_NL_S(DAY_3);
889
                DO_NL_S(DAY_4);
890
                DO_NL_S(DAY_5);
891
                DO_NL_S(DAY_6);
892
                DO_NL_S(DAY_7);
893
 
894
                DO_NL_S(ABMON_1);
895
                DO_NL_S(ABMON_2);
896
                DO_NL_S(ABMON_3);
897
                DO_NL_S(ABMON_4);
898
                DO_NL_S(ABMON_5);
899
                DO_NL_S(ABMON_6);
900
                DO_NL_S(ABMON_7);
901
                DO_NL_S(ABMON_8);
902
                DO_NL_S(ABMON_9);
903
                DO_NL_S(ABMON_10);
904
                DO_NL_S(ABMON_11);
905
                DO_NL_S(ABMON_12);
906
 
907
                DO_NL_S(MON_1);
908
                DO_NL_S(MON_2);
909
                DO_NL_S(MON_3);
910
                DO_NL_S(MON_4);
911
                DO_NL_S(MON_5);
912
                DO_NL_S(MON_6);
913
                DO_NL_S(MON_7);
914
                DO_NL_S(MON_8);
915
                DO_NL_S(MON_9);
916
                DO_NL_S(MON_10);
917
                DO_NL_S(MON_11);
918
                DO_NL_S(MON_12);
919
 
920
                DO_NL_S(AM_STR);
921
                DO_NL_S(PM_STR);
922
 
923
                DO_NL_S(D_T_FMT);
924
                DO_NL_S(D_FMT);
925
                DO_NL_S(T_FMT);
926
                DO_NL_S(T_FMT_AMPM);
927
                DO_NL_S(ERA);
928
 
929
                DO_NL_S(ERA_YEAR);              /* non SuSv3 */
930
                DO_NL_S(ERA_D_FMT);
931
                DO_NL_S(ALT_DIGITS);
932
                DO_NL_S(ERA_D_T_FMT);
933
                DO_NL_S(ERA_T_FMT);
934
 
935
                DL_LC_LOOPTAIL(time)
936
        }
937
 
938
        DO_LC_COMMON(time)
939
}
940
 
941
#undef DO_NL_S
942
 
943
#define NUM_NL_numeric 3
944
 
945
static int lc_numeric_item[NUM_NL_numeric][256];
946
static int lc_numeric_count[NUM_NL_numeric];
947
static unsigned char lc_numeric_uniq_X[700][NUM_NL_numeric];
948
static int lc_numeric_uniq;
949
 
950
#define DO_NL_S(X)      lc_numeric_S(X, k++)
951
 
952
static void lc_numeric_S(int X, int k)
953
{
954
        int j, m;
955
        char buf[256];
956
        char *e;
957
        char *s;
958
        char c;
959
 
960
        s = nl_langinfo(X);
961
        if (X == GROUPING) {
962
                if (s) {
963
                        if ((*s == CHAR_MAX) || (*s == -1)) { /* stupid glibc... :-( */
964
                                s = "";
965
                        }
966
                        e = s;
967
                        c = 0;
968
                        while (*e) { /* find end of string */
969
                                if (*e == CHAR_MAX) {
970
                                        c = CHAR_MAX;
971
                                        ++e;
972
                                        break;
973
                                }
974
                                ++e;
975
                        }
976
                        if ((e - s) > sizeof(buf)) {
977
                                printf("grouping specifier too long\n");
978
                                exit(EXIT_FAILURE);
979
                        }
980
                        strncpy(buf, s, (e-s));
981
                        e = buf + (e-s);
982
                        *e = 0;                          /* Make sure we're null-terminated. */
983
 
984
                        if (c != CHAR_MAX) { /* remove duplicate repeats */
985
                                while (e > buf) {
986
                                        --e;
987
                                        if (*e != e[-1]) {
988
                                                break;
989
                                        }
990
                                }
991
                                *++e = 0;
992
                        }
993
                        s = buf;
994
                }
995
        }
996
        j = addstring(s);
997
        for (m=0 ; m < lc_numeric_count[k] ; m++) {
998
                if (lc_numeric_item[k][m] == j) {
999
                        break;
1000
                }
1001
        }
1002
        if (m == lc_numeric_count[k]) { /* new for this nl_item */
1003
                if (m > 255) {
1004
                        printf("too many nl_item %d entries in lc_numeric\n", k);
1005
                        exit(EXIT_FAILURE);
1006
                }
1007
                lc_numeric_item[k][m] = j;
1008
                ++lc_numeric_count[k];
1009
        }
1010
/*      printf("\\x%02x", m); */
1011
        lc_numeric_uniq_X[lc_numeric_uniq][k] = m;
1012
}
1013
 
1014
static void do_lc_numeric(void)
1015
{
1016
        int i, k, m;
1017
 
1018
        last = buf+1;
1019
        uniq = 1;
1020
        *buf = 0;
1021
        *idx = buf;
1022
 
1023
        for (i=0 ; i < num_locales ; i++) {
1024
                k = 0;
1025
 
1026
                if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1027
                        printf("setlocale(LC_ALL,%s) failed!\n",
1028
                                   locales[i].glibc_name);
1029
                }
1030
 
1031
                DO_NL_S(RADIXCHAR);             /* DECIMAL_POINT */
1032
                DO_NL_S(THOUSEP);               /* THOUSANDS_SEP */
1033
                DO_NL_S(GROUPING);
1034
 
1035
                DL_LC_LOOPTAIL(numeric)
1036
        }
1037
 
1038
        DO_LC_COMMON(numeric)
1039
}
1040
 
1041
#undef DO_NL_S
1042
 
1043
#define NUM_NL_monetary (7+14+1)
1044
 
1045
static int lc_monetary_item[NUM_NL_monetary][256];
1046
static int lc_monetary_count[NUM_NL_monetary];
1047
static unsigned char lc_monetary_uniq_X[700][NUM_NL_monetary];
1048
static int lc_monetary_uniq;
1049
 
1050
#define DO_NL_S(X)      lc_monetary_S(X, k++)
1051
 
1052
/*  #define DO_NL_C(X)          printf("%#02x", (int)(unsigned char)(*nl_langinfo(X))); */
1053
#define DO_NL_C(X) lc_monetary_C(X, k++)
1054
 
1055
static void lc_monetary_C(int X, int k)
1056
{
1057
        int j, m;
1058
        char c_buf[2];
1059
 
1060
#warning fix the char entries for monetary... target signedness of char may be different!
1061
 
1062
        c_buf[1] = 0;
1063
        c_buf[0] = *nl_langinfo(X);
1064
        j = addstring(c_buf);
1065
        for (m=0 ; m < lc_monetary_count[k] ; m++) {
1066
                if (lc_monetary_item[k][m] == j) {
1067
                        break;
1068
                }
1069
        }
1070
        if (m == lc_monetary_count[k]) { /* new for this nl_item */
1071
                if (m > 255) {
1072
                        printf("too many nl_item %d entries in lc_monetary\n", k);
1073
                        exit(EXIT_FAILURE);
1074
                }
1075
                lc_monetary_item[k][m] = j;
1076
                ++lc_monetary_count[k];
1077
        }
1078
/*      printf("\\x%02x", m); */
1079
        lc_monetary_uniq_X[lc_monetary_uniq][k] = m;
1080
}
1081
 
1082
 
1083
static void lc_monetary_S(int X, int k)
1084
{
1085
        int j, m;
1086
        char buf[256];
1087
        char *e;
1088
        char *s;
1089
        char c;
1090
 
1091
        s = nl_langinfo(X);
1092
        if (X == MON_GROUPING) {
1093
                if (s) {
1094
                        if ((*s == CHAR_MAX) || (*s == -1)) { /* stupid glibc... :-( */
1095
                                s = "";
1096
                        }
1097
                        e = s;
1098
                        c = 0;
1099
                        while (*e) { /* find end of string */
1100
                                if (*e == CHAR_MAX) {
1101
                                        c = CHAR_MAX;
1102
                                        ++e;
1103
                                        break;
1104
                                }
1105
                                ++e;
1106
                        }
1107
                        if ((e - s) > sizeof(buf)) {
1108
                                printf("mon_grouping specifier too long\n");
1109
                                exit(EXIT_FAILURE);
1110
                        }
1111
                        strncpy(buf, s, (e-s));
1112
                        e = buf + (e-s);
1113
                        *e = 0;                          /* Make sure we're null-terminated. */
1114
 
1115
                        if (c != CHAR_MAX) { /* remove duplicate repeats */
1116
                                while (e > buf) {
1117
                                        --e;
1118
                                        if (*e != e[-1]) {
1119
                                                break;
1120
                                        }
1121
                                }
1122
                                *++e = 0;
1123
                        }
1124
                        s = buf;
1125
                }
1126
        }
1127
        j = addstring(s);
1128
        for (m=0 ; m < lc_monetary_count[k] ; m++) {
1129
                if (lc_monetary_item[k][m] == j) {
1130
                        break;
1131
                }
1132
        }
1133
        if (m == lc_monetary_count[k]) { /* new for this nl_item */
1134
                if (m > 255) {
1135
                        printf("too many nl_item %d entries in lc_monetary\n", k);
1136
                        exit(EXIT_FAILURE);
1137
                }
1138
                lc_monetary_item[k][m] = j;
1139
                ++lc_monetary_count[k];
1140
        }
1141
/*      printf("\\x%02x", m); */
1142
        lc_monetary_uniq_X[lc_monetary_uniq][k] = m;
1143
}
1144
 
1145
static void do_lc_monetary(void)
1146
{
1147
        int i, k, m;
1148
 
1149
        last = buf+1;
1150
        uniq = 1;
1151
        *buf = 0;
1152
        *idx = buf;
1153
 
1154
        for (i=0 ; i < num_locales ; i++) {
1155
                k = 0;
1156
 
1157
                if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1158
                        printf("setlocale(LC_ALL,%s) failed!\n",
1159
                                   locales[i].glibc_name);
1160
                }
1161
 
1162
 
1163
                /* non SUSv3 */
1164
                DO_NL_S(INT_CURR_SYMBOL);
1165
                DO_NL_S(CURRENCY_SYMBOL);
1166
                DO_NL_S(MON_DECIMAL_POINT);
1167
                DO_NL_S(MON_THOUSANDS_SEP);
1168
                DO_NL_S(MON_GROUPING);
1169
                DO_NL_S(POSITIVE_SIGN);
1170
                DO_NL_S(NEGATIVE_SIGN);
1171
                DO_NL_C(INT_FRAC_DIGITS);
1172
                DO_NL_C(FRAC_DIGITS);
1173
                DO_NL_C(P_CS_PRECEDES);
1174
                DO_NL_C(P_SEP_BY_SPACE);
1175
                DO_NL_C(N_CS_PRECEDES);
1176
                DO_NL_C(N_SEP_BY_SPACE);
1177
                DO_NL_C(P_SIGN_POSN);
1178
                DO_NL_C(N_SIGN_POSN);
1179
                DO_NL_C(INT_P_CS_PRECEDES);
1180
                DO_NL_C(INT_P_SEP_BY_SPACE);
1181
                DO_NL_C(INT_N_CS_PRECEDES);
1182
                DO_NL_C(INT_N_SEP_BY_SPACE);
1183
                DO_NL_C(INT_P_SIGN_POSN);
1184
                DO_NL_C(INT_N_SIGN_POSN);
1185
 
1186
                DO_NL_S(CRNCYSTR);              /* CURRENCY_SYMBOL */
1187
 
1188
                DL_LC_LOOPTAIL(monetary)
1189
        }
1190
 
1191
        DO_LC_COMMON(monetary)
1192
}
1193
 
1194
 
1195
#undef DO_NL_S
1196
 
1197
#define NUM_NL_messages 4
1198
 
1199
static int lc_messages_item[NUM_NL_messages][256];
1200
static int lc_messages_count[NUM_NL_messages];
1201
static unsigned char lc_messages_uniq_X[700][NUM_NL_messages];
1202
static int lc_messages_uniq;
1203
 
1204
#define DO_NL_S(X)      lc_messages_S(X, k++)
1205
 
1206
static void lc_messages_S(int X, int k)
1207
{
1208
        int j, m;
1209
        j = addstring(nl_langinfo(X));
1210
        for (m=0 ; m < lc_messages_count[k] ; m++) {
1211
                if (lc_messages_item[k][m] == j) {
1212
                        break;
1213
                }
1214
        }
1215
        if (m == lc_messages_count[k]) { /* new for this nl_item */
1216
                if (m > 255) {
1217
                        printf("too many nl_item %d entries in lc_messages\n", k);
1218
                        exit(EXIT_FAILURE);
1219
                }
1220
                lc_messages_item[k][m] = j;
1221
                ++lc_messages_count[k];
1222
        }
1223
/*      printf("\\x%02x", m); */
1224
        lc_messages_uniq_X[lc_messages_uniq][k] = m;
1225
}
1226
 
1227
static void do_lc_messages(void)
1228
{
1229
        int i, k, m;
1230
 
1231
        last = buf+1;
1232
        uniq = 1;
1233
        *buf = 0;
1234
        *idx = buf;
1235
 
1236
        for (i=0 ; i < num_locales ; i++) {
1237
                k = 0;
1238
 
1239
                if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1240
                        printf("setlocale(LC_ALL,%s) failed!\n",
1241
                                   locales[i].glibc_name);
1242
                }
1243
 
1244
                DO_NL_S(YESEXPR);
1245
                DO_NL_S(NOEXPR);
1246
                DO_NL_S(YESSTR);
1247
                DO_NL_S(NOSTR);
1248
 
1249
                DL_LC_LOOPTAIL(messages)
1250
        }
1251
 
1252
        DO_LC_COMMON(messages)
1253
}
1254
 
1255
#undef DO_NL_S
1256
 
1257
#define NUM_NL_ctype 10
1258
 
1259
static int lc_ctype_item[NUM_NL_ctype][256];
1260
static int lc_ctype_count[NUM_NL_ctype];
1261
static unsigned char lc_ctype_uniq_X[700][NUM_NL_ctype];
1262
static int lc_ctype_uniq;
1263
 
1264
#define DO_NL_S(X)      lc_ctype_S(X, k++)
1265
 
1266
static void lc_ctype_S(int X, int k)
1267
{
1268
        int j, m;
1269
        j = addstring(nl_langinfo(X));
1270
        for (m=0 ; m < lc_ctype_count[k] ; m++) {
1271
                if (lc_ctype_item[k][m] == j) {
1272
                        break;
1273
                }
1274
        }
1275
        if (m == lc_ctype_count[k]) { /* new for this nl_item */
1276
                if (m > 255) {
1277
                        printf("too many nl_item %d entries in lc_ctype\n", k);
1278
                        exit(EXIT_FAILURE);
1279
                }
1280
                lc_ctype_item[k][m] = j;
1281
                ++lc_ctype_count[k];
1282
        }
1283
/*      printf("\\x%02x", m); */
1284
        lc_ctype_uniq_X[lc_ctype_uniq][k] = m;
1285
}
1286
 
1287
static void do_lc_ctype(void)
1288
{
1289
        int i, k, m;
1290
 
1291
        last = buf+1;
1292
        uniq = 1;
1293
        *buf = 0;
1294
        *idx = buf;
1295
 
1296
        for (i=0 ; i < num_locales ; i++) {
1297
                k = 0;
1298
 
1299
                if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1300
                        printf("setlocale(LC_ALL,%s) failed!\n",
1301
                                   locales[i].glibc_name);
1302
                }
1303
 
1304
                DO_NL_S(_NL_CTYPE_OUTDIGIT0_MB);
1305
                DO_NL_S(_NL_CTYPE_OUTDIGIT1_MB);
1306
                DO_NL_S(_NL_CTYPE_OUTDIGIT2_MB);
1307
                DO_NL_S(_NL_CTYPE_OUTDIGIT3_MB);
1308
                DO_NL_S(_NL_CTYPE_OUTDIGIT4_MB);
1309
                DO_NL_S(_NL_CTYPE_OUTDIGIT5_MB);
1310
                DO_NL_S(_NL_CTYPE_OUTDIGIT6_MB);
1311
                DO_NL_S(_NL_CTYPE_OUTDIGIT7_MB);
1312
                DO_NL_S(_NL_CTYPE_OUTDIGIT8_MB);
1313
                DO_NL_S(_NL_CTYPE_OUTDIGIT9_MB);
1314
 
1315
                DL_LC_LOOPTAIL(ctype)
1316
        }
1317
 
1318
        DO_LC_COMMON(ctype)
1319
}

powered by: WebSVN 2.1.0

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