cp1133.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 1999-2001 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 Library General Public
  7. * License as published by the Free Software Foundation; either version 2
  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. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public
  16. * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
  17. * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
  18. * Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. /*
  21. * IBM-CP1133
  22. */
  23. static const unsigned short cp1133_2uni_1[64] = {
  24. /* 0xa0 */
  25. 0x00a0, 0x0e81, 0x0e82, 0x0e84, 0x0e87, 0x0e88, 0x0eaa, 0x0e8a,
  26. 0x0e8d, 0x0e94, 0x0e95, 0x0e96, 0x0e97, 0x0e99, 0x0e9a, 0x0e9b,
  27. /* 0xb0 */
  28. 0x0e9c, 0x0e9d, 0x0e9e, 0x0e9f, 0x0ea1, 0x0ea2, 0x0ea3, 0x0ea5,
  29. 0x0ea7, 0x0eab, 0x0ead, 0x0eae, 0xfffd, 0xfffd, 0xfffd, 0x0eaf,
  30. /* 0xc0 */
  31. 0x0eb0, 0x0eb2, 0x0eb3, 0x0eb4, 0x0eb5, 0x0eb6, 0x0eb7, 0x0eb8,
  32. 0x0eb9, 0x0ebc, 0x0eb1, 0x0ebb, 0x0ebd, 0xfffd, 0xfffd, 0xfffd,
  33. /* 0xd0 */
  34. 0x0ec0, 0x0ec1, 0x0ec2, 0x0ec3, 0x0ec4, 0x0ec8, 0x0ec9, 0x0eca,
  35. 0x0ecb, 0x0ecc, 0x0ecd, 0x0ec6, 0xfffd, 0x0edc, 0x0edd, 0x20ad,
  36. };
  37. static const unsigned short cp1133_2uni_2[16] = {
  38. /* 0xf0 */
  39. 0x0ed0, 0x0ed1, 0x0ed2, 0x0ed3, 0x0ed4, 0x0ed5, 0x0ed6, 0x0ed7,
  40. 0x0ed8, 0x0ed9, 0xfffd, 0xfffd, 0x00a2, 0x00ac, 0x00a6, 0xfffd,
  41. };
  42. static int
  43. cp1133_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
  44. {
  45. unsigned char c = *s;
  46. if (c < 0xa0) {
  47. *pwc = (ucs4_t) c;
  48. return 1;
  49. }
  50. else if (c < 0xe0) {
  51. unsigned short wc = cp1133_2uni_1[c-0xa0];
  52. if (wc != 0xfffd) {
  53. *pwc = (ucs4_t) wc;
  54. return 1;
  55. }
  56. }
  57. else if (c < 0xf0) {
  58. }
  59. else {
  60. unsigned short wc = cp1133_2uni_2[c-0xf0];
  61. if (wc != 0xfffd) {
  62. *pwc = (ucs4_t) wc;
  63. return 1;
  64. }
  65. }
  66. return RET_ILSEQ;
  67. }
  68. static const unsigned char cp1133_page00[16] = {
  69. 0xa0, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfe, 0x00, /* 0xa0-0xa7 */
  70. 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
  71. };
  72. static const unsigned char cp1133_page0e[96] = {
  73. 0x00, 0xa1, 0xa2, 0x00, 0xa3, 0x00, 0x00, 0xa4, /* 0x80-0x87 */
  74. 0xa5, 0x00, 0xa7, 0x00, 0x00, 0xa8, 0x00, 0x00, /* 0x88-0x8f */
  75. 0x00, 0x00, 0x00, 0x00, 0xa9, 0xaa, 0xab, 0xac, /* 0x90-0x97 */
  76. 0x00, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, /* 0x98-0x9f */
  77. 0x00, 0xb4, 0xb5, 0xb6, 0x00, 0xb7, 0x00, 0xb8, /* 0xa0-0xa7 */
  78. 0x00, 0x00, 0xa6, 0xb9, 0x00, 0xba, 0xbb, 0xbf, /* 0xa8-0xaf */
  79. 0xc0, 0xca, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, /* 0xb0-0xb7 */
  80. 0xc7, 0xc8, 0x00, 0xcb, 0xc9, 0xcc, 0x00, 0x00, /* 0xb8-0xbf */
  81. 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0x00, 0xdb, 0x00, /* 0xc0-0xc7 */
  82. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0x00, 0x00, /* 0xc8-0xcf */
  83. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 0xd0-0xd7 */
  84. 0xf8, 0xf9, 0x00, 0x00, 0xdd, 0xde, 0x00, 0x00, /* 0xd8-0xdf */
  85. };
  86. static int
  87. cp1133_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
  88. {
  89. unsigned char c = 0;
  90. if (wc < 0x00a0) {
  91. *r = wc;
  92. return 1;
  93. }
  94. else if (wc >= 0x00a0 && wc < 0x00b0)
  95. c = cp1133_page00[wc-0x00a0];
  96. else if (wc >= 0x0e80 && wc < 0x0ee0)
  97. c = cp1133_page0e[wc-0x0e80];
  98. else if (wc == 0x20ad)
  99. c = 0xdf;
  100. if (c != 0) {
  101. *r = c;
  102. return 1;
  103. }
  104. return RET_ILUNI;
  105. }