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