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