grep.hon commit Merge branch 'maint-1.5.4' into maint (a473445)
   1#ifndef GREP_H
   2#define GREP_H
   3
   4enum grep_pat_token {
   5        GREP_PATTERN,
   6        GREP_PATTERN_HEAD,
   7        GREP_PATTERN_BODY,
   8        GREP_AND,
   9        GREP_OPEN_PAREN,
  10        GREP_CLOSE_PAREN,
  11        GREP_NOT,
  12        GREP_OR,
  13};
  14
  15enum grep_context {
  16        GREP_CONTEXT_HEAD,
  17        GREP_CONTEXT_BODY,
  18};
  19
  20struct grep_pat {
  21        struct grep_pat *next;
  22        const char *origin;
  23        int no;
  24        enum grep_pat_token token;
  25        const char *pattern;
  26        regex_t regexp;
  27};
  28
  29enum grep_expr_node {
  30        GREP_NODE_ATOM,
  31        GREP_NODE_NOT,
  32        GREP_NODE_AND,
  33        GREP_NODE_OR,
  34};
  35
  36struct grep_expr {
  37        enum grep_expr_node node;
  38        unsigned hit;
  39        union {
  40                struct grep_pat *atom;
  41                struct grep_expr *unary;
  42                struct {
  43                        struct grep_expr *left;
  44                        struct grep_expr *right;
  45                } binary;
  46        } u;
  47};
  48
  49struct grep_opt {
  50        struct grep_pat *pattern_list;
  51        struct grep_pat **pattern_tail;
  52        struct grep_expr *pattern_expression;
  53        int prefix_length;
  54        regex_t regexp;
  55        unsigned linenum:1;
  56        unsigned invert:1;
  57        unsigned status_only:1;
  58        unsigned name_only:1;
  59        unsigned unmatch_name_only:1;
  60        unsigned count:1;
  61        unsigned word_regexp:1;
  62        unsigned fixed:1;
  63        unsigned all_match:1;
  64#define GREP_BINARY_DEFAULT     0
  65#define GREP_BINARY_NOMATCH     1
  66#define GREP_BINARY_TEXT        2
  67        unsigned binary:2;
  68        unsigned extended:1;
  69        unsigned relative:1;
  70        unsigned pathname:1;
  71        int regflags;
  72        unsigned pre_context;
  73        unsigned post_context;
  74};
  75
  76extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
  77extern void compile_grep_patterns(struct grep_opt *opt);
  78extern void free_grep_patterns(struct grep_opt *opt);
  79extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
  80
  81#endif