gen_locale.c 29 KB

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