gen_wc8bit.c 18 KB

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