xref: /titanic_50/usr/src/lib/libc/port/locale/mblocal.h (revision 3fc10f8cbc2fd5dd5cd13044edf9cb68a1ef422b)
14297a3b0SGarrett D'Amore /*
22d08521bSGarrett D'Amore  * Copyright 2013 Garrett D'Amore <garrett@damore.org>
39d04e500SGarrett D'Amore  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
44297a3b0SGarrett D'Amore  * Copyright (c) 2004 Tim J. Robbins.
54297a3b0SGarrett D'Amore  * All rights reserved.
64297a3b0SGarrett D'Amore  *
74297a3b0SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
84297a3b0SGarrett D'Amore  * modification, are permitted provided that the following conditions
94297a3b0SGarrett D'Amore  * are met:
104297a3b0SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright
114297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer.
124297a3b0SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright
134297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer in the
144297a3b0SGarrett D'Amore  *    documentation and/or other materials provided with the distribution.
154297a3b0SGarrett D'Amore  *
164297a3b0SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174297a3b0SGarrett D'Amore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184297a3b0SGarrett D'Amore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194297a3b0SGarrett D'Amore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
204297a3b0SGarrett D'Amore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214297a3b0SGarrett D'Amore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224297a3b0SGarrett D'Amore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234297a3b0SGarrett D'Amore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244297a3b0SGarrett D'Amore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254297a3b0SGarrett D'Amore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264297a3b0SGarrett D'Amore  * SUCH DAMAGE.
274297a3b0SGarrett D'Amore  */
284297a3b0SGarrett D'Amore 
294297a3b0SGarrett D'Amore #ifndef _MBLOCAL_H_
304297a3b0SGarrett D'Amore #define	_MBLOCAL_H_
314297a3b0SGarrett D'Amore 
324297a3b0SGarrett D'Amore #include "runetype.h"
332d08521bSGarrett D'Amore #include "lctype.h"
34*3fc10f8cSRobert Mustacchi #include <uchar.h>
35*3fc10f8cSRobert Mustacchi 
36*3fc10f8cSRobert Mustacchi /*
37*3fc10f8cSRobert Mustacchi  * Actual implementation structures for mbstate_t data.
38*3fc10f8cSRobert Mustacchi  *
39*3fc10f8cSRobert Mustacchi  * All of the conversion states are independent of one another, with the
40*3fc10f8cSRobert Mustacchi  * exception of that used for mbrtoc16(). That needs to encode data not as a
41*3fc10f8cSRobert Mustacchi  * wide-character but as UTF-16 data, which means handling surrogate pairs. To
42*3fc10f8cSRobert Mustacchi  * minimize the amount of state in each locale, we instead have a conversion
43*3fc10f8cSRobert Mustacchi  * state for this which includes all the other conversion states, plus extra
44*3fc10f8cSRobert Mustacchi  * data to accomodate this.
45*3fc10f8cSRobert Mustacchi  */
46*3fc10f8cSRobert Mustacchi typedef struct {
47*3fc10f8cSRobert Mustacchi 	wchar_t	ch;
48*3fc10f8cSRobert Mustacchi } _BIG5State;
49*3fc10f8cSRobert Mustacchi 
50*3fc10f8cSRobert Mustacchi typedef struct {
51*3fc10f8cSRobert Mustacchi 	wchar_t	ch;
52*3fc10f8cSRobert Mustacchi 	int	set;
53*3fc10f8cSRobert Mustacchi 	int	want;
54*3fc10f8cSRobert Mustacchi } _EucState;
55*3fc10f8cSRobert Mustacchi 
56*3fc10f8cSRobert Mustacchi typedef struct {
57*3fc10f8cSRobert Mustacchi 	int	count;
58*3fc10f8cSRobert Mustacchi 	uchar_t	bytes[4];
59*3fc10f8cSRobert Mustacchi } _GB18030State;
60*3fc10f8cSRobert Mustacchi 
61*3fc10f8cSRobert Mustacchi typedef struct {
62*3fc10f8cSRobert Mustacchi 	int	count;
63*3fc10f8cSRobert Mustacchi 	uchar_t	bytes[2];
64*3fc10f8cSRobert Mustacchi } _GB2312State;
65*3fc10f8cSRobert Mustacchi 
66*3fc10f8cSRobert Mustacchi typedef struct {
67*3fc10f8cSRobert Mustacchi 	wchar_t	ch;
68*3fc10f8cSRobert Mustacchi } _GBKState;
69*3fc10f8cSRobert Mustacchi 
70*3fc10f8cSRobert Mustacchi typedef struct {
71*3fc10f8cSRobert Mustacchi 	wchar_t	ch;
72*3fc10f8cSRobert Mustacchi } _MSKanjiState;
73*3fc10f8cSRobert Mustacchi 
74*3fc10f8cSRobert Mustacchi typedef struct {
75*3fc10f8cSRobert Mustacchi 	wchar_t	ch;
76*3fc10f8cSRobert Mustacchi 	int	want;
77*3fc10f8cSRobert Mustacchi 	wchar_t	lbound;
78*3fc10f8cSRobert Mustacchi } _UTF8State;
79*3fc10f8cSRobert Mustacchi 
80*3fc10f8cSRobert Mustacchi typedef struct {
81*3fc10f8cSRobert Mustacchi 	union {
82*3fc10f8cSRobert Mustacchi 		_BIG5State	c16_big5;
83*3fc10f8cSRobert Mustacchi 		_EucState	c16_euc;
84*3fc10f8cSRobert Mustacchi 		_GB18030State	c16_gb18030;
85*3fc10f8cSRobert Mustacchi 		_GB2312State	c16_gb2312;
86*3fc10f8cSRobert Mustacchi 		_GBKState	c16_gbk;
87*3fc10f8cSRobert Mustacchi 		_MSKanjiState	c16_mskanji;
88*3fc10f8cSRobert Mustacchi 		_UTF8State	c16_utf8;
89*3fc10f8cSRobert Mustacchi 	} c16_state;
90*3fc10f8cSRobert Mustacchi 	char16_t c16_surrogate;
91*3fc10f8cSRobert Mustacchi } _CHAR16State;
924297a3b0SGarrett D'Amore 
934297a3b0SGarrett D'Amore /*
944297a3b0SGarrett D'Amore  * Rune initialization function prototypes.
954297a3b0SGarrett D'Amore  */
962d08521bSGarrett D'Amore void	_none_init(struct lc_ctype *);
972d08521bSGarrett D'Amore void	_UTF8_init(struct lc_ctype *);
982d08521bSGarrett D'Amore void	_EUC_CN_init(struct lc_ctype *);
992d08521bSGarrett D'Amore void	_EUC_JP_init(struct lc_ctype *);
1002d08521bSGarrett D'Amore void	_EUC_KR_init(struct lc_ctype *);
1012d08521bSGarrett D'Amore void	_EUC_TW_init(struct lc_ctype *);
1022d08521bSGarrett D'Amore void	_GB18030_init(struct lc_ctype *);
1032d08521bSGarrett D'Amore void	_GB2312_init(struct lc_ctype *);
1042d08521bSGarrett D'Amore void	_GBK_init(struct lc_ctype *);
1052d08521bSGarrett D'Amore void	_BIG5_init(struct lc_ctype *);
1062d08521bSGarrett D'Amore void	_MSKanji_init(struct lc_ctype *);
1074297a3b0SGarrett D'Amore 
1082d08521bSGarrett D'Amore typedef size_t (*mbrtowc_pfn_t)(wchar_t *_RESTRICT_KYWD,
10950370af8SRobert Mustacchi     const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
1102d08521bSGarrett D'Amore typedef size_t (*wcrtomb_pfn_t)(char *_RESTRICT_KYWD, wchar_t,
1114297a3b0SGarrett D'Amore     mbstate_t *_RESTRICT_KYWD);
1124297a3b0SGarrett D'Amore size_t __mbsnrtowcs_std(wchar_t *_RESTRICT_KYWD, const char **_RESTRICT_KYWD,
1132d08521bSGarrett D'Amore     size_t, size_t, mbstate_t *_RESTRICT_KYWD, mbrtowc_pfn_t);
1144297a3b0SGarrett D'Amore size_t __wcsnrtombs_std(char *_RESTRICT_KYWD, const wchar_t **_RESTRICT_KYWD,
1152d08521bSGarrett D'Amore     size_t, size_t, mbstate_t *_RESTRICT_KYWD, wcrtomb_pfn_t);
1164297a3b0SGarrett D'Amore 
1174297a3b0SGarrett D'Amore #define	MIN(a, b)	((a) < (b) ? (a) : (b))
1184297a3b0SGarrett D'Amore 
1194297a3b0SGarrett D'Amore #endif	/* _MBLOCAL_H_ */
120