2 * sh.char.h: Table for spotting special characters quickly
3 * Makes for very obscure but efficient coding.
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #if defined(NeXT) && defined(NLS)
36 # include <appkit/NXCType.h>
48 typedef unsigned char tcshuc;
52 extern unsigned short _cmap[];
54 # define CHECK_MBYTEVAR STRdspmbyte
56 extern unsigned short _cmap_c[];
57 extern unsigned short _cmap_mbyte[];
58 extern short _enable_mbdisp;
59 extern unsigned short _mbmap[];
60 extern unsigned short _mbmap_euc[];
61 extern unsigned short _mbmap_sjis[];
62 extern unsigned short _mbmap_big5[];
63 extern unsigned short _mbmap_utf8[];
64 /* VARIABLE Check str */
65 /* same compiler require #define even not define DSPMBYTE */
72 extern tcshuc _cmap_lower[], _cmap_upper[];
78 #define _QF 0x0001 /* '" (Forward quotes) */
80 #define _QB 0x0002 /* ` (Backquote) */
82 #define _SP 0x0004 /* space and tab */
85 #define _XD 0x0001 /* As in <ctype.h> */
87 #define _UP 0x0002 /* As in <ctype.h> */
89 #define _SP 0x0004 /* As in <ctype.h> */
92 #define _NL 0x0008 /* \n */
94 #define _META 0x0010 /* lex meta characters, sp #'`";&<>()|\t\n */
96 #define _GLOB 0x0020 /* glob characters, *?{[` */
98 #define _ESC 0x0040 /* \ */
100 #define _DOL 0x0080 /* $ */
102 #define _DIG 0x0100 /* 0-9 */
104 #define _LET 0x0200 /* a-z, A-Z, _, or locale-specific */
107 #define _UP 0x0400 /* A-Z, or locale-specific */
110 #define _QF 0x0400 /* '" (Forward quotes) */
113 #define _DOW 0x0800 /* a-z, or locale-specific */
116 #define _XD 0x1000 /* 0-9, a-f, A-F */
119 #define _QB 0x1000 /* 0-9, a-f, A-F */
122 #define _CMD 0x2000 /* lex end of command chars, ;&(|` */
124 #define _CTR 0x4000 /* control */
126 #define _PUN 0x8000 /* punctuation */
129 # define ASC(ch) (ch)
130 # define CTL_ESC(ch) (ch)
133 /* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */
134 # include <ascii_ebcdic.h>
136 /* "OS/390 USS" is a POSIX on a main frame using an IBM1047 char set */
138 extern unsigned short _toascii[256];
139 extern unsigned short _toebcdic[256];
141 /* mainly for comparisons if (ASC(ch)=='\177')... */
142 # define ASC(ch) _toascii[(tcshuc)(ch)]
144 /* Literal escapes ('\010') must be mapped to EBCDIC,
145 * for C-Escapes ('\b'), the compiler already does it.
147 # define CTL_ESC(ch) _toebcdic[(tcshuc)(ch)]
151 # define cmap(c, bits) \
152 (((c) & QUOTE) || (unsigned int)(c) >= 0x0080 ? 0 : \
153 (_cmap[(tcshuc)ASC(c)] & (bits)))
154 #elif defined(SHORT_STRINGS) && defined(KANJI)
155 # define cmap(c, bits) \
156 ((((c) & QUOTE) || ((tcshuc)(ASC(c) & 0x80) && adrof(STRnokanji))) ? \
157 0 : (_cmap[(tcshuc)ASC(c)] & (bits)))
158 #else /* SHORT_STRINGS && KANJI */
159 # define cmap(c, bits) \
160 (((c) & QUOTE) ? 0 : (_cmap[(tcshuc)ASC(c)] & (bits)))
161 #endif /* SHORT_STRINGS && KANJI */
163 #define isglob(c) cmap((c), _GLOB)
164 #define isspc(c) cmap((c), _SP)
165 #define ismeta(c) cmap((c), _META)
166 #define iscmdmeta(c) cmap((c), _CMD)
168 #define letter(c) (((c) & QUOTE) ? 0 : \
169 (iswalpha((c)) || (c) == '_'))
170 #define alnum(c) (((c) & QUOTE) ? 0 : \
171 (iswalnum((c)) || (c) == '_'))
173 #define letter(c) (((Char)(c) & QUOTE) ? 0 : \
174 ((isalpha((c)) && !(cmap((c), _PUN))) \
176 #define alnum(c) (((Char)(c) & QUOTE) ? 0 : \
177 ((isalnum((c)) && !(cmap((c), _PUN))) \
182 #if defined(DSPMBYTE)
183 # define IsmbyteU(c) (Ismbyte1((Char)(c))||(Ismbyte2((Char)(c))&&((c)&0200)))
188 # define Isspace(c) (((c) & QUOTE) ? 0 : iswspace(c))
189 # define Isdigit(c) (((c) & QUOTE) ? 0 : iswdigit(c))
190 # define Isalpha(c) (((c) & QUOTE) ? 0 : iswalpha(c))
191 # define Islower(c) (((c) & QUOTE) ? 0 : iswlower(c))
192 # define Isupper(c) (((c) & QUOTE) ? 0 : iswupper(c))
193 # define Tolower(c) (((c) & QUOTE) ? 0 : (wchar_t)towlower(c))
194 # define Toupper(c) (((c) & QUOTE) ? 0 : (wchar_t)towupper(c))
195 # define Isxdigit(c) (((c) & QUOTE) ? 0 : iswxdigit(c))
196 # define Isalnum(c) (((c) & QUOTE) ? 0 : iswalnum(c))
197 # define Iscntrl(c) (((c) & QUOTE) ? 0 : iswcntrl(c))
198 # define Isprint(c) (((c) & QUOTE) ? 0 : iswprint(c))
199 # define Ispunct(c) (((c) & QUOTE) ? 0 : iswpunct(c))
200 # elif defined (NeXT)
201 # define Isspace(c) (((Char)(c) & QUOTE) ? 0 : NXIsSpace((unsigned) (c)))
202 # define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : NXIsDigit((unsigned) (c)))
203 # define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : NXIsAlpha((unsigned) (c)))
204 # define Islower(c) (((Char)(c) & QUOTE) ? 0 : NXIsLower((unsigned) (c)))
205 # define Isupper(c) (((Char)(c) & QUOTE) ? 0 : NXIsUpper((unsigned) (c)))
206 # define Tolower(c) (((Char)(c) & QUOTE) ? 0 : NXToLower((unsigned) (c)))
207 # define Toupper(c) (((Char)(c) & QUOTE) ? 0 : NXToUpper((unsigned) (c)))
208 # define Isxdigit(c) (((Char)(c) & QUOTE) ? 0 : NXIsXDigit((unsigned) (c)))
209 #if defined(DSPMBYTE)
210 # define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
211 # define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
212 # define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
213 # define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
215 # define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : NXIsAlNum((unsigned) (c)))
216 # define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
217 # define Isprint(c) (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
218 #endif /* !defined(DSPMBYTE) */
219 # define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : NXIsPunct((unsigned) (c)))
221 # ifndef WINNT_NATIVE
222 # define Isspace(c) (((Char)(c) & QUOTE) ? 0 : isspace((tcshuc) (c)))
223 # define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : isdigit((tcshuc) (c)))
224 # define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : isalpha((tcshuc) (c)))
225 # define Islower(c) (((Char)(c) & QUOTE) ? 0 : islower((tcshuc) (c)))
226 # define Isupper(c) (((Char)(c) & QUOTE) ? 0 : isupper((tcshuc) (c)))
227 # define Tolower(c) (((Char)(c) & QUOTE) ? 0 : tolower((tcshuc) (c)))
228 # define Toupper(c) (((Char)(c) & QUOTE) ? 0 : toupper((tcshuc) (c)))
229 # define Isxdigit(c) (((Char)(c) & QUOTE) ? 0 : isxdigit((tcshuc) (c)))
230 # define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : isalnum((tcshuc) (c)))
231 #if defined(DSPMBYTE)
232 # define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
233 # define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
235 # define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
236 #endif /* !defined(DSPMBYTE) */
239 * From <casper@fwi.uva.nl> Casper Dik:
240 * In Solaris 2.4, isprint('\t') returns true after setlocal(LC_ALL,"").
241 * This breaks commandline editing when you include tabs.
242 * (This is in the en_US locale).
244 #if defined(DSPMBYTE)
245 # define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : \
246 (isprint((tcshuc) (c)) && (c) != '\t'))
248 # define Isprint(c) (((Char)(c) & QUOTE) ? 0 : \
249 (isprint((tcshuc) (c)) && (c) != '\t'))
250 #endif /* !defined(DSPMBYTE) */
252 #if defined(DSPMBYTE)
253 # define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
255 # define Isprint(c) (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
256 #endif /* !defined(DSPMBYTE) */
257 # endif /* SOLARIS2 == 24 */
258 #if defined(DSPMBYTE)
259 # define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
260 #endif /* !defined(DSPMBYTE) */
261 # define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : ispunct((tcshuc) (c)))
262 # else /* WINNT_NATIVE */
263 # define Isspace(c) (((Char)(c) & QUOTE) ? 0 : isspace( oem_it((tcshuc)(c))))
264 # define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : isdigit( oem_it((tcshuc)(c))))
265 # define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : isalpha( oem_it((tcshuc)(c))))
266 # define Islower(c) (((Char)(c) & QUOTE) ? 0 : islower( oem_it((tcshuc)(c))))
267 # define Isupper(c) (((Char)(c) & QUOTE) ? 0 : isupper( oem_it((tcshuc)(c))))
268 # define Tolower(c) (((Char)(c) & QUOTE) ? 0 : tolower( oem_it((tcshuc)(c))))
269 # define Toupper(c) (((Char)(c) & QUOTE) ? 0 : toupper( oem_it((tcshuc)(c))))
270 # define Isxdigit(c)(((Char)(c) & QUOTE) ? 0 : isxdigit(oem_it((tcshuc)(c))))
271 # define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : isalnum( oem_it((tcshuc)(c))))
272 # define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : ispunct( oem_it((tcshuc)(c))))
273 #if defined(DSPMBYTE)
274 # define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
275 # define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
276 # define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
277 # define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
279 # define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
280 # define Isprint(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
281 #endif /* !defined(DSPMBYTE) */
282 # endif /* WINNT_NATIVE */
285 # define Isspace(c) cmap((c), _SP|_NL)
286 # define Isdigit(c) cmap((c), _DIG)
287 # define Isalpha(c) (cmap((c),_LET) && !(((c) & META) && AsciiOnly))
288 # define Islower(c) (cmap((c),_DOW) && !(((c) & META) && AsciiOnly))
289 # define Isupper(c) (cmap((c), _UP) && !(((c) & META) && AsciiOnly))
290 # define Tolower(c) (_cmap_lower[ASC(c)])
291 # define Toupper(c) (_cmap_upper[ASC(c)])
292 # define Isxdigit(c) cmap((c), _XD)
293 # define Isalnum(c) (cmap((c), _DIG|_LET) && !(((Char)(c) & META) && AsciiOnly))
294 #if defined(DSPMBYTE)
295 # define IscntrlM(c) (cmap((c),_CTR) && !(((c) & META) && AsciiOnly))
296 # define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
297 # define IsprintM(c) (!cmap((c),_CTR) && !(((c) & META) && AsciiOnly))
298 # define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
300 # define Iscntrl(c) (cmap((c),_CTR) && !(((c) & META) && AsciiOnly))
301 # define Isprint(c) (!cmap((c),_CTR) && !(((c) & META) && AsciiOnly))
302 #endif /* !defined(DSPMBYTE) */
303 # define Ispunct(c) (cmap((c),_PUN) && !(((c) & META) && AsciiOnly))
307 #if defined(DSPMBYTE)
308 # define Ismbyte1(c) ((_mbmap[(c) & 0377] & _MB1) ? 1 : 0)
309 # define Ismbyte2(c) ((_mbmap[(c) & 0377] & _MB2) ? 1 : 0)
312 #endif /* _h_sh_char */