xref: /titanic_41/usr/src/lib/libshell/common/include/lexstates.h (revision c93c462eec9d46f84d567abf52eb29a27c2e134b)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                  David Korn <dgk@research.att.com>                   *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 #ifndef S_BREAK
22 #define S_BREAK	1	/* end of token */
23 #define S_EOF	2	/* end of buffer */
24 #define S_NL	3	/* new-line when not a token */
25 #define S_RES	4	/* first character of reserved word */
26 #define S_NAME	5	/* other identifier characters */
27 #define S_REG	6	/* non-special characters */
28 #define S_TILDE	7	/* first char is tilde */
29 #define S_PUSH	8
30 #define S_POP	9
31 #define S_BRACT	10
32 #define S_LIT	11	/* literal quote character */
33 #define S_NLTOK	12	/* new-line token */
34 #define S_OP	13	/* operator character */
35 #define S_PAT	14	/* pattern characters * and ? */
36 #define S_EPAT	15	/* pattern char when followed by ( */
37 #define S_EQ	16	/* assignment character */
38 #define S_COM	17	/* comment character */
39 #define S_MOD1	18	/* ${...} modifier character - old quoting */
40 #define S_MOD2	19	/* ${...} modifier character - new quoting */
41 #define S_ERR	20	/* invalid character in ${...} */
42 #define S_SPC1	21	/* special prefix characters after $ */
43 #define S_SPC2	22	/* special characters after $ */
44 #define S_DIG	23	/* digit character after $*/
45 #define S_ALP	24	/* alpahbetic character after $ */
46 #define S_LBRA	25	/* left brace after $ */
47 #define S_RBRA	26	/* right brace after $ */
48 #define S_PAR	27	/* set for $( */
49 #define S_ENDCH	28	/* macro expansion terminator */
50 #define S_SLASH	29	/* / character terminates ~ expansion  */
51 #define S_COLON	30	/* for character : */
52 #define S_LABEL	31	/* for goto label */
53 #define S_EDOL	32	/* ends $identifier */
54 #define S_BRACE	33	/* left brace */
55 #define S_DOT	34	/* . char */
56 #define S_META	35	/* | & ; < > inside ${...} reserved for future use */
57 #define S_SPACE	S_BREAK	/* IFS space characters */
58 #define S_DELIM	S_RES	/* IFS delimter characters */
59 #define S_MBYTE S_NAME	/* IFS first byte of multi-byte char */
60 #define S_BLNK	36	/* space or tab */
61 /* The following must be the highest numbered states */
62 #define S_QUOTE	37	/* double quote character */
63 #define S_GRAVE	38	/* old comsub character */
64 #define S_ESC	39	/* escape character */
65 #define S_DOL	40	/* $ subsitution character */
66 #define S_ESC2	41	/* escape character inside '...' */
67 
68 /* These are the lexical state table names */
69 #define ST_BEGIN	0
70 #define ST_NAME		1
71 #define ST_NORM		2
72 #define ST_LIT		3
73 #define ST_QUOTE	4
74 #define ST_NESTED	5
75 #define ST_DOL		6
76 #define ST_BRACE	7
77 #define ST_DOLNAME	8
78 #define ST_MACRO	9
79 #define ST_QNEST	10
80 #define ST_NONE		11
81 
82 #include "FEATURE/locale"
83 
84 #if _hdr_wchar
85 #   include <wchar.h>
86 #   if _hdr_wctype
87 #       include <wctype.h>
88 #       undef  isalpha
89 #       define isalpha(x)      iswalpha(x)
90 #       if defined(iswblank) || _lib_iswblank
91 #           undef  isblank
92 #           define isblank(x)      iswblank(x)
93 #       else
94 #           if _lib_wctype && _lib_iswctype
95 #               define _lib_iswblank	-1
96 #               undef  isblank
97 #	        define isblank(x)	local_iswblank(x)
98 	        extern int		local_iswblank(wchar_t);
99 #           endif
100 #       endif
101 #   endif
102 #endif
103 #ifndef isblank
104 #   define isblank(x)      ((x)==' '||(x)=='\t')
105 #endif
106 
107 #undef LEN
108 #if SHOPT_MULTIBYTE
109     static int NXT, LEN;
110 #   define isaname(c)	((c)>0xff?isalpha(c): sh_lexstates[ST_NAME][(c)]==0)
111 #   define isaletter(c)	((c)>0xff?isalpha(c): sh_lexstates[ST_DOL][(c)]==S_ALP && (c)!='.')
112 #else
113 #   undef mbwide
114 #   define mbwide()	(0)
115 #   define LEN		1
116 #   define isaname(c)	(sh_lexstates[ST_NAME][c]==0)
117 #   define isaletter(c)	(sh_lexstates[ST_DOL][c]==S_ALP && (c)!='.')
118 #endif
119 #define STATE(s,c)  	(mbwide()?(c=fcmbstate(s,&NXT,&LEN),NXT):s[c=fcget()])
120 #define isadigit(c)	(sh_lexstates[ST_DOL][c]==S_DIG)
121 #define isastchar(c)	((c)=='@' || (c)=='*')
122 #define isexp(c)	(sh_lexstates[ST_MACRO][c]==S_PAT||(c)=='$'||(c)=='`')
123 #define ismeta(c)	(sh_lexstates[ST_NAME][c]==S_BREAK)
124 
125 extern char *sh_lexstates[ST_NONE];
126 extern const char *sh_lexrstates[ST_NONE];
127 extern const char e_lexversion[];
128 extern const char e_lexspace[];
129 extern const char e_lexslash[];
130 extern const char e_lexlabignore[];
131 extern const char e_lexlabunknown[];
132 extern const char e_lexsyntax1[];
133 extern const char e_lexsyntax2[];
134 extern const char e_lexsyntax3[];
135 extern const char e_lexobsolete1[];
136 extern const char e_lexobsolete2[];
137 extern const char e_lexobsolete3[];
138 extern const char e_lexobsolete4[];
139 extern const char e_lexobsolete5[];
140 extern const char e_lexobsolete6[];
141 extern const char e_lexusebrace[];
142 extern const char e_lexusequote[];
143 extern const char e_lexescape[];
144 extern const char e_lexquote[];
145 extern const char e_lexnested[];
146 extern const char e_lexbadchar[];
147 extern const char e_lexlongquote[];
148 extern const char e_lexfuture[];
149 extern const char e_lexzerobyte[];
150 extern const char e_lexemptyfor[];
151 extern const char e_lextypeset[];
152 #endif
153