gen_wc8bit.c 18 KB

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