1 #ifndef _NB_RUNETYPE_H_ 2 #define _NB_RUNETYPE_H_ 3 4 /* $OpenBSD: runetype.h,v 1.11 2022/07/27 22:24:26 guenther Exp $ */ 5 /* $NetBSD: runetype.h,v 1.18 2003/08/07 16:43:04 agc Exp $ */ 6 /*- 7 * Copyright (c) 1993 8 * The Regents of the University of California. All rights reserved. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * Paul Borman at Krystal Technologies. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * @(#)runetype.h 8.1 (Berkeley) 6/2/93 38 */ 39 40 #include <sys/types.h> 41 #include "ctype_private.h" 42 43 typedef uint32_t rune_t; 44 typedef uint64_t __runepad_t; 45 46 47 #define _CACHED_RUNES (1 << 8) /* Must be a power of 2 */ 48 #define _RUNE_ISCACHED(c) ((c)>=0 && (c)<_CACHED_RUNES) 49 50 #define _DEFAULT_INVALID_RUNE ((rune_t)-3) 51 52 /* 53 * The lower 8 bits of runetype[] contain the digit value of the rune. 54 */ 55 typedef uint32_t _RuneType; 56 57 #define _RUNETYPE_A 0x00000100U /* Alpha */ 58 #define _RUNETYPE_C 0x00000200U /* Control */ 59 #define _RUNETYPE_D 0x00000400U /* Digit */ 60 #define _RUNETYPE_G 0x00000800U /* Graph */ 61 #define _RUNETYPE_L 0x00001000U /* Lower */ 62 #define _RUNETYPE_P 0x00002000U /* Punct */ 63 #define _RUNETYPE_S 0x00004000U /* Space */ 64 #define _RUNETYPE_U 0x00008000U /* Upper */ 65 #define _RUNETYPE_X 0x00010000U /* X digit */ 66 #define _RUNETYPE_B 0x00020000U /* Blank */ 67 #define _RUNETYPE_R 0x00040000U /* Print */ 68 #define _RUNETYPE_I 0x00080000U /* Ideogram */ 69 #define _RUNETYPE_T 0x00100000U /* Special */ 70 #define _RUNETYPE_Q 0x00200000U /* Phonogram */ 71 #define _RUNETYPE_SWM 0xe0000000U /* Mask to get screen width data */ 72 #define _RUNETYPE_SWS 30 /* Bits to shift to get width */ 73 #define _RUNETYPE_SW0 0x20000000U /* 0 width character */ 74 #define _RUNETYPE_SW1 0x40000000U /* 1 width character */ 75 #define _RUNETYPE_SW2 0x80000000U /* 2 width character */ 76 #define _RUNETYPE_SW3 0xc0000000U /* 3 width character */ 77 78 79 /* 80 * rune file format. network endian. 81 */ 82 typedef struct { 83 int32_t fre_min; /* First rune of the range */ 84 int32_t fre_max; /* Last rune (inclusive) of the range */ 85 int32_t fre_map; /* What first maps to in maps */ 86 } __packed _FileRuneEntry; 87 88 89 typedef struct { 90 uint32_t frr_nranges; /* Number of ranges stored */ 91 } __packed _FileRuneRange; 92 93 94 typedef struct { 95 char frl_magic[8]; /* Magic saying what version we are */ 96 char frl_encoding[32];/* ASCII name of this encoding */ 97 98 int32_t frl_invalid_rune; 99 100 _RuneType frl_runetype[_CACHED_RUNES]; 101 int32_t frl_maplower[_CACHED_RUNES]; 102 int32_t frl_mapupper[_CACHED_RUNES]; 103 104 /* 105 * The following are to deal with Runes larger than _CACHED_RUNES - 1. 106 * Their data is actually contiguous with this structure so as to make 107 * it easier to read/write from/to disk. 108 */ 109 _FileRuneRange frl_runetype_ext; 110 _FileRuneRange frl_maplower_ext; 111 _FileRuneRange frl_mapupper_ext; 112 113 int32_t frl_variable_len;/* how long that data is */ 114 115 /* variable size data follows */ 116 } __packed _FileRuneLocale; 117 118 119 /* 120 * expanded rune locale declaration. local to the host. host endian. 121 */ 122 typedef struct { 123 rune_t re_min; /* First rune of the range */ 124 rune_t re_max; /* Last rune (inclusive) of the range */ 125 rune_t re_map; /* What first maps to in maps */ 126 _RuneType *re_rune_types; /* Array of types in range */ 127 } _RuneEntry; 128 129 130 typedef struct { 131 uint32_t rr_nranges; /* Number of ranges stored */ 132 _RuneEntry *rr_rune_ranges; 133 } _RuneRange; 134 135 136 /* 137 * wctrans stuffs. 138 */ 139 typedef struct _WCTransEntry { 140 char *te_name; 141 rune_t *te_cached; 142 _RuneRange *te_extmap; 143 } _WCTransEntry; 144 145 #define _WCTRANS_INDEX_LOWER 0 146 #define _WCTRANS_INDEX_UPPER 1 147 #define _WCTRANS_NINDEXES 2 148 149 /* 150 * wctype stuffs. 151 */ 152 typedef struct _WCTypeEntry { 153 char te_name[8]; 154 _RuneType te_mask; 155 } _WCTypeEntry; 156 #define _WCTYPE_INDEX_ALNUM 0 157 #define _WCTYPE_INDEX_ALPHA 1 158 #define _WCTYPE_INDEX_BLANK 2 159 #define _WCTYPE_INDEX_CNTRL 3 160 #define _WCTYPE_INDEX_DIGIT 4 161 #define _WCTYPE_INDEX_GRAPH 5 162 #define _WCTYPE_INDEX_LOWER 6 163 #define _WCTYPE_INDEX_PRINT 7 164 #define _WCTYPE_INDEX_PUNCT 8 165 #define _WCTYPE_INDEX_SPACE 9 166 #define _WCTYPE_INDEX_UPPER 10 167 #define _WCTYPE_INDEX_XDIGIT 11 168 #define _WCTYPE_NINDEXES 12 169 170 /* 171 * ctype stuffs 172 */ 173 174 struct old_tabs { 175 /* compatibility with `old' ctype */ 176 char ctype_tab[CTYPE_NUM_CHARS + 1]; 177 short tolower_tab[256 + 1]; 178 short toupper_tab[256 + 1]; 179 }; 180 181 typedef struct { 182 /* 183 * copied from _FileRuneLocale 184 */ 185 char rl_magic[8]; /* Magic saying what version we are */ 186 char rl_encoding[32];/* ASCII name of this encoding */ 187 rune_t rl_invalid_rune; 188 _RuneType rl_runetype[_CACHED_RUNES]; 189 rune_t rl_maplower[_CACHED_RUNES]; 190 rune_t rl_mapupper[_CACHED_RUNES]; 191 _RuneRange rl_runetype_ext; 192 _RuneRange rl_maplower_ext; 193 _RuneRange rl_mapupper_ext; 194 195 void *rl_variable; 196 size_t rl_variable_len; 197 198 /* 199 * the following portion is generated on the fly 200 */ 201 char *rl_codeset; 202 _WCTransEntry rl_wctrans[_WCTRANS_NINDEXES]; 203 204 struct old_tabs * rl_tabs; 205 206 } _RuneLocale; 207 208 /* magic number for LC_CTYPE (rune)locale declaration */ 209 #define _RUNE_MAGIC_1 "RuneCT10" /* Indicates version 0 of RuneLocale */ 210 211 /* magic string for dynamic link module - type should be like "LC_CTYPE" */ 212 #define _RUNE_MODULE_1(type) "RuneModule10." type 213 214 /* codeset tag */ 215 #define _RUNE_CODESET "CODESET=" 216 217 #endif 218