PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/fltk/src/xutf8/utils/convert_map.c

http://luafltk.googlecode.com/
C | 179 lines | 135 code | 12 blank | 32 comment | 45 complexity | ffacfbaf3f803cddbe0eca16c3dd25c3 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-3.0, 0BSD
  1. /* "$Id: $"
  2. *
  3. * Author: Jean-Marc Lienher ( http://oksid.ch )
  4. * Copyright 2000-2003 by O'ksi'D.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  19. * USA.
  20. *
  21. * Please report all bugs and problems on the following page:
  22. *
  23. * http://www.fltk.org/str.php
  24. */
  25. /*
  26. * read the http://www.unicode.org/Public/MAPPINGS/ and create something
  27. * usable in C.
  28. */
  29. #include <wchar.h>
  30. #include <stdio.h>
  31. char buffer[1000000];
  32. int JIS0208(unsigned char * ptr) {
  33. int i = 0;
  34. unsigned int fmap;
  35. unsigned int ucs;
  36. while(*ptr != '\t') { ptr++; i++; }
  37. ptr++; i++; *(ptr+6) = '\0';
  38. fmap = (unsigned int)strtoul(ptr, NULL, 16);
  39. while(*ptr != '\0') { ptr++; i++; }
  40. i++; ptr++; *(ptr+6) = '\0';
  41. ucs = (unsigned int)strtoul(ptr, NULL, 16);
  42. if (ucs)
  43. printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
  44. (fmap & 0xFF00) >> 8, fmap & 0xFF);
  45. while(*ptr != '\0') { ptr++; i++; }
  46. i++; ptr++;
  47. while(*ptr != '\n') { ptr++; i++; }
  48. i++;
  49. return i;
  50. }
  51. int JIS0201(unsigned char * ptr) {
  52. int i = 0;
  53. unsigned int fmap;
  54. unsigned int ucs;
  55. *(ptr+4) = '\0';
  56. fmap = (unsigned int)strtoul(ptr, NULL, 16);
  57. while(*ptr != '\0') { ptr++; i++; }
  58. i++; ptr++; *(ptr+6) = '\0';
  59. ucs = (unsigned int)strtoul(ptr, NULL, 16);
  60. if (*(ptr + 1) != 'x') {
  61. printf("/* EOF */\n");
  62. abort();
  63. }
  64. if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
  65. while(*ptr != '\0') { ptr++; i++; }
  66. i++; ptr++;
  67. while(*ptr != '\n') { ptr++; i++; }
  68. i++;
  69. return i;
  70. }
  71. int ADOBE(unsigned char * ptr) {
  72. int i = 0;
  73. unsigned int fmap;
  74. unsigned int ucs;
  75. *(ptr+4) = '\0';
  76. ucs = (unsigned int)strtoul(ptr, NULL, 16);
  77. while(*ptr != '\0') { ptr++; i++; }
  78. i++; ptr++; *(ptr+2) = '\0';
  79. fmap = (unsigned int)strtoul(ptr, NULL, 16);
  80. if (fmap < 1) {
  81. printf("/* EOF */\n");
  82. abort();
  83. }
  84. if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
  85. while(*ptr != '\0') { ptr++; i++; }
  86. i++; ptr++;
  87. while(*ptr != '\n') { ptr++; i++; }
  88. i++;
  89. return i;
  90. }
  91. int JIS0212(unsigned char * ptr) {
  92. int i = 0;
  93. unsigned int fmap;
  94. unsigned int ucs;
  95. *(ptr+6) = '\0';
  96. fmap = (unsigned int)strtoul(ptr, NULL, 16);
  97. ptr += 7;
  98. i += 7;
  99. while(*ptr == ' ') { ptr++; i++; }
  100. //i++; ptr++;
  101. *(ptr+6) = '\0';
  102. ucs = (unsigned int)strtoul(ptr, NULL, 16);
  103. if (*(ptr + 1) != 'x') {
  104. printf("/* EOF */\n");
  105. abort();
  106. }
  107. if (ucs)
  108. printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
  109. (fmap & 0xFF00) >> 8, fmap & 0xFF);
  110. while(*ptr != '\0') { ptr++; i++; }
  111. i++; ptr++;
  112. while(*ptr != '\n') { ptr++; i++; }
  113. i++;
  114. return i;
  115. }
  116. int main(int argc, char **argv) {
  117. char buf[80];
  118. int len;
  119. int i;
  120. unsigned char *ptr;
  121. size_t nb;
  122. len = fread(buffer, 1, 1000000, stdin);
  123. buffer[len] = '\0';
  124. ptr = (unsigned char *)buffer;
  125. while (*ptr !='\n') {ptr++; len--;};
  126. ptr++; len--;
  127. while (*ptr == '#') {
  128. while (*ptr !='\n') {
  129. ptr++;
  130. len--;
  131. }
  132. ptr++;
  133. len--;
  134. }
  135. while (len > 0) {
  136. nb = 0;
  137. if (!strcmp("jisx0208.1983-0", argv[1])) {
  138. nb = JIS0208(ptr);
  139. } else if (!strcmp("jisx0201.1976-0", argv[1])) {
  140. nb = JIS0201(ptr);
  141. } else if (!strcmp("jisx0212.1990-0", argv[1])) {
  142. nb = JIS0212(ptr);
  143. } else if (!strcmp("gb2312.1980-0", argv[1])) {
  144. nb = JIS0212(ptr);
  145. } else if (!strcmp("ksc5601.1987-0", argv[1])) {
  146. nb = JIS0212(ptr);
  147. } else if (!strcmp("big5-0", argv[1])) {
  148. nb = JIS0212(ptr);
  149. } else if (!strncmp("iso8859", argv[1], 7)) {
  150. nb = JIS0201(ptr);
  151. } else if (!strcmp("koi8-1", argv[1])) {
  152. nb = JIS0201(ptr);
  153. } else if (!strcmp("dingbats", argv[1]) ||
  154. !strcmp("symbol", argv[1]))
  155. {
  156. nb = ADOBE(ptr);
  157. } else {
  158. len = 0;
  159. }
  160. ptr += nb;
  161. len = len - nb;
  162. }
  163. return 0;
  164. }
  165. /*
  166. * End of "$Id$".
  167. */