xref: /freebsd/lib/libc/iconv/citrus_mapper_local.h (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 /* $FreeBSD$ */
2 /* $NetBSD: citrus_mapper_local.h,v 1.2 2008/02/09 14:56:20 junyoung Exp $ */
3 
4 /*-
5  * SPDX-License-Identifier: BSD-2-Clause
6  *
7  * Copyright (c)2003 Citrus Project,
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef _CITRUS_MAPPER_LOCAL_H_
33 #define _CITRUS_MAPPER_LOCAL_H_
34 
35 #define _CITRUS_MAPPER_GETOPS_FUNC_BASE(_n_)				\
36 int _n_(struct _citrus_mapper_ops *)
37 #define _CITRUS_MAPPER_GETOPS_FUNC(_n_)					\
38 _CITRUS_MAPPER_GETOPS_FUNC_BASE(_citrus_##_n_##_mapper_getops)
39 
40 #define _CITRUS_MAPPER_DECLS(_m_)					\
41 static int	 _citrus_##_m_##_mapper_init				\
42 		    (struct _citrus_mapper_area *__restrict,		\
43 		    struct _citrus_mapper * __restrict,			\
44 		    const char * __restrict, const void * __restrict,	\
45 		    size_t, struct _citrus_mapper_traits * __restrict,	\
46 		    size_t);						\
47 static void	 _citrus_##_m_##_mapper_uninit(				\
48 		    struct _citrus_mapper *);				\
49 static int	 _citrus_##_m_##_mapper_convert				\
50 		    (struct _citrus_mapper * __restrict,		\
51 		    _citrus_index_t * __restrict, _citrus_index_t,	\
52 		    void * __restrict);					\
53 static void	 _citrus_##_m_##_mapper_init_state			\
54 		    (void);
55 
56 #define _CITRUS_MAPPER_DEF_OPS(_m_)					\
57 extern struct _citrus_mapper_ops _citrus_##_m_##_mapper_ops;		\
58 struct _citrus_mapper_ops _citrus_##_m_##_mapper_ops = {		\
59 	/* mo_init */		&_citrus_##_m_##_mapper_init,		\
60 	/* mo_uninit */		&_citrus_##_m_##_mapper_uninit,		\
61 	/* mo_convert */	&_citrus_##_m_##_mapper_convert,	\
62 	/* mo_init_state */	&_citrus_##_m_##_mapper_init_state	\
63 }
64 
65 typedef _CITRUS_MAPPER_GETOPS_FUNC_BASE((*_citrus_mapper_getops_t));
66 typedef	int (*_citrus_mapper_init_t)(
67     struct _citrus_mapper_area *__restrict,
68     struct _citrus_mapper *__restrict, const char *__restrict,
69     const void *__restrict, size_t,
70     struct _citrus_mapper_traits * __restrict, size_t);
71 typedef void (*_citrus_mapper_uninit_t)(struct _citrus_mapper *);
72 typedef int (*_citrus_mapper_convert_t)(struct _citrus_mapper * __restrict,
73     _citrus_index_t * __restrict, _citrus_index_t, void * __restrict);
74 typedef void (*_citrus_mapper_init_state_t)(void);
75 
76 struct _citrus_mapper_ops {
77 	_citrus_mapper_init_t			 mo_init;
78 	_citrus_mapper_uninit_t			 mo_uninit;
79 	_citrus_mapper_convert_t		 mo_convert;
80 	_citrus_mapper_init_state_t		 mo_init_state;
81 };
82 
83 struct _citrus_mapper_traits {
84 	/* version 0x00000001 */
85 	size_t					 mt_state_size;
86 	size_t					 mt_src_max;
87 	size_t					 mt_dst_max;
88 };
89 
90 struct _citrus_mapper {
91 	struct _citrus_mapper_ops		*cm_ops;
92 	void					*cm_closure;
93 	_citrus_module_t			 cm_module;
94 	struct _citrus_mapper_traits		*cm_traits;
95 	_CITRUS_HASH_ENTRY(_citrus_mapper)	 cm_entry;
96 	int					 cm_refcount;
97 	char					*cm_key;
98 };
99 #endif
100