1*4887Schin /***********************************************************************
2*4887Schin *                                                                      *
3*4887Schin *               This software is part of the ast package               *
4*4887Schin *           Copyright (c) 1982-2007 AT&T Knowledge Ventures            *
5*4887Schin *                      and is licensed under the                       *
6*4887Schin *                  Common Public License, Version 1.0                  *
7*4887Schin *                      by AT&T Knowledge Ventures                      *
8*4887Schin *                                                                      *
9*4887Schin *                A copy of the License is available at                 *
10*4887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*4887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*4887Schin *                                                                      *
13*4887Schin *              Information and Software Systems Research               *
14*4887Schin *                            AT&T Research                             *
15*4887Schin *                           Florham Park NJ                            *
16*4887Schin *                                                                      *
17*4887Schin *                  David Korn <dgk@research.att.com>                   *
18*4887Schin *                                                                      *
19*4887Schin ***********************************************************************/
20*4887Schin #pragma prototyped
21*4887Schin #ifndef ARG_RAW
22*4887Schin /*
23*4887Schin  *	struct to hold a word argument
24*4887Schin  *	Written by David Korn
25*4887Schin  *
26*4887Schin  */
27*4887Schin 
28*4887Schin #include	<stak.h>
29*4887Schin 
30*4887Schin struct ionod
31*4887Schin {
32*4887Schin 	unsigned	iofile;
33*4887Schin 	char		*ioname;
34*4887Schin 	struct ionod	*ionxt;
35*4887Schin 	struct ionod	*iolst;
36*4887Schin 	char		*iodelim;
37*4887Schin 	off_t		iooffset;
38*4887Schin 	long		iosize;
39*4887Schin 	char		*iovname;
40*4887Schin };
41*4887Schin 
42*4887Schin struct comnod
43*4887Schin {
44*4887Schin 	int		comtyp;
45*4887Schin 	struct ionod	*comio;
46*4887Schin 	struct argnod	*comarg;
47*4887Schin 	struct argnod	*comset;
48*4887Schin 	void		*comnamp;
49*4887Schin 	void		*comnamq;
50*4887Schin 	void		*comstate;
51*4887Schin 	int		comline;
52*4887Schin };
53*4887Schin 
54*4887Schin #define COMBITS		4
55*4887Schin #define COMMSK		((1<<COMBITS)-1)
56*4887Schin #define COMSCAN		(01<<COMBITS)
57*4887Schin #define COMFIXED	(02<<COMBITS)
58*4887Schin 
59*4887Schin struct slnod 	/* struct for link list of stacks */
60*4887Schin {
61*4887Schin 	struct slnod	*slnext;
62*4887Schin 	struct slnod	*slchild;
63*4887Schin 	Stak_t		*slptr;
64*4887Schin };
65*4887Schin 
66*4887Schin /*
67*4887Schin  * This struct is use to hold $* lists and arrays
68*4887Schin  */
69*4887Schin 
70*4887Schin struct dolnod
71*4887Schin {
72*4887Schin 	short		dolrefcnt;	/* reference count */
73*4887Schin 	short		dolmax;		/* size of dolval array */
74*4887Schin 	short		dolnum;		/* number of elements */
75*4887Schin 	short		dolbot;		/* current first element */
76*4887Schin 	struct dolnod	*dolnxt;	/* used when list are chained */
77*4887Schin 	char		*dolval[1];	/* array of value pointers */
78*4887Schin };
79*4887Schin 
80*4887Schin /*
81*4887Schin  * This struct is used to hold word arguments of variable size during
82*4887Schin  * parsing and during expansion.  The flags indicate what processing
83*4887Schin  * is required on the argument.
84*4887Schin  */
85*4887Schin 
86*4887Schin struct argnod
87*4887Schin {
88*4887Schin 	union
89*4887Schin 	{
90*4887Schin 		struct argnod	*ap;
91*4887Schin 		char		*cp;
92*4887Schin 	}		argnxt;
93*4887Schin 	union
94*4887Schin 	{
95*4887Schin 		struct argnod	*ap;
96*4887Schin 		char		*cp;
97*4887Schin 		int		len;
98*4887Schin 	}		argchn;
99*4887Schin 	unsigned char	argflag;
100*4887Schin 	char		argval[4];
101*4887Schin };
102*4887Schin 
103*4887Schin 
104*4887Schin 
105*4887Schin /* The following should evaluate to the offset of argval in argnod */
106*4887Schin #define ARGVAL		offsetof(struct argnod,argval[0])
107*4887Schin #define sh_argstr(ap)	((ap)->argflag&ARG_RAW?sh_fmtq((ap)->argval):(ap)->argval)
108*4887Schin #define ARG_SPARE 1
109*4887Schin 
110*4887Schin 
111*4887Schin /* legal argument flags */
112*4887Schin #define ARG_RAW		0x1	/* string needs no processing */
113*4887Schin #define ARG_MAKE	0x2	/* bit set during argument expansion */
114*4887Schin #define ARG_COMSUB	0x2	/* command sub */
115*4887Schin #define ARG_MAC		0x4	/* string needs macro expansion */
116*4887Schin #define	ARG_EXP		0x8	/* string needs file expansion */
117*4887Schin #define ARG_ASSIGN	0x10	/* argument is an assignment */
118*4887Schin #define ARG_QUOTED	0x20	/* word contained quote characters */
119*4887Schin #define ARG_MESSAGE	0x40	/* contains international string */
120*4887Schin #define ARG_APPEND	0x80	/* for += assignment */
121*4887Schin /*  The following can be passed as options to sh_macexpand() */
122*4887Schin #define ARG_ARITH	0x100	/* arithmetic expansion */
123*4887Schin #define ARG_OPTIMIZE	0x200	/* try to optimize */
124*4887Schin #define ARG_NOGLOB	0x400	/* no file name expansion */
125*4887Schin #define ARG_LET		0x800	/* processing let command arguments */
126*4887Schin 
127*4887Schin extern char 		**sh_argbuild(int*,const struct comnod*,int);
128*4887Schin extern struct dolnod	*sh_argcreate(char*[]);
129*4887Schin extern char 		*sh_argdolminus(void);
130*4887Schin extern struct dolnod	*sh_argfree(struct dolnod*,int);
131*4887Schin extern struct dolnod	*sh_argnew(char*[],struct dolnod**);
132*4887Schin extern int		sh_argopts(int,char*[]);
133*4887Schin extern void 		sh_argreset(struct dolnod*,struct dolnod*);
134*4887Schin extern void 		sh_argset(char*[]);
135*4887Schin extern struct dolnod	*sh_arguse(void);
136*4887Schin 
137*4887Schin extern const char	e_heading[];
138*4887Schin extern const char	e_off[];
139*4887Schin extern const char	e_on[];
140*4887Schin extern const char	e_sptbnl[];
141*4887Schin extern const char	e_subst[];
142*4887Schin extern const char	e_option[];
143*4887Schin extern const char	e_exec[];
144*4887Schin extern const char	e_devfdNN[];
145*4887Schin extern const char	e_devfdstd[];
146*4887Schin 
147*4887Schin #endif /* ARG_RAW */
148