sh.char.h revision 167466
122706Smpp/* $Header: /p/tcsh/cvsroot/tcsh/sh.char.h,v 3.32 2006/09/26 16:44:37 christos Exp $ */ 222706Smpp/* 322706Smpp * sh.char.h: Table for spotting special characters quickly 422706Smpp * Makes for very obscure but efficient coding. 522706Smpp */ 622706Smpp/*- 722706Smpp * Copyright (c) 1980, 1991 The Regents of the University of California. 822706Smpp * All rights reserved. 922706Smpp * 1022706Smpp * Redistribution and use in source and binary forms, with or without 1122706Smpp * modification, are permitted provided that the following conditions 1222706Smpp * are met: 1322706Smpp * 1. Redistributions of source code must retain the above copyright 1422706Smpp * notice, this list of conditions and the following disclaimer. 1522706Smpp * 2. Redistributions in binary form must reproduce the above copyright 1622706Smpp * notice, this list of conditions and the following disclaimer in the 1722706Smpp * documentation and/or other materials provided with the distribution. 1822706Smpp * 3. Neither the name of the University nor the names of its contributors 1922706Smpp * may be used to endorse or promote products derived from this software 2022706Smpp * without specific prior written permission. 2122706Smpp * 2222706Smpp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2322706Smpp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2422706Smpp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2522706Smpp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2622706Smpp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2722706Smpp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2822706Smpp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2922706Smpp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3022706Smpp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3150476Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3248795Snik * SUCH DAMAGE. 3322706Smpp */ 3422706Smpp#ifndef _h_sh_char 3579538Sru#define _h_sh_char 3622706Smpp#if defined(NeXT) && defined(NLS) 3722706Smpp# include <appkit/NXCType.h> 3822706Smpp#else 3922706Smpp# include <ctype.h> 4022706Smpp# ifdef WIDE_STRINGS 4122706Smpp# ifdef HAVE_WCTYPE_H 4284306Sru# include <wctype.h> 4384306Sru# else 4422706Smpp# include <wchar.h> 4522706Smpp# endif 4622706Smpp# endif 47231564Sed#endif 4822706Smpp 4922706Smpptypedef unsigned char tcshuc; 5022706Smpp#ifdef _MINIX 51131530Sru# undef _SP 52131530Sru#endif /* _MINIX */ 53131530Sruextern unsigned short _cmap[]; 5422706Smpp#if defined(DSPMBYTE) 5522706Smpp# define CHECK_MBYTEVAR STRdspmbyte 5622706Smpp#endif 5722706Smppextern unsigned short _cmap_c[]; 5857695Ssheldonhextern unsigned short _cmap_mbyte[]; 5957695Ssheldonhextern short _enable_mbdisp; 6022706Smppextern unsigned short _mbmap[]; 6122706Smppextern unsigned short _mbmap_euc[]; 6222706Smppextern unsigned short _mbmap_sjis[]; 6322706Smppextern unsigned short _mbmap_big5[]; 6422706Smppextern unsigned short _mbmap_utf8[]; 6522706Smpp/* VARIABLE Check str */ 6622706Smpp/* same compiler require #define even not define DSPMBYTE */ 6722706Smpp#define _MB1 0x0001 6822706Smpp#define _MB2 0x0002 6922706Smpp 7022706Smpp#ifndef NLS 7122706Smppextern tcshuc _cmap_lower[], _cmap_upper[]; 7222706Smpp 7370466Sru#endif 7422706Smpp 7522706Smpp#define _QF 0x0001 /* '" (Forward quotes) */ 76121379Shmp#define _QB 0x0002 /* ` (Backquote) */ 77121379Shmp#define _SP 0x0004 /* space and tab */ 7822706Smpp#define _NL 0x0008 /* \n */ 79#define _META 0x0010 /* lex meta characters, sp #'`";&<>()|\t\n */ 80#define _GLOB 0x0020 /* glob characters, *?{[` */ 81#define _ESC 0x0040 /* \ */ 82#define _DOL 0x0080 /* $ */ 83#define _DIG 0x0100 /* 0-9 */ 84#define _LET 0x0200 /* a-z, A-Z, _, or locale-specific */ 85#define _UP 0x0400 /* A-Z, or locale-specific */ 86#define _DOW 0x0800 /* a-z, or locale-specific */ 87#define _XD 0x1000 /* 0-9, a-f, A-F */ 88#define _CMD 0x2000 /* lex end of command chars, ;&(|` */ 89#define _CTR 0x4000 /* control */ 90#define _PUN 0x8000 /* punctuation */ 91 92#ifdef IS_ASCII 93# define ASC(ch) (ch) 94# define CTL_ESC(ch) (ch) 95#else 96# ifdef _OSD_POSIX 97/* "BS2000 OSD" is a POSIX on a main frame using a EBCDIC char set */ 98# include <ascii_ebcdic.h> 99# else 100/* "OS/390 USS" is a POSIX on a main frame using an IBM1047 char set */ 101# endif 102 extern unsigned short _toascii[256]; 103 extern 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#endif /*IS_ASCII*/ 113 114#ifdef WIDE_STRINGS 115# define cmap(c, bits) \ 116 (((c) < 0) ? 0 : \ 117 ((c) & QUOTE) || (c) >= 0x0080 ? 0 : (_cmap[(tcshuc)ASC(c)] & (bits))) 118#elif defined(SHORT_STRINGS) && defined(KANJI) 119# define cmap(c, bits) \ 120 (((c) < 0) ? 0 : \ 121 (((c) & QUOTE) || ((ASC(c) & 0x80) && adrof(STRnokanji))) ? \ 122 0 : (_cmap[(tcshuc)ASC(c)] & (bits))) 123#else /* SHORT_STRINGS && KANJI */ 124# define cmap(c, bits) \ 125 (((c) < 0) ? 0 : \ 126 ((c) & QUOTE) ? 0 : (_cmap[(tcshuc)ASC(c)] & (bits))) 127#endif /* SHORT_STRINGS && KANJI */ 128 129#define isglob(c) cmap((c), _GLOB) 130#define isspc(c) cmap((c), _SP) 131#define ismeta(c) cmap((c), _META) 132#define iscmdmeta(c) cmap((c), _CMD) 133#ifdef WIDE_STRINGS 134#define letter(c) (((c) & QUOTE) ? 0 : \ 135 (iswalpha((tcshuc) (c)) || (c) == '_')) 136#define alnum(c) (((c) & QUOTE) ? 0 : \ 137 (iswalnum((tcshuc) (c)) || (c) == '_')) 138#else 139#define letter(c) (((Char)(c) & QUOTE) ? 0 : \ 140 (isalpha((tcshuc) (c)) || (c) == '_')) 141#define alnum(c) (((Char)(c) & QUOTE) ? 0 : \ 142 (isalnum((tcshuc) (c)) || (c) == '_')) 143#endif 144 145#if defined(DSPMBYTE) 146# define IsmbyteU(c) (Ismbyte1((Char)(c))||(Ismbyte2((Char)(c))&&((c)&0200))) 147#endif 148 149#ifdef NLS 150# ifdef WIDE_STRINGS 151# define Isspace(c) (((c) & QUOTE) ? 0 : iswspace(c)) 152# define Isdigit(c) (((c) & QUOTE) ? 0 : iswdigit(c)) 153# define Isalpha(c) (((c) & QUOTE) ? 0 : iswalpha(c)) 154# define Islower(c) (((c) & QUOTE) ? 0 : iswlower(c)) 155# define Isupper(c) (((c) & QUOTE) ? 0 : iswupper(c)) 156# define Tolower(c) (((c) & QUOTE) ? 0 : (wchar_t)towlower(c)) 157# define Toupper(c) (((c) & QUOTE) ? 0 : (wchar_t)towupper(c)) 158# define Isxdigit(c) (((c) & QUOTE) ? 0 : iswxdigit(c)) 159# define Isalnum(c) (((c) & QUOTE) ? 0 : iswalnum(c)) 160# define Iscntrl(c) (((c) & QUOTE) ? 0 : iswcntrl(c)) 161# define Isprint(c) (((c) & QUOTE) ? 0 : iswprint(c)) 162# define Ispunct(c) (((c) & QUOTE) ? 0 : iswpunct(c)) 163# elif defined (NeXT) 164# define Isspace(c) (((Char)(c) & QUOTE) ? 0 : NXIsSpace((unsigned) (c))) 165# define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : NXIsDigit((unsigned) (c))) 166# define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : NXIsAlpha((unsigned) (c))) 167# define Islower(c) (((Char)(c) & QUOTE) ? 0 : NXIsLower((unsigned) (c))) 168# define Isupper(c) (((Char)(c) & QUOTE) ? 0 : NXIsUpper((unsigned) (c))) 169# define Tolower(c) (((Char)(c) & QUOTE) ? 0 : NXToLower((unsigned) (c))) 170# define Toupper(c) (((Char)(c) & QUOTE) ? 0 : NXToUpper((unsigned) (c))) 171# define Isxdigit(c) (((Char)(c) & QUOTE) ? 0 : NXIsXDigit((unsigned) (c))) 172#if defined(DSPMBYTE) 173# define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c))) 174# define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) ) 175# define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c))) 176# define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) ) 177#else 178# define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : NXIsAlNum((unsigned) (c))) 179# define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : NXIsCntrl((unsigned) (c))) 180# define Isprint(c) (((Char)(c) & QUOTE) ? 0 : NXIsPrint((unsigned) (c))) 181#endif /* !defined(DSPMBYTE) */ 182# define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : NXIsPunct((unsigned) (c))) 183# else /* !NeXT */ 184# ifndef WINNT_NATIVE 185# define Isspace(c) (((Char)(c) & QUOTE) ? 0 : isspace((tcshuc) (c))) 186# define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : isdigit((tcshuc) (c))) 187# define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : isalpha((tcshuc) (c))) 188# define Islower(c) (((Char)(c) & QUOTE) ? 0 : islower((tcshuc) (c))) 189# define Isupper(c) (((Char)(c) & QUOTE) ? 0 : isupper((tcshuc) (c))) 190# define Tolower(c) (((Char)(c) & QUOTE) ? 0 : tolower((tcshuc) (c))) 191# define Toupper(c) (((Char)(c) & QUOTE) ? 0 : toupper((tcshuc) (c))) 192# define Isxdigit(c) (((Char)(c) & QUOTE) ? 0 : isxdigit((tcshuc) (c))) 193# define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : isalnum((tcshuc) (c))) 194#if defined(DSPMBYTE) 195# define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c))) 196# define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) ) 197#else 198# define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : iscntrl((tcshuc) (c))) 199#endif /* !defined(DSPMBYTE) */ 200# if SOLARIS2 == 24 201 /* 202 * From <casper@fwi.uva.nl> Casper Dik: 203 * In Solaris 2.4, isprint('\t') returns true after setlocal(LC_ALL,""). 204 * This breaks commandline editing when you include tabs. 205 * (This is in the en_US locale). 206 */ 207#if defined(DSPMBYTE) 208# define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : \ 209 (isprint((tcshuc) (c)) && (c) != '\t')) 210#else 211# define Isprint(c) (((Char)(c) & QUOTE) ? 0 : \ 212 (isprint((tcshuc) (c)) && (c) != '\t')) 213#endif /* !defined(DSPMBYTE) */ 214# else 215#if defined(DSPMBYTE) 216# define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c))) 217#else 218# define Isprint(c) (((Char)(c) & QUOTE) ? 0 : isprint((tcshuc) (c))) 219#endif /* !defined(DSPMBYTE) */ 220# endif /* SOLARIS2 == 24 */ 221#if defined(DSPMBYTE) 222# define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) ) 223#endif /* !defined(DSPMBYTE) */ 224# define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : ispunct((tcshuc) (c))) 225# else /* WINNT_NATIVE */ 226# define Isspace(c) (((Char)(c) & QUOTE) ? 0 : isspace( oem_it((tcshuc)(c)))) 227# define Isdigit(c) (((Char)(c) & QUOTE) ? 0 : isdigit( oem_it((tcshuc)(c)))) 228# define Isalpha(c) (((Char)(c) & QUOTE) ? 0 : isalpha( oem_it((tcshuc)(c)))) 229# define Islower(c) (((Char)(c) & QUOTE) ? 0 : islower( oem_it((tcshuc)(c)))) 230# define Isupper(c) (((Char)(c) & QUOTE) ? 0 : isupper( oem_it((tcshuc)(c)))) 231# define Tolower(c) (((Char)(c) & QUOTE) ? 0 : tolower( oem_it((tcshuc)(c)))) 232# define Toupper(c) (((Char)(c) & QUOTE) ? 0 : toupper( oem_it((tcshuc)(c)))) 233# define Isxdigit(c)(((Char)(c) & QUOTE) ? 0 : isxdigit(oem_it((tcshuc)(c)))) 234# define Isalnum(c) (((Char)(c) & QUOTE) ? 0 : isalnum( oem_it((tcshuc)(c)))) 235# define Ispunct(c) (((Char)(c) & QUOTE) ? 0 : ispunct( oem_it((tcshuc)(c)))) 236#if defined(DSPMBYTE) 237# define IscntrlM(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c)))) 238# define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) ) 239# define IsprintM(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c)))) 240# define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) ) 241#else 242# define Iscntrl(c) (((Char)(c) & QUOTE) ? 0 : iscntrl( oem_it((tcshuc)(c)))) 243# define Isprint(c) (((Char)(c) & QUOTE) ? 0 : isprint( oem_it((tcshuc)(c)))) 244#endif /* !defined(DSPMBYTE) */ 245# endif /* WINNT_NATIVE */ 246# endif /* !NeXT */ 247#else /* !NLS */ 248# define Isspace(c) cmap((c), _SP|_NL) 249# define Isdigit(c) cmap((c), _DIG) 250# define Isalpha(c) (cmap((c),_LET) && !(((c) & META) && AsciiOnly)) 251# define Islower(c) (cmap((c),_DOW) && !(((c) & META) && AsciiOnly)) 252# define Isupper(c) (cmap((c), _UP) && !(((c) & META) && AsciiOnly)) 253# define Tolower(c) (_cmap_lower[ASC(c)]) 254# define Toupper(c) (_cmap_upper[ASC(c)]) 255# define Isxdigit(c) cmap((c), _XD) 256# define Isalnum(c) (cmap((c), _DIG|_LET) && !(((Char)(c) & META) && AsciiOnly)) 257#if defined(DSPMBYTE) 258# define IscntrlM(c) (cmap((c),_CTR) && !(((c) & META) && AsciiOnly)) 259# define Iscntrl(c) ( (IscntrlM(c)) && !(_enable_mbdisp&&(IsmbyteU((c)))) ) 260# define IsprintM(c) (!cmap((c),_CTR) && !(((c) & META) && AsciiOnly)) 261# define Isprint(c) ( (IsprintM(c)) || (_enable_mbdisp&&(IsmbyteU((c)))) ) 262#else 263# define Iscntrl(c) (cmap((c),_CTR) && !(((c) & META) && AsciiOnly)) 264# define Isprint(c) (!cmap((c),_CTR) && !(((c) & META) && AsciiOnly)) 265#endif /* !defined(DSPMBYTE) */ 266# define Ispunct(c) (cmap((c),_PUN) && !(((c) & META) && AsciiOnly)) 267 268#endif /* !NLS */ 269 270#if defined(DSPMBYTE) 271# define Ismbyte1(c) ((_mbmap[(c) & 0377] & _MB1) ? 1 : 0) 272# define Ismbyte2(c) ((_mbmap[(c) & 0377] & _MB2) ? 1 : 0) 273#endif 274 275#endif /* _h_sh_char */ 276