cp50221_0212_ext.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (C) 1999-2011, 2016 Free Software Foundation, Inc.
  3. * This file is part of the GNU LIBICONV Library.
  4. *
  5. * The GNU LIBICONV Library is free software; you can redistribute it
  6. * and/or modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either version 2.1
  8. * of the License, or (at your option) any later version.
  9. *
  10. * The GNU LIBICONV Library is distributed in the hope that it will be
  11. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
  17. * If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * CP50221 JISX0212 extensions
  21. */
  22. static const unsigned short cp50221_0212_ext_2uni[112] = {
  23. /* 0x00 */
  24. 0xfffd, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176,
  25. 0x2177, 0x2178, 0x2179, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
  26. /* 0x10 */
  27. 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xff07, 0xff02, 0xfffd,
  28. 0xfffd, 0xfffd, 0x70bb, 0x4efc, 0x50f4, 0x51ec, 0x5307, 0x5324,
  29. /* 0x20 */
  30. 0xfa0e, 0x548a, 0x5759, 0xfa0f, 0xfa10, 0x589e, 0x5bec, 0x5cf5,
  31. 0x5d53, 0xfa11, 0x5fb7, 0x6085, 0x6120, 0x654e, 0xfffd, 0x6665,
  32. /* 0x30 */
  33. 0xfa12, 0xf929, 0x6801, 0xfa13, 0xfa14, 0x6a6b, 0x6ae2, 0x6df8,
  34. 0x6df2, 0x7028, 0xfa15, 0xfa16, 0x7501, 0x7682, 0x769e, 0xfa17,
  35. /* 0x40 */
  36. 0x7930, 0xfa18, 0xfa19, 0xfa1a, 0xfa1b, 0x7ae7, 0xfa1c, 0xfa1d,
  37. 0x7da0, 0x7dd6, 0xfa1e, 0x8362, 0xfa1f, 0x85b0, 0xfa20, 0xfa21,
  38. /* 0x50 */
  39. 0x8807, 0xfa22, 0x8b7f, 0x8cf4, 0x8d76, 0xfa23, 0xfa24, 0xfa25,
  40. 0x90de, 0xfa26, 0x9115, 0xfa27, 0xfa28, 0x9592, 0xf9dc, 0xfa29,
  41. /* 0x60 */
  42. 0x973b, 0xfffd, 0x9751, 0xfa2a, 0xfa2b, 0xfa2c, 0x999e, 0x9ad9,
  43. 0x9b72, 0xfa2d, 0x9ed1, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
  44. };
  45. static int
  46. cp50221_0212_ext_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, size_t n)
  47. {
  48. unsigned char c = *s;
  49. if (c < 0x70) {
  50. unsigned short wc = cp50221_0212_ext_2uni[c];
  51. if (wc != 0xfffd) {
  52. *pwc = (ucs4_t) wc;
  53. return 1;
  54. }
  55. }
  56. else if (c == 0xa1) {
  57. *pwc = 0x974d;
  58. return 1;
  59. }
  60. return RET_ILSEQ;
  61. }
  62. static const unsigned char cp50221_0212_ext_page21[16] = {
  63. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, /* 0x70-0x77 */
  64. 0x09, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
  65. };
  66. static const unsigned char cp50221_0212_ext_page53[40] = {
  67. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, /* 0x00-0x07 */
  68. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
  69. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
  70. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
  71. 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, /* 0x20-0x27 */
  72. };
  73. static const unsigned char cp50221_0212_ext_page6d[16] = {
  74. 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
  75. 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
  76. };
  77. static const unsigned char cp50221_0212_ext_page76[32] = {
  78. 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
  79. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
  80. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
  81. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, /* 0x98-0x9f */
  82. };
  83. static const unsigned char cp50221_0212_ext_page7d[56] = {
  84. 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
  85. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
  86. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
  87. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
  88. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
  89. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
  90. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, /* 0xd0-0xd7 */
  91. };
  92. static const unsigned char cp50221_0212_ext_page97[32] = {
  93. 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
  95. 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1, 0x00, 0x00, /* 0x48-0x4f */
  96. 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
  97. };
  98. static const unsigned char cp50221_0212_ext_pagefa[40] = {
  99. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x23, /* 0x08-0x0f */
  100. 0x24, 0x29, 0x30, 0x33, 0x34, 0x3a, 0x3b, 0x3f, /* 0x10-0x17 */
  101. 0x41, 0x42, 0x43, 0x44, 0x46, 0x47, 0x4a, 0x4c, /* 0x18-0x1f */
  102. 0x4e, 0x4f, 0x51, 0x55, 0x56, 0x57, 0x59, 0x5b, /* 0x20-0x27 */
  103. 0x5c, 0x5f, 0x63, 0x64, 0x65, 0x69, 0x00, 0x00, /* 0x28-0x2f */
  104. };
  105. static const unsigned char cp50221_0212_ext_pageff[8] = {
  106. 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x15, /* 0x00-0x07 */
  107. };
  108. static int
  109. cp50221_0212_ext_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
  110. {
  111. unsigned char c = 0;
  112. if (wc >= 0x2170 && wc < 0x2180)
  113. c = cp50221_0212_ext_page21[wc-0x2170];
  114. else if (wc == 0x4efc)
  115. c = 0x1b;
  116. else if (wc == 0x50f4)
  117. c = 0x1c;
  118. else if (wc == 0x51ec)
  119. c = 0x1d;
  120. else if (wc >= 0x5300 && wc < 0x5328)
  121. c = cp50221_0212_ext_page53[wc-0x5300];
  122. else if (wc == 0x548a)
  123. c = 0x21;
  124. else if (wc == 0x5759)
  125. c = 0x22;
  126. else if (wc == 0x589e)
  127. c = 0x25;
  128. else if (wc == 0x5bec)
  129. c = 0x26;
  130. else if (wc == 0x5cf5)
  131. c = 0x27;
  132. else if (wc == 0x5d53)
  133. c = 0x28;
  134. else if (wc == 0x5fb7)
  135. c = 0x2a;
  136. else if (wc == 0x6085)
  137. c = 0x2b;
  138. else if (wc == 0x6120)
  139. c = 0x2c;
  140. else if (wc == 0x654e)
  141. c = 0x2d;
  142. else if (wc == 0x6665)
  143. c = 0x2f;
  144. else if (wc == 0x6801)
  145. c = 0x32;
  146. else if (wc == 0x6a6b)
  147. c = 0x35;
  148. else if (wc == 0x6ae2)
  149. c = 0x36;
  150. else if (wc >= 0x6df0 && wc < 0x6e00)
  151. c = cp50221_0212_ext_page6d[wc-0x6df0];
  152. else if (wc == 0x7028)
  153. c = 0x39;
  154. else if (wc == 0x70bb)
  155. c = 0x1a;
  156. else if (wc == 0x7501)
  157. c = 0x3c;
  158. else if (wc >= 0x7680 && wc < 0x76a0)
  159. c = cp50221_0212_ext_page76[wc-0x7680];
  160. else if (wc == 0x7930)
  161. c = 0x40;
  162. else if (wc == 0x7ae7)
  163. c = 0x45;
  164. else if (wc >= 0x7da0 && wc < 0x7dd8)
  165. c = cp50221_0212_ext_page7d[wc-0x7da0];
  166. else if (wc == 0x8362)
  167. c = 0x4b;
  168. else if (wc == 0x85b0)
  169. c = 0x4d;
  170. else if (wc == 0x8807)
  171. c = 0x50;
  172. else if (wc == 0x8b7f)
  173. c = 0x52;
  174. else if (wc == 0x8cf4)
  175. c = 0x53;
  176. else if (wc == 0x8d76)
  177. c = 0x54;
  178. else if (wc == 0x90de)
  179. c = 0x58;
  180. else if (wc == 0x9115)
  181. c = 0x5a;
  182. else if (wc == 0x9592)
  183. c = 0x5d;
  184. else if (wc >= 0x9738 && wc < 0x9758)
  185. c = cp50221_0212_ext_page97[wc-0x9738];
  186. else if (wc == 0x999e)
  187. c = 0x66;
  188. else if (wc == 0x9ad9)
  189. c = 0x67;
  190. else if (wc == 0x9b72)
  191. c = 0x68;
  192. else if (wc == 0x9ed1)
  193. c = 0x6a;
  194. else if (wc == 0xf929)
  195. c = 0x31;
  196. else if (wc == 0xf9dc)
  197. c = 0x5e;
  198. else if (wc >= 0xfa08 && wc < 0xfa30)
  199. c = cp50221_0212_ext_pagefa[wc-0xfa08];
  200. else if (wc >= 0xff00 && wc < 0xff08)
  201. c = cp50221_0212_ext_pageff[wc-0xff00];
  202. if (c != 0) {
  203. *r = c;
  204. return 1;
  205. }
  206. return RET_ILUNI;
  207. }