xref: /titanic_41/usr/src/lib/libshell/common/include/shlex.h (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2010 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 NOTSYM
22 /*
23  *	UNIX shell
24  *	Written by David Korn
25  *	These are the definitions for the lexical analyzer
26  */
27 
28 #include	<cdt.h>
29 #include	"FEATURE/options"
30 #include	"shnodes.h"
31 #include	"shtable.h"
32 #include	"lexstates.h"
33 
34 
35 typedef struct  _shlex_
36 {
37 	Shell_t		*sh;		/* pointer to the interpreter */
38 	struct argnod	*arg;		/* current word */
39 	struct ionod	*heredoc;	/* pending here document list */
40 	int		token;		/* current token number */
41 	int		lastline;	/* last line number */
42 	int		lasttok;	/* previous token number */
43 	int		digits;		/* numerical value with word token */
44 	int		nonstandard;	/* nonstandard construct in profile */
45 	char		aliasok;	/* on when alias is legal */
46 	char		assignok;	/* on when name=value is legal */
47 	char		inexec;		/* on when processing exec */
48 	char		intypeset;	/* on when processing typeset */
49 	char		comp_assign;	/* in compound assignment */
50 	char		comsub;		/* parsing command substitution */
51 	int		inlineno;	/* saved value of sh.inlineno */
52 	int		firstline;	/* saved value of sh.st.firstline */
53 #if SHOPT_KIA
54 	Sfio_t		*kiafile;	/* kia output file */
55 	Sfio_t		*kiatmp;	/* kia reference file */
56 	unsigned long	script;		/* script entity number */
57 	unsigned long	fscript;	/* script file entity number */
58 	unsigned long	current;	/* current entity number */
59 	unsigned long	unknown;	/* <unknown> entity number */
60 	off_t		kiabegin;	/* offset of first entry */
61 	char		*scriptname;	/* name of script file */
62 	Dt_t		*entity_tree;	/* for entity ids */
63 #endif /* SHOPT_KIA */
64 #ifdef  _SHLEX_PRIVATE
65 	_SHLEX_PRIVATE
66 #endif
67 } Lex_t;
68 
69 /* symbols for parsing */
70 #define NL		'\n'
71 #define NOTSYM		'!'
72 #define SYMRES		0400		/* reserved word symbols */
73 #define DOSYM		(SYMRES|01)
74 #define FISYM		(SYMRES|02)
75 #define ELIFSYM		(SYMRES|03)
76 #define ELSESYM		(SYMRES|04)
77 #define INSYM		(SYMRES|05)
78 #define THENSYM		(SYMRES|06)
79 #define DONESYM		(SYMRES|07)
80 #define ESACSYM		(SYMRES|010)
81 #define IFSYM		(SYMRES|011)
82 #define FORSYM		(SYMRES|012)
83 #define WHILESYM	(SYMRES|013)
84 #define UNTILSYM	(SYMRES|014)
85 #define CASESYM		(SYMRES|015)
86 #define FUNCTSYM	(SYMRES|016)
87 #define SELECTSYM	(SYMRES|017)
88 #define TIMESYM		(SYMRES|020)
89 #define NSPACESYM	(SYMRES|021)
90 
91 #define SYMREP		01000		/* symbols for doubled characters */
92 #define BREAKCASESYM	(SYMREP|';')
93 #define ANDFSYM		(SYMREP|'&')
94 #define ORFSYM		(SYMREP|'|')
95 #define IOAPPSYM	(SYMREP|'>')
96 #define IODOCSYM	(SYMREP|'<')
97 #define EXPRSYM		(SYMREP|'(')
98 #define BTESTSYM 	(SYMREP|'[')
99 #define ETESTSYM	(SYMREP|']')
100 
101 #define SYMMASK		0170000
102 #define SYMPIPE		010000	/* trailing '|' */
103 #define SYMLPAR		020000	/* trailing LPAREN */
104 #define SYMAMP		040000	/* trailing '&' */
105 #define SYMGT		0100000	/* trailing '>' */
106 #define SYMSEMI		0110000	/* trailing ';' */
107 #define SYMSHARP	0120000	/* trailing '#' */
108 #define IOSEEKSYM	(SYMSHARP|'<')
109 #define IOMOV0SYM	(SYMAMP|'<')
110 #define IOMOV1SYM	(SYMAMP|'>')
111 #define FALLTHRUSYM	(SYMAMP|';')
112 #define COOPSYM		(SYMAMP|'|')
113 #define IORDWRSYM	(SYMGT|'<')
114 #define IORDWRSYMT	(SYMSEMI|'<')
115 #define IOCLOBSYM	(SYMPIPE|'>')
116 #define IPROCSYM	(SYMLPAR|'<')
117 #define OPROCSYM	(SYMLPAR|'>')
118 #define EOFSYM		04000	/* end-of-file */
119 #define TESTUNOP	04001
120 #define TESTBINOP	04002
121 #define LABLSYM		04003
122 #define IOVNAME		04004
123 
124 /* additional parser flag, others in <shell.h> */
125 #define SH_EMPTY	04
126 #define SH_NOIO		010
127 #define	SH_ASSIGN	020
128 #define	SH_FUNDEF	040
129 #define SH_ARRAY	0100
130 #define SH_SEMI		0200	/* semi-colon after NL ok */
131 
132 #define SH_COMPASSIGN	010	/* allow compound assignments only */
133 
134 #if 0
135 typedef struct  _shlex_
136 {
137 	struct shlex_t		_shlex;
138 #ifdef  _SHLEX_PRIVATE
139 	_SHLEX_PRIVATE
140 #endif
141 } Lex_t;
142 
143 #define	shlex			(((Lex_t*)(sh.lex_context))->_shlex)
144 #endif
145 extern const char		e_unexpected[];
146 extern const char		e_unmatched[];
147 extern const char		e_endoffile[];
148 extern const char		e_newline[];
149 
150 /* odd chars */
151 #define LBRACE	'{'
152 #define RBRACE	'}'
153 #define LPAREN	'('
154 #define RPAREN	')'
155 #define LBRACT	'['
156 #define RBRACT	']'
157 
158 extern int		sh_lex(Lex_t*);
159 extern Shnode_t		*sh_dolparen(Lex_t*);
160 extern Lex_t		*sh_lexopen(Lex_t*, Shell_t*, int);
161 extern void 		sh_lexskip(Lex_t*,int,int,int);
162 extern void 		sh_syntax(Lex_t*);
163 #if SHOPT_KIA
164     extern int                  kiaclose(Lex_t *);
165     extern unsigned long        kiaentity(Lex_t*, const char*,int,int,int,int,unsigned long,int,int,const char*);
166 #endif /* SHOPT_KIA */
167 
168 
169 #endif /* !NOTSYM */
170