cp50221_0208_ext.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 1999-2012, 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 JISX0208 extensions
  21. */
  22. static const unsigned short cp50221_0208_ext_2uni[96] = {
  23. /* 0x00 */
  24. 0xfffd, 0x2460, 0x2461, 0x2462, 0x2463, 0x2464, 0x2465, 0x2466,
  25. 0x2467, 0x2468, 0x2469, 0x246a, 0x246b, 0x246c, 0x246d, 0x246e,
  26. /* 0x10 */
  27. 0x246f, 0x2470, 0x2471, 0x2472, 0x2473, 0x2160, 0x2161, 0x2162,
  28. 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0xfffd,
  29. /* 0x20 */
  30. 0x3349, 0x3314, 0x3322, 0x334d, 0x3318, 0x3327, 0x3303, 0x3336,
  31. 0x3351, 0x3357, 0x330d, 0x3326, 0x3323, 0x332b, 0x334a, 0x333b,
  32. /* 0x30 */
  33. 0x339c, 0x339d, 0x339e, 0x338e, 0x338f, 0x33c4, 0x33a1, 0xfffd,
  34. 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0x337b,
  35. /* 0x40 */
  36. 0x301e, 0x301f, 0x2116, 0x33cd, 0x2121, 0x32a4, 0x32a5, 0x32a6,
  37. 0x32a7, 0x32a8, 0x3231, 0x3232, 0x3239, 0x337e, 0x337d, 0x337c,
  38. /* 0x50 */
  39. 0xfffd, 0xfffd, 0xfffd, 0x222e, 0x2211, 0xfffd, 0xfffd, 0xfffd,
  40. 0x221f, 0x22bf, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
  41. };
  42. static int
  43. cp50221_0208_ext_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, size_t n)
  44. {
  45. unsigned char c = *s;
  46. if (c < 0x60) {
  47. unsigned short wc = cp50221_0208_ext_2uni[c];
  48. if (wc != 0xfffd) {
  49. *pwc = (ucs4_t) wc;
  50. return 1;
  51. }
  52. }
  53. return RET_ILSEQ;
  54. }
  55. static const unsigned char cp50221_0208_ext_page21[96] = {
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, /* 0x10-0x17 */
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
  58. 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
  60. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
  61. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
  62. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
  64. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
  66. 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, /* 0x60-0x67 */
  67. 0x1d, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
  68. };
  69. static const unsigned char cp50221_0208_ext_page22[32] = {
  70. 0x00, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
  71. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, /* 0x18-0x1f */
  72. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
  73. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x00, /* 0x28-0x2f */
  74. };
  75. static const unsigned char cp50221_0208_ext_page24[24] = {
  76. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, /* 0x60-0x67 */
  77. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, /* 0x68-0x6f */
  78. 0x11, 0x12, 0x13, 0x14, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
  79. };
  80. static const unsigned char cp50221_0208_ext_page30[8] = {
  81. 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x41, /* 0x18-0x1f */
  82. };
  83. static const unsigned char cp50221_0208_ext_page32[16] = {
  84. 0x00, 0x4a, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
  85. 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
  86. };
  87. static const unsigned char cp50221_0208_ext_page32_1[16] = {
  88. 0x00, 0x00, 0x00, 0x00, 0x45, 0x46, 0x47, 0x48, /* 0xa0-0xa7 */
  89. 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
  90. };
  91. static const unsigned char cp50221_0208_ext_page33[208] = {
  92. 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
  93. 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, /* 0x08-0x0f */
  94. 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, /* 0x10-0x17 */
  95. 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
  96. 0x00, 0x00, 0x22, 0x2c, 0x00, 0x00, 0x2b, 0x25, /* 0x20-0x27 */
  97. 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
  98. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0x00, /* 0x30-0x37 */
  99. 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
  100. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
  101. 0x00, 0x20, 0x2e, 0x00, 0x00, 0x23, 0x00, 0x00, /* 0x48-0x4f */
  102. 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, /* 0x50-0x57 */
  103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
  104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
  105. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
  107. 0x00, 0x00, 0x00, 0x3f, 0x4f, 0x4e, 0x4d, 0x00, /* 0x78-0x7f */
  108. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
  109. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x34, /* 0x88-0x8f */
  110. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
  111. 0x00, 0x00, 0x00, 0x00, 0x30, 0x31, 0x32, 0x00, /* 0x98-0x9f */
  112. 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
  113. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
  114. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
  115. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
  116. 0x00, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
  117. 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, /* 0xc8-0xcf */
  118. };
  119. static int
  120. cp50221_0208_ext_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
  121. {
  122. unsigned char c = 0;
  123. if (wc >= 0x2110 && wc < 0x2170)
  124. c = cp50221_0208_ext_page21[wc-0x2110];
  125. else if (wc >= 0x2210 && wc < 0x2230)
  126. c = cp50221_0208_ext_page22[wc-0x2210];
  127. else if (wc == 0x22bf)
  128. c = 0x59;
  129. else if (wc >= 0x2460 && wc < 0x2478)
  130. c = cp50221_0208_ext_page24[wc-0x2460];
  131. else if (wc >= 0x3018 && wc < 0x3020)
  132. c = cp50221_0208_ext_page30[wc-0x3018];
  133. else if (wc >= 0x3230 && wc < 0x3240)
  134. c = cp50221_0208_ext_page32[wc-0x3230];
  135. else if (wc >= 0x32a0 && wc < 0x32b0)
  136. c = cp50221_0208_ext_page32_1[wc-0x32a0];
  137. else if (wc >= 0x3300 && wc < 0x33d0)
  138. c = cp50221_0208_ext_page33[wc-0x3300];
  139. if (c != 0) {
  140. *r = c;
  141. return 1;
  142. }
  143. return RET_ILUNI;
  144. }