xref: /onnv-gate/usr/src/lib/libshell/common/include/shlex.h (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                  David Korn <dgk@research.att.com>                   *
184887Schin *                                                                      *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin #ifndef NOTSYM
224887Schin /*
234887Schin  *	UNIX shell
244887Schin  *	Written by David Korn
254887Schin  *	These are the definitions for the lexical analyzer
264887Schin  */
274887Schin 
284887Schin #include	<cdt.h>
294887Schin #include	"FEATURE/options"
304887Schin #include	"shnodes.h"
314887Schin #include	"shtable.h"
324887Schin #include	"lexstates.h"
334887Schin 
348462SApril.Chin@Sun.COM 
358462SApril.Chin@Sun.COM typedef struct  _shlex_
364887Schin {
374887Schin 	Shell_t		*sh;		/* pointer to the interpreter */
384887Schin 	struct argnod	*arg;		/* current word */
394887Schin 	struct ionod	*heredoc;	/* pending here document list */
404887Schin 	int		token;		/* current token number */
414887Schin 	int		lastline;	/* last line number */
424887Schin 	int		lasttok;	/* previous token number */
434887Schin 	int		digits;		/* numerical value with word token */
4410898Sroland.mainz@nrubsig.org 	int		nonstandard;	/* nonstandard construct in profile */
454887Schin 	char		aliasok;	/* on when alias is legal */
464887Schin 	char		assignok;	/* on when name=value is legal */
478462SApril.Chin@Sun.COM 	char		inexec;		/* on when processing exec */
488462SApril.Chin@Sun.COM 	char		intypeset;	/* on when processing typeset */
498462SApril.Chin@Sun.COM 	char		comp_assign;	/* in compound assignment */
508462SApril.Chin@Sun.COM 	char		comsub;		/* parsing command substitution */
514887Schin 	int		inlineno;	/* saved value of sh.inlineno */
524887Schin 	int		firstline;	/* saved value of sh.st.firstline */
534887Schin #if SHOPT_KIA
544887Schin 	Sfio_t		*kiafile;	/* kia output file */
554887Schin 	Sfio_t		*kiatmp;	/* kia reference file */
564887Schin 	unsigned long	script;		/* script entity number */
574887Schin 	unsigned long	fscript;	/* script file entity number */
584887Schin 	unsigned long	current;	/* current entity number */
594887Schin 	unsigned long	unknown;	/* <unknown> entity number */
604887Schin 	off_t		kiabegin;	/* offset of first entry */
614887Schin 	char		*scriptname;	/* name of script file */
624887Schin 	Dt_t		*entity_tree;	/* for entity ids */
634887Schin #endif /* SHOPT_KIA */
648462SApril.Chin@Sun.COM #ifdef  _SHLEX_PRIVATE
658462SApril.Chin@Sun.COM 	_SHLEX_PRIVATE
668462SApril.Chin@Sun.COM #endif
678462SApril.Chin@Sun.COM } Lex_t;
684887Schin 
694887Schin /* symbols for parsing */
704887Schin #define NL		'\n'
714887Schin #define NOTSYM		'!'
724887Schin #define SYMRES		0400		/* reserved word symbols */
734887Schin #define DOSYM		(SYMRES|01)
744887Schin #define FISYM		(SYMRES|02)
754887Schin #define ELIFSYM		(SYMRES|03)
764887Schin #define ELSESYM		(SYMRES|04)
774887Schin #define INSYM		(SYMRES|05)
784887Schin #define THENSYM		(SYMRES|06)
794887Schin #define DONESYM		(SYMRES|07)
804887Schin #define ESACSYM		(SYMRES|010)
814887Schin #define IFSYM		(SYMRES|011)
824887Schin #define FORSYM		(SYMRES|012)
834887Schin #define WHILESYM	(SYMRES|013)
844887Schin #define UNTILSYM	(SYMRES|014)
854887Schin #define CASESYM		(SYMRES|015)
864887Schin #define FUNCTSYM	(SYMRES|016)
874887Schin #define SELECTSYM	(SYMRES|017)
884887Schin #define TIMESYM		(SYMRES|020)
894887Schin #define NSPACESYM	(SYMRES|021)
904887Schin 
914887Schin #define SYMREP		01000		/* symbols for doubled characters */
924887Schin #define BREAKCASESYM	(SYMREP|';')
934887Schin #define ANDFSYM		(SYMREP|'&')
944887Schin #define ORFSYM		(SYMREP|'|')
954887Schin #define IOAPPSYM	(SYMREP|'>')
964887Schin #define IODOCSYM	(SYMREP|'<')
974887Schin #define EXPRSYM		(SYMREP|'(')
984887Schin #define BTESTSYM 	(SYMREP|'[')
994887Schin #define ETESTSYM	(SYMREP|']')
1004887Schin 
1014887Schin #define SYMMASK		0170000
1024887Schin #define SYMPIPE		010000	/* trailing '|' */
1034887Schin #define SYMLPAR		020000	/* trailing LPAREN */
1044887Schin #define SYMAMP		040000	/* trailing '&' */
1054887Schin #define SYMGT		0100000	/* trailing '>' */
1064887Schin #define SYMSEMI		0110000	/* trailing ';' */
1074887Schin #define SYMSHARP	0120000	/* trailing '#' */
1084887Schin #define IOSEEKSYM	(SYMSHARP|'<')
1094887Schin #define IOMOV0SYM	(SYMAMP|'<')
1104887Schin #define IOMOV1SYM	(SYMAMP|'>')
1114887Schin #define FALLTHRUSYM	(SYMAMP|';')
1124887Schin #define COOPSYM		(SYMAMP|'|')
1134887Schin #define IORDWRSYM	(SYMGT|'<')
11410898Sroland.mainz@nrubsig.org #define IORDWRSYMT	(SYMSEMI|'<')
1154887Schin #define IOCLOBSYM	(SYMPIPE|'>')
1164887Schin #define IPROCSYM	(SYMLPAR|'<')
1174887Schin #define OPROCSYM	(SYMLPAR|'>')
1184887Schin #define EOFSYM		04000	/* end-of-file */
1194887Schin #define TESTUNOP	04001
1204887Schin #define TESTBINOP	04002
1214887Schin #define LABLSYM		04003
1224887Schin #define IOVNAME		04004
1234887Schin 
1244887Schin /* additional parser flag, others in <shell.h> */
1254887Schin #define SH_EMPTY	04
1264887Schin #define SH_NOIO		010
1274887Schin #define	SH_ASSIGN	020
1284887Schin #define	SH_FUNDEF	040
1294887Schin #define SH_ARRAY	0100
1304887Schin #define SH_SEMI		0200	/* semi-colon after NL ok */
1314887Schin 
1324887Schin #define SH_COMPASSIGN	010	/* allow compound assignments only */
1334887Schin 
1348462SApril.Chin@Sun.COM #if 0
1354887Schin typedef struct  _shlex_
1364887Schin {
1374887Schin 	struct shlex_t		_shlex;
1384887Schin #ifdef  _SHLEX_PRIVATE
1394887Schin 	_SHLEX_PRIVATE
1404887Schin #endif
1414887Schin } Lex_t;
1424887Schin 
1434887Schin #define	shlex			(((Lex_t*)(sh.lex_context))->_shlex)
1448462SApril.Chin@Sun.COM #endif
1454887Schin extern const char		e_unexpected[];
1464887Schin extern const char		e_unmatched[];
1474887Schin extern const char		e_endoffile[];
1484887Schin extern const char		e_newline[];
1494887Schin 
1504887Schin /* odd chars */
1514887Schin #define LBRACE	'{'
1524887Schin #define RBRACE	'}'
1534887Schin #define LPAREN	'('
1544887Schin #define RPAREN	')'
1554887Schin #define LBRACT	'['
1564887Schin #define RBRACT	']'
1574887Schin 
1588462SApril.Chin@Sun.COM extern int		sh_lex(Lex_t*);
1598462SApril.Chin@Sun.COM extern Shnode_t		*sh_dolparen(Lex_t*);
1604887Schin extern Lex_t		*sh_lexopen(Lex_t*, Shell_t*, int);
1618462SApril.Chin@Sun.COM extern void 		sh_lexskip(Lex_t*,int,int,int);
1628462SApril.Chin@Sun.COM extern void 		sh_syntax(Lex_t*);
1638462SApril.Chin@Sun.COM #if SHOPT_KIA
1648462SApril.Chin@Sun.COM     extern int                  kiaclose(Lex_t *);
1658462SApril.Chin@Sun.COM     extern unsigned long        kiaentity(Lex_t*, const char*,int,int,int,int,unsigned long,int,int,const char*);
1668462SApril.Chin@Sun.COM #endif /* SHOPT_KIA */
1678462SApril.Chin@Sun.COM 
1684887Schin 
1694887Schin #endif /* !NOTSYM */
170