gen_locale.c 29 KB

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