xref: /freebsd/lib/libc/iconv/citrus_mapper_local.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 /* $NetBSD: citrus_mapper_local.h,v 1.2 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 #ifndef _CITRUS_MAPPER_LOCAL_H_
32 #define _CITRUS_MAPPER_LOCAL_H_
33 
34 #define _CITRUS_MAPPER_GETOPS_FUNC_BASE(_n_)				\
35 int _n_(struct _citrus_mapper_ops *)
36 #define _CITRUS_MAPPER_GETOPS_FUNC(_n_)					\
37 _CITRUS_MAPPER_GETOPS_FUNC_BASE(_citrus_##_n_##_mapper_getops)
38 
39 #define _CITRUS_MAPPER_DECLS(_m_)					\
40 static int	 _citrus_##_m_##_mapper_init				\
41 		    (struct _citrus_mapper_area *__restrict,		\
42 		    struct _citrus_mapper * __restrict,			\
43 		    const char * __restrict, const void * __restrict,	\
44 		    size_t, struct _citrus_mapper_traits * __restrict,	\
45 		    size_t);						\
46 static void	 _citrus_##_m_##_mapper_uninit(				\
47 		    struct _citrus_mapper *);				\
48 static int	 _citrus_##_m_##_mapper_convert				\
49 		    (struct _citrus_mapper * __restrict,		\
50 		    _citrus_index_t * __restrict, _citrus_index_t,	\
51 		    void * __restrict);					\
52 static void	 _citrus_##_m_##_mapper_init_state			\
53 		    (void);
54 
55 #define _CITRUS_MAPPER_DEF_OPS(_m_)					\
56 extern struct _citrus_mapper_ops _citrus_##_m_##_mapper_ops;		\
57 struct _citrus_mapper_ops _citrus_##_m_##_mapper_ops = {		\
58 	/* mo_init */		&_citrus_##_m_##_mapper_init,		\
59 	/* mo_uninit */		&_citrus_##_m_##_mapper_uninit,		\
60 	/* mo_convert */	&_citrus_##_m_##_mapper_convert,	\
61 	/* mo_init_state */	&_citrus_##_m_##_mapper_init_state	\
62 }
63 
64 typedef _CITRUS_MAPPER_GETOPS_FUNC_BASE((*_citrus_mapper_getops_t));
65 typedef	int (*_citrus_mapper_init_t)(
66     struct _citrus_mapper_area *__restrict,
67     struct _citrus_mapper *__restrict, const char *__restrict,
68     const void *__restrict, size_t,
69     struct _citrus_mapper_traits * __restrict, size_t);
70 typedef void (*_citrus_mapper_uninit_t)(struct _citrus_mapper *);
71 typedef int (*_citrus_mapper_convert_t)(struct _citrus_mapper * __restrict,
72     _citrus_index_t * __restrict, _citrus_index_t, void * __restrict);
73 typedef void (*_citrus_mapper_init_state_t)(void);
74 
75 struct _citrus_mapper_ops {
76 	_citrus_mapper_init_t			 mo_init;
77 	_citrus_mapper_uninit_t			 mo_uninit;
78 	_citrus_mapper_convert_t		 mo_convert;
79 	_citrus_mapper_init_state_t		 mo_init_state;
80 };
81 
82 struct _citrus_mapper_traits {
83 	/* version 0x00000001 */
84 	size_t					 mt_state_size;
85 	size_t					 mt_src_max;
86 	size_t					 mt_dst_max;
87 };
88 
89 struct _citrus_mapper {
90 	struct _citrus_mapper_ops		*cm_ops;
91 	void					*cm_closure;
92 	_citrus_module_t			 cm_module;
93 	struct _citrus_mapper_traits		*cm_traits;
94 	_CITRUS_HASH_ENTRY(_citrus_mapper)	 cm_entry;
95 	int					 cm_refcount;
96 	char					*cm_key;
97 };
98 #endif
99