Commit | Line | Data |
---|---|---|
83b5d2f5 JH |
1 | #ifndef GREP_H |
2 | #define GREP_H | |
7e8f59d5 | 3 | #include "color.h" |
63e7e9d8 MK |
4 | #ifdef USE_LIBPCRE |
5 | #include <pcre.h> | |
6 | #else | |
7 | typedef int pcre; | |
8 | typedef int pcre_extra; | |
9 | #endif | |
9eceddee | 10 | #include "kwset.h" |
0579f91d | 11 | #include "thread-utils.h" |
94ad9d9e | 12 | #include "userdiff.h" |
83b5d2f5 JH |
13 | |
14 | enum grep_pat_token { | |
15 | GREP_PATTERN, | |
480c1ca6 JH |
16 | GREP_PATTERN_HEAD, |
17 | GREP_PATTERN_BODY, | |
83b5d2f5 JH |
18 | GREP_AND, |
19 | GREP_OPEN_PAREN, | |
20 | GREP_CLOSE_PAREN, | |
21 | GREP_NOT, | |
4b05548f | 22 | GREP_OR |
83b5d2f5 JH |
23 | }; |
24 | ||
480c1ca6 JH |
25 | enum grep_context { |
26 | GREP_CONTEXT_HEAD, | |
4b05548f | 27 | GREP_CONTEXT_BODY |
480c1ca6 JH |
28 | }; |
29 | ||
a4d7d2c6 | 30 | enum grep_header_field { |
3ce3ffb8 AP |
31 | GREP_HEADER_FIELD_MIN = 0, |
32 | GREP_HEADER_AUTHOR = GREP_HEADER_FIELD_MIN, | |
ad4813b3 | 33 | GREP_HEADER_COMMITTER, |
72fd13f7 | 34 | GREP_HEADER_REFLOG, |
ad4813b3 NTND |
35 | |
36 | /* Must be at the end of the enum */ | |
37 | GREP_HEADER_FIELD_MAX | |
a4d7d2c6 JH |
38 | }; |
39 | ||
83b5d2f5 JH |
40 | struct grep_pat { |
41 | struct grep_pat *next; | |
42 | const char *origin; | |
43 | int no; | |
44 | enum grep_pat_token token; | |
526a858a | 45 | char *pattern; |
ed40a095 | 46 | size_t patternlen; |
a4d7d2c6 | 47 | enum grep_header_field field; |
83b5d2f5 | 48 | regex_t regexp; |
63e7e9d8 MK |
49 | pcre *pcre_regexp; |
50 | pcre_extra *pcre_extra_info; | |
9eceddee | 51 | kwset_t kws; |
c822255c | 52 | unsigned fixed:1; |
5183bf67 | 53 | unsigned ignore_case:1; |
d7eb527d | 54 | unsigned word_regexp:1; |
83b5d2f5 JH |
55 | }; |
56 | ||
57 | enum grep_expr_node { | |
58 | GREP_NODE_ATOM, | |
59 | GREP_NODE_NOT, | |
60 | GREP_NODE_AND, | |
5aaeb733 | 61 | GREP_NODE_TRUE, |
4b05548f | 62 | GREP_NODE_OR |
83b5d2f5 JH |
63 | }; |
64 | ||
84befcd0 S |
65 | enum grep_pattern_type { |
66 | GREP_PATTERN_TYPE_UNSPECIFIED = 0, | |
67 | GREP_PATTERN_TYPE_BRE, | |
68 | GREP_PATTERN_TYPE_ERE, | |
69 | GREP_PATTERN_TYPE_FIXED, | |
70 | GREP_PATTERN_TYPE_PCRE | |
71 | }; | |
72 | ||
83b5d2f5 JH |
73 | struct grep_expr { |
74 | enum grep_expr_node node; | |
0ab7befa | 75 | unsigned hit; |
83b5d2f5 JH |
76 | union { |
77 | struct grep_pat *atom; | |
78 | struct grep_expr *unary; | |
79 | struct { | |
80 | struct grep_expr *left; | |
81 | struct grep_expr *right; | |
82 | } binary; | |
83 | } u; | |
84 | }; | |
85 | ||
86 | struct grep_opt { | |
87 | struct grep_pat *pattern_list; | |
88 | struct grep_pat **pattern_tail; | |
80235ba7 JH |
89 | struct grep_pat *header_list; |
90 | struct grep_pat **header_tail; | |
83b5d2f5 | 91 | struct grep_expr *pattern_expression; |
493b7a08 | 92 | const char *prefix; |
83b5d2f5 JH |
93 | int prefix_length; |
94 | regex_t regexp; | |
3e230fa1 RS |
95 | int linenum; |
96 | int invert; | |
5183bf67 | 97 | int ignore_case; |
3e230fa1 RS |
98 | int status_only; |
99 | int name_only; | |
100 | int unmatch_name_only; | |
101 | int count; | |
102 | int word_regexp; | |
103 | int fixed; | |
104 | int all_match; | |
17bf35a3 | 105 | int debug; |
83b5d2f5 JH |
106 | #define GREP_BINARY_DEFAULT 0 |
107 | #define GREP_BINARY_NOMATCH 1 | |
108 | #define GREP_BINARY_TEXT 2 | |
3e230fa1 RS |
109 | int binary; |
110 | int extended; | |
baa6378f | 111 | int use_reflog_filter; |
63e7e9d8 | 112 | int pcre; |
3e230fa1 RS |
113 | int relative; |
114 | int pathname; | |
115 | int null_following_name; | |
7e8f59d5 | 116 | int color; |
a91f453f | 117 | int max_depth; |
2944e4e6 | 118 | int funcname; |
ba8ea749 | 119 | int funcbody; |
84befcd0 S |
120 | int extended_regexp_option; |
121 | int pattern_type_option; | |
00588bb5 | 122 | char color_context[COLOR_MAXLEN]; |
55f638bd | 123 | char color_filename[COLOR_MAXLEN]; |
00588bb5 | 124 | char color_function[COLOR_MAXLEN]; |
55f638bd | 125 | char color_lineno[COLOR_MAXLEN]; |
7e8f59d5 | 126 | char color_match[COLOR_MAXLEN]; |
00588bb5 | 127 | char color_selected[COLOR_MAXLEN]; |
55f638bd | 128 | char color_sep[COLOR_MAXLEN]; |
83b5d2f5 JH |
129 | int regflags; |
130 | unsigned pre_context; | |
131 | unsigned post_context; | |
5dd06d38 | 132 | unsigned last_shown; |
046802d0 | 133 | int show_hunk_mark; |
a8f0e764 | 134 | int file_break; |
1d84f72e | 135 | int heading; |
60ecac98 | 136 | void *priv; |
5b594f45 FK |
137 | |
138 | void (*output)(struct grep_opt *opt, const void *data, size_t size); | |
139 | void *output_priv; | |
83b5d2f5 JH |
140 | }; |
141 | ||
7687a054 JH |
142 | extern void init_grep_defaults(void); |
143 | extern int grep_config(const char *var, const char *value, void *); | |
144 | extern void grep_init(struct grep_opt *, const char *prefix); | |
c5c31d33 JH |
145 | void grep_set_pattern_type_option(enum grep_pattern_type, struct grep_opt *opt); |
146 | void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); | |
7687a054 | 147 | |
ed40a095 | 148 | 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); |
83b5d2f5 | 149 | extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t); |
a4d7d2c6 | 150 | extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *); |
83b5d2f5 | 151 | extern void compile_grep_patterns(struct grep_opt *opt); |
b48fb5b6 | 152 | extern void free_grep_patterns(struct grep_opt *opt); |
c876d6da | 153 | extern int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size); |
83b5d2f5 | 154 | |
e1327023 JK |
155 | struct grep_source { |
156 | char *name; | |
157 | ||
158 | enum grep_source_type { | |
159 | GREP_SOURCE_SHA1, | |
160 | GREP_SOURCE_FILE, | |
161 | GREP_SOURCE_BUF, | |
162 | } type; | |
163 | void *identifier; | |
164 | ||
165 | char *buf; | |
166 | unsigned long size; | |
94ad9d9e | 167 | |
55c61688 | 168 | char *path; /* for attribute lookups */ |
94ad9d9e | 169 | struct userdiff_driver *driver; |
e1327023 JK |
170 | }; |
171 | ||
172 | void grep_source_init(struct grep_source *gs, enum grep_source_type type, | |
55c61688 NTND |
173 | const char *name, const char *path, |
174 | const void *identifier); | |
e1327023 JK |
175 | void grep_source_clear_data(struct grep_source *gs); |
176 | void grep_source_clear(struct grep_source *gs); | |
94ad9d9e | 177 | void grep_source_load_driver(struct grep_source *gs); |
07a7d656 | 178 | |
e1327023 JK |
179 | |
180 | int grep_source(struct grep_opt *opt, struct grep_source *gs); | |
181 | ||
5b594f45 FK |
182 | extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt); |
183 | extern int grep_threads_ok(const struct grep_opt *opt); | |
184 | ||
0579f91d TR |
185 | #ifndef NO_PTHREADS |
186 | /* | |
187 | * Mutex used around access to the attributes machinery if | |
188 | * opt->use_threads. Must be initialized/destroyed by callers! | |
189 | */ | |
78db6ea9 | 190 | extern int grep_use_locks; |
0579f91d | 191 | extern pthread_mutex_t grep_attr_mutex; |
b3aeb285 JK |
192 | extern pthread_mutex_t grep_read_mutex; |
193 | ||
194 | static inline void grep_read_lock(void) | |
195 | { | |
196 | if (grep_use_locks) | |
197 | pthread_mutex_lock(&grep_read_mutex); | |
198 | } | |
199 | ||
200 | static inline void grep_read_unlock(void) | |
201 | { | |
202 | if (grep_use_locks) | |
203 | pthread_mutex_unlock(&grep_read_mutex); | |
204 | } | |
205 | ||
206 | #else | |
207 | #define grep_read_lock() | |
208 | #define grep_read_unlock() | |
0579f91d TR |
209 | #endif |
210 | ||
83b5d2f5 | 211 | #endif |