multibyte.h revision 1.1 1 /* $NetBSD: multibyte.h,v 1.1 2002/03/17 22:14:29 tshiozak Exp $ */
2
3 /*-
4 * Copyright (c)2002 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 #ifndef _MULTIBYTE_H_
30 #define _MULTIBYTE_H_
31
32 static __inline _citrus_ctype_t
33 _to_cur_ctype(void)
34 {
35 return (_CurrentRuneLocale->rl_citrus_ctype);
36 }
37
38 static __inline _RuneState *
39 _ps_to_runestate(mbstate_t *ps)
40 {
41 return (_RuneState *)(void *)ps;
42 }
43
44 static __inline _RuneState const *
45 _ps_to_runestate_const(mbstate_t const *ps)
46 {
47 return (_RuneState const *)(void const *)ps;
48 }
49
50 static __inline _RuneLocale *
51 _ps_to_runelocale(mbstate_t const *ps)
52 {
53 return _ps_to_runestate_const(ps)->rs_runelocale;
54 }
55
56 static __inline _citrus_ctype_t
57 _ps_to_ctype(mbstate_t const *ps)
58 {
59 if (!ps)
60 return _to_cur_ctype();
61
62 _DIAGASSERT(_ps_to_runelocale(ps) != NULL);
63
64 return _ps_to_runelocale(ps)->rl_citrus_ctype;
65 }
66
67 static __inline void *
68 _ps_to_private(mbstate_t *ps)
69 {
70 if (ps == NULL)
71 return NULL;
72 return (void *)&_ps_to_runestate(ps)->rs_private;
73 }
74
75 static __inline void const *
76 _ps_to_private_const(mbstate_t const *ps)
77 {
78 if (ps == NULL)
79 return NULL;
80 return (void const *)&_ps_to_runestate_const(ps)->rs_private;
81 }
82
83 static __inline void
84 _init_ps(_RuneLocale *rl, mbstate_t *ps)
85 {
86 size_t dum;
87 _ps_to_runestate(ps)->rs_runelocale = rl;
88 _citrus_ctype_mbrtowc(rl->rl_citrus_ctype, NULL, NULL, NULL,
89 _ps_to_private(ps), &dum);
90 }
91
92 static __inline void
93 _fixup_ps(_RuneLocale *rl, mbstate_t *ps, int forceinit)
94 {
95 /* for future multi-locale facility */
96 _DIAGASSERT(rl != NULL);
97
98 if (ps != NULL && (_ps_to_runelocale(ps) == NULL || forceinit)) {
99 _init_ps(rl, ps);
100 }
101 }
102
103 #endif
104