Home | History | Annotate | Line # | Download | only in ksh
c_test.h revision 1.1
      1  1.1  jtc /* Various types of operations.  Keeping things grouped nicely
      2  1.1  jtc  * (unary,binary) makes switch() statements more efficeint.
      3  1.1  jtc  */
      4  1.1  jtc enum Test_op {
      5  1.1  jtc 	TO_NONOP = 0,	/* non-operator */
      6  1.1  jtc 	/* unary operators */
      7  1.1  jtc 	TO_STNZE, TO_STZER, TO_OPTION,
      8  1.1  jtc 	TO_FILAXST,
      9  1.1  jtc 	TO_FILEXST,
     10  1.1  jtc 	TO_FILREG, TO_FILBDEV, TO_FILCDEV, TO_FILSYM, TO_FILFIFO, TO_FILSOCK,
     11  1.1  jtc 	TO_FILCDF, TO_FILID, TO_FILGID, TO_FILSETG, TO_FILSTCK, TO_FILUID,
     12  1.1  jtc 	TO_FILRD, TO_FILGZ, TO_FILTT, TO_FILSETU, TO_FILWR, TO_FILEX,
     13  1.1  jtc 	/* binary operators */
     14  1.1  jtc 	TO_STEQL, TO_STNEQ, TO_STLT, TO_STGT, TO_INTEQ, TO_INTNE, TO_INTGT,
     15  1.1  jtc 	TO_INTGE, TO_INTLT, TO_INTLE, TO_FILEQ, TO_FILNT, TO_FILOT
     16  1.1  jtc };
     17  1.1  jtc typedef enum Test_op Test_op;
     18  1.1  jtc 
     19  1.1  jtc /* Used by Test_env.isa() (order important - used to index *_tokens[] arrays) */
     20  1.1  jtc enum Test_meta {
     21  1.1  jtc 	TM_OR,		/* -o or || */
     22  1.1  jtc 	TM_AND,		/* -a or && */
     23  1.1  jtc 	TM_NOT,		/* ! */
     24  1.1  jtc 	TM_OPAREN,	/* ( */
     25  1.1  jtc 	TM_CPAREN,	/* ) */
     26  1.1  jtc 	TM_UNOP,	/* unary operator */
     27  1.1  jtc 	TM_BINOP,	/* binary operator */
     28  1.1  jtc 	TM_END		/* end of input */
     29  1.1  jtc };
     30  1.1  jtc typedef enum Test_meta Test_meta;
     31  1.1  jtc 
     32  1.1  jtc #define TEF_ERROR	BIT(0)		/* set if we've hit an error */
     33  1.1  jtc #define TEF_DBRACKET	BIT(1)		/* set if [[ .. ]] test */
     34  1.1  jtc 
     35  1.1  jtc typedef struct test_env Test_env;
     36  1.1  jtc struct test_env {
     37  1.1  jtc 	int	flags;		/* TEF_* */
     38  1.1  jtc 	union {
     39  1.1  jtc 		char	**wp;		/* used by ptest_* */
     40  1.1  jtc 		XPtrV	*av;		/* used by dbtestp_* */
     41  1.1  jtc 	} pos;
     42  1.1  jtc 	char **wp_end;			/* used by ptest_* */
     43  1.1  jtc 	int	(*isa) ARGS((Test_env *te, Test_meta meta));
     44  1.1  jtc 	const char *(*getopnd) ARGS((Test_env *te, Test_op op, int do_eval));
     45  1.1  jtc 	int	(*eval) ARGS((Test_env *te, Test_op op, const char *opnd1,
     46  1.1  jtc 				 const char *opnd2, int do_eval));
     47  1.1  jtc 	void	(*error) ARGS((Test_env *te, int offset, const char *msg));
     48  1.1  jtc };
     49  1.1  jtc 
     50  1.1  jtc Test_op	test_isop ARGS((Test_env *te, Test_meta meta, const char *s));
     51  1.1  jtc int     test_eval ARGS((Test_env *te, Test_op op, const char *opnd1,
     52  1.1  jtc 			const char *opnd2, int do_eval));
     53  1.1  jtc int	test_parse ARGS((Test_env *te));
     54