2 |
- |
1 |
/*
|
|
|
2 |
* command trees for compile/execute
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
/* $Id: tree.h,v 1.3 1994/05/31 13:34:34 michael 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 |
* time hook for TCOM.
|
|
|
28 |
*/
|
|
|
29 |
int lineno; /* TCOM/TFUNC: LINENO for this */
|
|
|
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 ${ subst (followed by { or X) */
|
|
|
68 |
#define CSUBST 8 /* closing } of above (followed by } or X) */
|
|
|
69 |
#define OPAT 9 /* open pattern: *(, @(, etc. */
|
|
|
70 |
#define SPAT 10 /* separate 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 (unused if heredoc) */
|
|
|
80 |
char *delim; /* delimiter for <<,<<- */
|
|
|
81 |
char *heredoc;/* content of heredoc */
|
|
|
82 |
};
|
|
|
83 |
|
|
|
84 |
/* ioword.flag - type of redirection */
|
|
|
85 |
#define IOTYPE 0xF /* type: bits 0:3 */
|
|
|
86 |
#define IOREAD 0x1 /* < */
|
|
|
87 |
#define IOWRITE 0x2 /* > */
|
|
|
88 |
#define IORDWR 0x3 /* <>: todo */
|
|
|
89 |
#define IOHERE 0x4 /* << (here file) */
|
|
|
90 |
#define IOCAT 0x5 /* >> */
|
|
|
91 |
#define IODUP 0x6 /* <&/>& */
|
|
|
92 |
#define IOEVAL BIT(4) /* expand in << */
|
|
|
93 |
#define IOSKIP BIT(5) /* <<-, skip ^\t* */
|
|
|
94 |
#define IOCLOB BIT(6) /* >|, override -o noclobber */
|
|
|
95 |
#define IORDUP BIT(7) /* x<&y (as opposed to x>&y) */
|
|
|
96 |
#define IONAMEXP BIT(8) /* name has been expanded */
|
|
|
97 |
|
|
|
98 |
/* execute/exchild flags */
|
|
|
99 |
#define XEXEC BIT(0) /* execute without forking */
|
|
|
100 |
#define XFORK BIT(1) /* fork before executing */
|
|
|
101 |
#define XBGND BIT(2) /* command & */
|
|
|
102 |
#define XPIPEI BIT(3) /* input is pipe */
|
|
|
103 |
#define XPIPEO BIT(4) /* output is pipe */
|
|
|
104 |
#define XPIPE (XPIPEI|XPIPEO) /* member of pipe */
|
|
|
105 |
#define XXCOM BIT(5) /* `...` command */
|
|
|
106 |
#define XPCLOSE BIT(6) /* exchild: close close_fd in parent */
|
|
|
107 |
#define XCCLOSE BIT(7) /* exchild: close close_fd in child */
|
|
|
108 |
#define XERROK BIT(8) /* non-zero exit ok (for set -e) */
|
|
|
109 |
#define XCOPROC BIT(9) /* starting a co-process */
|
|
|
110 |
#define XTIME BIT(10) /* timeing TCOM command */
|
|
|
111 |
#define XINTACT BIT(11) /* OS2: proc started from interactive session */
|
|
|
112 |
|
|
|
113 |
/*
|
|
|
114 |
* flags to control expansion of words (assumed by t->evalflags to fit
|
|
|
115 |
* in a short)
|
|
|
116 |
*/
|
|
|
117 |
#define DOBLANK BIT(0) /* perform blank interpretation */
|
|
|
118 |
#define DOGLOB BIT(1) /* expand [?* */
|
|
|
119 |
#define DOPAT BIT(2) /* quote *?[ */
|
|
|
120 |
#define DOTILDE BIT(3) /* normal ~ expansion (first char) */
|
|
|
121 |
#define DONTRUNCOMMAND BIT(4) /* do not run $(command) things */
|
|
|
122 |
#define DOASNTILDE BIT(5) /* assignment ~ expansion (after =, :) */
|
|
|
123 |
#define DOBRACE_ BIT(6) /* used by expand(): do brace expansion */
|
|
|
124 |
#define DOMAGIC_ BIT(7) /* used by expand(): string contains MAGIC */
|
|
|
125 |
#define DOTEMP_ BIT(8) /* ditto : in word part of ${..[%#=?]..} */
|
|
|
126 |
#define DOVACHECK BIT(9) /* var assign check (for typeset, set, etc) */
|
|
|
127 |
#define DOMARKDIRS BIT(10) /* force markdirs behaviour */
|
|
|
128 |
|
|
|
129 |
/*
|
|
|
130 |
* The arguments of [[ .. ]] expressions are kept in t->args[] and flags
|
|
|
131 |
* indicating how the arguments have been munged are kept in t->vars[].
|
|
|
132 |
* The contents of t->vars[] are stuffed strings (so they can be treated
|
|
|
133 |
* like all other t->vars[]) in which the second character is the one that
|
|
|
134 |
* is examined. The DB_* defines are the values for these second characters.
|
|
|
135 |
*/
|
|
|
136 |
#define DB_NORM 1 /* normal argument */
|
|
|
137 |
#define DB_OR 2 /* || -> -o conversion */
|
|
|
138 |
#define DB_AND 3 /* && -> -a conversion */
|
|
|
139 |
#define DB_BE 4 /* an inserted -BE */
|
|
|
140 |
#define DB_PAT 5 /* a pattern argument */
|