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