1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #if defined(sun)
27 #pragma ident	"@(#)ctype.h	1.8	05/06/08 SMI"	/* SVr4.0 1.10.1.1 */
28 #endif
29 /*
30  * Copyright 2009-2019 J. Schilling
31  *
32  * @(#)ctype.h	1.10 19/09/28 2009-2019 J. Schilling
33  */
34 /*
35  *	UNIX shell
36  */
37 
38 
39 /* table 1 */
40 #define	T_SUB	01
41 #define	T_MET	02
42 #define	T_SPC	04
43 #define	T_DIP	010
44 #define	T_EOF	020
45 #define	T_EOR	040
46 #define	T_QOT	0100
47 #define	T_ESC	0200
48 
49 /* table 2 */
50 #define	T_BRC	01			/* '{'			*/
51 #define	T_DEF	02			/* defchars "}=-+?"	*/
52 #define	T_AST	04			/* '*' or '@'		*/
53 #define	T_DIG	010			/* Digits		*/
54 #define	T_SHN	040			/* Legal parameter characters */
55 #define	T_IDC	0100			/* Upper + Lower ID Characters */
56 #define	T_SET	0200			/* Parameter set '+'	*/
57 
58 /* for single chars */
59 #define	_TAB	(T_SPC)			/* '\11' (^I)	*/
60 #define	_SPC	(T_SPC)			/* ' '		*/
61 #define	_UPC	(T_IDC)			/* Upper case	*/
62 #define	_LPC	(T_IDC)			/* Lower case	*/
63 #define	_DIG	(T_DIG)			/* Digits	*/
64 #define	_EOF	(T_EOF)			/* '\0'		*/
65 #define	_EOR	(T_EOR)			/* '\n'		*/
66 #define	_BAR	(T_DIP)			/* '|'		*/
67 #define	_HAT	(T_MET)			/* '^'		*/
68 #define	_BRA	(T_MET)			/* '('		*/
69 #define	_KET	(T_MET)			/* ')'		*/
70 #define	_AMP	(T_DIP)			/* '&'		*/
71 #define	_SEM	(T_DIP)			/* ';'		*/
72 #define	_LT	(T_DIP)			/* '<'		*/
73 #define	_GT	(T_DIP)			/* '>'		*/
74 #define	_LQU	(T_QOT|T_ESC)		/* '`'		*/
75 #define	_BSL	(T_ESC)			/* '\\'		*/
76 #define	_DQU	(T_QOT|T_ESC)		/* '"'		*/
77 #define	_DOL1	(T_SUB|T_ESC)		/* '$'		*/
78 
79 #define	_CBR	T_BRC			/* '{'		*/
80 #define	_CKT	T_DEF			/* '}'		*/
81 #define	_AST	(T_AST)			/* '*'		*/
82 #define	_EQ	(T_DEF)			/* '='		*/
83 #define	_MIN	(T_DEF|T_SHN)		/* '-'		*/
84 #define	_PCS	(T_SHN)			/* '!'		*/
85 #ifdef	DO_SUBSTRING			/* ${parm%word}	*/
86 #define	_PCT	(T_DEF|T_SET)		/* '%'		*/
87 #define	_NUM	(T_DEF|T_SHN|T_SET)	/* '#'		*/
88 #else
89 #define	_PCT	(0)			/* '%'		*/
90 #define	_NUM	(T_SHN)			/* '#'		*/
91 #endif
92 #ifdef	DO_DOL_SLASH
93 #define	_SLA	(T_SHN)			/* '/'		*/
94 #else
95 #define	_SLA	(0)			/* '/'		*/
96 #endif
97 #define	_DOL2	(T_SHN)			/* '$'		*/
98 #define	_PLS	(T_DEF|T_SET)		/* '+'		*/
99 #define	_AT	(T_AST)			/* '@'		*/
100 #define	_QU	(T_DEF|T_SHN)		/* '?'		*/
101 
102 /* abbreviations for tests */
103 #define	_IDCH	(T_IDC|T_DIG)		/* Alphanumeric	*/
104 #define	_META	(T_SPC|T_DIP|T_MET|T_EOR) /* " |&;<>^()\n" */
105 
106 extern
107 #ifdef __STDC__
108 const
109 #endif
110 unsigned char	_ctype1[];
111 
112 /* nb these args are not call by value !!!! */
113 #define	space(c)	((c < QUOTE) && _ctype1[c]&(T_SPC))
114 #define	white(c)	((c < QUOTE) && _ctype1[c]&(T_SPC|T_EOR))
115 #define	eofmeta(c)	((c < QUOTE) && _ctype1[c]&(_META|T_EOF))
116 #define	qotchar(c)	((c < QUOTE) && _ctype1[c]&(T_QOT))
117 #define	eolchar(c)	((c < QUOTE) && _ctype1[c]&(T_EOR|T_EOF))
118 #define	dipchar(c)	((c < QUOTE) && _ctype1[c]&(T_DIP))
119 #define	subchar(c)	((c < QUOTE) && _ctype1[c]&(T_SUB|T_QOT))
120 #define	escchar(c)	((c < QUOTE) && _ctype1[c]&(T_ESC))
121 #define	escmeta(c)	((c < QUOTE) && _ctype1[c]&(_META|T_ESC))
122 
123 extern
124 #ifdef __STDC__
125 const
126 #endif
127 unsigned char   _ctype2[];
128 
129 #define	digit(c)	((c < QUOTE) && _ctype2[c]&(T_DIG))
130 #define	dolchar(c)	((c < QUOTE) && \
131 				_ctype2[c]&(T_AST|T_BRC|T_DIG|T_IDC|T_SHN))
132 #define	defchar(c)	((c < QUOTE) && _ctype2[c]&(T_DEF))
133 #define	setchar(c)	((c < QUOTE) && _ctype2[c]&(T_SET))
134 #define	digchar(c)	((c < QUOTE) && _ctype2[c]&(T_AST|T_DIG))
135 #define	letter(c)	((c < QUOTE) && _ctype2[c]&(T_IDC))
136 #define	alphanum(c)	((c < QUOTE) && _ctype2[c]&(_IDCH))
137 #define	astchar(c)	((c < QUOTE) && _ctype2[c]&(T_AST))
138