1*1beef8feStshiozak /* $NetBSD: citrus_stdenc.h,v 1.4 2005/10/29 18:02:04 tshiozak Exp $ */
204e58308Stshiozak
304e58308Stshiozak /*-
404e58308Stshiozak * Copyright (c)2003 Citrus Project,
504e58308Stshiozak * All rights reserved.
604e58308Stshiozak *
704e58308Stshiozak * Redistribution and use in source and binary forms, with or without
804e58308Stshiozak * modification, are permitted provided that the following conditions
904e58308Stshiozak * are met:
1004e58308Stshiozak * 1. Redistributions of source code must retain the above copyright
1104e58308Stshiozak * notice, this list of conditions and the following disclaimer.
1204e58308Stshiozak * 2. Redistributions in binary form must reproduce the above copyright
1304e58308Stshiozak * notice, this list of conditions and the following disclaimer in the
1404e58308Stshiozak * documentation and/or other materials provided with the distribution.
1504e58308Stshiozak *
1604e58308Stshiozak * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1704e58308Stshiozak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1804e58308Stshiozak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1904e58308Stshiozak * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2004e58308Stshiozak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2104e58308Stshiozak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2204e58308Stshiozak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2304e58308Stshiozak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2404e58308Stshiozak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2504e58308Stshiozak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2604e58308Stshiozak * SUCH DAMAGE.
2704e58308Stshiozak *
2804e58308Stshiozak */
2904e58308Stshiozak
3004e58308Stshiozak #ifndef _CITRUS_STDENC_H_
3104e58308Stshiozak #define _CITRUS_STDENC_H_
3204e58308Stshiozak
3304e58308Stshiozak struct _citrus_stdenc;
3404e58308Stshiozak struct _citrus_stdenc_ops;
3504e58308Stshiozak struct _citrus_stdenc_traits;
3604e58308Stshiozak
37*1beef8feStshiozak #define _CITRUS_STDENC_SDID_GENERIC 0
38*1beef8feStshiozak struct _citrus_stdenc_state_desc
39*1beef8feStshiozak {
40*1beef8feStshiozak union {
41*1beef8feStshiozak struct {
42*1beef8feStshiozak int state;
43*1beef8feStshiozak #define _CITRUS_STDENC_SDGEN_UNKNOWN 0
44*1beef8feStshiozak #define _CITRUS_STDENC_SDGEN_INITIAL 1
45*1beef8feStshiozak #define _CITRUS_STDENC_SDGEN_STABLE 2
46*1beef8feStshiozak #define _CITRUS_STDENC_SDGEN_INCOMPLETE_CHAR 3
47*1beef8feStshiozak #define _CITRUS_STDENC_SDGEN_INCOMPLETE_SHIFT 4
48*1beef8feStshiozak } generic;
49*1beef8feStshiozak } u;
50*1beef8feStshiozak };
51*1beef8feStshiozak
5204e58308Stshiozak #include "citrus_stdenc_local.h"
5304e58308Stshiozak
5404e58308Stshiozak __BEGIN_DECLS
5504e58308Stshiozak int _citrus_stdenc_open(struct _citrus_stdenc * __restrict * __restrict,
5604e58308Stshiozak char const * __restrict,
5704e58308Stshiozak const void * __restrict, size_t);
5804e58308Stshiozak void _citrus_stdenc_close(struct _citrus_stdenc *);
5904e58308Stshiozak __END_DECLS
6004e58308Stshiozak
6104e58308Stshiozak static __inline int
_citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,void * __restrict ps)6204e58308Stshiozak _citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,
6304e58308Stshiozak void * __restrict ps)
6404e58308Stshiozak {
658adfd9b7Stshiozak _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_init_state);
6604e58308Stshiozak return (*ce->ce_ops->eo_init_state)(ce, ps);
6704e58308Stshiozak }
6804e58308Stshiozak
6904e58308Stshiozak static __inline int
_citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,_citrus_csid_t * __restrict csid,_citrus_index_t * __restrict idx,const char ** __restrict s,size_t n,void * __restrict ps,size_t * __restrict nresult)7004e58308Stshiozak _citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,
7104e58308Stshiozak _citrus_csid_t * __restrict csid,
7204e58308Stshiozak _citrus_index_t * __restrict idx,
7304e58308Stshiozak const char ** __restrict s, size_t n,
7404e58308Stshiozak void * __restrict ps, size_t * __restrict nresult)
7504e58308Stshiozak {
7604e58308Stshiozak _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
7704e58308Stshiozak return (*ce->ce_ops->eo_mbtocs)(ce, csid, idx, s, n, ps, nresult);
7804e58308Stshiozak }
7904e58308Stshiozak
8004e58308Stshiozak static __inline int
_citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce,char * __restrict s,size_t n,_citrus_csid_t csid,_citrus_index_t idx,void * __restrict ps,size_t * __restrict nresult)8104e58308Stshiozak _citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce,
8204e58308Stshiozak char * __restrict s, size_t n,
8304e58308Stshiozak _citrus_csid_t csid, _citrus_index_t idx,
8404e58308Stshiozak void * __restrict ps, size_t * __restrict nresult)
8504e58308Stshiozak {
8604e58308Stshiozak _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
8704e58308Stshiozak return (*ce->ce_ops->eo_cstomb)(ce, s, n, csid, idx, ps, nresult);
8804e58308Stshiozak }
8904e58308Stshiozak
9004e58308Stshiozak static __inline int
_citrus_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce,_citrus_wc_t * __restrict wc,const char ** __restrict s,size_t n,void * __restrict ps,size_t * __restrict nresult)9104e58308Stshiozak _citrus_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce,
9204e58308Stshiozak _citrus_wc_t * __restrict wc,
9304e58308Stshiozak const char ** __restrict s, size_t n,
9404e58308Stshiozak void * __restrict ps, size_t * __restrict nresult)
9504e58308Stshiozak {
9604e58308Stshiozak _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
9704e58308Stshiozak return (*ce->ce_ops->eo_mbtowc)(ce, wc, s, n, ps, nresult);
9804e58308Stshiozak }
9904e58308Stshiozak
10004e58308Stshiozak static __inline int
_citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce,char * __restrict s,size_t n,_citrus_wc_t wc,void * __restrict ps,size_t * __restrict nresult)10104e58308Stshiozak _citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce,
10204e58308Stshiozak char * __restrict s, size_t n, _citrus_wc_t wc,
10304e58308Stshiozak void * __restrict ps, size_t * __restrict nresult)
10404e58308Stshiozak {
10504e58308Stshiozak _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
10604e58308Stshiozak return (*ce->ce_ops->eo_wctomb)(ce, s, n, wc, ps, nresult);
10704e58308Stshiozak }
10804e58308Stshiozak
109f3995f1aStshiozak static __inline int
_citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce,char * __restrict s,size_t n,void * __restrict ps,size_t * __restrict nresult)110f3995f1aStshiozak _citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce,
111f3995f1aStshiozak char * __restrict s, size_t n,
112f3995f1aStshiozak void * __restrict ps,
113f3995f1aStshiozak size_t * __restrict nresult)
114f3995f1aStshiozak {
115f3995f1aStshiozak _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_put_state_reset);
116f3995f1aStshiozak return (*ce->ce_ops->eo_put_state_reset)(ce, s, n, ps, nresult);
117f3995f1aStshiozak }
118f3995f1aStshiozak
11904e58308Stshiozak static __inline size_t
_citrus_stdenc_get_state_size(struct _citrus_stdenc * ce)12004e58308Stshiozak _citrus_stdenc_get_state_size(struct _citrus_stdenc *ce)
12104e58308Stshiozak {
12204e58308Stshiozak _DIAGASSERT(ce && ce->ce_traits);
12304e58308Stshiozak return ce->ce_traits->et_state_size;
12404e58308Stshiozak }
12504e58308Stshiozak
12604e58308Stshiozak static __inline size_t
_citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc * ce)12704e58308Stshiozak _citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc *ce)
12804e58308Stshiozak {
12904e58308Stshiozak _DIAGASSERT(ce && ce->ce_traits);
13004e58308Stshiozak return ce->ce_traits->et_mb_cur_max;
13104e58308Stshiozak }
13204e58308Stshiozak
133*1beef8feStshiozak static __inline int
_citrus_stdenc_get_state_desc(struct _citrus_stdenc * __restrict ce,void * __restrict ps,int id,struct _citrus_stdenc_state_desc * __restrict d)134*1beef8feStshiozak _citrus_stdenc_get_state_desc(struct _citrus_stdenc * __restrict ce,
135*1beef8feStshiozak void * __restrict ps,
136*1beef8feStshiozak int id,
137*1beef8feStshiozak struct _citrus_stdenc_state_desc * __restrict d)
138*1beef8feStshiozak {
139*1beef8feStshiozak
140*1beef8feStshiozak _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_get_state_desc);
141*1beef8feStshiozak
142*1beef8feStshiozak return (*ce->ce_ops->eo_get_state_desc)(ce, ps, id, d);
143*1beef8feStshiozak }
144*1beef8feStshiozak
14504e58308Stshiozak #endif
146