gen_wc8bit.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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. #ifndef __metag__
  157. printf("} __codeset_8_bit_t;\n\n");
  158. #else
  159. printf("} __attribute__((__packed__)) __codeset_8_bit_t;\n\n");
  160. #endif /* __metag__ */
  161. printf("#ifdef WANT_DATA\n\n");
  162. printf("static const __codeset_8_bit_t codeset_8_bit[%d] = {\n", argc-1);
  163. max_wchar = 0x7f;
  164. numsets = 0;
  165. codeset_index[0] = 0;
  166. while (--argc) {
  167. if (!(fp = fopen(*++argv,"r"))) {
  168. fprintf(stderr, "cannot open file \"%s\"\n", *argv);
  169. return EXIT_FAILURE;
  170. }
  171. fprintf(stderr, "processing %s... ", *argv);
  172. {
  173. char *s0;
  174. char *s1;
  175. int n;
  176. s0 = strrchr(*argv, '/');
  177. if (!s0) {
  178. s0 = *argv;
  179. } else {
  180. ++s0;
  181. }
  182. s1 = strrchr(s0, '.');
  183. if (!s1) {
  184. n = strlen(s0);
  185. } else {
  186. n = s1 - s0;
  187. }
  188. /* if ((numsets == 0) && strncmp("ASCII", s0, n)) { */
  189. /* printf("error - first codeset isn't ASCII!\n"); */
  190. /* return EXIT_FAILURE; */
  191. /* } */
  192. if (numsets >= sizeof(codeset_index)) {
  193. fprintf(stderr, "error - too many codesets!\n");
  194. return EXIT_FAILURE;
  195. }
  196. if (codeset_list_end + n + 1 + numsets + 1 + 1 >= 256) {
  197. fprintf(stderr, "error - codeset list to big!\n");
  198. return EXIT_FAILURE;
  199. }
  200. codeset_index[numsets+1] = codeset_index[numsets] + n+1;
  201. strncpy(codeset_list + codeset_list_end, s0, n);
  202. codeset_list_end += (n+1);
  203. codeset_list[codeset_list_end - 1] = 0;
  204. printf("\t{ /* %.*s */", n, s0);
  205. }
  206. memset(&csd[numsets], 0, sizeof(charset_data));
  207. memset(xi, 0, sizeof(xi));
  208. {
  209. unsigned long c, wc;
  210. int lines;
  211. lines = 0;
  212. while (fgets(buf,sizeof(buf),fp)) {
  213. if ((2 != sscanf(buf, "{ %lx , %lx", &c, &wc))
  214. || (c >= 256) || (wc > MAX_WCHAR)) {
  215. fprintf(stderr, "error: scanf failure! \"%s\"\n", buf);
  216. return EXIT_FAILURE;
  217. }
  218. /* don't put in w2c... dynamicly build tt instead. */
  219. if (c <= 0x7f) { /* check the 7bit entries but don't store */
  220. if (c != wc) {
  221. fprintf(stderr, "error: c != wc in %s\n", buf);
  222. return EXIT_FAILURE;
  223. }
  224. csd[numsets].c2w[c] = wc;
  225. csd[numsets].w2c[wc] = 0; /* ignore */
  226. if (wc > max_wchar) {
  227. max_wchar = wc;
  228. }
  229. } else {
  230. csd[numsets].c2w[c] = wc;
  231. csd[numsets].w2c[wc] = c;
  232. if (wc > max_wchar) {
  233. max_wchar = wc;
  234. }
  235. }
  236. ++lines;
  237. }
  238. fprintf(stderr, "%d lines ", lines);
  239. for (i = 0 ; i <= MAX_WCHAR ; i += (1 << TT_SHIFT)) {
  240. p = &csd[numsets].w2c[i];
  241. for (j = 0 ; j < tt_num ; j++) {
  242. if (!memcmp(p, &tt[j << TT_SHIFT], (1 << TT_SHIFT))) {
  243. break;
  244. }
  245. }
  246. if (j == tt_num) { /* new entry */
  247. memcpy(&tt[j << TT_SHIFT], p, (1 << TT_SHIFT));
  248. ++tt_num;
  249. }
  250. xi[i >> TT_SHIFT] = j;
  251. }
  252. for (i = 0 ; i <= (MAX_WCHAR >> TT_SHIFT) ; i += (1 << TI_SHIFT)) {
  253. p = &xi[i];
  254. for (j = 0 ; j < ti_num ; j++) {
  255. if (!memcmp(p, &ti[j << TI_SHIFT], (1 << TI_SHIFT))) {
  256. break;
  257. }
  258. }
  259. if (j == ti_num) { /* new entry */
  260. memcpy(&ti[j << TI_SHIFT], p, (1 << TI_SHIFT));
  261. ++ti_num;
  262. }
  263. csd[numsets].ii[i >> TI_SHIFT] = j;
  264. /* fprintf(stderr, "%d ", i >> TI_SHIFT); */
  265. }
  266. #if 1
  267. printf("\n\t\t/* idx8ctype data */\n\t\t{");
  268. for (i = 128 ; i < 256 ; i++) {
  269. wchar_t c;
  270. unsigned int d;
  271. /* if (!(i & 0x7)) { */
  272. /* printf("\n"); */
  273. /* } */
  274. c = csd[numsets].c2w[i];
  275. if (c == 0) { /* non-existant char in codeset */
  276. d = __CTYPE_unclassified;
  277. } else if (iswdigit(c)) {
  278. d = __CTYPE_digit;
  279. } else if (iswalpha(c)) {
  280. d = __CTYPE_alpha_nonupper_nonlower;
  281. if (iswlower(c)) {
  282. d = __CTYPE_alpha_lower;
  283. if (iswupper(c)) {
  284. d = __CTYPE_alpha_upper_lower;
  285. }
  286. } else if (iswupper(c)) {
  287. d = __CTYPE_alpha_upper;
  288. }
  289. } else if (iswpunct(c)) {
  290. d = __CTYPE_punct;
  291. } else if (iswgraph(c)) {
  292. d = __CTYPE_graph;
  293. } else if (iswprint(c)) {
  294. d = __CTYPE_print_space_nonblank;
  295. if (iswblank(c)) {
  296. d = __CTYPE_print_space_blank;
  297. }
  298. } else if (iswspace(c) && !iswcntrl(c)) {
  299. d = __CTYPE_space_nonblank_noncntrl;
  300. if (iswblank(c)) {
  301. d = __CTYPE_space_blank_noncntrl;
  302. }
  303. } else if (iswcntrl(c)) {
  304. d = __CTYPE_cntrl_nonspace;
  305. if (iswspace(c)) {
  306. d = __CTYPE_cntrl_space_nonblank;
  307. if (iswblank(c)) {
  308. d = __CTYPE_cntrl_space_blank;
  309. }
  310. }
  311. } else {
  312. d = __CTYPE_unclassified;
  313. }
  314. #if 1
  315. row[i & (CTYPE_ROW_LEN-1)] = d;
  316. if ((i & (CTYPE_ROW_LEN-1)) == (CTYPE_ROW_LEN-1)) {
  317. p = ctype_tbl;
  318. for (j=0 ; j < n_ctype_rows ; j++) {
  319. if (!memcmp(p, row, CTYPE_ROW_LEN)) {
  320. break;
  321. }
  322. p += CTYPE_ROW_LEN;
  323. }
  324. if (j == n_ctype_rows) { /* new entry */
  325. if (++n_ctype_rows > 256) {
  326. fprintf(stderr, "error -- to many ctype rows!\n");
  327. return EXIT_FAILURE;
  328. }
  329. memcpy(p, row, CTYPE_ROW_LEN);
  330. }
  331. csd[numsets].ctype_idx[i >> CTYPE_IDX_SHIFT] = j;
  332. if (!((i >> CTYPE_IDX_SHIFT) & 0x7)
  333. && (i != (127 + CTYPE_ROW_LEN))
  334. ) {
  335. printf("\n\t\t ");
  336. }
  337. printf(" %#4x,", j);
  338. }
  339. #else
  340. printf(" %#4x,", d);
  341. #endif
  342. }
  343. #endif
  344. printf(" }");
  345. #if 1
  346. printf(",\n\t\t/* idx8uplow data */\n\t\t{");
  347. for (i = 128 ; i < 256 ; i++) {
  348. wchar_t c, u, l;
  349. /* if (!(i & 0x7)) { */
  350. /* printf("\n"); */
  351. /* } */
  352. c = csd[numsets].c2w[i];
  353. if ((c != 0) || 1) {
  354. u = towupper(c);
  355. l = towlower(c);
  356. if (u >= 0x80) u = csd[numsets].w2c[u];
  357. if (l >= 0x80) l = csd[numsets].w2c[l];
  358. if (u == 0) u = i; /* upper is missing, so ignore */
  359. if (l == 0) l = i; /* lower is missing, so ignore */
  360. #if 1
  361. /* store as unsigned char and let overflow handle it. */
  362. /* if ((((u-i) < CHAR_MIN) || ((u-i) > CHAR_MAX)) */
  363. /* || (((i-l) < CHAR_MIN) || ((i-l) > CHAR_MAX)) */
  364. /* ) { */
  365. /* fprintf(stderr, "error - uplow diff out of range! %d %ld %ld\n", */
  366. /* i, u, l); */
  367. /* return EXIT_FAILURE; */
  368. /* } */
  369. row[i & (UPLOW_ROW_LEN-1)] = ((l==i) ? (u-i) : (i-l));
  370. if ((i & (UPLOW_ROW_LEN-1)) == (UPLOW_ROW_LEN-1)) {
  371. p = uplow_tbl;
  372. for (j=0 ; j < n_uplow_rows ; j++) {
  373. if (!memcmp(p, row, UPLOW_ROW_LEN)) {
  374. break;
  375. }
  376. p += UPLOW_ROW_LEN;
  377. }
  378. if (j == n_uplow_rows) { /* new entry */
  379. if (++n_uplow_rows > 256) {
  380. fprintf(stderr, "error -- to many uplow rows!\n");
  381. return EXIT_FAILURE;
  382. }
  383. memcpy(p, row, UPLOW_ROW_LEN);
  384. }
  385. csd[numsets].uplow_idx[i >> UPLOW_IDX_SHIFT] = j;
  386. if (!((i >> UPLOW_IDX_SHIFT) & 0x7)
  387. && (i != (127 + UPLOW_ROW_LEN))
  388. ) {
  389. printf("\n\t\t ");
  390. }
  391. printf(" %#4x,", j);
  392. }
  393. #elif 0
  394. if (!(i & 0x7) && i) {
  395. printf("\n");
  396. }
  397. printf(" %4ld,", (l==i) ? (u-i) : (i-l));
  398. /* printf(" %4ld,", (l==i) ? u : l); */
  399. #else
  400. if ((u != i) || (l != i)) {
  401. #if 0
  402. printf(" %#08lx, %#08lx, %#08lx, %#08lx, %#08lx, %#08lx, \n",
  403. (unsigned long) i,
  404. (unsigned long) c,
  405. (unsigned long) l,
  406. (unsigned long) towlower(c),
  407. (unsigned long) u,
  408. (unsigned long) towupper(c));
  409. #else
  410. printf(" %#08lx, %8ld, %d, %8ld, %d, %#08lx\n",
  411. (unsigned long) i,
  412. (long) (l - i),
  413. iswupper(c),
  414. (long) (i - u),
  415. iswlower(c),
  416. (unsigned long) c);
  417. #endif
  418. }
  419. #endif
  420. }
  421. }
  422. printf(" }");
  423. #endif
  424. #ifndef DO_WIDE_CHAR
  425. printf("\n");
  426. #else /* DO_WIDE_CHAR */
  427. #if 1
  428. printf(",\n\t\t/* idx8c2wc data */\n\t\t{");
  429. for (i = 128 ; i < 256 ; i++) {
  430. #if 1
  431. wrow[i & (C2WC_ROW_LEN-1)] = csd[numsets].c2w[i];
  432. if ((i & (C2WC_ROW_LEN-1)) == (C2WC_ROW_LEN-1)) {
  433. p = (unsigned char *) c2wc_tbl;
  434. for (j=0 ; j < n_c2wc_rows ; j++) {
  435. if (!memcmp(p, (char *) wrow, 2*C2WC_ROW_LEN)) {
  436. break;
  437. }
  438. p += 2*C2WC_ROW_LEN;
  439. }
  440. if (j == n_c2wc_rows) { /* new entry */
  441. if (++n_c2wc_rows > 256) {
  442. fprintf(stderr, "error -- to many c2wc rows!\n");
  443. return EXIT_FAILURE;
  444. }
  445. memcpy(p, (char *) wrow, 2*C2WC_ROW_LEN);
  446. }
  447. csd[numsets].c2wc_idx[i >> C2WC_IDX_SHIFT] = j;
  448. if (!((i >> C2WC_IDX_SHIFT) & 0x7)
  449. && (i != (127 + C2WC_ROW_LEN))
  450. ) {
  451. printf("\n\t\t ");
  452. }
  453. printf(" %#4x,", j);
  454. }
  455. #else
  456. if (!(i & 0x7) && i) {
  457. printf("\n");
  458. }
  459. printf(" %#6lx,", csd[numsets].c2w[i]);
  460. #endif
  461. }
  462. printf(" },\n");
  463. #endif
  464. #if 1
  465. /* fprintf(stderr, "\nII_LEN = %d\n", II_LEN); */
  466. printf("\t\t/* idx8wc2c data */\n\t\t{");
  467. for (i = 0 ; i < II_LEN ; i++) {
  468. if (!(i & 0x7) && i) {
  469. printf("\n\t\t ");
  470. }
  471. printf(" %#4x,", csd[numsets].ii[i]);
  472. }
  473. printf(" }\n");
  474. #endif
  475. #endif /* DO_WIDE_CHAR */
  476. printf("\t},\n");
  477. }
  478. ++numsets;
  479. fprintf(stderr, "done\n");
  480. }
  481. printf("};\n");
  482. printf("\n#endif /* WANT_DATA */\n");
  483. #ifdef DO_WIDE_CHAR
  484. printf("\n");
  485. printf("#define __LOCALE_DATA_Cwc2c_DOMAIN_MAX\t%#x\n", RANGE);
  486. printf("#define __LOCALE_DATA_Cwc2c_TI_SHIFT\t\t%d\n", TI_SHIFT);
  487. printf("#define __LOCALE_DATA_Cwc2c_TT_SHIFT\t\t%d\n", TT_SHIFT);
  488. printf("#define __LOCALE_DATA_Cwc2c_II_LEN\t\t%d\n", II_LEN);
  489. printf("#define __LOCALE_DATA_Cwc2c_TI_LEN\t\t%d\n", ti_num << TI_SHIFT);
  490. printf("#define __LOCALE_DATA_Cwc2c_TT_LEN\t\t%d\n", tt_num << TT_SHIFT);
  491. printf("\n");
  492. printf("\n#define __LOCALE_DATA_Cwc2c_TBL_LEN\t\t%d\n",
  493. (ti_num << TI_SHIFT) + (tt_num << TT_SHIFT));
  494. printf("#ifdef WANT_DATA\n\n");
  495. printf("static const unsigned char __LOCALE_DATA_Cwc2c_data[%d] = {\n",
  496. (ti_num << TI_SHIFT) + (tt_num << TT_SHIFT));
  497. printf("\t/* ti_table */\n\t");
  498. for (i=0 ; i < ti_num << TI_SHIFT ; i++) {
  499. if (!(i & 7) && i) {
  500. printf("\n\t");
  501. }
  502. printf(" %#4x,", ti[i]);
  503. }
  504. printf("\n");
  505. printf("\t/* tt_table */\n\t");
  506. for (i=0 ; i < tt_num << TT_SHIFT ; i++) {
  507. if (!(i & 7) && i) {
  508. printf("\n\t");
  509. }
  510. printf(" %#4x,", tt[i]);
  511. }
  512. printf("\n};\n");
  513. printf("\n#endif /* WANT_DATA */\n");
  514. #endif /* DO_WIDE_CHAR */
  515. printf("\n#define __LOCALE_DATA_Cuplow_TBL_LEN\t\t%d\n",
  516. n_uplow_rows * UPLOW_ROW_LEN);
  517. printf("\n#ifdef WANT_DATA\n\n");
  518. printf("\nstatic const unsigned char __LOCALE_DATA_Cuplow_data[%d] = {\n",
  519. n_uplow_rows * UPLOW_ROW_LEN);
  520. p = uplow_tbl;
  521. for (j=0 ; j < n_uplow_rows ; j++) {
  522. printf("\t");
  523. for (i=0 ; i < UPLOW_ROW_LEN ; i++) {
  524. printf(" %#4x,", (unsigned int)((unsigned char) p[i]));
  525. }
  526. printf("\n");
  527. p += UPLOW_ROW_LEN;
  528. }
  529. printf("};\n");
  530. printf("\n#endif /* WANT_DATA */\n");
  531. printf("\n#define __LOCALE_DATA_Cctype_TBL_LEN\t\t%d\n",
  532. #ifdef CTYPE_PACKED
  533. n_ctype_rows * CTYPE_ROW_LEN / 2
  534. #else
  535. n_ctype_rows * CTYPE_ROW_LEN
  536. #endif
  537. );
  538. printf("\n#ifdef WANT_DATA\n\n");
  539. printf("\nstatic const unsigned char __LOCALE_DATA_Cctype_data[%d] = {\n",
  540. #ifdef CTYPE_PACKED
  541. n_ctype_rows * CTYPE_ROW_LEN / 2
  542. #else
  543. n_ctype_rows * CTYPE_ROW_LEN
  544. #endif
  545. );
  546. p = ctype_tbl;
  547. for (j=0 ; j < n_ctype_rows ; j++) {
  548. printf("\t");
  549. for (i=0 ; i < CTYPE_ROW_LEN ; i++) {
  550. #ifdef CTYPE_PACKED
  551. printf(" %#4x,", (unsigned int)(p[i] + (p[i+1] << 4)));
  552. ++i;
  553. #else
  554. printf(" %#4x,", (unsigned int)p[i]);
  555. #endif
  556. }
  557. printf("\n");
  558. p += CTYPE_ROW_LEN;
  559. }
  560. printf("};\n");
  561. printf("\n#endif /* WANT_DATA */\n");
  562. #ifdef DO_WIDE_CHAR
  563. printf("\n#define __LOCALE_DATA_Cc2wc_TBL_LEN\t\t%d\n",
  564. n_c2wc_rows * C2WC_ROW_LEN);
  565. printf("\n#ifdef WANT_DATA\n\n");
  566. printf("\nstatic const unsigned short __LOCALE_DATA_Cc2wc_data[%d] = {\n",
  567. n_c2wc_rows * C2WC_ROW_LEN);
  568. p = (unsigned char *) c2wc_tbl;
  569. for (j=0 ; j < n_c2wc_rows ; j++) {
  570. printf("\t");
  571. for (i=0 ; i < C2WC_ROW_LEN ; i++) {
  572. printf(" %#6x,", (unsigned int)(((unsigned short *)p)[i]));
  573. }
  574. printf("\n");
  575. p += 2*C2WC_ROW_LEN;
  576. }
  577. printf("};\n");
  578. printf("\n#endif /* WANT_DATA */\n");
  579. #endif /* DO_WIDE_CHAR */
  580. printf("\n\n");
  581. printf("#define __LOCALE_DATA_NUM_CODESETS\t\t%d\n", numsets);
  582. printf("#define __LOCALE_DATA_CODESET_LIST \\\n\t\"");
  583. for (i=0 ; i < numsets ; i++) {
  584. printf("\\x%02x", numsets + 1 + (unsigned char) codeset_index[i]);
  585. if (((i & 7) == 7) && (i + 1 < numsets)) {
  586. printf("\" \\\n\t\"");
  587. }
  588. }
  589. printf("\" \\\n\t\"\\0\"");
  590. for (i=0 ; i < numsets ; i++) {
  591. printf(" \\\n\t\"%s\\0\"",
  592. codeset_list + ((unsigned char)codeset_index[i]));
  593. }
  594. printf("\n\n");
  595. for (i=0 ; i < numsets ; i++) {
  596. char buf[30];
  597. char *z;
  598. strcpy(buf, codeset_list + ((unsigned char)codeset_index[i]));
  599. for (z=buf ; *z ; z++) {
  600. if (*z == '-') {
  601. *z = '_';
  602. }
  603. }
  604. printf("#define __CTYPE_HAS_CODESET_%s\n", buf);
  605. }
  606. #ifdef DO_WIDE_CHAR
  607. printf("#define __CTYPE_HAS_CODESET_UTF_8\n");
  608. #endif /* DO_WIDE_CHAR */
  609. #if 0
  610. printf("\n#endif /* __CTYPE_HAS_8_BIT_LOCALES */\n\n");
  611. #endif
  612. total_size = 0;
  613. #ifdef DO_WIDE_CHAR
  614. fprintf(stderr, "tt_num = %d ti_num = %d\n", tt_num, ti_num);
  615. fprintf(stderr, "max_wchar = %#lx\n", max_wchar);
  616. fprintf(stderr, "size is %d * %d + %d * %d + %d * %d = %d\n",
  617. tt_num, 1 << TT_SHIFT, ti_num, 1 << TI_SHIFT,
  618. ((MAX_WCHAR >> (TT_SHIFT + TI_SHIFT)) + 1), numsets,
  619. j = tt_num * (1 << TT_SHIFT) + ti_num * (1 << TI_SHIFT)
  620. + ((MAX_WCHAR >> (TT_SHIFT + TI_SHIFT)) + 1) * numsets);
  621. total_size += j;
  622. #endif /* DO_WIDE_CHAR */
  623. #ifdef CTYPE_PACKED
  624. i = 2;
  625. #else
  626. i = 1;
  627. #endif
  628. fprintf(stderr, "ctype - CTYPE_IDX_SHIFT = %d -- %d * %d + %d * %d = %d\n",
  629. CTYPE_IDX_SHIFT, numsets, CTYPE_IDX_LEN, n_ctype_rows, CTYPE_ROW_LEN / i,
  630. j = numsets * CTYPE_IDX_LEN + n_ctype_rows * CTYPE_ROW_LEN / i);
  631. total_size += j;
  632. fprintf(stderr, "uplow - UPLOW_IDX_SHIFT = %d -- %d * %d + %d * %d = %d\n",
  633. UPLOW_IDX_SHIFT, numsets, UPLOW_IDX_LEN, n_uplow_rows, UPLOW_ROW_LEN,
  634. j = numsets * UPLOW_IDX_LEN + n_uplow_rows * UPLOW_ROW_LEN);
  635. total_size += j;
  636. #ifdef DO_WIDE_CHAR
  637. fprintf(stderr, "c2wc - C2WC_IDX_SHIFT = %d -- %d * %d + 2 * %d * %d = %d\n",
  638. C2WC_IDX_SHIFT, numsets, C2WC_IDX_LEN, n_c2wc_rows, C2WC_ROW_LEN,
  639. j = numsets * C2WC_IDX_LEN + 2 * n_c2wc_rows * C2WC_ROW_LEN);
  640. total_size += j;
  641. #endif /* DO_WIDE_CHAR */
  642. fprintf(stderr, "total size = %d\n", total_size);
  643. /* for (i=0 ; i < numsets ; i++) { */
  644. /* printf("codeset_index[i] = %d codeset_list[ci[i]] = \"%s\"\n", */
  645. /* (unsigned char) codeset_index[i], */
  646. /* codeset_list + ((unsigned char)codeset_index[i])); */
  647. /* } */
  648. return EXIT_SUCCESS;
  649. }