xref: /netbsd/lib/libc/locale/runetype_local.h (revision 6550d01e)
1 /*	$NetBSD: runetype_local.h,v 1.12 2010/06/20 02:23:15 tnozaki Exp $	*/
2 
3 /*-
4  * Copyright (c) 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Paul Borman at Krystal Technologies.
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  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)rune.h	8.1 (Berkeley) 6/27/93
35  *	@(#)runetype.h	8.1 (Berkeley) 6/2/93
36  */
37 
38 #ifndef	_RUNETYPE_LOCAL_H_
39 #define	_RUNETYPE_LOCAL_H_
40 
41 #include <sys/cdefs.h>
42 #include <sys/types.h>
43 #include <stdio.h>
44 
45 #include "runetype_misc.h"
46 
47 #define _RUNE_ISCACHED(c)	((c)>=0 && (c)<_CTYPE_CACHE_SIZE)
48 
49 
50 /*
51  * expanded rune locale declaration.  local to the host.  host endian.
52  */
53 typedef struct {
54 	__nbrune_t	re_min;		/* First rune of the range */
55 	__nbrune_t	re_max;		/* Last rune (inclusive) of the range */
56 	__nbrune_t	re_map;		/* What first maps to in maps */
57 	_RuneType	*re_rune_types;	/* Array of types in range */
58 } _RuneEntry;
59 
60 
61 typedef struct {
62 	uint32_t	rr_nranges;	/* Number of ranges stored */
63 	_RuneEntry	*rr_rune_ranges;
64 } _RuneRange;
65 
66 
67 /*
68  * wctrans stuffs.
69  */
70 typedef struct _WCTransEntry {
71 	const char	*te_name;
72 	__nbrune_t	*te_cached;
73 	_RuneRange	*te_extmap;
74 } _WCTransEntry;
75 #define _WCTRANS_INDEX_LOWER	0
76 #define _WCTRANS_INDEX_UPPER	1
77 #define _WCTRANS_NINDEXES	2
78 
79 /*
80  * wctype stuffs.
81  */
82 typedef struct _WCTypeEntry {
83 	const char	*te_name;
84 	_RuneType	te_mask;
85 } _WCTypeEntry;
86 #define _WCTYPE_INDEX_ALNUM	0
87 #define _WCTYPE_INDEX_ALPHA	1
88 #define _WCTYPE_INDEX_BLANK	2
89 #define _WCTYPE_INDEX_CNTRL	3
90 #define _WCTYPE_INDEX_DIGIT	4
91 #define _WCTYPE_INDEX_GRAPH	5
92 #define _WCTYPE_INDEX_LOWER	6
93 #define _WCTYPE_INDEX_PRINT	7
94 #define _WCTYPE_INDEX_PUNCT	8
95 #define _WCTYPE_INDEX_SPACE	9
96 #define _WCTYPE_INDEX_UPPER	10
97 #define _WCTYPE_INDEX_XDIGIT	11
98 #define _WCTYPE_NINDEXES	12
99 
100 /*
101  * ctype stuffs
102  */
103 
104 typedef struct _RuneLocale {
105 	/*
106 	 * copied from _FileRuneLocale
107 	 */
108 	_RuneType	rl_runetype[_CTYPE_CACHE_SIZE];
109 	__nbrune_t	rl_maplower[_CTYPE_CACHE_SIZE];
110 	__nbrune_t	rl_mapupper[_CTYPE_CACHE_SIZE];
111 	_RuneRange	rl_runetype_ext;
112 	_RuneRange	rl_maplower_ext;
113 	_RuneRange	rl_mapupper_ext;
114 
115 	void		*rl_variable;
116 	size_t		rl_variable_len;
117 
118 	/*
119 	 * the following portion is generated on the fly
120 	 */
121 	const char			*rl_codeset;
122 	struct _citrus_ctype_rec	*rl_citrus_ctype;
123 	_WCTransEntry			rl_wctrans[_WCTRANS_NINDEXES];
124 	_WCTypeEntry			rl_wctype[_WCTYPE_NINDEXES];
125 
126 	const unsigned char		*rl_ctype_tab;
127 	const short			*rl_tolower_tab;
128 	const short			*rl_toupper_tab;
129 } _RuneLocale;
130 
131 /*
132  * global variables
133  */
134 extern const _RuneLocale _DefaultRuneLocale;
135 extern const _RuneLocale *_CurrentRuneLocale;
136 
137 __BEGIN_DECLS
138 int _rune_load(const char * __restrict, size_t, _RuneLocale ** __restrict);
139 __END_DECLS
140 
141 #endif	/* !_RUNETYPE_LOCAL_H_ */
142