1#ifndef GREP_H2#define GREP_H34enum grep_pat_token {5GREP_PATTERN,6GREP_PATTERN_HEAD,7GREP_PATTERN_BODY,8GREP_AND,9GREP_OPEN_PAREN,10GREP_CLOSE_PAREN,11GREP_NOT,12GREP_OR,13};1415enum grep_context {16GREP_CONTEXT_HEAD,17GREP_CONTEXT_BODY,18};1920struct grep_pat {21struct grep_pat *next;22const char *origin;23int no;24enum grep_pat_token token;25const char *pattern;26regex_t regexp;27};2829enum grep_expr_node {30GREP_NODE_ATOM,31GREP_NODE_NOT,32GREP_NODE_AND,33GREP_NODE_OR,34};3536struct grep_expr {37enum grep_expr_node node;38union {39struct grep_pat *atom;40struct grep_expr *unary;41struct {42struct grep_expr *left;43struct grep_expr *right;44} binary;45} u;46};4748struct grep_opt {49struct grep_pat *pattern_list;50struct grep_pat **pattern_tail;51struct grep_expr *pattern_expression;52int prefix_length;53regex_t regexp;54unsigned linenum:1;55unsigned invert:1;56unsigned status_only:1;57unsigned name_only:1;58unsigned unmatch_name_only:1;59unsigned count:1;60unsigned word_regexp:1;61unsigned fixed:1;62#define GREP_BINARY_DEFAULT 063#define GREP_BINARY_NOMATCH 164#define GREP_BINARY_TEXT 265unsigned binary:2;66unsigned extended:1;67unsigned relative:1;68unsigned pathname:1;69int regflags;70unsigned pre_context;71unsigned post_context;72};7374extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);75extern void compile_grep_patterns(struct grep_opt *opt);76extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);7778#endif