]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/tcsh/sh.char.h
This commit was generated by cvs2svn to compensate for changes in r71756,
[FreeBSD/FreeBSD.git] / contrib / tcsh / sh.char.h
1 /* $Header: /src/pub/tcsh/sh.char.h,v 3.17 2000/11/11 23:03:35 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. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  */
38 #ifndef _h_sh_char
39 #define _h_sh_char
40 #if defined(NeXT) && defined(NLS)
41 # include <appkit/NXCType.h>
42 #else
43 # include <ctype.h>
44 #endif
45
46 typedef unsigned char tcshuc;
47 #ifdef _MINIX
48 # undef _SP
49 #endif /* _MINIX */
50 extern unsigned short _cmap[];
51 #if defined(DSPMBYTE)
52 extern unsigned short _mbmap[];
53 # define CHECK_MBYTEVAR STRdspmbyte
54 #endif
55 extern unsigned short _cmap_c[];
56 extern unsigned short _cmap_mbyte[];
57 extern short _enable_mbdisp;
58 extern unsigned short _mbmap[];
59 extern unsigned short _mbmap_euc[];
60 extern unsigned short _mbmap_sjis[];
61 /* VARIABLE Check str */
62 /* same compiler require #define even not define DSPMBYTE */
63 #define _MB1    0x0001
64 #define _MB2    0x0002
65
66 #ifndef NLS
67 extern tcshuc _cmap_lower[], _cmap_upper[];
68
69 #endif
70
71 #define _QF     0x0001          /* '" (Forward quotes) */
72 #define _QB     0x0002          /* ` (Backquote) */
73 #define _SP     0x0004          /* space and tab */
74 #define _NL     0x0008          /* \n */
75 #define _META   0x0010          /* lex meta characters, sp #'`";&<>()|\t\n */
76 #define _GLOB   0x0020          /* glob characters, *?{[` */
77 #define _ESC    0x0040          /* \ */
78 #define _DOL    0x0080          /* $ */
79 #define _DIG    0x0100          /* 0-9 */
80 #define _LET    0x0200          /* a-z, A-Z, _ */
81 #define _UP     0x0400          /* A-Z */
82 #define _DOW    0x0800          /* a-z */
83 #define _XD     0x1000          /* 0-9, a-f, A-F */
84 #define _CMD    0x2000          /* lex end of command chars, ;&(|` */
85 #define _CTR    0x4000          /* control */
86 #define _PUN    0x8000          /* punctuation */
87
88 #if defined(SHORT_STRINGS) && defined(KANJI)
89 # define ASC(ch) ch
90 # define CTL_ESC(ch) ch
91 # define cmap(c, bits)  \
92         ((((c) & QUOTE) || ((c & 0x80) && adrof(STRnokanji))) ? \
93         0 : (_cmap[(tcshuc)(c)] & (bits)))
94 #else /* SHORT_STRINGS && KANJI */
95 # ifdef IS_ASCII
96 #  define ASC(ch) ch
97 #  define CTL_ESC(ch) ch
98 #  define cmap(c, bits) \
99         (((c) & QUOTE) ? 0 : (_cmap[(tcshuc)(c)] & (bits)))
100 # else /* IS_ASCII */
101 /* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */
102 /* "OS/390 USS" is a POSIX on a main frame using an IBM1047 char set */
103 extern unsigned short _toascii[256];
104 extern unsigned short _toebcdic[256];
105
106 /* mainly for comparisons if (ASC(ch)=='\177')... */
107 #  define ASC(ch)     _toascii[(tcshuc)ch]
108
109 /* Literal escapes ('\010') must be mapped to EBCDIC,
110  * for C-Escapes   ('\b'), the compiler already does it.
111  */
112 #  define CTL_ESC(ch) _toebcdic[(tcshuc)ch]
113
114 #  define cmap(c, bits) \
115         (((c) & QUOTE) ? 0 : (_cmap[_toascii[(tcshuc)(c)]] & (bits)))
116 # endif /* IS_ASCII */
117 #endif /* SHORT_STRINGS && KANJI */
118
119 #define isglob(c)       cmap(c, _GLOB)
120 #define isspc(c)        cmap(c, _SP)
121 #define ismeta(c)       cmap(c, _META)
122 #define iscmdmeta(c)    cmap(c, _CMD)
123 #define letter(c)       (((Char)(c) & QUOTE) ? 0 : \
124                          (isalpha((tcshuc) (c)) || (c) == '_'))
125 #define alnum(c)        (((Char)(c) & QUOTE) ? 0 : \
126                          (isalnum((tcshuc) (c)) || (c) == '_'))
127
128 #if defined(DSPMBYTE)
129 # define IsmbyteU(c)    (Ismbyte1((Char)(c))||(Ismbyte2((Char)(c))&&((c)&0200)))
130 #endif
131
132 #ifdef NLS
133 # ifdef NeXT
134 #  define Isspace(c)    (((Char)(c) & QUOTE) ? 0 : NXIsSpace((unsigned) (c)))
135 #  define Isdigit(c)    (((Char)(c) & QUOTE) ? 0 : NXIsDigit((unsigned) (c)))
136 #  define Isalpha(c)    (((Char)(c) & QUOTE) ? 0 : NXIsAlpha((unsigned) (c)))
137 #  define Islower(c)    (((Char)(c) & QUOTE) ? 0 : NXIsLower((unsigned) (c)))
138 #  define Isupper(c)    (((Char)(c) & QUOTE) ? 0 : NXIsUpper((unsigned) (c)))
139 #  define Tolower(c)    (((Char)(c) & QUOTE) ? 0 : NXToLower((unsigned) (c)))
140 #  define Toupper(c)    (((Char)(c) & QUOTE) ? 0 : NXToUpper((unsigned) (c)))
141 #  define Isxdigit(c)   (((Char)(c) & QUOTE) ? 0 : NXIsXDigit((unsigned) (c)))
142 #if defined(DSPMBYTE)
143 #  define IscntrlM(c)   (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
144 #  define Iscntrl(c)    ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
145 #  define IsprintM(c)   (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
146 #  define Isprint(c)    ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
147 #else
148 #  define Isalnum(c)    (((Char)(c) & QUOTE) ? 0 : NXIsAlNum((unsigned) (c)))
149 #  define Iscntrl(c)    (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
150 #  define Isprint(c)    (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
151 #endif /* !defined(DSPMBYTE) */
152 #  define Ispunct(c)    (((Char)(c) & QUOTE) ? 0 : NXIsPunct((unsigned) (c)))
153 # else /* !NeXT */
154 #  ifndef WINNT_NATIVE
155 #   define Isspace(c)   (((Char)(c) & QUOTE) ? 0 : isspace((tcshuc) (c)))
156 #   define Isdigit(c)   (((Char)(c) & QUOTE) ? 0 : isdigit((tcshuc) (c)))
157 #   define Isalpha(c)   (((Char)(c) & QUOTE) ? 0 : isalpha((tcshuc) (c)))
158 #   define Islower(c)   (((Char)(c) & QUOTE) ? 0 : islower((tcshuc) (c)))
159 #   define Isupper(c)   (((Char)(c) & QUOTE) ? 0 : isupper((tcshuc) (c)))
160 #   define Tolower(c)   (((Char)(c) & QUOTE) ? 0 : tolower((tcshuc) (c)))
161 #   define Toupper(c)   (((Char)(c) & QUOTE) ? 0 : toupper((tcshuc) (c)))
162 #   define Isxdigit(c)  (((Char)(c) & QUOTE) ? 0 : isxdigit((tcshuc) (c)))
163 #   define Isalnum(c)   (((Char)(c) & QUOTE) ? 0 : isalnum((tcshuc) (c)))
164 #if defined(DSPMBYTE)
165 #   define IscntrlM(c)  (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
166 #   define Iscntrl(c)   ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
167 #else
168 #   define Iscntrl(c)   (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
169 #endif /* !defined(DSPMBYTE) */
170 #   if SOLARIS2 == 24
171     /* 
172      * From <casper@fwi.uva.nl> Casper Dik:
173      * In Solaris 2.4, isprint('\t') returns true after setlocal(LC_ALL,"").
174      * This breaks commandline editing when you include tabs.
175      * (This is in the en_US locale).
176      */
177 #if defined(DSPMBYTE)
178 #    define IsprintM(c)         (((Char)(c) & QUOTE) ? 0 : \
179                                 (isprint((tcshuc) (c)) && (c) != '\t'))
180 #else
181 #    define Isprint(c)  (((Char)(c) & QUOTE) ? 0 : \
182                                 (isprint((tcshuc) (c)) && (c) != '\t'))
183 #endif /* !defined(DSPMBYTE) */
184 #   else
185 #if defined(DSPMBYTE)
186 #    define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
187 #else
188 #    define Isprint(c)  (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
189 #endif /* !defined(DSPMBYTE) */
190 #   endif /* SOLARIS2 == 24 */
191 #if defined(DSPMBYTE)
192 #   define Isprint(c)   ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
193 #endif /* !defined(DSPMBYTE) */
194 #    define Ispunct(c)  (((Char)(c) & QUOTE) ? 0 : ispunct((tcshuc) (c)))
195 #  else /* WINNT_NATIVE */
196 #   define Isspace(c) (((Char)(c) & QUOTE) ? 0 : isspace( oem_it((tcshuc)(c))))
197 #   define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : isdigit( oem_it((tcshuc)(c))))
198 #   define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : isalpha( oem_it((tcshuc)(c))))
199 #   define Islower(c) (((Char)(c) & QUOTE) ? 0 : islower( oem_it((tcshuc)(c))))
200 #   define Isupper(c) (((Char)(c) & QUOTE) ? 0 : isupper( oem_it((tcshuc)(c))))
201 #   define Tolower(c) (((Char)(c) & QUOTE) ? 0 : tolower( oem_it((tcshuc)(c))))
202 #   define Toupper(c) (((Char)(c) & QUOTE) ? 0 : toupper( oem_it((tcshuc)(c))))
203 #   define Isxdigit(c)(((Char)(c) & QUOTE) ? 0 : isxdigit(oem_it((tcshuc)(c))))
204 #   define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : isalnum( oem_it((tcshuc)(c))))
205 #   define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : ispunct( oem_it((tcshuc)(c))))
206 #if defined(DSPMBYTE)
207 #   define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
208 #   define Iscntrl(c)   ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
209 #   define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
210 #   define Isprint(c)   ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
211 #else
212 #   define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
213 #   define Isprint(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
214 #endif /* !defined(DSPMBYTE) */
215 #  endif /* WINNT_NATIVE */
216 # endif /* !NeXT */
217 #else /* !NLS */
218 # define Isspace(c)     cmap(c, _SP|_NL)
219 # define Isdigit(c)     cmap(c, _DIG)
220 # define Isalpha(c)     (cmap(c,_LET) && !(((c) & META) && AsciiOnly))
221 # define Islower(c)     (cmap(c,_DOW) && !(((c) & META) && AsciiOnly))
222 # define Isupper(c)     (cmap(c, _UP) && !(((c) & META) && AsciiOnly))
223 # ifdef IS_ASCII
224 #  define Tolower(c)    (_cmap_lower[(tcshuc)(c)])
225 #  define Toupper(c)    (_cmap_upper[(tcshuc)(c)])
226 # else
227 /* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */
228 #  define Tolower(c)    (_cmap_lower[_toascii[(tcshuc)(c)]])
229 #  define Toupper(c)    (_cmap_upper[_toascii[(tcshuc)(c)]])
230 # endif
231 # define Isxdigit(c)    cmap(c, _XD)
232 # define Isalnum(c)     (cmap(c, _DIG|_LET) && !(((Char)(c) & META) && AsciiOnly))
233 #if defined(DSPMBYTE)
234 # define IscntrlM(c)    (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
235 # define Iscntrl(c)     ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
236 # define IsprintM(c)    (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
237 # define Isprint(c)     ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
238 #else
239 # define Iscntrl(c)     (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
240 # define Isprint(c)     (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
241 #endif /* !defined(DSPMBYTE) */
242 # define Ispunct(c)     (cmap(c,_PUN) && !(((c) & META) && AsciiOnly))
243
244 #endif /* !NLS */
245
246 #if defined(DSPMBYTE)
247 # define Ismbyte1(c)    ((_mbmap[(c) & 0377] & _MB1) ? 1 : 0)
248 # define Ismbyte2(c)    ((_mbmap[(c) & 0377] & _MB2) ? 1 : 0)
249 #endif
250
251 #endif /* _h_sh_char */