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