xref: /netbsd/lib/libc/locale/runetype_file.h (revision 6550d01e)
1 /* $NetBSD: runetype_file.h,v 1.3 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  *	@(#)runetype.h	8.1 (Berkeley) 6/2/93
35  */
36 
37 #ifndef	_RUNETYPE_FILE_H_
38 #define	_RUNETYPE_FILE_H_
39 
40 #include <sys/cdefs.h>
41 #include <sys/types.h>
42 
43 #include "ctype_local.h"
44 
45 /* for cross host tools on older systems */
46 #ifndef UINT32_C
47 /* assumes sizeof(unsigned int)>=4 */
48 #define UINT32_C(c) ((uint32_t)(c##U))
49 #endif
50 
51 typedef uint32_t	__nbrune_t;
52 typedef uint64_t	__runepad_t;
53 
54 #define _DEFAULT_INVALID_RUNE ((__nbrune_t)-3)
55 
56 /*
57  * The lower 8 bits of runetype[] contain the digit value of the rune.
58  */
59 typedef uint32_t _RuneType;
60 #define	_RUNETYPE_A	UINT32_C(0x00000100)	/* Alpha */
61 #define	_RUNETYPE_C	UINT32_C(0x00000200)	/* Control */
62 #define	_RUNETYPE_D	UINT32_C(0x00000400)	/* Digit */
63 #define	_RUNETYPE_G	UINT32_C(0x00000800)	/* Graph */
64 #define	_RUNETYPE_L	UINT32_C(0x00001000)	/* Lower */
65 #define	_RUNETYPE_P	UINT32_C(0x00002000)	/* Punct */
66 #define	_RUNETYPE_S	UINT32_C(0x00004000)	/* Space */
67 #define	_RUNETYPE_U	UINT32_C(0x00008000)	/* Upper */
68 #define	_RUNETYPE_X	UINT32_C(0x00010000)	/* X digit */
69 #define	_RUNETYPE_B	UINT32_C(0x00020000)	/* Blank */
70 #define	_RUNETYPE_R	UINT32_C(0x00040000)	/* Print */
71 #define	_RUNETYPE_I	UINT32_C(0x00080000)	/* Ideogram */
72 #define	_RUNETYPE_T	UINT32_C(0x00100000)	/* Special */
73 #define	_RUNETYPE_Q	UINT32_C(0x00200000)	/* Phonogram */
74 #define	_RUNETYPE_SWM	UINT32_C(0xc0000000)/* Mask to get screen width data */
75 #define	_RUNETYPE_SWS	30		/* Bits to shift to get width */
76 #define	_RUNETYPE_SW0	UINT32_C(0x20000000)	/* 0 width character */
77 #define	_RUNETYPE_SW1	UINT32_C(0x40000000)	/* 1 width character */
78 #define	_RUNETYPE_SW2	UINT32_C(0x80000000)	/* 2 width character */
79 #define	_RUNETYPE_SW3	UINT32_C(0xc0000000)	/* 3 width character */
80 
81 /*
82  * rune file format.  network endian.
83  */
84 typedef struct {
85 	int32_t		fre_min;	/* First rune of the range */
86 	int32_t		fre_max;	/* Last rune (inclusive) of the range */
87 	int32_t		fre_map;	/* What first maps to in maps */
88 	uint32_t	fre_pad1;	/* backward compatibility */
89 	__runepad_t	fre_pad2;	/* backward compatibility */
90 } __packed _FileRuneEntry;
91 
92 
93 typedef struct {
94 	uint32_t	frr_nranges;	/* Number of ranges stored */
95 	uint32_t	frr_pad1;	/* backward compatibility */
96 	__runepad_t	frr_pad2;	/* backward compatibility */
97 } __packed _FileRuneRange;
98 
99 
100 typedef struct {
101 	char		frl_magic[8];	/* Magic saying what version we are */
102 	char		frl_encoding[32];/* ASCII name of this encoding */
103 
104 	__runepad_t	frl_pad1;	/* backward compatibility */
105 	__runepad_t	frl_pad2;	/* backward compatibility */
106 	int32_t		frl_invalid_rune;
107 	uint32_t	frl_pad3;	/* backward compatibility */
108 
109 	_RuneType	frl_runetype[_CTYPE_CACHE_SIZE];
110 	int32_t		frl_maplower[_CTYPE_CACHE_SIZE];
111 	int32_t		frl_mapupper[_CTYPE_CACHE_SIZE];
112 
113 	/*
114 	 * The following are to deal with Runes larger than _CTYPE_CACHE_SIZE - 1.
115 	 * Their data is actually contiguous with this structure so as to make
116 	 * it easier to read/write from/to disk.
117 	 */
118 	_FileRuneRange	frl_runetype_ext;
119 	_FileRuneRange	frl_maplower_ext;
120 	_FileRuneRange	frl_mapupper_ext;
121 
122 	__runepad_t	frl_pad4;	/* backward compatibility */
123 	int32_t		frl_variable_len;/* how long that data is */
124 	uint32_t	frl_pad5;	/* backward compatibility */
125 
126 	/* variable size data follows */
127 } __packed _FileRuneLocale;
128 
129 
130 /* magic number for LC_CTYPE (rune)locale declaration */
131 #define	_RUNECT10_MAGIC	"RuneCT10"	/* Indicates version 0 of RuneLocale */
132 
133 /* codeset tag */
134 #define _RUNE_CODESET "CODESET="
135 
136 #endif	/* !_RUNETYPE_FILE_H_ */
137