cjk_variants.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 Unicode variants table from Koichi Yasuoka's UniVariants file.
  16. */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #define ENTRIES 8176 /* number of lines in UniVariants file */
  20. #define MAX_PER_ENTRY 10 /* max number of entries per line in file */
  21. int main (int argc, char *argv[])
  22. {
  23. int variants[MAX_PER_ENTRY*ENTRIES];
  24. int uni2index[0x10000];
  25. int index;
  26. if (argc != 1)
  27. exit(1);
  28. printf("/*\n");
  29. printf(" * Copyright (C) 1999-2002 Free Software Foundation, Inc.\n");
  30. printf(" * This file is part of the GNU LIBICONV Library.\n");
  31. printf(" *\n");
  32. printf(" * The GNU LIBICONV Library is free software; you can redistribute it\n");
  33. printf(" * and/or modify it under the terms of the GNU Library General Public\n");
  34. printf(" * License as published by the Free Software Foundation; either version 2\n");
  35. printf(" * of the License, or (at your option) any later version.\n");
  36. printf(" *\n");
  37. printf(" * The GNU LIBICONV Library is distributed in the hope that it will be\n");
  38. printf(" * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
  39. printf(" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
  40. printf(" * Library General Public License for more details.\n");
  41. printf(" *\n");
  42. printf(" * You should have received a copy of the GNU Library General Public\n");
  43. printf(" * License along with the GNU LIBICONV Library; see the file COPYING.LIB.\n");
  44. printf(" * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,\n");
  45. printf(" * Fifth Floor, Boston, MA 02110-1301, USA.\n");
  46. printf(" */\n");
  47. printf("\n");
  48. printf("/*\n");
  49. printf(" * CJK variants table\n");
  50. printf(" */\n");
  51. printf("\n");
  52. {
  53. int c;
  54. int j;
  55. for (j = 0; j < 0x10000; j++)
  56. uni2index[j] = -1;
  57. index = 0;
  58. for (;;) {
  59. c = getc(stdin);
  60. if (c == EOF)
  61. break;
  62. if (c == '#') {
  63. do { c = getc(stdin); } while (!(c == EOF || c == '\n'));
  64. continue;
  65. }
  66. ungetc(c,stdin);
  67. if (scanf("%x",&j) != 1)
  68. exit(1);
  69. c = getc(stdin);
  70. if (c != '\t')
  71. exit(1);
  72. uni2index[j] = index;
  73. for (;;) {
  74. int i;
  75. if (scanf("%x",&i) != 1)
  76. exit(1);
  77. if (!(i >= 0x3000 && i < 0x3000+0x8000))
  78. exit(1);
  79. variants[index++] = i-0x3000;
  80. c = getc(stdin);
  81. if (c != ' ')
  82. break;
  83. }
  84. variants[index-1] |= 0x8000; /* end of list marker */
  85. if (c != '\n')
  86. exit(1);
  87. }
  88. }
  89. printf("static const unsigned short cjk_variants[%d] = {",index);
  90. {
  91. int i;
  92. for (i = 0; i < index; i++) {
  93. if ((i % 8) == 0)
  94. printf("\n ");
  95. printf(" 0x%04x,",variants[i]);
  96. }
  97. printf("\n};\n");
  98. }
  99. printf("\n");
  100. printf("static const short cjk_variants_indx[0x5200] = {\n");
  101. {
  102. int j;
  103. for (j = 0x4e00; j < 0xa000; j++) {
  104. if ((j % 0x100) == 0)
  105. printf(" /* 0x%04x */\n", j);
  106. if ((j % 8) == 0)
  107. printf(" ");
  108. printf(" %5d,",uni2index[j]);
  109. if ((j % 8) == 7)
  110. printf("\n");
  111. }
  112. printf("};\n");
  113. }
  114. printf("\n");
  115. return 0;
  116. }