gen_wc8bit.c 19 KB

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