2 * Copyright (C) 1999-2001, 2005 Free Software Foundation, Inc.
3 * This file is part of the GNU LIBICONV Library.
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.
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.
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.
26 euc_jp_mbtowc (conv_t conv
, ucs4_t
*pwc
, const unsigned char *s
, int n
)
29 /* Code set 0 (ASCII or JIS X 0201-1976 Roman) */
31 return ascii_mbtowc(conv
,pwc
,s
,n
);
32 /* Code set 1 (JIS X 0208) */
33 if (c
>= 0xa1 && c
< 0xff) {
37 unsigned char c2
= s
[1];
38 if (c2
>= 0xa1 && c2
< 0xff) {
40 buf
[0] = c
-0x80; buf
[1] = c2
-0x80;
41 return jisx0208_mbtowc(conv
,pwc
,buf
,2);
45 /* User-defined range. See
46 * Ken Lunde's "CJKV Information Processing", table 4-66, p. 206. */
47 unsigned char c2
= s
[1];
48 if (c2
>= 0xa1 && c2
< 0xff) {
49 *pwc
= 0xe000 + 94*(c
-0xf5) + (c2
-0xa1);
55 /* Code set 2 (half-width katakana) */
60 unsigned char c2
= s
[1];
61 if (c2
>= 0xa1 && c2
< 0xe0) {
62 int ret
= jisx0201_mbtowc(conv
,pwc
,s
+1,n
-1);
65 if (ret
!= 1) abort();
71 /* Code set 3 (JIS X 0212-1990) */
76 unsigned char c2
= s
[1];
77 if (c2
>= 0xa1 && c2
< 0xff) {
81 unsigned char c3
= s
[2];
82 if (c3
>= 0xa1 && c3
< 0xff) {
85 buf
[0] = c2
-0x80; buf
[1] = c3
-0x80;
86 ret
= jisx0212_mbtowc(conv
,pwc
,buf
,2);
89 if (ret
!= 2) abort();
94 /* User-defined range. See
95 * Ken Lunde's "CJKV Information Processing", table 4-66, p. 206. */
96 unsigned char c3
= s
[2];
97 if (c3
>= 0xa1 && c3
< 0xff) {
98 *pwc
= 0xe3ac + 94*(c2
-0xf5) + (c3
-0xa1);
111 euc_jp_wctomb (conv_t conv
, unsigned char *r
, ucs4_t wc
, int n
)
113 unsigned char buf
[2];
116 /* Code set 0 (ASCII or JIS X 0201-1976 Roman) */
117 ret
= ascii_wctomb(conv
,r
,wc
,n
);
118 if (ret
!= RET_ILUNI
)
121 /* Code set 1 (JIS X 0208) */
122 ret
= jisx0208_wctomb(conv
,buf
,wc
,2);
123 if (ret
!= RET_ILUNI
) {
124 if (ret
!= 2) abort();
132 /* Code set 2 (half-width katakana) */
133 ret
= jisx0201_wctomb(conv
,buf
,wc
,1);
134 if (ret
!= RET_ILUNI
&& buf
[0] >= 0x80) {
135 if (ret
!= 1) abort();
143 /* Code set 3 (JIS X 0212-1990) */
144 ret
= jisx0212_wctomb(conv
,buf
,wc
,2);
145 if (ret
!= RET_ILUNI
) {
146 if (ret
!= 2) abort();
155 /* Extra compatibility with Shift_JIS. */
165 /* User-defined range. See
166 * Ken Lunde's "CJKV Information Processing", table 4-66, p. 206. */
167 if (wc
>= 0xe000 && wc
< 0xe758) {
169 unsigned char c1
, c2
;
172 c1
= (unsigned int) (wc
- 0xe000) / 94;
173 c2
= (unsigned int) (wc
- 0xe000) % 94;
178 unsigned char c1
, c2
;
181 c1
= (unsigned int) (wc
- 0xe3ac) / 94;
182 c2
= (unsigned int) (wc
- 0xe3ac) % 94;