gen_wc8bit.c 19 KB

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