gen_wc8bit.c 19 KB

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