Commit | Line | Data |
---|---|---|
b98fec69 WJ |
1 | /*- |
2 | * Copyright (c) 1980, 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)char.h 5.6 (Berkeley) 6/4/91 | |
34 | */ | |
35 | ||
36 | #include <ctype.h> | |
37 | ||
38 | extern unsigned short _cmap[]; | |
39 | ||
40 | #ifndef NLS | |
41 | extern unsigned char _cmap_lower[], _cmap_upper[]; | |
42 | ||
43 | #endif | |
44 | ||
45 | #define _Q 0x0001 /* '" */ | |
46 | #define _Q1 0x0002 /* ` */ | |
47 | #define _SP 0x0004 /* space and tab */ | |
48 | #define _NL 0x0008 /* \n */ | |
49 | #define _META 0x0010 /* lex meta characters, sp #'`";&<>()|\t\n */ | |
50 | #define _GLOB 0x0020 /* glob characters, *?{[` */ | |
51 | #define _ESC 0x0040 /* \ */ | |
52 | #define _DOL 0x0080 /* $ */ | |
53 | #define _DIG 0x0100 /* 0-9 */ | |
54 | #define _LET 0x0200 /* a-z, A-Z, _ */ | |
55 | #define _UP 0x0400 /* A-Z */ | |
56 | #define _LOW 0x0800 /* a-z */ | |
57 | #define _XD 0x1000 /* 0-9, a-f, A-F */ | |
58 | #define _CMD 0x2000 /* lex end of command chars, ;&(|` */ | |
59 | #define _CTR 0x4000 /* control */ | |
60 | ||
61 | #define cmap(c, bits) \ | |
62 | (((c) & QUOTE) ? 0 : (_cmap[(unsigned char)(c)] & (bits))) | |
63 | ||
64 | #define isglob(c) cmap(c, _GLOB) | |
65 | #define isspc(c) cmap(c, _SP) | |
66 | #define ismeta(c) cmap(c, _META) | |
67 | #define iscmdmeta(c) cmap(c, _CMD) | |
68 | #define letter(c) (((c) & QUOTE) ? 0 : \ | |
69 | (isalpha((unsigned char) (c)) || (c) == '_')) | |
70 | #define alnum(c) (((c) & QUOTE) ? 0 : \ | |
71 | (isalnum((unsigned char) (c)) || (c) == '_')) | |
72 | #ifdef NLS | |
73 | #define Isspace(c) (((c) & QUOTE) ? 0 : isspace((unsigned char) (c))) | |
74 | #define Isdigit(c) (((c) & QUOTE) ? 0 : isdigit((unsigned char) (c))) | |
75 | #define Isalpha(c) (((c) & QUOTE) ? 0 : isalpha((unsigned char) (c))) | |
76 | #define Islower(c) (((c) & QUOTE) ? 0 : islower((unsigned char) (c))) | |
77 | #define Isupper(c) (((c) & QUOTE) ? 0 : isupper((unsigned char) (c))) | |
78 | #define Tolower(c) (((c) & QUOTE) ? 0 : tolower((unsigned char) (c))) | |
79 | #define Toupper(c) (((c) & QUOTE) ? 0 : toupper((unsigned char) (c))) | |
80 | #define Isxdigit(c) (((c) & QUOTE) ? 0 : isxdigit((unsigned char) (c))) | |
81 | #define Isalnum(c) (((c) & QUOTE) ? 0 : isalnum((unsigned char) (c))) | |
82 | #define Iscntrl(c) (((c) & QUOTE) ? 0 : iscntrl((unsigned char) (c))) | |
83 | #define Isprint(c) (((c) & QUOTE) ? 0 : isprint((unsigned char) (c))) | |
84 | #else | |
85 | #define Isspace(c) cmap(c, _SP|_NL) | |
86 | #define Isdigit(c) cmap(c, _DIG) | |
87 | #define Isalpha(c) (cmap(c,_LET) && !(((c) & META) && AsciiOnly)) | |
88 | #define Islower(c) (cmap(c,_LOW) && !(((c) & META) && AsciiOnly)) | |
89 | #define Isupper(c) (cmap(c, _UP) && !(((c) & META) && AsciiOnly)) | |
90 | #define Tolower(c) (_cmap_lower[(unsigned char)(c)]) | |
91 | #define Toupper(c) (_cmap_upper[(unsigned char)(c)]) | |
92 | #define Isxdigit(c) cmap(c, _XD) | |
93 | #define Isalnum(c) (cmap(c, _DIG|_LET) && !(((c) & META) && AsciiOnly)) | |
94 | #define Iscntrl(c) (cmap(c,_CTR) && !(((c) & META) && AsciiOnly)) | |
95 | #define Isprint(c) (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly)) | |
96 | #endif |