gen_wc8bit.c 19 KB

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