Plug in missing brelse calls as to fix a bug in the FFS reload code.
[dragonfly.git] / contrib / tcsh / sh.char.h
1 /* $Header: /src/pub/tcsh/sh.char.h,v 3.20 2002/07/01 20:50:21 christos Exp $ */
2 /*
3  * sh.char.h: Table for spotting special characters quickly
4  *            Makes for very obscure but efficient coding.
5  */
6 /*-
7  * Copyright (c) 1980, 1991 The Regents of the University of California.
8  * All rights reserved.
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 #ifndef _h_sh_char
35 #define _h_sh_char
36 #if defined(NeXT) && defined(NLS)
37 # include <appkit/NXCType.h>
38 #else
39 # include <ctype.h>
40 #endif
41
42 typedef unsigned char tcshuc;
43 #ifdef _MINIX
44 # undef _SP
45 #endif /* _MINIX */
46 extern unsigned short _cmap[];
47 #if defined(DSPMBYTE)
48 extern unsigned short _mbmap[];
49 # define CHECK_MBYTEVAR STRdspmbyte
50 #endif
51 extern unsigned short _cmap_c[];
52 extern unsigned short _cmap_mbyte[];
53 extern short _enable_mbdisp;
54 extern unsigned short _mbmap[];
55 extern unsigned short _mbmap_euc[];
56 extern unsigned short _mbmap_sjis[];
57 extern unsigned short _mbmap_big5[];
58 extern unsigned short _mbmap_utf8[];
59 /* VARIABLE Check str */
60 /* same compiler require #define even not define DSPMBYTE */
61 #define _MB1    0x0001
62 #define _MB2    0x0002
63
64 #ifndef NLS
65 extern tcshuc _cmap_lower[], _cmap_upper[];
66
67 #endif
68
69 #define _QF     0x0001          /* '" (Forward quotes) */
70 #define _QB     0x0002          /* ` (Backquote) */
71 #define _SP     0x0004          /* space and tab */
72 #define _NL     0x0008          /* \n */
73 #define _META   0x0010          /* lex meta characters, sp #'`";&<>()|\t\n */
74 #define _GLOB   0x0020          /* glob characters, *?{[` */
75 #define _ESC    0x0040          /* \ */
76 #define _DOL    0x0080          /* $ */
77 #define _DIG    0x0100          /* 0-9 */
78 #define _LET    0x0200          /* a-z, A-Z, _ */
79 #define _UP     0x0400          /* A-Z */
80 #define _DOW    0x0800          /* a-z */
81 #define _XD     0x1000          /* 0-9, a-f, A-F */
82 #define _CMD    0x2000          /* lex end of command chars, ;&(|` */
83 #define _CTR    0x4000          /* control */
84 #define _PUN    0x8000          /* punctuation */
85
86 #if defined(SHORT_STRINGS) && defined(KANJI)
87 # define ASC(ch) ch
88 # define CTL_ESC(ch) ch
89 # define cmap(c, bits)  \
90         ((((c) & QUOTE) || ((c & 0x80) && adrof(STRnokanji))) ? \
91         0 : (_cmap[(tcshuc)(c)] & (bits)))
92 #else /* SHORT_STRINGS && KANJI */
93 # ifdef IS_ASCII
94 #  define ASC(ch) ch
95 #  define CTL_ESC(ch) ch
96 #  define cmap(c, bits) \
97         (((c) & QUOTE) ? 0 : (_cmap[(tcshuc)(c)] & (bits)))
98 # else /* IS_ASCII */
99 /* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */
100 /* "OS/390 USS" is a POSIX on a main frame using an IBM1047 char set */
101 extern unsigned short _toascii[256];
102 extern unsigned short _toebcdic[256];
103
104 /* mainly for comparisons if (ASC(ch)=='\177')... */
105 #  define ASC(ch)     _toascii[(tcshuc)ch]
106
107 /* Literal escapes ('\010') must be mapped to EBCDIC,
108  * for C-Escapes   ('\b'), the compiler already does it.
109  */
110 #  define CTL_ESC(ch) _toebcdic[(tcshuc)ch]
111
112 #  define cmap(c, bits) \
113         (((c) & QUOTE) ? 0 : (_cmap[_toascii[(tcshuc)(c)]] & (bits)))
114 # endif /* IS_ASCII */
115 #endif /* SHORT_STRINGS && KANJI */
116
117 #define isglob(c)       cmap(c, _GLOB)
118 #define isspc(c)        cmap(c, _SP)
119 #define ismeta(c)       cmap(c, _META)
120 #define iscmdmeta(c)    cmap(c, _CMD)
121 #define letter(c)       (((Char)(c) & QUOTE) ? 0 : \
122                          (isalpha((tcshuc) (c)) || (c) == '_'))
123 #define alnum(c)        (((Char)(c) & QUOTE) ? 0 : \
124                          (isalnum((tcshuc) (c)) || (c) == '_'))
125
126 #if defined(DSPMBYTE)
127 # define IsmbyteU(c)    (Ismbyte1((Char)(c))||(Ismbyte2((Char)(c))&&((c)&0200)))
128 #endif
129
130 #ifdef NLS
131 # ifdef NeXT
132 #  define Isspace(c)    (((Char)(c) & QUOTE) ? 0 : NXIsSpace((unsigned) (c)))
133 #  define Isdigit(c)    (((Char)(c) & QUOTE) ? 0 : NXIsDigit((unsigned) (c)))
134 #  define Isalpha(c)    (((Char)(c) & QUOTE) ? 0 : NXIsAlpha((unsigned) (c)))
135 #  define Islower(c)    (((Char)(c) & QUOTE) ? 0 : NXIsLower((unsigned) (c)))
136 #  define Isupper(c)    (((Char)(c) & QUOTE) ? 0 : NXIsUpper((unsigned) (c)))
137 #  define Tolower(c)    (((Char)(c) & QUOTE) ? 0 : NXToLower((unsigned) (c)))
138 #  define Toupper(c)    (((Char)(c) & QUOTE) ? 0 : NXToUpper((unsigned) (c)))
139 #  define Isxdigit(c)   (((Char)(c) & QUOTE) ? 0 : NXIsXDigit((unsigned) (c)))
140 #if defined(DSPMBYTE)
141 #  define IscntrlM(c)   (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
142 #  define Iscntrl(c)    ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
143 #  define IsprintM(c)   (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
144 #  define Isprint(c)    ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
145 #else
146 #  define Isalnum(c)    (((Char)(c) & QUOTE) ? 0 : NXIsAlNum((unsigned) (c)))
147 #  define Iscntrl(c)    (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
148 #  define Isprint(c)    (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
149 #endif /* !defined(DSPMBYTE) */
150 #  define Ispunct(c)    (((Char)(c) & QUOTE) ? 0 : NXIsPunct((unsigned) (c)))
151 # else /* !NeXT */
152 #  ifndef WINNT_NATIVE
153 #   define Isspace(c)   (((Char)(c) & QUOTE) ? 0 : isspace((tcshuc) (c)))
154 #   define Isdigit(c)   (((Char)(c) & QUOTE) ? 0 : isdigit((tcshuc) (c)))
155 #   define Isalpha(c)   (((Char)(c) & QUOTE) ? 0 : isalpha((tcshuc) (c)))
156 #   define Islower(c)   (((Char)(c) & QUOTE) ? 0 : islower((tcshuc) (c)))
157 #   define Isupper(c)   (((Char)(c) & QUOTE) ? 0 : isupper((tcshuc) (c)))
158 #   define Tolower(c)   (((Char)(c) & QUOTE) ? 0 : tolower((tcshuc) (c)))
159 #   define Toupper(c)   (((Char)(c) & QUOTE) ? 0 : toupper((tcshuc) (c)))
160 #   define Isxdigit(c)  (((Char)(c) & QUOTE) ? 0 : isxdigit((tcshuc) (c)))
161 #   define Isalnum(c)   (((Char)(c) & QUOTE) ? 0 : isalnum((tcshuc) (c)))
162 #if defined(DSPMBYTE)
163 #   define IscntrlM(c)  (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
164 #   define Iscntrl(c)   ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
165 #else
166 #   define Iscntrl(c)   (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
167 #endif /* !defined(DSPMBYTE) */
168 #   if SOLARIS2 == 24
169     /* 
170      * From <casper@fwi.uva.nl> Casper Dik:
171      * In Solaris 2.4, isprint('\t') returns true after setlocal(LC_ALL,"").
172      * This breaks commandline editing when you include tabs.
173      * (This is in the en_US locale).
174      */
175 #if defined(DSPMBYTE)
176 #    define IsprintM(c)         (((Char)(c) & QUOTE) ? 0 : \
177                                 (isprint((tcshuc) (c)) && (c) != '\t'))
178 #else
179 #    define Isprint(c)  (((Char)(c) & QUOTE) ? 0 : \
180                                 (isprint((tcshuc) (c)) && (c) != '\t'))
181 #endif /* !defined(DSPMBYTE) */
182 #   else
183 #if defined(DSPMBYTE)
184 #    define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
185 #else
186 #    define Isprint(c)  (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
187 #endif /* !defined(DSPMBYTE) */
188 #   endif /* SOLARIS2 == 24 */
189 #if defined(DSPMBYTE)
190 #   define Isprint(c)   ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
191 #endif /* !defined(DSPMBYTE) */
192 #    define Ispunct(c)  (((Char)(c) & QUOTE) ? 0 : ispunct((tcshuc) (c)))
193 #  else /* WINNT_NATIVE */
194 #   define Isspace(c) (((Char)(c) & QUOTE) ? 0 : isspace( oem_it((tcshuc)(c))))
195 #   define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : isdigit( oem_it((tcshuc)(c))))
196 #   define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : isalpha( oem_it((tcshuc)(c))))
197 #   define Islower(c) (((Char)(c) & QUOTE) ? 0 : islower( oem_it((tcshuc)(c))))
198 #   define Isupper(c) (((Char)(c) & QUOTE) ? 0 : isupper( oem_it((tcshuc)(c))))
199 #   define Tolower(c) (((Char)(c) & QUOTE) ? 0 : tolower( oem_it((tcshuc)(c))))
200 #   define Toupper(c) (((Char)(c) & QUOTE) ? 0 : toupper( oem_it((tcshuc)(c))))
201 #   define Isxdigit(c)(((Char)(c) & QUOTE) ? 0 : isxdigit(oem_it((tcshuc)(c))))
202 #   define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : isalnum( oem_it((tcshuc)(c))))
203 #   define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : ispunct( oem_it((tcshuc)(c))))
204 #if defined(DSPMBYTE)
205 #   define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
206 #   define Iscntrl(c)   ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
207 #   define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
208 #   define Isprint(c)   ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
209 #else
210 #   define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
211 #   define Isprint(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
212 #endif /* !defined(DSPMBYTE) */
213 #  endif /* WINNT_NATIVE */
214 # endif /* !NeXT */
215 #else /* !NLS */
216 # define Isspace(c)     cmap(c, _SP|_NL)
217 # define Isdigit(c)     cmap(c, _DIG)
218 # define Isalpha(c)     (cmap(c,_LET) && !(((c) & META) && AsciiOnly))
219 # define Islower(c)     (cmap(c,_DOW) && !(((c) & META) && AsciiOnly))
220 # define Isupper(c)     (cmap(c, _UP) && !(((c) & META) && AsciiOnly))
221 # ifdef IS_ASCII
222 #  define Tolower(c)    (_cmap_lower[(tcshuc)(c)])
223 #  define Toupper(c)    (_cmap_upper[(tcshuc)(c)])
224 # else
225 /* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */
226 #  define Tolower(c)    (_cmap_lower[_toascii[(tcshuc)(c)]])
227 #  define Toupper(c)    (_cmap_upper[_toascii[(tcshuc)(c)]])
228 # endif
229 # define Isxdigit(c)    cmap(c, _XD)
230 # define Isalnum(c)     (cmap(c, _DIG|_LET) && !(((Char)(c) & META) && AsciiOnly))
231 #if defined(DSPMBYTE)
232 # define IscntrlM(c)    (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
233 # define Iscntrl(c)     ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
234 # define IsprintM(c)    (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
235 # define Isprint(c)     ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
236 #else
237 # define Iscntrl(c)     (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
238 # define Isprint(c)     (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
239 #endif /* !defined(DSPMBYTE) */
240 # define Ispunct(c)     (cmap(c,_PUN) && !(((c) & META) && AsciiOnly))
241
242 #endif /* !NLS */
243
244 #if defined(DSPMBYTE)
245 # define Ismbyte1(c)    ((_mbmap[(c) & 0377] & _MB1) ? 1 : 0)
246 # define Ismbyte2(c)    ((_mbmap[(c) & 0377] & _MB2) ? 1 : 0)
247 #endif
248
249 #endif /* _h_sh_char */