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