#include <sys/types.h>
#include <regex.h>
#include <sys/stat.h>
typedef struct {
	char *wholename;
	char *name;
	struct stat stat;
	int filetype,access;
	int ts,accessts,statts;
	int prune;
	char *retname;
	regmatch_t matches[11];
} fileinfo;
#define INIT(var,tpe) var=malloc(sizeof(t_##tpe));var->tpe.tp=T_##tpe;
#define MT_stat(f) if (f.ts <f.statts) { stat(f.name ,&f.stats) statts=ts;}
#define MT_access(f) if (f.ts <f.accessts) {f.access=access(f.name);}
union _exp;
typedef union _exp exp;
typedef struct {int tp;
} t_expr;
typedef struct { int tp;
	char **buf;
  regex_t reg;
	int flags;
	fileinfo *f;
} t_regexp;
typedef struct {int tp;
	char **buf;
	char *pattern;
	int flags;
} t_wildcard;
typedef struct {int tp;
	int oper;
	exp *ex1,*ex2;
} t_logic;
enum {L_AND,L_OR,L_NOT,L_COMMA};
typedef struct {int tp;
	int stat;
	int val,comptp;
	fileinfo *f;
} t_stat;
typedef struct {int tp;
	int val;
	fileinfo *f;
} t_access;
typedef struct { int tp;
	fileinfo *f;
} t_prune;
typedef struct { int tp;
	fileinfo *f;
} t_print;
typedef struct { int tp;
	fileinfo *f;
	char *cmd;
} t_exec;
typedef struct { int tp;
	int val;
} t_boole;
enum {ST_ino,ST_mode,ST_nlink,ST_uid,ST_gid,ST_rdev,ST_size,ST_atime,ST_mtime,ST_ctime,ST_less,ST_greater,ST_equal,ST_subset,ST_superset};
enum {
	T_expr,T_regexp,T_wildcard,T_logic,T_stat,T_access,T_boole,T_prune,T_print,T_exec
};
union _exp{
	t_expr expr;
	t_regexp regexp;
	t_wildcard wildcard;
	t_stat stat;
	t_logic logic;
	t_access access;
	t_boole boole;
	t_prune prune;
	t_exec exec;
	t_print print;
};
int evaluate(exp *t);
