1 /* $NetBSD: citrus_stdenc_local.h,v 1.4 2008/02/09 14:56:20 junyoung Exp $ */ 2 3 /*- 4 * SPDX-License-Identifier: BSD-2-Clause 5 * 6 * Copyright (c)2003 Citrus Project, 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 */ 31 32 #ifndef _CITRUS_STDENC_LOCAL_H_ 33 #define _CITRUS_STDENC_LOCAL_H_ 34 35 #include <iconv.h> 36 37 #include "citrus_module.h" 38 39 #define _CITRUS_STDENC_GETOPS_FUNC_BASE(n) \ 40 int n(struct _citrus_stdenc_ops *, size_t) 41 #define _CITRUS_STDENC_GETOPS_FUNC(_e_) \ 42 _CITRUS_STDENC_GETOPS_FUNC_BASE(_citrus_##_e_##_stdenc_getops) 43 typedef _CITRUS_STDENC_GETOPS_FUNC_BASE((*_citrus_stdenc_getops_t)); 44 45 46 #define _CITRUS_STDENC_DECLS(_e_) \ 47 static int _citrus_##_e_##_stdenc_init \ 48 (struct _citrus_stdenc * __restrict, \ 49 const void * __restrict, size_t, \ 50 struct _citrus_stdenc_traits * __restrict); \ 51 static void _citrus_##_e_##_stdenc_uninit(struct _citrus_stdenc *);\ 52 static int _citrus_##_e_##_stdenc_init_state \ 53 (struct _citrus_stdenc * __restrict, \ 54 void * __restrict); \ 55 static int _citrus_##_e_##_stdenc_mbtocs \ 56 (struct _citrus_stdenc * __restrict, \ 57 _citrus_csid_t * __restrict, \ 58 _citrus_index_t * __restrict, \ 59 char ** __restrict, size_t, \ 60 void * __restrict, size_t * __restrict, \ 61 struct iconv_hooks *); \ 62 static int _citrus_##_e_##_stdenc_cstomb \ 63 (struct _citrus_stdenc * __restrict, \ 64 char * __restrict, size_t, _citrus_csid_t, \ 65 _citrus_index_t, void * __restrict, \ 66 size_t * __restrict, struct iconv_hooks *); \ 67 static int _citrus_##_e_##_stdenc_mbtowc \ 68 (struct _citrus_stdenc * __restrict, \ 69 _citrus_wc_t * __restrict, \ 70 char ** __restrict, size_t, \ 71 void * __restrict, size_t * __restrict, \ 72 struct iconv_hooks *); \ 73 static int _citrus_##_e_##_stdenc_wctomb \ 74 (struct _citrus_stdenc * __restrict, \ 75 char * __restrict, size_t, _citrus_wc_t, \ 76 void * __restrict, size_t * __restrict, \ 77 struct iconv_hooks *); \ 78 static int _citrus_##_e_##_stdenc_put_state_reset \ 79 (struct _citrus_stdenc * __restrict, \ 80 char * __restrict, size_t, void * __restrict, \ 81 size_t * __restrict); \ 82 static int _citrus_##_e_##_stdenc_get_state_desc \ 83 (struct _citrus_stdenc * __restrict, \ 84 void * __restrict, int, \ 85 struct _citrus_stdenc_state_desc * __restrict) 86 87 #define _CITRUS_STDENC_DEF_OPS(_e_) \ 88 extern struct _citrus_stdenc_ops _citrus_##_e_##_stdenc_ops; \ 89 struct _citrus_stdenc_ops _citrus_##_e_##_stdenc_ops = { \ 90 /* eo_init */ &_citrus_##_e_##_stdenc_init, \ 91 /* eo_uninit */ &_citrus_##_e_##_stdenc_uninit, \ 92 /* eo_init_state */ &_citrus_##_e_##_stdenc_init_state, \ 93 /* eo_mbtocs */ &_citrus_##_e_##_stdenc_mbtocs, \ 94 /* eo_cstomb */ &_citrus_##_e_##_stdenc_cstomb, \ 95 /* eo_mbtowc */ &_citrus_##_e_##_stdenc_mbtowc, \ 96 /* eo_wctomb */ &_citrus_##_e_##_stdenc_wctomb, \ 97 /* eo_put_state_reset */&_citrus_##_e_##_stdenc_put_state_reset,\ 98 /* eo_get_state_desc */ &_citrus_##_e_##_stdenc_get_state_desc \ 99 } 100 101 typedef int (*_citrus_stdenc_init_t) 102 (struct _citrus_stdenc * __reatrict, const void * __restrict , size_t, 103 struct _citrus_stdenc_traits * __restrict); 104 typedef void (*_citrus_stdenc_uninit_t)(struct _citrus_stdenc * __restrict); 105 typedef int (*_citrus_stdenc_init_state_t) 106 (struct _citrus_stdenc * __restrict, void * __restrict); 107 typedef int (*_citrus_stdenc_mbtocs_t) 108 (struct _citrus_stdenc * __restrict, 109 _citrus_csid_t * __restrict, _citrus_index_t * __restrict, 110 char ** __restrict, size_t, 111 void * __restrict, size_t * __restrict, 112 struct iconv_hooks *); 113 typedef int (*_citrus_stdenc_cstomb_t) 114 (struct _citrus_stdenc *__restrict, char * __restrict, size_t, 115 _citrus_csid_t, _citrus_index_t, void * __restrict, 116 size_t * __restrict, struct iconv_hooks *); 117 typedef int (*_citrus_stdenc_mbtowc_t) 118 (struct _citrus_stdenc * __restrict, 119 _citrus_wc_t * __restrict, 120 char ** __restrict, size_t, 121 void * __restrict, size_t * __restrict, 122 struct iconv_hooks *); 123 typedef int (*_citrus_stdenc_wctomb_t) 124 (struct _citrus_stdenc *__restrict, char * __restrict, size_t, 125 _citrus_wc_t, void * __restrict, size_t * __restrict, 126 struct iconv_hooks *); 127 typedef int (*_citrus_stdenc_put_state_reset_t) 128 (struct _citrus_stdenc *__restrict, char * __restrict, size_t, 129 void * __restrict, size_t * __restrict); 130 typedef int (*_citrus_stdenc_get_state_desc_t) 131 (struct _citrus_stdenc * __restrict, void * __restrict, int, 132 struct _citrus_stdenc_state_desc * __restrict); 133 134 struct _citrus_stdenc_ops { 135 _citrus_stdenc_init_t eo_init; 136 _citrus_stdenc_uninit_t eo_uninit; 137 _citrus_stdenc_init_state_t eo_init_state; 138 _citrus_stdenc_mbtocs_t eo_mbtocs; 139 _citrus_stdenc_cstomb_t eo_cstomb; 140 _citrus_stdenc_mbtowc_t eo_mbtowc; 141 _citrus_stdenc_wctomb_t eo_wctomb; 142 _citrus_stdenc_put_state_reset_t eo_put_state_reset; 143 /* version 0x00000002 */ 144 _citrus_stdenc_get_state_desc_t eo_get_state_desc; 145 }; 146 147 struct _citrus_stdenc_traits { 148 /* version 0x00000001 */ 149 size_t et_state_size; 150 size_t et_mb_cur_max; 151 /* version 0x00000005 */ 152 size_t et_mb_cur_min; 153 }; 154 155 struct _citrus_stdenc { 156 /* version 0x00000001 */ 157 struct _citrus_stdenc_ops *ce_ops; 158 void *ce_closure; 159 _citrus_module_t ce_module; 160 struct _citrus_stdenc_traits *ce_traits; 161 }; 162 163 #define _CITRUS_DEFAULT_STDENC_NAME "NONE" 164 165 #endif 166