xref: /titanic_41/usr/src/lib/libshell/common/include/argnod.h (revision e521049d0fdbd76727f036cb77c99c98d7ee1125)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
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 	/* slpad aligns struct functnod = struct slnod + 1 on some architectures */
65 	struct slnod	*slpad;
66 };
67 
68 /*
69  * This struct is use to hold $* lists and arrays
70  */
71 
72 struct dolnod
73 {
74 	int		dolrefcnt;	/* reference count */
75 	int		dolmax;		/* size of dolval array */
76 	int		dolnum;		/* number of elements */
77 	int		dolbot;		/* current first element */
78 	struct dolnod	*dolnxt;	/* used when list are chained */
79 	char		*dolval[1];	/* array of value pointers */
80 };
81 
82 /*
83  * This struct is used to hold word arguments of variable size during
84  * parsing and during expansion.  The flags indicate what processing
85  * is required on the argument.
86  */
87 
88 struct argnod
89 {
90 	union
91 	{
92 		struct argnod	*ap;
93 		char		*cp;
94 	}		argnxt;
95 	union
96 	{
97 		struct argnod	*ap;
98 		char		*cp;
99 		int		len;
100 	}		argchn;
101 	unsigned char	argflag;
102 	char		argval[4];
103 };
104 
105 
106 
107 /* The following should evaluate to the offset of argval in argnod */
108 #define ARGVAL		offsetof(struct argnod,argval[0])
109 #define sh_argstr(ap)	((ap)->argflag&ARG_RAW?sh_fmtq((ap)->argval):(ap)->argval)
110 #define ARG_SPARE 1
111 
112 
113 /* legal argument flags */
114 #define ARG_RAW		0x1	/* string needs no processing */
115 #define ARG_MAKE	0x2	/* bit set during argument expansion */
116 #define ARG_COMSUB	0x2	/* command sub */
117 #define ARG_MAC		0x4	/* string needs macro expansion */
118 #define	ARG_EXP		0x8	/* string needs file expansion */
119 #define ARG_ASSIGN	0x10	/* argument is an assignment */
120 #define ARG_QUOTED	0x20	/* word contained quote characters */
121 #define ARG_MESSAGE	0x40	/* contains international string */
122 #define ARG_APPEND	0x80	/* for += assignment */
123 /*  The following can be passed as options to sh_macexpand() */
124 #define ARG_ARITH	0x100	/* arithmetic expansion */
125 #define ARG_OPTIMIZE	0x200	/* try to optimize */
126 #define ARG_NOGLOB	0x400	/* no file name expansion */
127 #define ARG_LET		0x800	/* processing let command arguments */
128 #define ARG_ARRAYOK	0x1000	/* $x[sub] ==> ${x[sub]} */
129 
130 extern struct dolnod	*sh_argcreate(char*[]);
131 extern char 		*sh_argdolminus(void*);
132 extern int		sh_argopts(int,char*[],void*);
133 
134 
135 extern const char	e_heading[];
136 extern const char	e_off[];
137 extern const char	e_on[];
138 extern const char	e_sptbnl[];
139 extern const char	e_subst[];
140 extern const char	e_option[];
141 extern const char	e_exec[];
142 extern const char	e_devfdNN[];
143 extern const char	e_devfdstd[];
144 
145 #endif /* ARG_RAW */
146