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