grep.hon commit git-p4: clone does not use --git-dir (ef86890)
   1#ifndef GREP_H
   2#define GREP_H
   3#include "color.h"
   4#ifdef USE_LIBPCRE
   5#include <pcre.h>
   6#else
   7typedef int pcre;
   8typedef int pcre_extra;
   9#endif
  10#include "kwset.h"
  11
  12enum grep_pat_token {
  13        GREP_PATTERN,
  14        GREP_PATTERN_HEAD,
  15        GREP_PATTERN_BODY,
  16        GREP_AND,
  17        GREP_OPEN_PAREN,
  18        GREP_CLOSE_PAREN,
  19        GREP_NOT,
  20        GREP_OR
  21};
  22
  23enum grep_context {
  24        GREP_CONTEXT_HEAD,
  25        GREP_CONTEXT_BODY
  26};
  27
  28enum grep_header_field {
  29        GREP_HEADER_AUTHOR = 0,
  30        GREP_HEADER_COMMITTER
  31};
  32#define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
  33
  34struct grep_pat {
  35        struct grep_pat *next;
  36        const char *origin;
  37        int no;
  38        enum grep_pat_token token;
  39        const char *pattern;
  40        size_t patternlen;
  41        enum grep_header_field field;
  42        regex_t regexp;
  43        pcre *pcre_regexp;
  44        pcre_extra *pcre_extra_info;
  45        kwset_t kws;
  46        unsigned fixed:1;
  47        unsigned ignore_case:1;
  48        unsigned word_regexp:1;
  49};
  50
  51enum grep_expr_node {
  52        GREP_NODE_ATOM,
  53        GREP_NODE_NOT,
  54        GREP_NODE_AND,
  55        GREP_NODE_TRUE,
  56        GREP_NODE_OR
  57};
  58
  59struct grep_expr {
  60        enum grep_expr_node node;
  61        unsigned hit;
  62        union {
  63                struct grep_pat *atom;
  64                struct grep_expr *unary;
  65                struct {
  66                        struct grep_expr *left;
  67                        struct grep_expr *right;
  68                } binary;
  69        } u;
  70};
  71
  72struct grep_opt {
  73        struct grep_pat *pattern_list;
  74        struct grep_pat **pattern_tail;
  75        struct grep_pat *header_list;
  76        struct grep_pat **header_tail;
  77        struct grep_expr *pattern_expression;
  78        const char *prefix;
  79        int prefix_length;
  80        regex_t regexp;
  81        int linenum;
  82        int invert;
  83        int ignore_case;
  84        int status_only;
  85        int name_only;
  86        int unmatch_name_only;
  87        int count;
  88        int word_regexp;
  89        int fixed;
  90        int all_match;
  91#define GREP_BINARY_DEFAULT     0
  92#define GREP_BINARY_NOMATCH     1
  93#define GREP_BINARY_TEXT        2
  94        int binary;
  95        int extended;
  96        int pcre;
  97        int relative;
  98        int pathname;
  99        int null_following_name;
 100        int color;
 101        int max_depth;
 102        int funcname;
 103        int funcbody;
 104        char color_context[COLOR_MAXLEN];
 105        char color_filename[COLOR_MAXLEN];
 106        char color_function[COLOR_MAXLEN];
 107        char color_lineno[COLOR_MAXLEN];
 108        char color_match[COLOR_MAXLEN];
 109        char color_selected[COLOR_MAXLEN];
 110        char color_sep[COLOR_MAXLEN];
 111        int regflags;
 112        unsigned pre_context;
 113        unsigned post_context;
 114        unsigned last_shown;
 115        int show_hunk_mark;
 116        int file_break;
 117        int heading;
 118        void *priv;
 119
 120        void (*output)(struct grep_opt *opt, const void *data, size_t size);
 121        void *output_priv;
 122};
 123
 124extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
 125extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
 126extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
 127extern void compile_grep_patterns(struct grep_opt *opt);
 128extern void free_grep_patterns(struct grep_opt *opt);
 129extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
 130
 131extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
 132extern int grep_threads_ok(const struct grep_opt *opt);
 133
 134#endif