source: trunk/third/tcsh/sh.char.h @ 12039

Revision 12039, 10.6 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12038, which included commits to RCS files with non-trunk default branches.
Line 
1/* $Header: /afs/dev.mit.edu/source/repository/third/tcsh/sh.char.h,v 1.1.1.2 1998-10-03 21:09:56 danw 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
46typedef unsigned char tcshuc;
47#ifdef _MINIX
48# undef _SP
49#endif /* _MINIX */
50extern unsigned short _cmap[];
51#if defined(DSPMBYTE)
52extern unsigned short _mbmap[];
53# define CHECK_MBYTEVAR STRdspmbyte
54#endif
55extern unsigned short _cmap_c[];
56extern unsigned short _cmap_mbyte[];
57extern short _enable_mbdisp;
58extern unsigned short _mbmap[];
59extern unsigned short _mbmap_euc[];
60extern 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
67extern 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
95#ifndef _OSD_POSIX
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 /*_OSD_POSIX*/
101/* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */
102extern unsigned short _toascii[256];
103extern unsigned short _toebcdic[256];
104
105/* mainly for comparisons if (ASC(ch)=='\177')... */
106#define ASC(ch)     _toascii[(tcshuc)ch]
107
108/* Literal escapes ('\010') must be mapped to EBCDIC,
109 * for C-Escapes   ('\b'), the compiler already does it.
110 */
111#define CTL_ESC(ch) _toebcdic[(tcshuc)ch]
112
113#define cmap(c, bits)   \
114        (((c) & QUOTE) ? 0 : (_cmap[_toascii[(tcshuc)(c)]] & (bits)))
115#endif /*_OSD_POSIX*/
116#endif
117
118#define isglob(c)       cmap(c, _GLOB)
119#define isspc(c)        cmap(c, _SP)
120#define ismeta(c)       cmap(c, _META)
121#define iscmdmeta(c)    cmap(c, _CMD)
122#define letter(c)       (((Char)(c) & QUOTE) ? 0 : \
123                         (isalpha((tcshuc) (c)) || (c) == '_'))
124#define alnum(c)        (((Char)(c) & QUOTE) ? 0 : \
125                         (isalnum((tcshuc) (c)) || (c) == '_'))
126
127#if defined(DSPMBYTE)
128# define IsmbyteU(c)    (Ismbyte1((Char)(c))||(Ismbyte2((Char)(c))&&((c)&0200)))
129#endif
130
131#ifdef NLS
132# ifdef NeXT
133#  define Isspace(c)    (((Char)(c) & QUOTE) ? 0 : NXIsSpace((unsigned) (c)))
134#  define Isdigit(c)    (((Char)(c) & QUOTE) ? 0 : NXIsDigit((unsigned) (c)))
135#  define Isalpha(c)    (((Char)(c) & QUOTE) ? 0 : NXIsAlpha((unsigned) (c)))
136#  define Islower(c)    (((Char)(c) & QUOTE) ? 0 : NXIsLower((unsigned) (c)))
137#  define Isupper(c)    (((Char)(c) & QUOTE) ? 0 : NXIsUpper((unsigned) (c)))
138#  define Tolower(c)    (((Char)(c) & QUOTE) ? 0 : NXToLower((unsigned) (c)))
139#  define Toupper(c)    (((Char)(c) & QUOTE) ? 0 : NXToUpper((unsigned) (c)))
140#  define Isxdigit(c)   (((Char)(c) & QUOTE) ? 0 : NXIsXDigit((unsigned) (c)))
141#if defined(DSPMBYTE)
142#  define IscntrlM(c)   (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
143#  define Iscntrl(c)    ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
144#  define IsprintM(c)   (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
145#  define Isprint(c)    ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
146#else
147#  define Isalnum(c)    (((Char)(c) & QUOTE) ? 0 : NXIsAlNum((unsigned) (c)))
148#  define Iscntrl(c)    (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c)))
149#  define Isprint(c)    (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c)))
150#endif /* !defined(DSPMBYTE) */
151#  define Ispunct(c)    (((Char)(c) & QUOTE) ? 0 : NXIsPunct((unsigned) (c)))
152# else /* !NeXT */
153#  ifndef WINNT
154#   define Isspace(c)   (((Char)(c) & QUOTE) ? 0 : isspace((tcshuc) (c)))
155#   define Isdigit(c)   (((Char)(c) & QUOTE) ? 0 : isdigit((tcshuc) (c)))
156#   define Isalpha(c)   (((Char)(c) & QUOTE) ? 0 : isalpha((tcshuc) (c)))
157#   define Islower(c)   (((Char)(c) & QUOTE) ? 0 : islower((tcshuc) (c)))
158#   define Isupper(c)   (((Char)(c) & QUOTE) ? 0 : isupper((tcshuc) (c)))
159#   define Tolower(c)   (((Char)(c) & QUOTE) ? 0 : tolower((tcshuc) (c)))
160#   define Toupper(c)   (((Char)(c) & QUOTE) ? 0 : toupper((tcshuc) (c)))
161#   define Isxdigit(c)  (((Char)(c) & QUOTE) ? 0 : isxdigit((tcshuc) (c)))
162#   define Isalnum(c)   (((Char)(c) & QUOTE) ? 0 : isalnum((tcshuc) (c)))
163#if defined(DSPMBYTE)
164#   define IscntrlM(c)  (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
165#   define Iscntrl(c)   ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
166#else
167#   define Iscntrl(c)   (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c)))
168#endif /* !defined(DSPMBYTE) */
169#   if SOLARIS2 == 24
170    /*
171     * From <casper@fwi.uva.nl> Casper Dik:
172     * In Solaris 2.4, isprint('\t') returns true after setlocal(LC_ALL,"").
173     * This breaks commandline editing when you include tabs.
174     * (This is in the en_US locale).
175     */
176#if defined(DSPMBYTE)
177#    define IsprintM(c)         (((Char)(c) & QUOTE) ? 0 : \
178                                (isprint((tcshuc) (c)) && (c) != '\t'))
179#else
180#    define Isprint(c)  (((Char)(c) & QUOTE) ? 0 : \
181                                (isprint((tcshuc) (c)) && (c) != '\t'))
182#endif /* !defined(DSPMBYTE) */
183#   else
184#if defined(DSPMBYTE)
185#    define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
186#else
187#    define Isprint(c)  (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c)))
188#endif /* !defined(DSPMBYTE) */
189#   endif /* SOLARIS2 == 24 */
190#if defined(DSPMBYTE)
191#   define Isprint(c)   ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
192#endif /* !defined(DSPMBYTE) */
193#    define Ispunct(c)  (((Char)(c) & QUOTE) ? 0 : ispunct((tcshuc) (c)))
194#  else /* WINNT */
195#   define Isspace(c) (((Char)(c) & QUOTE) ? 0 : isspace( oem_it((tcshuc)(c))))
196#   define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : isdigit( oem_it((tcshuc)(c))))
197#   define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : isalpha( oem_it((tcshuc)(c))))
198#   define Islower(c) (((Char)(c) & QUOTE) ? 0 : islower( oem_it((tcshuc)(c))))
199#   define Isupper(c) (((Char)(c) & QUOTE) ? 0 : isupper( oem_it((tcshuc)(c))))
200#   define Tolower(c) (((Char)(c) & QUOTE) ? 0 : tolower( oem_it((tcshuc)(c))))
201#   define Toupper(c) (((Char)(c) & QUOTE) ? 0 : toupper( oem_it((tcshuc)(c))))
202#   define Isxdigit(c)(((Char)(c) & QUOTE) ? 0 : isxdigit(oem_it((tcshuc)(c))))
203#   define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : isalnum( oem_it((tcshuc)(c))))
204#   define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : ispunct( oem_it((tcshuc)(c))))
205#if defined(DSPMBYTE)
206#   define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
207#   define Iscntrl(c)   ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
208#   define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
209#   define Isprint(c)   ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
210#else
211#   define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c))))
212#   define Isprint(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c))))
213#endif /* !defined(DSPMBYTE) */
214#  endif /* WINNT */
215# endif /* !NeXT */
216#else /* !NLS */
217# define Isspace(c)     cmap(c, _SP|_NL)
218# define Isdigit(c)     cmap(c, _DIG)
219# define Isalpha(c)     (cmap(c,_LET) && !(((c) & META) && AsciiOnly))
220# define Islower(c)     (cmap(c,_DOW) && !(((c) & META) && AsciiOnly))
221# define Isupper(c)     (cmap(c, _UP) && !(((c) & META) && AsciiOnly))
222#ifndef _OSD_POSIX
223# define Tolower(c)     (_cmap_lower[(tcshuc)(c)])
224# define Toupper(c)     (_cmap_upper[(tcshuc)(c)])
225#else /*_OSD_POSIX*/
226/* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */
227# define Tolower(c)     (_cmap_lower[_toascii[(tcshuc)(c)]])
228# define Toupper(c)     (_cmap_upper[_toascii[(tcshuc)(c)]])
229#endif /*_OSD_POSIX*/
230# define Isxdigit(c)    cmap(c, _XD)
231# define Isalnum(c)     (cmap(c, _DIG|_LET) && !(((Char)(c) & META) && AsciiOnly))
232#if defined(DSPMBYTE)
233# define IscntrlM(c)    (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
234# define Iscntrl(c)     ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) )
235# define IsprintM(c)    (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
236# define Isprint(c)     ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) )
237#else
238# define Iscntrl(c)     (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
239# define Isprint(c)     (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
240#endif /* !defined(DSPMBYTE) */
241# define Ispunct(c)     (cmap(c,_PUN) && !(((c) & META) && AsciiOnly))
242
243#endif /* !NLS */
244
245#if defined(DSPMBYTE)
246# define Ismbyte1(c)    ((_mbmap[(c) & 0377] & _MB1) ? 1 : 0)
247# define Ismbyte2(c)    ((_mbmap[(c) & 0377] & _MB2) ? 1 : 0)
248#endif
249
250#endif /* _h_sh_char */
Note: See TracBrowser for help on using the repository browser.