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