1 /* $OpenBSD: tree.h,v 1.12 2015/10/15 22:53:50 mmcc 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 /* 10 * Description of a command or an operation on commands. 11 */ 12 struct op { 13 short type; /* operation type, see below */ 14 union { /* WARNING: newtp(), tcopy() use evalflags = 0 to clear union */ 15 short evalflags; /* TCOM: arg expansion eval() flags */ 16 short ksh_func; /* TFUNC: function x (vs x()) */ 17 } u; 18 char **args; /* arguments to a command */ 19 char **vars; /* variable assignments */ 20 struct ioword **ioact; /* IO actions (eg, < > >>) */ 21 struct op *left, *right; /* descendents */ 22 char *str; /* word for case; identifier for for, 23 * select, and functions; 24 * path to execute for TEXEC; 25 * time hook for TCOM. 26 */ 27 int lineno; /* TCOM/TFUNC: LINENO for this */ 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 ${ subst (followed by { or X) */ 66 #define CSUBST 8 /* closing } of above (followed by } or X) */ 67 #define OPAT 9 /* open pattern: *(, @(, etc. */ 68 #define SPAT 10 /* separate 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 (unused if heredoc) */ 78 char *delim; /* delimiter for <<,<<- */ 79 char *heredoc;/* content of heredoc */ 80 }; 81 82 /* ioword.flag - type of redirection */ 83 #define IOTYPE 0xF /* type: bits 0:3 */ 84 #define IOREAD 0x1 /* < */ 85 #define IOWRITE 0x2 /* > */ 86 #define IORDWR 0x3 /* <>: todo */ 87 #define IOHERE 0x4 /* << (here file) */ 88 #define IOCAT 0x5 /* >> */ 89 #define IODUP 0x6 /* <&/>& */ 90 #define IOEVAL BIT(4) /* expand in << */ 91 #define IOSKIP BIT(5) /* <<-, skip ^\t* */ 92 #define IOCLOB BIT(6) /* >|, override -o noclobber */ 93 #define IORDUP BIT(7) /* x<&y (as opposed to x>&y) */ 94 #define IONAMEXP BIT(8) /* name has been expanded */ 95 96 /* execute/exchild flags */ 97 #define XEXEC BIT(0) /* execute without forking */ 98 #define XFORK BIT(1) /* fork before executing */ 99 #define XBGND BIT(2) /* command & */ 100 #define XPIPEI BIT(3) /* input is pipe */ 101 #define XPIPEO BIT(4) /* output is pipe */ 102 #define XPIPE (XPIPEI|XPIPEO) /* member of pipe */ 103 #define XXCOM BIT(5) /* `...` command */ 104 #define XPCLOSE BIT(6) /* exchild: close close_fd in parent */ 105 #define XCCLOSE BIT(7) /* exchild: close close_fd in child */ 106 #define XERROK BIT(8) /* non-zero exit ok (for set -e) */ 107 #define XCOPROC BIT(9) /* starting a co-process */ 108 #define XTIME BIT(10) /* timing TCOM command */ 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 139 void fptreef(struct shf *, int, const char *, ...); 140 char * snptreef(char *, int, const char *, ...); 141 struct op * tcopy(struct op *, Area *); 142 char * wdcopy(const char *, Area *); 143 char * wdscan(const char *, int); 144 char * wdstrip(const char *); 145 void tfree(struct op *, Area *); 146