xref: /onnv-gate/usr/src/lib/libshell/common/include/argnod.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 ARG_RAW
224887Schin /*
234887Schin  *	struct to hold a word argument
244887Schin  *	Written by David Korn
254887Schin  *
264887Schin  */
274887Schin 
284887Schin #include	<stak.h>
294887Schin 
304887Schin struct ionod
314887Schin {
324887Schin 	unsigned	iofile;
334887Schin 	char		*ioname;
344887Schin 	struct ionod	*ionxt;
354887Schin 	struct ionod	*iolst;
364887Schin 	char		*iodelim;
374887Schin 	off_t		iooffset;
384887Schin 	long		iosize;
394887Schin 	char		*iovname;
404887Schin };
414887Schin 
424887Schin struct comnod
434887Schin {
444887Schin 	int		comtyp;
454887Schin 	struct ionod	*comio;
464887Schin 	struct argnod	*comarg;
474887Schin 	struct argnod	*comset;
484887Schin 	void		*comnamp;
494887Schin 	void		*comnamq;
504887Schin 	void		*comstate;
514887Schin 	int		comline;
524887Schin };
534887Schin 
544887Schin #define COMBITS		4
554887Schin #define COMMSK		((1<<COMBITS)-1)
564887Schin #define COMSCAN		(01<<COMBITS)
574887Schin #define COMFIXED	(02<<COMBITS)
584887Schin 
594887Schin struct slnod 	/* struct for link list of stacks */
604887Schin {
614887Schin 	struct slnod	*slnext;
624887Schin 	struct slnod	*slchild;
634887Schin 	Stak_t		*slptr;
6410898Sroland.mainz@nrubsig.org 	/* slpad aligns struct functnod = struct slnod + 1 on some architectures */
6510898Sroland.mainz@nrubsig.org 	struct slnod	*slpad;
664887Schin };
674887Schin 
684887Schin /*
694887Schin  * This struct is use to hold $* lists and arrays
704887Schin  */
714887Schin 
724887Schin struct dolnod
734887Schin {
748462SApril.Chin@Sun.COM 	int		dolrefcnt;	/* reference count */
758462SApril.Chin@Sun.COM 	int		dolmax;		/* size of dolval array */
768462SApril.Chin@Sun.COM 	int		dolnum;		/* number of elements */
778462SApril.Chin@Sun.COM 	int		dolbot;		/* current first element */
784887Schin 	struct dolnod	*dolnxt;	/* used when list are chained */
794887Schin 	char		*dolval[1];	/* array of value pointers */
804887Schin };
814887Schin 
824887Schin /*
834887Schin  * This struct is used to hold word arguments of variable size during
844887Schin  * parsing and during expansion.  The flags indicate what processing
854887Schin  * is required on the argument.
864887Schin  */
874887Schin 
884887Schin struct argnod
894887Schin {
904887Schin 	union
914887Schin 	{
924887Schin 		struct argnod	*ap;
934887Schin 		char		*cp;
944887Schin 	}		argnxt;
954887Schin 	union
964887Schin 	{
974887Schin 		struct argnod	*ap;
984887Schin 		char		*cp;
994887Schin 		int		len;
1004887Schin 	}		argchn;
1014887Schin 	unsigned char	argflag;
1024887Schin 	char		argval[4];
1034887Schin };
1044887Schin 
1054887Schin 
1064887Schin 
1074887Schin /* The following should evaluate to the offset of argval in argnod */
1084887Schin #define ARGVAL		offsetof(struct argnod,argval[0])
1094887Schin #define sh_argstr(ap)	((ap)->argflag&ARG_RAW?sh_fmtq((ap)->argval):(ap)->argval)
1104887Schin #define ARG_SPARE 1
1114887Schin 
1124887Schin 
1134887Schin /* legal argument flags */
1144887Schin #define ARG_RAW		0x1	/* string needs no processing */
1154887Schin #define ARG_MAKE	0x2	/* bit set during argument expansion */
1164887Schin #define ARG_COMSUB	0x2	/* command sub */
1174887Schin #define ARG_MAC		0x4	/* string needs macro expansion */
1184887Schin #define	ARG_EXP		0x8	/* string needs file expansion */
1194887Schin #define ARG_ASSIGN	0x10	/* argument is an assignment */
1204887Schin #define ARG_QUOTED	0x20	/* word contained quote characters */
1214887Schin #define ARG_MESSAGE	0x40	/* contains international string */
1224887Schin #define ARG_APPEND	0x80	/* for += assignment */
1234887Schin /*  The following can be passed as options to sh_macexpand() */
1244887Schin #define ARG_ARITH	0x100	/* arithmetic expansion */
1254887Schin #define ARG_OPTIMIZE	0x200	/* try to optimize */
1264887Schin #define ARG_NOGLOB	0x400	/* no file name expansion */
1274887Schin #define ARG_LET		0x800	/* processing let command arguments */
1288462SApril.Chin@Sun.COM #define ARG_ARRAYOK	0x1000	/* $x[sub] ==> ${x[sub]} */
1294887Schin 
1304887Schin extern struct dolnod	*sh_argcreate(char*[]);
1318462SApril.Chin@Sun.COM extern char 		*sh_argdolminus(void*);
1328462SApril.Chin@Sun.COM extern int		sh_argopts(int,char*[],void*);
1338462SApril.Chin@Sun.COM 
1344887Schin 
1354887Schin extern const char	e_heading[];
1364887Schin extern const char	e_off[];
1374887Schin extern const char	e_on[];
1384887Schin extern const char	e_sptbnl[];
1394887Schin extern const char	e_subst[];
1404887Schin extern const char	e_option[];
1414887Schin extern const char	e_exec[];
1424887Schin extern const char	e_devfdNN[];
1434887Schin extern const char	e_devfdstd[];
1444887Schin 
1454887Schin #endif /* ARG_RAW */
146