1/* $NetBSD: citrus_stdenc.h,v 1.5 2024/01/20 14:52:45 christos Exp $ */ 2 3/*- 4 * Copyright (c)2003 Citrus Project, 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29 30#ifndef _CITRUS_STDENC_H_ 31#define _CITRUS_STDENC_H_ 32 33struct _citrus_stdenc; 34struct _citrus_stdenc_ops; 35struct _citrus_stdenc_traits; 36 37#define _CITRUS_STDENC_SDID_GENERIC 0 38struct _citrus_stdenc_state_desc 39{ 40 union { 41 struct { 42 int state; 43#define _CITRUS_STDENC_SDGEN_UNKNOWN 0 44#define _CITRUS_STDENC_SDGEN_INITIAL 1 45#define _CITRUS_STDENC_SDGEN_STABLE 2 46#define _CITRUS_STDENC_SDGEN_INCOMPLETE_CHAR 3 47#define _CITRUS_STDENC_SDGEN_INCOMPLETE_SHIFT 4 48 } generic; 49 } u; 50}; 51 52#include "citrus_stdenc_local.h" 53 54__BEGIN_DECLS 55int _citrus_stdenc_open(struct _citrus_stdenc * __restrict * __restrict, 56 char const * __restrict, 57 const void * __restrict, size_t); 58void _citrus_stdenc_close(struct _citrus_stdenc *); 59 60extern struct _citrus_stdenc _citrus_stdenc_default; 61 62__END_DECLS 63 64static __inline int 65_citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce, 66 void * __restrict ps) 67{ 68 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_init_state); 69 return (*ce->ce_ops->eo_init_state)(ce, ps); 70} 71 72static __inline int 73_citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce, 74 _citrus_csid_t * __restrict csid, 75 _citrus_index_t * __restrict idx, 76 const char ** __restrict s, size_t n, 77 void * __restrict ps, size_t * __restrict nresult) 78{ 79 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs); 80 return (*ce->ce_ops->eo_mbtocs)(ce, csid, idx, s, n, ps, nresult); 81} 82 83static __inline int 84_citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce, 85 char * __restrict s, size_t n, 86 _citrus_csid_t csid, _citrus_index_t idx, 87 void * __restrict ps, size_t * __restrict nresult) 88{ 89 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb); 90 return (*ce->ce_ops->eo_cstomb)(ce, s, n, csid, idx, ps, nresult); 91} 92 93static __inline int 94_citrus_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce, 95 _citrus_wc_t * __restrict wc, 96 const char ** __restrict s, size_t n, 97 void * __restrict ps, size_t * __restrict nresult) 98{ 99 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs); 100 return (*ce->ce_ops->eo_mbtowc)(ce, wc, s, n, ps, nresult); 101} 102 103static __inline int 104_citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce, 105 char * __restrict s, size_t n, _citrus_wc_t wc, 106 void * __restrict ps, size_t * __restrict nresult) 107{ 108 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb); 109 return (*ce->ce_ops->eo_wctomb)(ce, s, n, wc, ps, nresult); 110} 111 112static __inline int 113_citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce, 114 char * __restrict s, size_t n, 115 void * __restrict ps, 116 size_t * __restrict nresult) 117{ 118 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_put_state_reset); 119 return (*ce->ce_ops->eo_put_state_reset)(ce, s, n, ps, nresult); 120} 121 122static __inline size_t 123_citrus_stdenc_get_state_size(struct _citrus_stdenc *ce) 124{ 125 _DIAGASSERT(ce && ce->ce_traits); 126 return ce->ce_traits->et_state_size; 127} 128 129static __inline size_t 130_citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc *ce) 131{ 132 _DIAGASSERT(ce && ce->ce_traits); 133 return ce->ce_traits->et_mb_cur_max; 134} 135 136static __inline int 137_citrus_stdenc_get_state_desc(struct _citrus_stdenc * __restrict ce, 138 void * __restrict ps, 139 int id, 140 struct _citrus_stdenc_state_desc * __restrict d) 141{ 142 143 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_get_state_desc); 144 145 return (*ce->ce_ops->eo_get_state_desc)(ce, ps, id, d); 146} 147 148#endif 149