6
/* Specification: RFC 1468 */
11
* The state can be one of the following values.
14
#define STATE_JISX0201ROMAN 1
15
#define STATE_JISX0208 2
18
iso2022_jp_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
20
state_t state = conv->istate;
37
state = STATE_JISX0201ROMAN;
46
if (s[2] == '@' || s[2] == 'B') {
47
/* We don't distinguish JIS X 0208-1978 and JIS X 0208-1983. */
48
state = STATE_JISX0208;
63
int ret = ascii_mbtowc(conv,pwc,s,1);
66
if (ret != 1) abort();
71
case STATE_JISX0201ROMAN:
73
int ret = jisx0201_mbtowc(conv,pwc,s,1);
76
if (ret != 1) abort();
84
if (s[0] < 0x80 && s[1] < 0x80) {
85
int ret = jisx0208_mbtowc(conv,pwc,s,2);
88
if (ret != 2) abort();
98
return RET_TOOFEW(count);
102
iso2022_jp_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
104
state_t state = conv->ostate;
105
unsigned char buf[2];
109
ret = ascii_wctomb(conv,buf,wc,1);
110
if (ret != RET_ILSEQ) {
111
if (ret != 1) abort();
113
int count = (state == STATE_ASCII ? 1 : 4);
116
if (state != STATE_ASCII) {
124
conv->ostate = state;
129
/* Try JIS X 0201-1976 Roman. */
130
ret = jisx0201_wctomb(conv,buf,wc,1);
131
if (ret != RET_ILSEQ) {
132
if (ret != 1) abort();
134
int count = (state == STATE_JISX0201ROMAN ? 1 : 4);
137
if (state != STATE_JISX0201ROMAN) {
142
state = STATE_JISX0201ROMAN;
145
conv->ostate = state;
150
/* Try JIS X 0208-1990 in place of JIS X 0208-1978 and JIS X 0208-1983. */
151
ret = jisx0208_wctomb(conv,buf,wc,2);
152
if (ret != RET_ILSEQ) {
153
if (ret != 2) abort();
154
if (buf[0] < 0x80 && buf[1] < 0x80) {
155
int count = (state == STATE_JISX0208 ? 2 : 5);
158
if (state != STATE_JISX0208) {
163
state = STATE_JISX0208;
167
conv->ostate = state;
176
iso2022_jp_reset (conv_t conv, unsigned char *r, int n)
178
state_t state = conv->ostate;
179
if (state != STATE_ASCII) {
185
/* conv->ostate = 0; will be done by the caller */
191
#undef STATE_JISX0208
192
#undef STATE_JISX0201ROMAN