xref: /openbsd/bin/ksh/tree.h (revision 07ea8d15)
1 /*	$OpenBSD: tree.h,v 1.2 1996/08/19 20:09:02 downsj Exp $	*/
2 
3 /*
4  * command trees for compile/execute
5  */
6 
7 /* $From: tree.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */
8 
9 #define	NOBLOCK	((struct op *)NULL)
10 #define	NOWORD	((char *)NULL)
11 #define	NOWORDS	((char **)NULL)
12 
13 /*
14  * Description of a command or an operation on commands.
15  */
16 struct op {
17 	short	type;			/* operation type, see below */
18 	union { /* WARNING: newtp(), tcopy() use evalflags = 0 to clear union */
19 		short	evalflags;	/* TCOM: arg expansion eval() flags */
20 		short	ksh_func;	/* TFUNC: function x (vs x()) */
21 	} u;
22 	char  **args;			/* arguments to a command */
23 	char  **vars;			/* variable assignments */
24 	struct ioword	**ioact;	/* IO actions (eg, < > >>) */
25 	struct op *left, *right; 	/* descendents */
26 	char   *str;			/* word for case; identifier for for,
27 					 * select, and functions;
28 					 * path to execute for TEXEC
29 					 */
30 };
31 
32 /* Tree.type values */
33 #define	TEOF		0
34 #define	TCOM		1	/* command */
35 #define	TPAREN		2	/* (c-list) */
36 #define	TPIPE		3	/* a | b */
37 #define	TLIST		4	/* a ; b */
38 #define	TOR		5	/* || */
39 #define	TAND		6	/* && */
40 #define TBANG		7	/* ! */
41 #define TDBRACKET	8	/* [[ .. ]] */
42 #define	TFOR		9
43 #define TSELECT		10
44 #define	TCASE		11
45 #define	TIF		12
46 #define	TWHILE		13
47 #define	TUNTIL		14
48 #define	TELIF		15
49 #define	TPAT		16	/* pattern in case */
50 #define	TBRACE		17	/* {c-list} */
51 #define	TASYNC		18	/* c & */
52 #define	TFUNCT		19	/* function name { command; } */
53 #define	TTIME		20	/* time pipeline */
54 #define	TEXEC		21	/* fork/exec eval'd TCOM */
55 #define TCOPROC		22	/* coprocess |& */
56 
57 /*
58  * prefix codes for words in command tree
59  */
60 #define	EOS	0		/* end of string */
61 #define	CHAR	1		/* unquoted character */
62 #define	QCHAR	2		/* quoted character */
63 #define	COMSUB	3		/* $() substitution (0 terminated) */
64 #define EXPRSUB	4		/* $(()) substitution (0 terminated) */
65 #define	OQUOTE	5		/* opening " or ' */
66 #define	CQUOTE	6		/* closing " or ' */
67 #define	OSUBST	7		/* opening ${ substitution */
68 #define	CSUBST	8		/* closing } of above */
69 #define OPAT	9		/* open pattern: *(, @(, etc. */
70 #define SPAT	10		/* seperate pattern: | */
71 #define CPAT	11		/* close pattern: ) */
72 
73 /*
74  * IO redirection
75  */
76 struct ioword {
77 	int	unit;	/* unit affected */
78 	int	flag;	/* action (below) */
79 	char	*name;	/* file name */
80 	char	*delim;	/* delimiter for <<,<<- */
81 };
82 
83 /* ioword.flag - type of redirection */
84 #define	IOTYPE	0xF		/* type: bits 0:3 */
85 #define	IOREAD	0x1		/* < */
86 #define	IOWRITE	0x2		/* > */
87 #define	IORDWR	0x3		/* <>: todo */
88 #define	IOHERE	0x4		/* << (here file) */
89 #define	IOCAT	0x5		/* >> */
90 #define	IODUP	0x6		/* <&/>& */
91 #define	IOEVAL	BIT(4)		/* expand in << */
92 #define	IOSKIP	BIT(5)		/* <<-, skip ^\t* */
93 #define	IOCLOB	BIT(6)		/* >|, override -o noclobber */
94 #define IORDUP	BIT(7)		/* x<&y (as opposed to x>&y) */
95 #define IONAMEXP BIT(8)		/* name has been expanded */
96 
97 /* execute/exchild flags */
98 #define	XEXEC	BIT(0)		/* execute without forking */
99 #define	XFORK	BIT(1)		/* fork before executing */
100 #define	XBGND	BIT(2)		/* command & */
101 #define	XPIPEI	BIT(3)		/* input is pipe */
102 #define	XPIPEO	BIT(4)		/* output is pipe */
103 #define	XPIPE	(XPIPEI|XPIPEO)	/* member of pipe */
104 #define	XXCOM	BIT(5)		/* `...` command */
105 #define	XPCLOSE	BIT(6)		/* exchild: close close_fd in parent */
106 #define	XCCLOSE	BIT(7)		/* exchild: close close_fd in child */
107 #define XERROK	BIT(8)		/* non-zero exit ok (for set -e) */
108 #define XCOPROC BIT(9)		/* starting a co-process */
109 
110 /*
111  * flags to control expansion of words (assumed by t->evalflags to fit
112  * in a short)
113  */
114 #define	DOBLANK	BIT(0)		/* perform blank interpretation */
115 #define	DOGLOB	BIT(1)		/* expand [?* */
116 #define	DOPAT	BIT(2)		/* quote *?[ */
117 #define	DOTILDE	BIT(3)		/* normal ~ expansion (first char) */
118 #define DONTRUNCOMMAND BIT(4)	/* do not run $(command) things */
119 #define DOASNTILDE BIT(5)	/* assignment ~ expansion (after =, :) */
120 #define DOBRACE_ BIT(6)		/* used by expand(): do brace expansion */
121 #define DOMAGIC_ BIT(7)		/* used by expand(): string contains MAGIC */
122 #define DOTEMP_	BIT(8)		/* ditto : in word part of ${..[%#=?]..} */
123 #define DOVACHECK BIT(9)	/* var assign check (for typeset, set, etc) */
124 #define DOMARKDIRS BIT(10)	/* force markdirs behaviour */
125 
126 /*
127  * The arguments of [[ .. ]] expressions are kept in t->args[] and flags
128  * indicating how the arguments have been munged are kept in t->vars[].
129  * The contents of t->vars[] are stuffed strings (so they can be treated
130  * like all other t->vars[]) in which the second character is the one that
131  * is examined.  The DB_* defines are the values for these second characters.
132  */
133 #define DB_NORM	1		/* normal argument */
134 #define DB_OR	2		/* || -> -o conversion */
135 #define DB_AND	3		/* && -> -a conversion */
136 #define DB_BE	4		/* an inserted -BE */
137 #define DB_PAT	5		/* a pattern argument */
138