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