xref: /illumos-gate/usr/src/lib/libc/port/locale/mblocal.h (revision eda3ef2d)
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*eda3ef2dSRobert Mustacchi #include <uchar.h>
35*eda3ef2dSRobert Mustacchi 
36*eda3ef2dSRobert Mustacchi /*
37*eda3ef2dSRobert Mustacchi  * Actual implementation structures for mbstate_t data.
38*eda3ef2dSRobert Mustacchi  *
39*eda3ef2dSRobert Mustacchi  * All of the conversion states are independent of one another, with the
40*eda3ef2dSRobert Mustacchi  * exception of that used for mbrtoc16(). That needs to encode data not as a
41*eda3ef2dSRobert Mustacchi  * wide-character but as UTF-16 data, which means handling surrogate pairs. To
42*eda3ef2dSRobert Mustacchi  * minimize the amount of state in each locale, we instead have a conversion
43*eda3ef2dSRobert Mustacchi  * state for this which includes all the other conversion states, plus extra
44*eda3ef2dSRobert Mustacchi  * data to accomodate this.
45*eda3ef2dSRobert Mustacchi  */
46*eda3ef2dSRobert Mustacchi typedef struct {
47*eda3ef2dSRobert Mustacchi 	wchar_t	ch;
48*eda3ef2dSRobert Mustacchi } _BIG5State;
49*eda3ef2dSRobert Mustacchi 
50*eda3ef2dSRobert Mustacchi typedef struct {
51*eda3ef2dSRobert Mustacchi 	wchar_t	ch;
52*eda3ef2dSRobert Mustacchi 	int	set;
53*eda3ef2dSRobert Mustacchi 	int	want;
54*eda3ef2dSRobert Mustacchi } _EucState;
55*eda3ef2dSRobert Mustacchi 
56*eda3ef2dSRobert Mustacchi typedef struct {
57*eda3ef2dSRobert Mustacchi 	int	count;
58*eda3ef2dSRobert Mustacchi 	uchar_t	bytes[4];
59*eda3ef2dSRobert Mustacchi } _GB18030State;
60*eda3ef2dSRobert Mustacchi 
61*eda3ef2dSRobert Mustacchi typedef struct {
62*eda3ef2dSRobert Mustacchi 	int	count;
63*eda3ef2dSRobert Mustacchi 	uchar_t	bytes[2];
64*eda3ef2dSRobert Mustacchi } _GB2312State;
65*eda3ef2dSRobert Mustacchi 
66*eda3ef2dSRobert Mustacchi typedef struct {
67*eda3ef2dSRobert Mustacchi 	wchar_t	ch;
68*eda3ef2dSRobert Mustacchi } _GBKState;
69*eda3ef2dSRobert Mustacchi 
70*eda3ef2dSRobert Mustacchi typedef struct {
71*eda3ef2dSRobert Mustacchi 	wchar_t	ch;
72*eda3ef2dSRobert Mustacchi } _MSKanjiState;
73*eda3ef2dSRobert Mustacchi 
74*eda3ef2dSRobert Mustacchi typedef struct {
75*eda3ef2dSRobert Mustacchi 	wchar_t	ch;
76*eda3ef2dSRobert Mustacchi 	int	want;
77*eda3ef2dSRobert Mustacchi 	wchar_t	lbound;
78*eda3ef2dSRobert Mustacchi } _UTF8State;
79*eda3ef2dSRobert Mustacchi 
80*eda3ef2dSRobert Mustacchi typedef struct {
81*eda3ef2dSRobert Mustacchi 	union {
82*eda3ef2dSRobert Mustacchi 		_BIG5State	c16_big5;
83*eda3ef2dSRobert Mustacchi 		_EucState	c16_euc;
84*eda3ef2dSRobert Mustacchi 		_GB18030State	c16_gb18030;
85*eda3ef2dSRobert Mustacchi 		_GB2312State	c16_gb2312;
86*eda3ef2dSRobert Mustacchi 		_GBKState	c16_gbk;
87*eda3ef2dSRobert Mustacchi 		_MSKanjiState	c16_mskanji;
88*eda3ef2dSRobert Mustacchi 		_UTF8State	c16_utf8;
89*eda3ef2dSRobert Mustacchi 	} c16_state;
90*eda3ef2dSRobert Mustacchi 	char16_t c16_surrogate;
91*eda3ef2dSRobert 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 *);
1072d08521bSGarrett D'Amore 
1082d08521bSGarrett D'Amore typedef size_t (*mbrtowc_pfn_t)(wchar_t *_RESTRICT_KYWD,
1090ac311baSRobert 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