Home | History | Annotate | Line # | Download | only in modules
citrus_euctw.c revision 1.12.22.1
      1  1.12.22.1  perseant /*	$NetBSD: citrus_euctw.c,v 1.12.22.1 2017/07/14 15:53:07 perseant Exp $	*/
      2        1.1  tshiozak 
      3        1.1  tshiozak /*-
      4        1.1  tshiozak  * Copyright (c)2002 Citrus Project,
      5        1.1  tshiozak  * All rights reserved.
      6        1.1  tshiozak  *
      7        1.1  tshiozak  * Redistribution and use in source and binary forms, with or without
      8        1.1  tshiozak  * modification, are permitted provided that the following conditions
      9        1.1  tshiozak  * are met:
     10        1.1  tshiozak  * 1. Redistributions of source code must retain the above copyright
     11        1.1  tshiozak  *    notice, this list of conditions and the following disclaimer.
     12        1.1  tshiozak  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1  tshiozak  *    notice, this list of conditions and the following disclaimer in the
     14        1.1  tshiozak  *    documentation and/or other materials provided with the distribution.
     15        1.1  tshiozak  *
     16        1.1  tshiozak  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17        1.1  tshiozak  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18        1.1  tshiozak  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19        1.1  tshiozak  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20        1.1  tshiozak  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21        1.1  tshiozak  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22        1.1  tshiozak  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23        1.1  tshiozak  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24        1.1  tshiozak  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25        1.1  tshiozak  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26        1.1  tshiozak  * SUCH DAMAGE.
     27        1.1  tshiozak  */
     28        1.1  tshiozak 
     29        1.1  tshiozak /*-
     30        1.1  tshiozak  * Copyright (c)1999 Citrus Project,
     31        1.1  tshiozak  * All rights reserved.
     32        1.1  tshiozak  *
     33        1.1  tshiozak  * Redistribution and use in source and binary forms, with or without
     34        1.1  tshiozak  * modification, are permitted provided that the following conditions
     35        1.1  tshiozak  * are met:
     36        1.1  tshiozak  * 1. Redistributions of source code must retain the above copyright
     37        1.1  tshiozak  *    notice, this list of conditions and the following disclaimer.
     38        1.1  tshiozak  * 2. Redistributions in binary form must reproduce the above copyright
     39        1.1  tshiozak  *    notice, this list of conditions and the following disclaimer in the
     40        1.1  tshiozak  *    documentation and/or other materials provided with the distribution.
     41        1.1  tshiozak  *
     42        1.1  tshiozak  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     43        1.1  tshiozak  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     44        1.1  tshiozak  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     45        1.1  tshiozak  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     46        1.1  tshiozak  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     47        1.1  tshiozak  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     48        1.1  tshiozak  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     49        1.1  tshiozak  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     50        1.1  tshiozak  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     51        1.1  tshiozak  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     52        1.1  tshiozak  * SUCH DAMAGE.
     53        1.1  tshiozak  *
     54        1.1  tshiozak  *	$Citrus: xpg4dl/FreeBSD/lib/libc/locale/euctw.c,v 1.13 2001/06/21 01:51:44 yamt Exp $
     55        1.1  tshiozak  */
     56        1.1  tshiozak 
     57        1.1  tshiozak #include <sys/cdefs.h>
     58        1.1  tshiozak #if defined(LIBC_SCCS) && !defined(lint)
     59  1.12.22.1  perseant __RCSID("$NetBSD: citrus_euctw.c,v 1.12.22.1 2017/07/14 15:53:07 perseant Exp $");
     60        1.1  tshiozak #endif /* LIBC_SCCS and not lint */
     61        1.1  tshiozak 
     62        1.1  tshiozak #include <assert.h>
     63        1.1  tshiozak #include <errno.h>
     64        1.1  tshiozak #include <string.h>
     65        1.1  tshiozak #include <stdio.h>
     66        1.1  tshiozak #include <stdlib.h>
     67        1.1  tshiozak #include <stddef.h>
     68        1.1  tshiozak #include <wchar.h>
     69        1.1  tshiozak #include <sys/types.h>
     70        1.1  tshiozak #include <limits.h>
     71        1.6  tshiozak 
     72        1.6  tshiozak #include "citrus_namespace.h"
     73        1.6  tshiozak #include "citrus_types.h"
     74        1.1  tshiozak #include "citrus_module.h"
     75        1.1  tshiozak #include "citrus_ctype.h"
     76        1.6  tshiozak #include "citrus_stdenc.h"
     77        1.1  tshiozak #include "citrus_euctw.h"
     78        1.1  tshiozak 
     79        1.1  tshiozak 
     80        1.1  tshiozak /* ----------------------------------------------------------------------
     81        1.1  tshiozak  * private stuffs used by templates
     82        1.1  tshiozak  */
     83        1.1  tshiozak 
     84        1.1  tshiozak typedef struct {
     85        1.1  tshiozak 	char ch[4];
     86        1.1  tshiozak 	int chlen;
     87        1.1  tshiozak } _EUCTWState;
     88        1.1  tshiozak 
     89        1.1  tshiozak typedef struct {
     90        1.1  tshiozak 	int dummy;
     91        1.1  tshiozak } _EUCTWEncodingInfo;
     92        1.1  tshiozak typedef struct {
     93        1.1  tshiozak 	_EUCTWEncodingInfo	ei;
     94        1.1  tshiozak 	struct {
     95        1.1  tshiozak 		/* for future multi-locale facility */
     96        1.1  tshiozak 		_EUCTWState	s_mblen;
     97        1.1  tshiozak 		_EUCTWState	s_mbrlen;
     98        1.1  tshiozak 		_EUCTWState	s_mbrtowc;
     99        1.1  tshiozak 		_EUCTWState	s_mbtowc;
    100        1.1  tshiozak 		_EUCTWState	s_mbsrtowcs;
    101       1.12     joerg 		_EUCTWState	s_mbsnrtowcs;
    102        1.1  tshiozak 		_EUCTWState	s_wcrtomb;
    103        1.1  tshiozak 		_EUCTWState	s_wcsrtombs;
    104       1.12     joerg 		_EUCTWState	s_wcsnrtombs;
    105        1.1  tshiozak 		_EUCTWState	s_wctomb;
    106        1.1  tshiozak 	} states;
    107        1.1  tshiozak } _EUCTWCTypeInfo;
    108        1.1  tshiozak 
    109        1.1  tshiozak #define	_SS2	0x008e
    110        1.1  tshiozak #define	_SS3	0x008f
    111        1.1  tshiozak 
    112        1.1  tshiozak #define _CEI_TO_EI(_cei_)		(&(_cei_)->ei)
    113        1.1  tshiozak #define _CEI_TO_STATE(_cei_, _func_)	(_cei_)->states.s_##_func_
    114        1.1  tshiozak 
    115        1.1  tshiozak #define _FUNCNAME(m)			_citrus_EUCTW_##m
    116        1.1  tshiozak #define _ENCODING_INFO			_EUCTWEncodingInfo
    117        1.1  tshiozak #define _CTYPE_INFO			_EUCTWCTypeInfo
    118        1.1  tshiozak #define _ENCODING_STATE			_EUCTWState
    119        1.2      yamt #define _ENCODING_MB_CUR_MAX(_ei_)	4
    120        1.1  tshiozak #define _ENCODING_IS_STATE_DEPENDENT	0
    121        1.4      yamt #define _STATE_NEEDS_EXPLICIT_INIT(_ps_)	0
    122        1.1  tshiozak 
    123        1.1  tshiozak static __inline int
    124        1.1  tshiozak _citrus_EUCTW_cs(u_int c)
    125        1.1  tshiozak {
    126        1.1  tshiozak 	c &= 0xff;
    127        1.1  tshiozak 
    128        1.1  tshiozak 	return ((c & 0x80) ? (c == _SS2 ? 2 : 1) : 0);
    129        1.1  tshiozak }
    130        1.1  tshiozak 
    131        1.1  tshiozak static __inline int
    132        1.1  tshiozak _citrus_EUCTW_count(int cs)
    133        1.1  tshiozak {
    134        1.1  tshiozak 	switch (cs) {
    135        1.1  tshiozak 	case 0:
    136        1.1  tshiozak 		return 1;
    137        1.1  tshiozak 	case 1:
    138        1.1  tshiozak 		return 2;
    139        1.1  tshiozak 	case 2:
    140        1.1  tshiozak 		return 4;
    141        1.1  tshiozak 	case 3:
    142        1.1  tshiozak 		abort();
    143        1.1  tshiozak 		/*NOTREACHED*/
    144        1.1  tshiozak 	}
    145        1.1  tshiozak 	return 0;
    146        1.1  tshiozak }
    147        1.1  tshiozak 
    148        1.1  tshiozak static __inline void
    149        1.1  tshiozak /*ARGSUSED*/
    150        1.1  tshiozak _citrus_EUCTW_init_state(_EUCTWEncodingInfo * __restrict ei,
    151        1.1  tshiozak 			 _EUCTWState * __restrict s)
    152        1.1  tshiozak {
    153        1.1  tshiozak 	memset(s, 0, sizeof(*s));
    154        1.1  tshiozak }
    155        1.1  tshiozak 
    156        1.1  tshiozak static __inline void
    157        1.1  tshiozak /*ARGSUSED*/
    158        1.1  tshiozak _citrus_EUCTW_pack_state(_EUCTWEncodingInfo * __restrict ei,
    159        1.1  tshiozak 			 void * __restrict pspriv,
    160        1.1  tshiozak 			 const _EUCTWState * __restrict s)
    161        1.1  tshiozak {
    162        1.1  tshiozak 	memcpy(pspriv, (const void *)s, sizeof(*s));
    163        1.1  tshiozak }
    164        1.1  tshiozak 
    165        1.1  tshiozak static __inline void
    166        1.1  tshiozak /*ARGSUSED*/
    167        1.1  tshiozak _citrus_EUCTW_unpack_state(_EUCTWEncodingInfo * __restrict ei,
    168        1.1  tshiozak 			   _EUCTWState * __restrict s,
    169        1.1  tshiozak 			   const void * __restrict pspriv)
    170        1.1  tshiozak {
    171        1.1  tshiozak 	memcpy((void *)s, pspriv, sizeof(*s));
    172        1.1  tshiozak }
    173        1.1  tshiozak 
    174        1.1  tshiozak static int
    175        1.1  tshiozak /*ARGSUSED*/
    176        1.6  tshiozak _citrus_EUCTW_encoding_module_init(_EUCTWEncodingInfo * __restrict ei,
    177        1.6  tshiozak 				   const void * __restrict var, size_t lenvar)
    178        1.1  tshiozak {
    179        1.1  tshiozak 
    180        1.1  tshiozak 	_DIAGASSERT(ei != NULL);
    181        1.1  tshiozak 
    182        1.1  tshiozak 	memset((void *)ei, 0, sizeof(*ei));
    183        1.1  tshiozak 
    184        1.1  tshiozak 	return 0;
    185        1.1  tshiozak }
    186        1.1  tshiozak 
    187        1.1  tshiozak static void
    188        1.1  tshiozak /*ARGSUSED*/
    189        1.6  tshiozak _citrus_EUCTW_encoding_module_uninit(_EUCTWEncodingInfo *ei)
    190        1.1  tshiozak {
    191        1.1  tshiozak }
    192        1.1  tshiozak 
    193        1.1  tshiozak static int
    194        1.1  tshiozak _citrus_EUCTW_mbrtowc_priv(_EUCTWEncodingInfo * __restrict ei,
    195        1.1  tshiozak 			   wchar_t * __restrict pwc,
    196        1.1  tshiozak 			   const char ** __restrict s,
    197        1.1  tshiozak 			   size_t n, _EUCTWState * __restrict psenc,
    198        1.1  tshiozak 			   size_t * __restrict nresult)
    199        1.1  tshiozak {
    200        1.1  tshiozak 	wchar_t wchar;
    201        1.1  tshiozak 	int c, cs;
    202        1.1  tshiozak 	int chlenbak;
    203        1.1  tshiozak 	const char *s0;
    204        1.1  tshiozak 
    205        1.1  tshiozak 	_DIAGASSERT(nresult != 0);
    206        1.1  tshiozak 	_DIAGASSERT(ei != NULL);
    207        1.1  tshiozak 	_DIAGASSERT(psenc != NULL);
    208        1.1  tshiozak 	_DIAGASSERT(s != NULL);
    209        1.1  tshiozak 
    210        1.1  tshiozak 	s0 = *s;
    211        1.1  tshiozak 
    212        1.1  tshiozak 	if (s0 == NULL) {
    213        1.1  tshiozak 		_citrus_EUCTW_init_state(ei, psenc);
    214        1.1  tshiozak 		*nresult = 0; /* state independent */
    215        1.1  tshiozak 		return (0);
    216        1.1  tshiozak 	}
    217        1.8      yamt 
    218        1.8      yamt 	chlenbak = psenc->chlen;
    219        1.1  tshiozak 
    220        1.1  tshiozak 	/* make sure we have the first byte in the buffer */
    221        1.1  tshiozak 	switch (psenc->chlen) {
    222        1.1  tshiozak 	case 0:
    223        1.1  tshiozak 		if (n < 1)
    224        1.1  tshiozak 			goto restart;
    225        1.1  tshiozak 		psenc->ch[0] = *s0++;
    226        1.1  tshiozak 		psenc->chlen = 1;
    227        1.1  tshiozak 		n--;
    228        1.1  tshiozak 		break;
    229        1.1  tshiozak 	case 1:
    230        1.1  tshiozak 	case 2:
    231        1.1  tshiozak 		break;
    232        1.1  tshiozak 	default:
    233        1.1  tshiozak 		/* illgeal state */
    234        1.1  tshiozak 		goto ilseq;
    235        1.1  tshiozak 	}
    236        1.1  tshiozak 
    237        1.1  tshiozak 	c = _citrus_EUCTW_count(cs = _citrus_EUCTW_cs(psenc->ch[0] & 0xff));
    238        1.1  tshiozak 	if (c == 0)
    239        1.1  tshiozak 		goto ilseq;
    240        1.1  tshiozak 	while (psenc->chlen < c) {
    241        1.1  tshiozak 		if (n < 1)
    242        1.1  tshiozak 			goto ilseq;
    243        1.1  tshiozak 		psenc->ch[psenc->chlen] = *s0++;
    244        1.1  tshiozak 		psenc->chlen++;
    245        1.1  tshiozak 		n--;
    246        1.1  tshiozak 	}
    247        1.1  tshiozak 
    248        1.1  tshiozak 	wchar = 0;
    249        1.1  tshiozak 	switch (cs) {
    250        1.1  tshiozak 	case 0:
    251        1.1  tshiozak 		if (psenc->ch[0] & 0x80)
    252        1.1  tshiozak 			goto ilseq;
    253        1.1  tshiozak 		wchar = psenc->ch[0] & 0xff;
    254        1.1  tshiozak 		break;
    255        1.1  tshiozak 	case 1:
    256        1.1  tshiozak 		if (!(psenc->ch[0] & 0x80) || !(psenc->ch[1] & 0x80))
    257        1.1  tshiozak 			goto ilseq;
    258        1.1  tshiozak 		wchar = ((psenc->ch[0] & 0xff) << 8) | (psenc->ch[1] & 0xff);
    259        1.1  tshiozak 		wchar |= 'G' << 24;
    260        1.1  tshiozak 		break;
    261        1.1  tshiozak 	case 2:
    262        1.1  tshiozak 		if ((u_char)psenc->ch[1] < 0xa1 || 0xa7 < (u_char)psenc->ch[1])
    263        1.1  tshiozak 			goto ilseq;
    264        1.1  tshiozak 		if (!(psenc->ch[2] & 0x80) || !(psenc->ch[3] & 0x80))
    265        1.1  tshiozak 			goto ilseq;
    266        1.1  tshiozak 		wchar = ((psenc->ch[2] & 0xff) << 8) | (psenc->ch[3] & 0xff);
    267        1.1  tshiozak 		wchar |= ('G' + psenc->ch[1] - 0xa1) << 24;
    268        1.1  tshiozak 		break;
    269        1.1  tshiozak 	default:
    270        1.1  tshiozak 		goto ilseq;
    271        1.1  tshiozak 	}
    272        1.1  tshiozak 
    273        1.1  tshiozak 	*s = s0;
    274        1.1  tshiozak 	psenc->chlen = 0;
    275        1.1  tshiozak 
    276        1.1  tshiozak 	if (pwc)
    277        1.1  tshiozak 		*pwc = wchar;
    278        1.1  tshiozak 
    279        1.1  tshiozak 	if (!wchar)
    280        1.1  tshiozak 		*nresult = 0;
    281        1.1  tshiozak 	else
    282        1.1  tshiozak 		*nresult = c - chlenbak;
    283        1.1  tshiozak 
    284        1.1  tshiozak 	return (0);
    285        1.1  tshiozak 
    286        1.1  tshiozak ilseq:
    287        1.1  tshiozak 	psenc->chlen = 0;
    288        1.1  tshiozak 	*nresult = (size_t)-1;
    289        1.1  tshiozak 	return (EILSEQ);
    290        1.1  tshiozak 
    291        1.1  tshiozak restart:
    292        1.1  tshiozak 	*s = s0;
    293        1.1  tshiozak 	*nresult = (size_t)-1;
    294        1.1  tshiozak 	return (0);
    295        1.1  tshiozak }
    296        1.1  tshiozak 
    297        1.1  tshiozak static int
    298        1.1  tshiozak _citrus_EUCTW_wcrtomb_priv(_EUCTWEncodingInfo * __restrict ei,
    299        1.1  tshiozak 			   char * __restrict s, size_t n, wchar_t wc,
    300        1.1  tshiozak 			   _EUCTWState * __restrict psenc,
    301        1.1  tshiozak 			   size_t * __restrict nresult)
    302        1.1  tshiozak {
    303        1.1  tshiozak 	wchar_t cs = wc & 0x7f000080;
    304        1.1  tshiozak 	wchar_t v;
    305        1.6  tshiozak 	int i, len, clen, ret;
    306        1.1  tshiozak 
    307        1.1  tshiozak 	_DIAGASSERT(ei != NULL);
    308        1.1  tshiozak 	_DIAGASSERT(nresult != 0);
    309        1.1  tshiozak 	_DIAGASSERT(s != NULL);
    310        1.6  tshiozak 
    311        1.1  tshiozak 	clen = 1;
    312        1.1  tshiozak 	if (wc & 0x00007f00)
    313        1.1  tshiozak 		clen = 2;
    314        1.1  tshiozak 	if ((wc & 0x007f0000) && !(wc & 0x00800000))
    315        1.1  tshiozak 		clen = 3;
    316        1.1  tshiozak 
    317        1.1  tshiozak 	if (clen == 1 && cs == 0x00000000) {
    318        1.1  tshiozak 		/* ASCII */
    319        1.1  tshiozak 		len = 1;
    320        1.6  tshiozak 		if (n < len) {
    321        1.6  tshiozak 			ret = E2BIG;
    322        1.6  tshiozak 			goto err;
    323        1.6  tshiozak 		}
    324        1.1  tshiozak 		v = wc & 0x0000007f;
    325        1.1  tshiozak 	} else if (clen == 2 && cs == ('G' << 24)) {
    326        1.1  tshiozak 		/* CNS-11643-1 */
    327        1.1  tshiozak 		len = 2;
    328        1.6  tshiozak 		if (n < len) {
    329        1.6  tshiozak 			ret = E2BIG;
    330        1.6  tshiozak 			goto err;
    331        1.6  tshiozak 		}
    332        1.1  tshiozak 		v = wc & 0x00007f7f;
    333        1.1  tshiozak 		v |= 0x00008080;
    334        1.1  tshiozak 	} else if (clen == 2 && 'H' <= (cs >> 24) && (cs >> 24) <= 'M') {
    335        1.1  tshiozak 		/* CNS-11643-[2-7] */
    336        1.1  tshiozak 		len = 4;
    337        1.6  tshiozak 		if (n < len) {
    338        1.6  tshiozak 			ret = E2BIG;
    339        1.6  tshiozak 			goto err;
    340        1.6  tshiozak 		}
    341        1.1  tshiozak 		*s++ = _SS2;
    342        1.1  tshiozak 		*s++ = (cs >> 24) - 'H' + 0xa2;
    343        1.1  tshiozak 		v = wc & 0x00007f7f;
    344        1.1  tshiozak 		v |= 0x00008080;
    345        1.6  tshiozak 	} else {
    346        1.6  tshiozak 		ret = EILSEQ;
    347        1.6  tshiozak 		goto err;
    348        1.6  tshiozak 	}
    349        1.1  tshiozak 
    350        1.1  tshiozak 	i = clen;
    351        1.1  tshiozak 	while (i-- > 0)
    352        1.1  tshiozak 		*s++ = (v >> (i << 3)) & 0xff;
    353        1.1  tshiozak 
    354        1.1  tshiozak 	*nresult = len;
    355        1.6  tshiozak 	return 0;
    356        1.6  tshiozak 
    357        1.6  tshiozak err:
    358        1.6  tshiozak 	*nresult = (size_t)-1;
    359        1.6  tshiozak 	return ret;
    360        1.6  tshiozak }
    361        1.6  tshiozak 
    362  1.12.22.1  perseant static int
    363        1.6  tshiozak /*ARGSUSED*/
    364  1.12.22.1  perseant _citrus_EUCTW_stdenc_wctocs(struct _citrus_stdenc *ce,
    365        1.6  tshiozak 			    _csid_t * __restrict csid,
    366        1.6  tshiozak 			    _index_t * __restrict idx, wchar_t wc)
    367        1.6  tshiozak {
    368        1.6  tshiozak 
    369        1.6  tshiozak 	_DIAGASSERT(ei != NULL && csid != NULL && idx != NULL);
    370        1.6  tshiozak 
    371        1.6  tshiozak 	*csid = (_csid_t)(wc >> 24) & 0xFF;
    372        1.6  tshiozak 	*idx  = (_index_t)(wc & 0x7F7F);
    373        1.6  tshiozak 
    374        1.1  tshiozak 	return (0);
    375        1.6  tshiozak }
    376        1.6  tshiozak 
    377  1.12.22.1  perseant static int
    378        1.6  tshiozak /*ARGSUSED*/
    379  1.12.22.1  perseant _citrus_EUCTW_stdenc_cstowc(struct _citrus_stdenc *ce,
    380        1.6  tshiozak 			    wchar_t * __restrict wc,
    381        1.6  tshiozak 			    _csid_t csid, _index_t idx)
    382        1.6  tshiozak {
    383        1.6  tshiozak 
    384        1.6  tshiozak 	_DIAGASSERT(ei != NULL && wc != NULL);
    385        1.6  tshiozak 
    386        1.6  tshiozak 	if (csid==0) {
    387        1.6  tshiozak 		if ((idx & ~0x7F) != 0)
    388        1.6  tshiozak 			return (EINVAL);
    389        1.6  tshiozak 		*wc = (wchar_t)idx;
    390        1.6  tshiozak 	} else {
    391        1.9   tnozaki 		if (csid < 'G' || csid > 'M' || (idx & ~0x7F7F) != 0)
    392        1.6  tshiozak 			return (EINVAL);
    393        1.6  tshiozak 		*wc = (wchar_t)idx | ((wchar_t)csid<<24);
    394        1.6  tshiozak 	}
    395        1.1  tshiozak 
    396        1.6  tshiozak 	return (0);
    397        1.1  tshiozak }
    398        1.1  tshiozak 
    399       1.10  tshiozak static __inline int
    400       1.10  tshiozak /*ARGSUSED*/
    401       1.10  tshiozak _citrus_EUCTW_stdenc_get_state_desc_generic(_EUCTWEncodingInfo * __restrict ei,
    402       1.10  tshiozak 					    _EUCTWState * __restrict psenc,
    403       1.10  tshiozak 					    int * __restrict rstate)
    404       1.10  tshiozak {
    405       1.10  tshiozak 
    406       1.10  tshiozak 	if (psenc->chlen == 0)
    407       1.10  tshiozak 		*rstate = _STDENC_SDGEN_INITIAL;
    408       1.10  tshiozak 	else
    409       1.10  tshiozak 		*rstate = _STDENC_SDGEN_INCOMPLETE_CHAR;
    410       1.10  tshiozak 
    411       1.10  tshiozak 	return 0;
    412       1.10  tshiozak }
    413       1.10  tshiozak 
    414        1.1  tshiozak /* ----------------------------------------------------------------------
    415        1.1  tshiozak  * public interface for ctype
    416        1.1  tshiozak  */
    417        1.1  tshiozak 
    418        1.1  tshiozak _CITRUS_CTYPE_DECLS(EUCTW);
    419        1.1  tshiozak _CITRUS_CTYPE_DEF_OPS(EUCTW);
    420        1.1  tshiozak 
    421        1.1  tshiozak #include "citrus_ctype_template.h"
    422        1.6  tshiozak 
    423        1.6  tshiozak /* ----------------------------------------------------------------------
    424        1.6  tshiozak  * public interface for stdenc
    425        1.6  tshiozak  */
    426        1.6  tshiozak 
    427        1.6  tshiozak _CITRUS_STDENC_DECLS(EUCTW);
    428        1.6  tshiozak _CITRUS_STDENC_DEF_OPS(EUCTW);
    429        1.6  tshiozak 
    430        1.6  tshiozak #include "citrus_stdenc_template.h"
    431