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