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