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