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