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