1*aef5731fSOliver Tappe /*
2*aef5731fSOliver Tappe * Copyright (C) 1999-2001 Free Software Foundation, Inc.
3*aef5731fSOliver Tappe * This file is part of the GNU LIBICONV Library.
4*aef5731fSOliver Tappe *
5*aef5731fSOliver Tappe * The GNU LIBICONV Library is free software; you can redistribute it
6*aef5731fSOliver Tappe * and/or modify it under the terms of the GNU Library General Public
7*aef5731fSOliver Tappe * License as published by the Free Software Foundation; either version 2
8*aef5731fSOliver Tappe * of the License, or (at your option) any later version.
9*aef5731fSOliver Tappe *
10*aef5731fSOliver Tappe * The GNU LIBICONV Library is distributed in the hope that it will be
11*aef5731fSOliver Tappe * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12*aef5731fSOliver Tappe * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13*aef5731fSOliver Tappe * Library General Public License for more details.
14*aef5731fSOliver Tappe *
15*aef5731fSOliver Tappe * You should have received a copy of the GNU Library General Public
16*aef5731fSOliver Tappe * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
17*aef5731fSOliver Tappe * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
18*aef5731fSOliver Tappe * Fifth Floor, Boston, MA 02110-1301, USA.
19*aef5731fSOliver Tappe */
20*aef5731fSOliver Tappe
21*aef5731fSOliver Tappe /*
22*aef5731fSOliver Tappe * EUC-CN
23*aef5731fSOliver Tappe */
24*aef5731fSOliver Tappe
25*aef5731fSOliver Tappe static int
euc_cn_mbtowc(conv_t conv,ucs4_t * pwc,const unsigned char * s,int n)26*aef5731fSOliver Tappe euc_cn_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
27*aef5731fSOliver Tappe {
28*aef5731fSOliver Tappe unsigned char c = *s;
29*aef5731fSOliver Tappe /* Code set 0 (ASCII or GB 1988-89) */
30*aef5731fSOliver Tappe if (c < 0x80)
31*aef5731fSOliver Tappe return ascii_mbtowc(conv,pwc,s,n);
32*aef5731fSOliver Tappe /* Code set 1 (GB 2312-1980) */
33*aef5731fSOliver Tappe if (c >= 0xa1 && c < 0xff) {
34*aef5731fSOliver Tappe if (n < 2)
35*aef5731fSOliver Tappe return RET_TOOFEW(0);
36*aef5731fSOliver Tappe {
37*aef5731fSOliver Tappe unsigned char c2 = s[1];
38*aef5731fSOliver Tappe if (c2 >= 0xa1 && c2 < 0xff) {
39*aef5731fSOliver Tappe unsigned char buf[2];
40*aef5731fSOliver Tappe buf[0] = c-0x80; buf[1] = c2-0x80;
41*aef5731fSOliver Tappe return gb2312_mbtowc(conv,pwc,buf,2);
42*aef5731fSOliver Tappe } else
43*aef5731fSOliver Tappe return RET_ILSEQ;
44*aef5731fSOliver Tappe }
45*aef5731fSOliver Tappe }
46*aef5731fSOliver Tappe return RET_ILSEQ;
47*aef5731fSOliver Tappe }
48*aef5731fSOliver Tappe
49*aef5731fSOliver Tappe static int
euc_cn_wctomb(conv_t conv,unsigned char * r,ucs4_t wc,int n)50*aef5731fSOliver Tappe euc_cn_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
51*aef5731fSOliver Tappe {
52*aef5731fSOliver Tappe unsigned char buf[2];
53*aef5731fSOliver Tappe int ret;
54*aef5731fSOliver Tappe
55*aef5731fSOliver Tappe /* Code set 0 (ASCII or GB 1988-89) */
56*aef5731fSOliver Tappe ret = ascii_wctomb(conv,r,wc,n);
57*aef5731fSOliver Tappe if (ret != RET_ILUNI)
58*aef5731fSOliver Tappe return ret;
59*aef5731fSOliver Tappe
60*aef5731fSOliver Tappe /* Code set 1 (GB 2312-1980) */
61*aef5731fSOliver Tappe ret = gb2312_wctomb(conv,buf,wc,2);
62*aef5731fSOliver Tappe if (ret != RET_ILUNI) {
63*aef5731fSOliver Tappe if (ret != 2) abort();
64*aef5731fSOliver Tappe if (n < 2)
65*aef5731fSOliver Tappe return RET_TOOSMALL;
66*aef5731fSOliver Tappe r[0] = buf[0]+0x80;
67*aef5731fSOliver Tappe r[1] = buf[1]+0x80;
68*aef5731fSOliver Tappe return 2;
69*aef5731fSOliver Tappe }
70*aef5731fSOliver Tappe
71*aef5731fSOliver Tappe return RET_ILUNI;
72*aef5731fSOliver Tappe }
73