8bit_tab_to_h.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /* Copyright (C) 1999-2002 Free Software Foundation, Inc.
  2. This file is part of the GNU LIBICONV Tools.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. /*
  15. * Generates an 8-bit character set table from a .TXT table as found on
  16. * ftp.unicode.org or from a table containing the 256 Unicode values as
  17. * hexadecimal integers.
  18. * Examples:
  19. *
  20. * ./8bit_tab_to_h ISO-8859-1 iso8859_1 < tab8859_1
  21. * ./8bit_tab_to_h ISO-8859-2 iso8859_2 < tab8859_2
  22. * ./8bit_tab_to_h ISO-8859-3 iso8859_3 < tab8859_3
  23. * ./8bit_tab_to_h ISO-8859-4 iso8859_4 < tab8859_4
  24. * ./8bit_tab_to_h ISO-8859-5 iso8859_5 < tab8859_5
  25. * ./8bit_tab_to_h ISO-8859-6 iso8859_6 < tab8859_6
  26. * ./8bit_tab_to_h ISO-8859-7 iso8859_7 < tab8859_7
  27. * ./8bit_tab_to_h ISO-8859-8 iso8859_8 < tab8859_8
  28. * ./8bit_tab_to_h ISO-8859-9 iso8859_9 < tab8859_9
  29. * ./8bit_tab_to_h ISO-8859-10 iso8859_10 < tab8859_10
  30. * ./8bit_tab_to_h ISO-8859-14 iso8859_14 < tab8859_14
  31. * ./8bit_tab_to_h ISO-8859-15 iso8859_15 < tab8859_15
  32. * ./8bit_tab_to_h JISX0201.1976-0 jisx0201 < jis0201
  33. * ./8bit_tab_to_h TIS620.2533-1 tis620 < tabtis620
  34. * ./8bit_tab_to_h KOI8-R koi8_r < tabkoi8_r
  35. * ./8bit_tab_to_h KOI8-U koi8_u < tabkoi8_u
  36. * ./8bit_tab_to_h ARMSCII-8 armscii_8 < tabarmscii_8
  37. * ./8bit_tab_to_h CP1133 cp1133 < tabibm_cp1133
  38. * ./8bit_tab_to_h MULELAO-1 mulelao < tabmulelao_1
  39. * ./8bit_tab_to_h VISCII1.1-1 viscii1 < tabviscii
  40. * ./8bit_tab_to_h TCVN-5712 tcvn < tabtcvn
  41. * ./8bit_tab_to_h GEORGIAN-ACADEMY georgian_ac < tabgeorgian_academy
  42. * ./8bit_tab_to_h GEORGIAN-PS georgian_ps < tabgeorgian_ps
  43. *
  44. * ./8bit_tab_to_h ISO-8859-1 iso8859_1 < 8859-1.TXT
  45. * ./8bit_tab_to_h ISO-8859-2 iso8859_2 < 8859-2.TXT
  46. * ./8bit_tab_to_h ISO-8859-3 iso8859_3 < 8859-3.TXT
  47. * ./8bit_tab_to_h ISO-8859-4 iso8859_4 < 8859-4.TXT
  48. * ./8bit_tab_to_h ISO-8859-5 iso8859_5 < 8859-5.TXT
  49. * ./8bit_tab_to_h ISO-8859-6 iso8859_6 < 8859-6.TXT
  50. * ./8bit_tab_to_h ISO-8859-7 iso8859_7 < 8859-7.TXT
  51. * ./8bit_tab_to_h ISO-8859-8 iso8859_8 < 8859-8.TXT
  52. * ./8bit_tab_to_h ISO-8859-9 iso8859_9 < 8859-9.TXT
  53. * ./8bit_tab_to_h ISO-8859-10 iso8859_10 < 8859-10.TXT
  54. * ./8bit_tab_to_h ISO-8859-14 iso8859_14 < 8859-14.TXT
  55. * ./8bit_tab_to_h ISO-8859-15 iso8859_15 < 8859-15.TXT
  56. * ./8bit_tab_to_h JISX0201.1976-0 jisx0201 < JIS0201.TXT
  57. * ./8bit_tab_to_h KOI8-R koi8_r < KOI8-R.TXT
  58. */
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <stdbool.h>
  62. #include <string.h>
  63. int main (int argc, char *argv[])
  64. {
  65. const char* charsetname;
  66. const char* c_charsetname;
  67. const char* filename;
  68. const char* directory;
  69. int charset2uni[0x100];
  70. if (argc != 3 && argc != 4 && argc != 5)
  71. exit(1);
  72. charsetname = argv[1];
  73. c_charsetname = argv[2];
  74. if (argc > 3) {
  75. filename = argv[3];
  76. } else {
  77. char* s = (char*) malloc(strlen(c_charsetname)+strlen(".h")+1);
  78. strcpy(s,c_charsetname); strcat(s,".h");
  79. filename = s;
  80. }
  81. directory = (argc > 4 ? argv[4] : "");
  82. fprintf(stderr, "Creating %s%s\n", directory, filename);
  83. {
  84. int i, c;
  85. c = getc(stdin);
  86. ungetc(c,stdin);
  87. if (c == '#') {
  88. /* Read a unicode.org style .TXT file. */
  89. for (i = 0; i < 0x100; i++)
  90. charset2uni[i] = 0xfffd;
  91. for (;;) {
  92. c = getc(stdin);
  93. if (c == EOF)
  94. break;
  95. if (c == '\n' || c == ' ' || c == '\t')
  96. continue;
  97. if (c == '#') {
  98. do { c = getc(stdin); } while (!(c == EOF || c == '\n'));
  99. continue;
  100. }
  101. ungetc(c,stdin);
  102. if (scanf("0x%x", &i) != 1 || !(i >= 0 && i < 0x100))
  103. exit(1);
  104. do { c = getc(stdin); } while (c == ' ' || c == '\t');
  105. if (c != EOF)
  106. ungetc(c,stdin);
  107. if (c == '\n' || c == '#')
  108. continue;
  109. if (scanf("0x%x", &charset2uni[i]) != 1)
  110. exit(1);
  111. }
  112. } else {
  113. /* Read a table of hexadecimal Unicode values. */
  114. for (i = 0; i < 0x100; i++) {
  115. if (scanf("%x", &charset2uni[i]) != 1)
  116. exit(1);
  117. if (charset2uni[i] < 0 || charset2uni[i] == 0xffff)
  118. charset2uni[i] = 0xfffd;
  119. }
  120. if (scanf("%x", &i) != EOF)
  121. exit(1);
  122. }
  123. }
  124. /* Write the output file. */
  125. {
  126. FILE* f;
  127. {
  128. char* fname = malloc(strlen(directory)+strlen(filename)+1);
  129. strcpy(fname,directory); strcat(fname,filename);
  130. f = fopen(fname,"w");
  131. if (f == NULL)
  132. exit(1);
  133. }
  134. fprintf(f, "/*\n");
  135. fprintf(f, " * Copyright (C) 1999-2002 Free Software Foundation, Inc.\n");
  136. fprintf(f, " * This file is part of the GNU LIBICONV Library.\n");
  137. fprintf(f, " *\n");
  138. fprintf(f, " * The GNU LIBICONV Library is free software; you can redistribute it\n");
  139. fprintf(f, " * and/or modify it under the terms of the GNU Library General Public\n");
  140. fprintf(f, " * License as published by the Free Software Foundation; either version 2\n");
  141. fprintf(f, " * of the License, or (at your option) any later version.\n");
  142. fprintf(f, " *\n");
  143. fprintf(f, " * The GNU LIBICONV Library is distributed in the hope that it will be\n");
  144. fprintf(f, " * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
  145. fprintf(f, " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
  146. fprintf(f, " * Library General Public License for more details.\n");
  147. fprintf(f, " *\n");
  148. fprintf(f, " * You should have received a copy of the GNU Library General Public\n");
  149. fprintf(f, " * License along with the GNU LIBICONV Library; see the file COPYING.LIB.\n");
  150. fprintf(f, " * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,\n");
  151. fprintf(f, " * Fifth Floor, Boston, MA 02110-1301, USA.\n");
  152. fprintf(f, " */\n");
  153. fprintf(f, "\n");
  154. fprintf(f, "/*\n");
  155. fprintf(f, " * %s\n", charsetname);
  156. fprintf(f, " */\n");
  157. fprintf(f, "\n");
  158. {
  159. int i, i1, i2, i3;
  160. int line[16];
  161. int tableno;
  162. struct { int minline; int maxline; } tables[16];
  163. bool some_invalid;
  164. bool final_ret_reached;
  165. for (i1 = 0; i1 < 16; i1++) {
  166. bool all_invalid = true;
  167. bool all_identity = true;
  168. for (i2 = 0; i2 < 16; i2++) {
  169. i = 16*i1+i2;
  170. if (charset2uni[i] != 0xfffd)
  171. all_invalid = false;
  172. if (charset2uni[i] != i)
  173. all_identity = false;
  174. }
  175. if (all_invalid)
  176. line[i1] = -2;
  177. else if (all_identity)
  178. line[i1] = -1;
  179. else
  180. line[i1] = 0;
  181. }
  182. tableno = 0;
  183. for (i1 = 0; i1 < 16; i1++) {
  184. if (line[i1] >= 0) {
  185. if (i1 > 0 && tableno > 0 && line[i1-1] == tableno-1) {
  186. line[i1] = tableno-1;
  187. tables[tableno-1].maxline = i1;
  188. } else {
  189. tableno++;
  190. line[i1] = tableno-1;
  191. tables[tableno-1].minline = tables[tableno-1].maxline = i1;
  192. }
  193. }
  194. }
  195. some_invalid = false;
  196. for (i = 0; i < 0x100; i++)
  197. if (charset2uni[i] == 0xfffd)
  198. some_invalid = true;
  199. if (tableno > 0) {
  200. int t;
  201. for (t = 0; t < tableno; t++) {
  202. fprintf(f, "static const unsigned short %s_2uni", c_charsetname);
  203. if (tableno > 1)
  204. fprintf(f, "_%d", t+1);
  205. fprintf(f, "[%d] = {\n", 16*(tables[t].maxline-tables[t].minline+1));
  206. for (i1 = tables[t].minline; i1 <= tables[t].maxline; i1++) {
  207. fprintf(f, " /* 0x%02x */\n", 16*i1);
  208. for (i2 = 0; i2 < 2; i2++) {
  209. fprintf(f, " ");
  210. for (i3 = 0; i3 < 8; i3++) {
  211. i = 16*i1+8*i2+i3;
  212. fprintf(f, " 0x%04x,", charset2uni[i]);
  213. }
  214. fprintf(f, "\n");
  215. }
  216. }
  217. fprintf(f, "};\n");
  218. }
  219. fprintf(f, "\n");
  220. }
  221. final_ret_reached = false;
  222. fprintf(f, "static int\n%s_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)\n", c_charsetname);
  223. fprintf(f, "{\n");
  224. fprintf(f, " unsigned char c = *s;\n");
  225. if (some_invalid) {
  226. for (i1 = 0; i1 < 16;) {
  227. int t = line[i1];
  228. const char* indent;
  229. for (i2 = i1; i2 < 16 && line[i2] == t; i2++);
  230. indent = (i1 == 0 && i2 == 16 ? " " : " ");
  231. if (i1 == 0) {
  232. if (i2 == 16) {
  233. } else {
  234. fprintf(f, " if (c < 0x%02x) {\n", 16*i2);
  235. }
  236. } else {
  237. if (i2 == 16) {
  238. fprintf(f, " else {\n");
  239. } else {
  240. fprintf(f, " else if (c < 0x%02x) {\n", 16*i2);
  241. }
  242. }
  243. if (t == -2) {
  244. final_ret_reached = true;
  245. } else if (t == -1) {
  246. fprintf(f, "%s*pwc = (ucs4_t) c;\n", indent);
  247. fprintf(f, "%sreturn 1;\n", indent);
  248. } else {
  249. fprintf(f, "%s", indent);
  250. some_invalid = false;
  251. for (i = 16*i1; i < 16*i2; i++)
  252. if (charset2uni[i] == 0xfffd)
  253. some_invalid = true;
  254. if (some_invalid)
  255. fprintf(f, "unsigned short wc = ");
  256. else
  257. fprintf(f, "*pwc = (ucs4_t) ");
  258. fprintf(f, "%s_2uni", c_charsetname);
  259. if (tableno > 1)
  260. fprintf(f, "_%d", t+1);
  261. fprintf(f, "[c");
  262. if (tables[t].minline > 0)
  263. fprintf(f, "-0x%02x", 16*tables[t].minline);
  264. fprintf(f, "];\n");
  265. if (some_invalid) {
  266. fprintf(f, "%sif (wc != 0xfffd) {\n", indent);
  267. fprintf(f, "%s *pwc = (ucs4_t) wc;\n", indent);
  268. fprintf(f, "%s return 1;\n", indent);
  269. fprintf(f, "%s}\n", indent);
  270. final_ret_reached = true;
  271. } else {
  272. fprintf(f, "%sreturn 1;\n", indent);
  273. }
  274. }
  275. if (!(i1 == 0 && i2 == 16))
  276. fprintf(f, " }\n");
  277. i1 = i2;
  278. }
  279. if (final_ret_reached)
  280. fprintf(f, " return RET_ILSEQ;\n");
  281. } else {
  282. for (i1 = 0; i1 < 16;) {
  283. int t = line[i1];
  284. for (i2 = i1; i2 < 16 && line[i2] == t; i2++);
  285. if (i1 == 0) {
  286. if (i2 == 16) {
  287. fprintf(f, " ");
  288. } else {
  289. fprintf(f, " if (c < 0x%02x)\n ", 16*i2);
  290. }
  291. } else {
  292. if (i2 == 16) {
  293. fprintf(f, " else\n ");
  294. } else {
  295. fprintf(f, " else if (c < 0x%02x)\n ", 16*i2);
  296. }
  297. }
  298. if (t == -1)
  299. fprintf(f, "*pwc = (ucs4_t) c;\n");
  300. else {
  301. fprintf(f, "*pwc = (ucs4_t) %s_2uni", c_charsetname);
  302. if (tableno > 1)
  303. fprintf(f, "_%d", t+1);
  304. fprintf(f, "[c");
  305. if (tables[t].minline > 0)
  306. fprintf(f, "-0x%02x", 16*tables[t].minline);
  307. fprintf(f, "];\n");
  308. }
  309. i1 = i2;
  310. }
  311. fprintf(f, " return 1;\n");
  312. }
  313. fprintf(f, "}\n");
  314. }
  315. fprintf(f, "\n");
  316. {
  317. int uni2charset[0x10000];
  318. bool pages[0x100];
  319. int line[0x2000];
  320. int tableno;
  321. struct { int minline; int maxline; int usecount; const char* suffix; } tables[0x2000];
  322. bool need_c;
  323. bool fix_0000;
  324. int i, j, p, j1, j2, t;
  325. for (j = 0; j < 0x10000; j++)
  326. uni2charset[j] = 0;
  327. for (p = 0; p < 0x100; p++)
  328. pages[p] = false;
  329. for (i = 0; i < 0x100; i++) {
  330. j = charset2uni[i];
  331. if (j != 0xfffd) {
  332. uni2charset[j] = i;
  333. pages[j>>8] = true;
  334. }
  335. }
  336. for (j1 = 0; j1 < 0x2000; j1++) {
  337. bool all_invalid = true;
  338. bool all_identity = true;
  339. for (j2 = 0; j2 < 8; j2++) {
  340. j = 8*j1+j2;
  341. if (uni2charset[j] != 0)
  342. all_invalid = false;
  343. if (uni2charset[j] != j)
  344. all_identity = false;
  345. }
  346. if (all_invalid)
  347. line[j1] = -2;
  348. else if (all_identity)
  349. line[j1] = -1;
  350. else
  351. line[j1] = 0;
  352. }
  353. tableno = 0;
  354. for (j1 = 0; j1 < 0x2000; j1++) {
  355. if (line[j1] >= 0) {
  356. if (tableno > 0
  357. && ((j1 > 0 && line[j1-1] == tableno-1)
  358. || ((tables[tableno-1].maxline >> 5) == (j1 >> 5)
  359. && j1 - tables[tableno-1].maxline <= 8))) {
  360. line[j1] = tableno-1;
  361. tables[tableno-1].maxline = j1;
  362. } else {
  363. tableno++;
  364. line[j1] = tableno-1;
  365. tables[tableno-1].minline = tables[tableno-1].maxline = j1;
  366. }
  367. }
  368. }
  369. for (t = 0; t < tableno; t++) {
  370. tables[t].usecount = 0;
  371. j1 = 8*tables[t].minline;
  372. j2 = 8*(tables[t].maxline+1);
  373. for (j = j1; j < j2; j++)
  374. if (uni2charset[j] != 0)
  375. tables[t].usecount++;
  376. }
  377. for (t = 0, p = -1, i = 0; t < tableno; t++) {
  378. if (tables[t].usecount > 1) {
  379. char* s;
  380. if (p == tables[t].minline >> 5) {
  381. s = (char*) malloc(5+1);
  382. sprintf(s, "%02x_%d", p, ++i);
  383. } else {
  384. p = tables[t].minline >> 5;
  385. s = (char*) malloc(2+1);
  386. sprintf(s, "%02x", p);
  387. }
  388. tables[t].suffix = s;
  389. } else
  390. tables[t].suffix = NULL;
  391. }
  392. {
  393. p = -1;
  394. for (t = 0; t < tableno; t++)
  395. if (tables[t].usecount > 1) {
  396. p = 0;
  397. fprintf(f, "static const unsigned char %s_page%s[%d] = {\n", c_charsetname, tables[t].suffix, 8*(tables[t].maxline-tables[t].minline+1));
  398. for (j1 = tables[t].minline; j1 <= tables[t].maxline; j1++) {
  399. if ((j1 % 0x20) == 0 && j1 > tables[t].minline)
  400. fprintf(f, " /* 0x%04x */\n", 8*j1);
  401. fprintf(f, " ");
  402. for (j2 = 0; j2 < 8; j2++) {
  403. j = 8*j1+j2;
  404. fprintf(f, " 0x%02x,", uni2charset[j]);
  405. }
  406. fprintf(f, " /* 0x%02x-0x%02x */\n", 8*(j1 % 0x20), 8*(j1 % 0x20)+7);
  407. }
  408. fprintf(f, "};\n");
  409. }
  410. if (p >= 0)
  411. fprintf(f, "\n");
  412. }
  413. need_c = false;
  414. for (j1 = 0; j1 < 0x2000;) {
  415. t = line[j1];
  416. for (j2 = j1; j2 < 0x2000 && line[j2] == t; j2++);
  417. if (t >= 0)
  418. j2 = tables[t].maxline+1;
  419. if (!(t == -2 || (t == -1 && j1 == 0)))
  420. need_c = true;
  421. j1 = j2;
  422. }
  423. fix_0000 = false;
  424. fprintf(f, "static int\n%s_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)\n", c_charsetname);
  425. fprintf(f, "{\n");
  426. if (need_c)
  427. fprintf(f, " unsigned char c = 0;\n");
  428. for (j1 = 0; j1 < 0x2000;) {
  429. t = line[j1];
  430. for (j2 = j1; j2 < 0x2000 && line[j2] == t; j2++);
  431. if (t >= 0) {
  432. if (j1 != tables[t].minline) abort();
  433. if (j2 > tables[t].maxline+1) abort();
  434. j2 = tables[t].maxline+1;
  435. }
  436. if (t == -2) {
  437. } else {
  438. if (j1 == 0)
  439. fprintf(f, " ");
  440. else
  441. fprintf(f, " else ");
  442. if (t >= 0 && tables[t].usecount == 0) abort();
  443. if (t >= 0 && tables[t].usecount == 1) {
  444. if (j2 != j1+1) abort();
  445. for (j = 8*j1; j < 8*j2; j++)
  446. if (uni2charset[j] != 0) {
  447. fprintf(f, "if (wc == 0x%04x)\n c = 0x%02x;\n", j, uni2charset[j]);
  448. break;
  449. }
  450. } else {
  451. if (j1 == 0) {
  452. fprintf(f, "if (wc < 0x%04x)", 8*j2);
  453. } else {
  454. fprintf(f, "if (wc >= 0x%04x && wc < 0x%04x)", 8*j1, 8*j2);
  455. }
  456. if (t == -1) {
  457. if (j1 == 0)
  458. /* If wc == 0, the function must return 1, not -1. */
  459. fprintf(f, " {\n *r = wc;\n return 1;\n }\n");
  460. else
  461. fprintf(f, "\n c = wc;\n");
  462. } else {
  463. fprintf(f, "\n c = %s_page%s[wc", c_charsetname, tables[t].suffix);
  464. if (tables[t].minline > 0)
  465. fprintf(f, "-0x%04x", 8*j1);
  466. fprintf(f, "];\n");
  467. if (j1 == 0 && uni2charset[0] == 0)
  468. /* If wc == 0, the function must return 1, not -1. */
  469. fix_0000 = true;
  470. }
  471. }
  472. }
  473. j1 = j2;
  474. }
  475. if (need_c) {
  476. if (fix_0000)
  477. fprintf(f, " if (c != 0 || wc == 0) {\n");
  478. else
  479. fprintf(f, " if (c != 0) {\n");
  480. fprintf(f, " *r = c;\n");
  481. fprintf(f, " return 1;\n");
  482. fprintf(f, " }\n");
  483. }
  484. fprintf(f, " return RET_ILUNI;\n");
  485. fprintf(f, "}\n");
  486. }
  487. if (ferror(f) || fclose(f))
  488. exit(1);
  489. }
  490. #if 0
  491. int i1, i2, i3, i1_min, i1_max, j1, j2;
  492. i1_min = 16;
  493. i1_max = -1;
  494. for (i1 = 0; i1 < 16; i1++)
  495. for (i2 = 0; i2 < 16; i2++)
  496. if (charset2uni[16*i1+i2] != 0xfffd) {
  497. if (i1_min > i1) i1_min = i1;
  498. if (i1_max < i1) i1_max = i1;
  499. }
  500. printf("static const unsigned short %s_2uni[%d] = {\n",
  501. name, 16*(i1_max-i1_min+1));
  502. for (i1 = i1_min; i1 <= i1_max; i1++) {
  503. printf(" /""* 0x%02x *""/\n", 16*i1);
  504. for (i2 = 0; i2 < 2; i2++) {
  505. printf(" ");
  506. for (i3 = 0; i3 < 8; i3++) {
  507. if (i3 > 0) printf(" ");
  508. printf("0x%04x,", charset2uni[16*i1+8*i2+i3]);
  509. }
  510. printf("\n");
  511. }
  512. }
  513. printf("};\n");
  514. printf("\n");
  515. for (p = 0; p < 0x100; p++)
  516. pages[p] = 0;
  517. for (i = 0; i < 0x100; i++)
  518. if (charset2uni[i] != 0xfffd)
  519. pages[charset2uni[i]>>8] = 1;
  520. for (p = 0; p < 0x100; p++)
  521. if (pages[p]) {
  522. int j1_min = 32;
  523. int j1_max = -1;
  524. for (j1 = 0; j1 < 32; j1++)
  525. for (j2 = 0; j2 < 8; j2++)
  526. if (uni2charset[256*p+8*j1+j2] != 0) {
  527. if (j1_min > j1) j1_min = j1;
  528. if (j1_max < j1) j1_max = j1;
  529. }
  530. printf("static const unsigned char %s_page%02x[%d] = {\n",
  531. name, p, 8*(j1_max-j1_min+1));
  532. for (j1 = j1_min; j1 <= j1_max; j1++) {
  533. printf(" ");
  534. for (j2 = 0; j2 < 8; j2++)
  535. printf("0x%02x, ", uni2charset[256*p+8*j1+j2]);
  536. printf("/""* 0x%02x-0x%02x *""/\n", 8*j1, 8*j1+7);
  537. }
  538. printf("};\n");
  539. }
  540. printf("\n");
  541. }
  542. #endif
  543. exit(0);
  544. }