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