* libc/stdlib/mbctype.h (_iseucjp1): Like _iseucjp, but also
recognizes 0x8e and 0x8f lead bytes. (_iseucjp2): Rename from _iseucjp. * libc/stdlib/mbtowc_r.c (__eucjp_mbtowc): Convert JIS-X-0212 triplebyte sequences as well. * libc/stdlib/wctomb_r.c (__eucjp_wctomb): Convert to JIS-X-0212 triplebyte sequences as well.
This commit is contained in:
		| @@ -14,7 +14,8 @@ int _EXFUN(_isjis, (int c)); | ||||
|  | ||||
| #define _issjis1(c)    (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xef)) | ||||
| #define _issjis2(c)    (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc)) | ||||
| #define _iseucjp(c)    ((c) >= 0xa1 && (c) <= 0xfe) | ||||
| #define _iseucjp1(c)   ((c) == 0x8e || (c) == 0x8f || ((c) >= 0xa1 && (c) <= 0xfe)) | ||||
| #define _iseucjp2(c)   ((c) >= 0xa1 && (c) <= 0xfe) | ||||
| #define _isjis(c)      ((c) >= 0x21 && (c) <= 0x7e) | ||||
|  | ||||
| #endif /* _MBCTYPE_H_ */ | ||||
|   | ||||
| @@ -470,7 +470,7 @@ _DEFUN (__eucjp_mbtowc, (r, pwc, s, n, charset, state), | ||||
|   ch = t[i++]; | ||||
|   if (state->__count == 0) | ||||
|     { | ||||
|       if (_iseucjp (ch)) | ||||
|       if (_iseucjp1 (ch)) | ||||
| 	{ | ||||
| 	  state->__value.__wchb[0] = ch; | ||||
| 	  state->__count = 1; | ||||
| @@ -481,9 +481,35 @@ _DEFUN (__eucjp_mbtowc, (r, pwc, s, n, charset, state), | ||||
|     } | ||||
|   if (state->__count == 1) | ||||
|     { | ||||
|       if (_iseucjp (ch)) | ||||
|       if (_iseucjp2 (ch)) | ||||
| 	{ | ||||
| 	  *pwc = (((wchar_t)state->__value.__wchb[0]) << 8) + (wchar_t)ch; | ||||
| 	  if (state->__value.__wchb[0] == 0x8f) | ||||
| 	    { | ||||
| 	      state->__value.__wchb[1] = ch; | ||||
| 	      state->__count = 2; | ||||
| 	      if (n <= i) | ||||
| 		return -2; | ||||
| 	      ch = t[i++]; | ||||
| 	    } | ||||
| 	  else | ||||
| 	    { | ||||
| 	      *pwc = (((wchar_t)state->__value.__wchb[0]) << 8) + (wchar_t)ch; | ||||
| 	      state->__count = 0; | ||||
| 	      return i; | ||||
| 	    } | ||||
| 	} | ||||
|       else | ||||
| 	{ | ||||
| 	  r->_errno = EILSEQ; | ||||
| 	  return -1; | ||||
| 	} | ||||
|     } | ||||
|   if (state->__count == 2) | ||||
|     { | ||||
|       if (_iseucjp2 (ch)) | ||||
| 	{ | ||||
| 	  *pwc = (((wchar_t)state->__value.__wchb[1]) << 8) | ||||
| 		 + (wchar_t)(ch & 0x7f); | ||||
| 	  state->__count = 0; | ||||
| 	  return i; | ||||
| 	} | ||||
|   | ||||
| @@ -195,12 +195,19 @@ _DEFUN (__eucjp_wctomb, (r, s, wchar, charset, state), | ||||
|   if (char1 != 0x00) | ||||
|     { | ||||
|     /* first byte is non-zero..validate multi-byte char */ | ||||
|       if (_iseucjp (char1) && _iseucjp (char2))  | ||||
|       if (_iseucjp1 (char1) && _iseucjp2 (char2))  | ||||
| 	{ | ||||
| 	  *s++ = (char)char1; | ||||
| 	  *s = (char)char2; | ||||
| 	  return 2; | ||||
| 	} | ||||
|       else if (_iseucjp2 (char1) && _iseucjp2 (char2 | 0x80)) | ||||
| 	{ | ||||
| 	  *s++ = (char)0x8f; | ||||
| 	  *s++ = (char)char1; | ||||
| 	  *s = (char)(char2 | 0x80); | ||||
| 	  return 3; | ||||
| 	} | ||||
|       else | ||||
| 	{ | ||||
| 	  r->_errno = EILSEQ; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user