16 #define __LOCALE_DATA_CATEGORIES 6
18 /* must agree with ordering of gen_mmap! */
19 static const char *lc_names[] = {
26 #if __LOCALE_DATA_CATEGORIES == 12
33 #elif __LOCALE_DATA_CATEGORIES != 6
34 #error unsupported __LOCALE_DATA_CATEGORIES value!
43 char dot_cs; /* 0 if no codeset specified */
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
56 static void read_at_mappings(void);
57 static void read_enable_disable(void);
58 static void read_locale_list(void);
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);
67 static void do_lc_time(void);
68 static void do_lc_numeric(void);
69 static void do_lc_monetary(void);
71 static void do_lc_messages(void);
72 static void do_lc_ctype(void);
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];
85 static int num_locales;
87 static int default_utf8;
88 static int default_8bit;
90 static int total_size;
91 static int null_count;
93 static unsigned verbose = 0;
98 static int verbose_msg(const unsigned lvl, const char *fmt, ...)
105 ret = vfprintf(stderr, fmt, arg);
111 static void error_msg(const char *fmt, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
112 static void error_msg(const char *fmt, ...)
116 fprintf(stderr, "Error: ");
118 fprintf(stderr, "file %s (%d): ", fname[fno], lineno[fno]);
121 vfprintf(stderr, fmt, arg);
123 fprintf(stderr, "\n");
128 static void do_locale_names(void)
130 /* "C" locale name is handled specially by the setlocale code. */
134 if (num_locales <= 1) {
135 /* error_msg("only C locale?"); */
136 fprintf(ofp, "static const unsigned char __locales[%d];\n", (3 + __LOCALE_DATA_CATEGORIES));
137 fprintf(ofp, "static const unsigned char __locale_names5[5];\n");
140 fprintf(ofp, "#define __CTYPE_HAS_UTF_8_LOCALES\t\t\t1\n");
142 fprintf(ofp, "#define __LOCALE_DATA_CATEGORIES\t\t\t%d\n", __LOCALE_DATA_CATEGORIES);
143 fprintf(ofp, "#define __LOCALE_DATA_WIDTH_LOCALES\t\t\t%d\n", 3+__LOCALE_DATA_CATEGORIES);
144 fprintf(ofp, "#define __LOCALE_DATA_NUM_LOCALES\t\t\t%d\n", num_locales);
145 fprintf(ofp, "static const unsigned char __locales[%d] = {\n",
146 (num_locales) * (3 + __LOCALE_DATA_CATEGORIES));
147 for (i=0 ; i < num_locales ; i++) {
148 if (memcmp(locales[i].name, locales[i-1].name, 5) != 0) {
149 locales[i].idx_name = uniq;
152 locales[i].idx_name = uniq - 1;
154 fprintf(ofp, "\t%#4x, ", (int)((unsigned char) locales[i].idx_name));
155 fprintf(ofp, "\t%#4x, ", (int)((unsigned char) locales[i].dot_cs));
156 fprintf(ofp, "\t%#4x, ", (int)((unsigned char) locales[i].cs));
157 /* lc_ctype would store translit flags and turkish up/low flag. */
158 fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_ctype_row));
159 fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_numeric_row));
160 fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_monetary_row));
161 fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_time_row));
164 if (strlen(locales[i].glibc_name) >= 5) {
165 fprintf(ofp, "COL_IDX_%.2s_%.2s, ", locales[i].glibc_name, locales[i].glibc_name+3);
166 } else if (!strcmp(locales[i].glibc_name, "C")) {
167 fprintf(ofp, "COL_IDX_C , ");
169 error_msg("don't know how to handle COL_IDX_ for %s", locales[i].glibc_name);
172 fprintf(ofp, "%#4x, ", 0); /* place holder for lc_collate */
174 fprintf(ofp, "%#4x, ", (int)((unsigned char) locales[i].lc_messages_row));
175 fprintf(ofp, "\t/* %s */\n", locales[i].glibc_name);
177 fprintf(ofp, "};\n\n");
179 fprintf(ofp, "#define __LOCALE_DATA_NUM_LOCALE_NAMES\t\t%d\n", uniq );
180 fprintf(ofp, "static const unsigned char __locale_names5[%d] = \n\t", uniq * 5);
182 for (i=1 ; i < num_locales ; i++) {
183 if (memcmp(locales[i].name, locales[i-1].name, 5) != 0) {
184 fprintf(ofp, "\"%5.5s\" ", locales[i].name);
186 if ((uniq % 8) == 0) {
187 fprintf(ofp, "\n\t");
191 fprintf(ofp,";\n\n");
193 if (at_strings_end > at_strings) {
200 p += 1 + (unsigned char) *p;
202 /* len, char, string\0 */
203 fprintf(ofp, "#define __LOCALE_DATA_AT_MODIFIERS_LENGTH\t\t%d\n",
204 i + (at_strings_end - at_strings));
205 fprintf(ofp, "static const unsigned char __locale_at_modifiers[%d] = {",
206 i + (at_strings_end - at_strings));
210 fprintf(ofp, "\n\t%4d, '%c',",
211 (unsigned char) *p, /* len of string\0 */
213 for (j=1 ; j < ((unsigned char) *p) ; j++) {
214 fprintf(ofp, " '%c',", p[j]);
218 p += 1 + (unsigned char) *p;
220 fprintf(ofp, "\n};\n\n");
224 int pos[__LOCALE_DATA_CATEGORIES];
225 pos[0] = __LOCALE_DATA_CATEGORIES;
226 for (i=0 ; i < __LOCALE_DATA_CATEGORIES ; i++) {
227 fprintf(ofp, "#define __%s\t\t%d\n", lc_names[i], i);
228 if (i + 1 < __LOCALE_DATA_CATEGORIES) {
229 pos[i+1] = 1 + strlen(lc_names[i]) + pos[i];
232 if (pos[__LOCALE_DATA_CATEGORIES-1] > 255) {
233 error_msg("lc_names is too big (%d)", pos[__LOCALE_DATA_CATEGORIES-1]);
235 fprintf(ofp, "#define __LC_ALL\t\t%d\n\n", i);
237 fprintf(ofp, "#define __lc_names_LEN\t\t%d\n",
238 pos[__LOCALE_DATA_CATEGORIES-1] + strlen(lc_names[__LOCALE_DATA_CATEGORIES-1]) + 1);
239 total_size += pos[__LOCALE_DATA_CATEGORIES-1] + strlen(lc_names[__LOCALE_DATA_CATEGORIES-1]) + 1;
241 fprintf(ofp, "static unsigned const char lc_names[%d] =\n",
242 pos[__LOCALE_DATA_CATEGORIES-1] + strlen(lc_names[__LOCALE_DATA_CATEGORIES-1]) + 1);
243 fprintf(ofp, "\t\"");
244 for (i=0 ; i < __LOCALE_DATA_CATEGORIES ; i++) {
245 fprintf(ofp, "\\x%02x", (unsigned char) pos[i]);
248 for (i=0 ; i < __LOCALE_DATA_CATEGORIES ; i++) {
249 fprintf(ofp, "\n\t\"%s\\0\"", lc_names[i]);
251 fprintf(ofp, ";\n\n");
254 verbose_msg(VDETAIL,"locale data = %d name data = %d for %d uniq\n",
255 num_locales * (3 + __LOCALE_DATA_CATEGORIES), uniq * 5, uniq);
257 total_size += num_locales * (3 + __LOCALE_DATA_CATEGORIES) + uniq * 5;
262 static void read_at_mappings(void)
269 if (!(p = strtok(line_buf, " \t\n")) || (*p == '#')) {
270 if (!fgets(line_buf, sizeof(line_buf), fp)) {
272 error_msg("reading file");
276 if ((*line_buf == '#') && (line_buf[1] == '-')) {
283 error_msg("missing @modifier name");
285 m = p; /* save the modifier name */
286 if (!(p = strtok(NULL, " \t\n")) || p[1] || (((unsigned char) *p) > 0x7f)) {
287 error_msg("missing or illegal @modifier mapping char");
289 if (at_mappings[(int)((unsigned char) *p)]) {
290 error_msg("reused @modifier mapping char");
292 at_mappings[(int)((unsigned char) *p)] = 1;
295 *at_strings_end = (char)( (unsigned char) (strlen(m)) );
296 strcpy(++at_strings_end, m+1);
297 at_strings_end += (unsigned char) at_strings_end[-1];
299 verbose_msg(VDETAIL,"@mapping: \"%s\" to '%c'\n", m, *p);
301 if (((p = strtok(NULL, " \t\n")) != NULL) && (*p != '#')) {
302 fprintf(stderr,"ignoring trailing text: %s...\n", p);
315 verbose_msg(VDETAIL,"no @ strings\n");
320 verbose_msg(VDETAIL,"%s\n", p+1);
321 p += 1 + (unsigned char) *p;
327 static void read_enable_disable(void)
332 if (!(p = strtok(line_buf, " =\t\n")) || (*p == '#')) {
333 if (!fgets(line_buf, sizeof(line_buf), fp)) {
335 error_msg("reading file");
339 if ((*line_buf == '#') && (line_buf[1] == '-')) {
344 if (!strcmp(p, "UTF-8")) {
345 if (!(p = strtok(NULL, " =\t\n"))
346 || ((toupper(*p) != 'Y') && (toupper(*p) != 'N'))) {
347 error_msg("missing or illegal UTF-8 setting");
349 default_utf8 = (toupper(*p) == 'Y');
350 verbose_msg(VINFO,"UTF-8 locales are %sabled\n", "dis\0en"+ (default_utf8 << 2));
351 } else if (!strcmp(p, "8-BIT")) {
352 if (!(p = strtok(NULL, " =\t\n"))
353 || ((toupper(*p) != 'Y') && (toupper(*p) != 'N'))) {
354 error_msg("missing or illegal 8-BIT setting");
356 default_8bit = (toupper(*p) == 'Y');
357 verbose_msg(VINFO,"8-BIT locales are %sabled\n", "dis\0en" + (default_8bit << 2));
362 if (((p = strtok(NULL, " \t\n")) != NULL) && (*p != '#')) {
363 fprintf(stderr,"ignoring trailing text: %s...\n", p);
371 #ifdef __LOCALE_DATA_CODESET_LIST
373 static int find_codeset_num(const char *cs)
376 char *s = __LOCALE_DATA_CODESET_LIST;
378 /* 7-bit is 1, UTF-8 is 2, 8-bits are > 2 */
380 if (strcmp(cs, "UTF-8") != 0) {
382 while (*s && strcmp(__LOCALE_DATA_CODESET_LIST+ ((unsigned char) *s), cs)) {
383 /* verbose_msg(VDETAIL,"tried %s\n", __LOCALE_DATA_CODESET_LIST + ((unsigned char) *s)); */
388 error_msg("unsupported codeset %s", cs);
396 static int find_codeset_num(const char *cs)
400 /* 7-bit is 1, UTF-8 is 2, 8-bits are > 2 */
402 if (strcmp(cs, "UTF-8") != 0) {
403 error_msg("unsupported codeset %s", cs);
410 static int find_at_string_num(const char *as)
413 char *p = at_strings;
416 if (!strcmp(p+1, as)) {
420 p += 1 + (unsigned char) *p;
423 error_msg("error: unmapped @string %s", as);
426 static void read_locale_list(void)
430 char *ln; /* locale name */
431 char *ls; /* locale name ll_CC */
432 char *as; /* at string */
433 char *ds; /* dot string */
434 char *cs; /* codeset */
440 char dot_cs; /* 0 if no codeset specified */
444 /* First the C locale. */
445 locales[0].glibc_name = locales[0].name;
446 strncpy(locales[0].name,"C",5);
447 locales[0].dot_cs = 0;
448 locales[0].cs = 1; /* 7-bit encoding */
452 if (!(p = strtok(line_buf, " \t\n")) || (*p == '#')) {
453 if (!fgets(line_buf, sizeof(line_buf), fp)) {
455 error_msg("reading file");
459 if ((*line_buf == '#') && (line_buf[1] == '-')) {
465 s = glibc_locale_names;
466 for (i=0 ; i < num_locales ; i++) {
467 if (!strcmp(s+1, p)) {
470 s += 1 + ((unsigned char) *s);
472 if (i < num_locales) {
473 fprintf(stderr,"ignoring duplicate locale name: %s", p);
478 /* New locale, but don't increment num until codeset verified! */
479 *s = (char)((unsigned char) (strlen(p) + 1));
481 locales[num_locales].glibc_name = s+1;
482 ln = p; /* save locale name */
484 if (!(p = strtok(NULL, " \t\n"))) {
485 error_msg("missing codeset for locale %s", ln);
488 i = find_codeset_num(p);
489 if ((i == 2) && !default_utf8) {
490 fprintf(stderr,"ignoring UTF-8 locale %s\n", ln);
493 } else if ((i > 2) && !default_8bit) {
494 fprintf(stderr,"ignoring 8-bit codeset locale %s\n", ln);
498 locales[num_locales].cs = (char)((unsigned char) i);
500 if (((p = strtok(NULL, " \t\n")) != NULL) && (*p != '#')) {
501 verbose_msg(VINFO,"ignoring trailing text: %s...\n", p);
504 /* Now go back to locale string for .codeset and @modifier */
505 as = strtok(ln, "@");
507 as = strtok(NULL, "@");
509 ds = strtok(ln, ".");
511 ds = strtok(NULL, ".");
515 if ((strlen(ls) != 5) || (ls[2] != '_')) {
516 error_msg("illegal locale name %s", ls);
519 i = 0; /* value for unspecified codeset */
521 i = find_codeset_num(ds);
522 if ((i == 2) && !default_utf8) {
523 fprintf(stderr,"ignoring UTF-8 locale %s\n", ln);
526 } else if ((i > 2) && !default_8bit) {
527 fprintf(stderr,"ignoring 8-bit codeset locale %s\n", ln);
532 locales[num_locales].dot_cs = (char)((unsigned char) i);
535 i = find_at_string_num(as);
538 memcpy(locales[num_locales].name, ls, 5);
539 /* verbose_msg(VDETAIL,"locale: %5.5s %2d %2d %s\n", */
540 /* locales[num_locales].name, */
541 /* locales[num_locales].cs, */
542 /* locales[num_locales].dot_cs, */
543 /* locales[num_locales].glibc_name */
550 static int le_cmp(const void *a, const void *b)
552 const locale_entry *p;
553 const locale_entry *q;
556 p = (const locale_entry *) a;
557 q = (const locale_entry *) b;
559 if (!(r = p->name[0] - q->name[0])
560 && !(r = p->name[1] - q->name[1])
561 && !(r = p->name[3] - q->name[3])
562 && !(r = p->name[4] - q->name[4])
563 && !(r = p->name[2] - q->name[2])
564 && !(r = -(p->cs - q->cs))
566 r = -(p->dot_cs - q->dot_cs);
567 /* Reverse the ordering of the codesets so UTF-8 comes last.
568 * Work-around (hopefully) for glibc bug affecting at least
569 * the euro currency symbol. */
575 int main(int argc, char **argv)
577 char *output_file = NULL;
581 if (!strcmp(*argv, "-o")) {
583 output_file = strdup(*++argv);
584 } else if (!strcmp(*argv, "-v")) {
586 } else if (!(fp = fopen(*argv, "r"))) {
588 error_msg("missing filename or file!");
593 if (output_file == NULL)
594 output_file = strdup("locale_tables.h");
596 at_strings_end = at_strings;
599 read_enable_disable();
604 /* handle C locale specially */
605 qsort(locales+1, num_locales-1, sizeof(locale_entry), le_cmp);
608 for (i=0 ; i < num_locales ; i++) {
609 verbose_msg(VDETAIL,"locale: %5.5s %2d %2d %s\n",
613 locales[i].glibc_name
618 output_file = *++argv;
619 if (output_file == NULL || !(ofp = fopen(output_file, "w"))) {
620 error_msg("cannot open output file '%s'!", output_file);
633 verbose_msg(VINFO, "total data size = %d\n", total_size);
634 verbose_msg(VDETAIL, "null count = %d\n", null_count);
639 static char *idx[10000];
640 static char buf[100000];
644 static int addblock(const char *s, size_t n) /* l includes nul terminator */
653 for (j=0 ; (j < uniq) && (idx[j] + n < last) ; j++) {
654 if (!memcmp(s, idx[j], n)) {
658 if (uniq >= sizeof(idx)) {
659 error_msg("too many uniq strings!");
661 if (last + n >= buf + sizeof(buf)) {
662 error_msg("need to increase size of buf!");
669 return idx[uniq - 1] - buf;
672 static int addstring(const char *s)
682 for (j=0 ; j < uniq ; j++) {
683 if (!strcmp(s, idx[j])) {
687 if (uniq >= sizeof(idx)) {
688 error_msg("too many uniq strings!");
691 if (last + l >= buf + sizeof(buf)) {
692 error_msg("need to increase size of buf!");
699 return idx[uniq - 1] - buf;
702 #define DO_LC_COMMON(CATEGORY) \
703 verbose_msg(VDETAIL, "buf-size=%d uniq=%d rows=%d\n", \
704 (int)(last - buf), uniq, lc_##CATEGORY##_uniq); \
705 verbose_msg(VDETAIL, "total = %d + %d * %d + %d = %d\n", \
706 num_locales, lc_##CATEGORY##_uniq, NUM_NL_##CATEGORY, (int)(last - buf), \
707 i = num_locales + lc_##CATEGORY##_uniq*NUM_NL_##CATEGORY + (int)(last - buf)); \
709 dump_table8c("__lc_" #CATEGORY "_data", buf, (int)(last - buf)); \
710 for (i=0 ; i < lc_##CATEGORY##_uniq ; i++) { \
711 m = locales[i].lc_##CATEGORY##_row; \
712 for (k=0 ; k < NUM_NL_##CATEGORY ; k++) { \
713 buf[NUM_NL_##CATEGORY*i + k] = (char)((unsigned char) lc_##CATEGORY##_uniq_X[i][k]); \
716 dump_table8("__lc_" #CATEGORY "_rows", buf, lc_##CATEGORY##_uniq * NUM_NL_##CATEGORY); \
718 for (i=0 ; i < NUM_NL_##CATEGORY - 1 ; i++) { \
719 buf16[i+1] = buf16[i] + lc_##CATEGORY##_count[i]; \
721 dump_table16("__lc_" #CATEGORY "_item_offsets", buf16, NUM_NL_##CATEGORY); \
723 for (k=0 ; k < NUM_NL_##CATEGORY ; k++) { \
724 for (i=0 ; i < lc_##CATEGORY##_count[k] ; i++) { \
725 buf16[m] = lc_##CATEGORY##_item[k][i]; \
729 dump_table16("__lc_" #CATEGORY "_item_idx", buf16, m);
732 #define DL_LC_LOOPTAIL(CATEGORY) \
733 if (k > NUM_NL_##CATEGORY) { \
734 error_msg("lc_" #CATEGORY " nl_item count > %d!", NUM_NL_##CATEGORY); \
738 for (r=0 ; r < lc_##CATEGORY##_uniq ; r++) { \
739 if (!memcmp(lc_##CATEGORY##_uniq_X[lc_##CATEGORY##_uniq], \
740 lc_##CATEGORY##_uniq_X[r], NUM_NL_##CATEGORY)) { \
744 if (r == lc_##CATEGORY##_uniq) { /* new locale row */ \
745 ++lc_##CATEGORY##_uniq; \
746 if (lc_##CATEGORY##_uniq > 255) { \
747 error_msg("too many unique lc_" #CATEGORY " rows!"); \
750 locales[i].lc_##CATEGORY##_row = r; \
755 static int buf16[100*256];
757 static void dump_table8(const char *name, const char *tbl, int len)
761 fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);
762 fprintf(ofp, "static const unsigned char %s[%d] = {", name, len);
763 for (i=0 ; i < len ; i++) {
765 fprintf(ofp, "\n\t");
767 fprintf(ofp, "%#4x, ", (int)((unsigned char) tbl[i]));
769 fprintf(ofp, "\n};\n\n");
772 #define __C_isdigit(c) \
773 ((sizeof(c) == sizeof(char)) \
774 ? (((unsigned char)((c) - '0')) < 10) \
775 : (((unsigned int)((c) - '0')) < 10))
776 #define __C_isalpha(c) \
777 ((sizeof(c) == sizeof(char)) \
778 ? (((unsigned char)(((c) | 0x20) - 'a')) < 26) \
779 : (((unsigned int)(((c) | 0x20) - 'a')) < 26))
780 #define __C_isalnum(c) (__C_isalpha(c) || __C_isdigit(c))
782 static void dump_table8c(const char *name, const char *tbl, int len)
786 fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);
787 fprintf(ofp, "static const unsigned char %s[%d] = {", name, len);
788 for (i=0 ; i < len ; i++) {
790 fprintf(ofp, "\n\t");
792 if (__C_isalnum(tbl[i]) || (tbl[i] == ' ')) {
793 fprintf(ofp, " '%c', ", (int)((unsigned char) tbl[i]));
795 fprintf(ofp, "%#4x, ", (int)((unsigned char) tbl[i]));
798 fprintf(ofp, "\n};\n\n");
801 static void dump_table16(const char *name, const int *tbl, int len)
805 fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);
806 fprintf(ofp, "static const uint16_t %s[%d] = {", name, len);
807 for (i=0 ; i < len ; i++) {
809 fprintf(ofp, "\n\t");
811 if (tbl[i] != (uint16_t) tbl[i]) {
812 error_msg("falls outside uint16 range!");
814 fprintf(ofp, "%#6x, ", tbl[i]);
816 fprintf(ofp, "\n};\n\n");
820 #define NUM_NL_time 50
822 static int lc_time_item[NUM_NL_time][256];
823 static int lc_time_count[NUM_NL_time];
824 static unsigned char lc_time_uniq_X[700][NUM_NL_time];
825 static int lc_time_uniq;
827 #define DO_NL_S(X) lc_time_S(X, k++)
829 static void lc_time_S(int X, int k)
833 const char *s = nl_langinfo(X);
835 static const char nulbuf[] = "";
837 if (X == ALT_DIGITS) {
844 for (j = 0 ; j < 100 ; j++) {
852 j = addblock(s, len);
853 /* if (len > 1) verbose_msg(VDETAIL, "alt_digit: called addblock with len %zd\n", len); */
854 } else if (X == ERA) {
866 j = addblock(s, p - s);
867 /* if (p-s > 1) verbose_msg(VDETAIL, "era: called addblock with len %d\n", p-s); */
871 for (m=0 ; m < lc_time_count[k] ; m++) {
872 if (lc_time_item[k][m] == j) {
876 if (m == lc_time_count[k]) { /* new for this nl_item */
878 error_msg("too many nl_item %d entries in lc_time", k);
880 lc_time_item[k][m] = j;
883 lc_time_uniq_X[lc_time_uniq][k] = m;
886 static void do_lc_time(void)
895 for (i=0 ; i < num_locales ; i++) {
898 if (!setlocale(LC_ALL, locales[i].glibc_name)) {
899 verbose_msg(VDETAIL, "setlocale(LC_ALL,%s) failed!\n",
900 locales[i].glibc_name);
954 DO_NL_S(ERA_YEAR); /* non SuSv3 */
957 DO_NL_S(ERA_D_T_FMT);
968 #define NUM_NL_numeric 3
970 static int lc_numeric_item[NUM_NL_numeric][256];
971 static int lc_numeric_count[NUM_NL_numeric];
972 static unsigned char lc_numeric_uniq_X[700][NUM_NL_numeric];
973 static int lc_numeric_uniq;
975 #define DO_NL_S(X) lc_numeric_S(X, k++)
977 static void lc_numeric_S(int X, int k)
988 if ((*s == CHAR_MAX) || (*s == -1)) { /* stupid glibc... :-( */
993 while (*e) { /* find end of string */
994 if (*e == CHAR_MAX) {
1001 if ((e - s) > sizeof(buf)) {
1002 error_msg("grouping specifier too long");
1004 strncpy(buf, s, (e-s));
1006 *e = 0; /* Make sure we're null-terminated. */
1008 if (c != CHAR_MAX) { /* remove duplicate repeats */
1021 for (m=0 ; m < lc_numeric_count[k] ; m++) {
1022 if (lc_numeric_item[k][m] == j) {
1026 if (m == lc_numeric_count[k]) { /* new for this nl_item */
1028 error_msg("too many nl_item %d entries in lc_numeric", k);
1030 lc_numeric_item[k][m] = j;
1031 ++lc_numeric_count[k];
1033 /* verbose_msg(VDETAIL, "\\x%02x", m); */
1034 lc_numeric_uniq_X[lc_numeric_uniq][k] = m;
1037 static void do_lc_numeric(void)
1046 for (i=0 ; i < num_locales ; i++) {
1049 if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1050 verbose_msg(VDETAIL,"setlocale(LC_ALL,%s) failed!\n",
1051 locales[i].glibc_name);
1054 DO_NL_S(RADIXCHAR); /* DECIMAL_POINT */
1055 DO_NL_S(THOUSEP); /* THOUSANDS_SEP */
1058 DL_LC_LOOPTAIL(numeric)
1061 DO_LC_COMMON(numeric)
1066 #define NUM_NL_monetary (7+14+1)
1068 static int lc_monetary_item[NUM_NL_monetary][256];
1069 static int lc_monetary_count[NUM_NL_monetary];
1070 static unsigned char lc_monetary_uniq_X[700][NUM_NL_monetary];
1071 static int lc_monetary_uniq;
1073 #define DO_NL_S(X) lc_monetary_S(X, k++)
1075 /* #define DO_NL_C(X) verbose_msg(VDETAIL,"%#02x", (int)(unsigned char)(*nl_langinfo(X))); */
1076 #define DO_NL_C(X) lc_monetary_C(X, k++)
1078 static void lc_monetary_C(int X, int k)
1083 #warning fix the char entries for monetary... target signedness of char may be different!
1086 c_buf[0] = *nl_langinfo(X);
1087 j = addstring(c_buf);
1088 for (m=0 ; m < lc_monetary_count[k] ; m++) {
1089 if (lc_monetary_item[k][m] == j) {
1093 if (m == lc_monetary_count[k]) { /* new for this nl_item */
1095 error_msg("too many nl_item %d entries in lc_monetary", k);
1097 lc_monetary_item[k][m] = j;
1098 ++lc_monetary_count[k];
1100 /* verbose_msg(VDETAIL,"\\x%02x", m); */
1101 lc_monetary_uniq_X[lc_monetary_uniq][k] = m;
1105 static void lc_monetary_S(int X, int k)
1114 if (X == MON_GROUPING) {
1116 if ((*s == CHAR_MAX) || (*s == -1)) { /* stupid glibc... :-( */
1121 while (*e) { /* find end of string */
1122 if (*e == CHAR_MAX) {
1129 if ((e - s) > sizeof(buf)) {
1130 error_msg("mon_grouping specifier too long");
1132 strncpy(buf, s, (e-s));
1134 *e = 0; /* Make sure we're null-terminated. */
1136 if (c != CHAR_MAX) { /* remove duplicate repeats */
1149 for (m=0 ; m < lc_monetary_count[k] ; m++) {
1150 if (lc_monetary_item[k][m] == j) {
1154 if (m == lc_monetary_count[k]) { /* new for this nl_item */
1156 error_msg("too many nl_item %d entries in lc_monetary", k);
1158 lc_monetary_item[k][m] = j;
1159 ++lc_monetary_count[k];
1161 /* verbose_msg(VDETAIL,"\\x%02x", m); */
1162 lc_monetary_uniq_X[lc_monetary_uniq][k] = m;
1165 static void do_lc_monetary(void)
1174 for (i=0 ; i < num_locales ; i++) {
1177 if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1178 verbose_msg(VDETAIL,"setlocale(LC_ALL,%s) failed!\n",
1179 locales[i].glibc_name);
1184 DO_NL_S(INT_CURR_SYMBOL);
1185 DO_NL_S(CURRENCY_SYMBOL);
1186 DO_NL_S(MON_DECIMAL_POINT);
1187 DO_NL_S(MON_THOUSANDS_SEP);
1188 DO_NL_S(MON_GROUPING);
1189 DO_NL_S(POSITIVE_SIGN);
1190 DO_NL_S(NEGATIVE_SIGN);
1191 DO_NL_C(INT_FRAC_DIGITS);
1192 DO_NL_C(FRAC_DIGITS);
1193 DO_NL_C(P_CS_PRECEDES);
1194 DO_NL_C(P_SEP_BY_SPACE);
1195 DO_NL_C(N_CS_PRECEDES);
1196 DO_NL_C(N_SEP_BY_SPACE);
1197 DO_NL_C(P_SIGN_POSN);
1198 DO_NL_C(N_SIGN_POSN);
1199 DO_NL_C(INT_P_CS_PRECEDES);
1200 DO_NL_C(INT_P_SEP_BY_SPACE);
1201 DO_NL_C(INT_N_CS_PRECEDES);
1202 DO_NL_C(INT_N_SEP_BY_SPACE);
1203 DO_NL_C(INT_P_SIGN_POSN);
1204 DO_NL_C(INT_N_SIGN_POSN);
1206 DO_NL_S(CRNCYSTR); /* CURRENCY_SYMBOL */
1208 DL_LC_LOOPTAIL(monetary)
1211 DO_LC_COMMON(monetary)
1217 #define NUM_NL_messages 4
1219 static int lc_messages_item[NUM_NL_messages][256];
1220 static int lc_messages_count[NUM_NL_messages];
1221 static unsigned char lc_messages_uniq_X[700][NUM_NL_messages];
1222 static int lc_messages_uniq;
1224 #define DO_NL_S(X) lc_messages_S(X, k++)
1226 static void lc_messages_S(int X, int k)
1229 j = addstring(nl_langinfo(X));
1230 for (m=0 ; m < lc_messages_count[k] ; m++) {
1231 if (lc_messages_item[k][m] == j) {
1235 if (m == lc_messages_count[k]) { /* new for this nl_item */
1237 error_msg("too many nl_item %d entries in lc_messages", k);
1239 lc_messages_item[k][m] = j;
1240 ++lc_messages_count[k];
1242 /* verbose_msg(VDETAIL, "\\x%02x", m); */
1243 lc_messages_uniq_X[lc_messages_uniq][k] = m;
1246 static void do_lc_messages(void)
1255 for (i=0 ; i < num_locales ; i++) {
1258 if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1259 verbose_msg(VDETAIL, "setlocale(LC_ALL,%s) failed!\n",
1260 locales[i].glibc_name);
1268 DL_LC_LOOPTAIL(messages)
1271 DO_LC_COMMON(messages)
1276 #define NUM_NL_ctype 10
1278 static int lc_ctype_item[NUM_NL_ctype][256];
1279 static int lc_ctype_count[NUM_NL_ctype];
1280 static unsigned char lc_ctype_uniq_X[700][NUM_NL_ctype];
1281 static int lc_ctype_uniq;
1283 #define DO_NL_S(X) lc_ctype_S(X, k++)
1285 static void lc_ctype_S(int X, int k)
1288 j = addstring(nl_langinfo(X));
1289 for (m=0 ; m < lc_ctype_count[k] ; m++) {
1290 if (lc_ctype_item[k][m] == j) {
1294 if (m == lc_ctype_count[k]) { /* new for this nl_item */
1296 error_msg("too many nl_item %d entries in lc_ctype", k);
1298 lc_ctype_item[k][m] = j;
1299 ++lc_ctype_count[k];
1301 /* verbose_msg(VDETAIL, "\\x%02x", m); */
1302 lc_ctype_uniq_X[lc_ctype_uniq][k] = m;
1305 static void do_lc_ctype(void)
1314 for (i=0 ; i < num_locales ; i++) {
1317 if (!setlocale(LC_ALL, locales[i].glibc_name)) {
1318 verbose_msg(VDETAIL, "setlocale(LC_ALL,%s) failed!\n",
1319 locales[i].glibc_name);
1322 DO_NL_S(_NL_CTYPE_OUTDIGIT0_MB);
1323 DO_NL_S(_NL_CTYPE_OUTDIGIT1_MB);
1324 DO_NL_S(_NL_CTYPE_OUTDIGIT2_MB);
1325 DO_NL_S(_NL_CTYPE_OUTDIGIT3_MB);
1326 DO_NL_S(_NL_CTYPE_OUTDIGIT4_MB);
1327 DO_NL_S(_NL_CTYPE_OUTDIGIT5_MB);
1328 DO_NL_S(_NL_CTYPE_OUTDIGIT6_MB);
1329 DO_NL_S(_NL_CTYPE_OUTDIGIT7_MB);
1330 DO_NL_S(_NL_CTYPE_OUTDIGIT8_MB);
1331 DO_NL_S(_NL_CTYPE_OUTDIGIT9_MB);
1333 DL_LC_LOOPTAIL(ctype)