]>
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; | |
9d9babb8 | 51 | const unsigned char *pcre_tables; |
9eceddee | 52 | kwset_t kws; |
c822255c | 53 | unsigned fixed:1; |
5183bf67 | 54 | unsigned ignore_case:1; |
d7eb527d | 55 | unsigned word_regexp:1; |
83b5d2f5 JH |
56 | }; |
57 | ||
58 | enum grep_expr_node { | |
59 | GREP_NODE_ATOM, | |
60 | GREP_NODE_NOT, | |
61 | GREP_NODE_AND, | |
5aaeb733 | 62 | GREP_NODE_TRUE, |
4b05548f | 63 | GREP_NODE_OR |
83b5d2f5 JH |
64 | }; |
65 | ||
84befcd0 S |
66 | enum grep_pattern_type { |
67 | GREP_PATTERN_TYPE_UNSPECIFIED = 0, | |
68 | GREP_PATTERN_TYPE_BRE, | |
69 | GREP_PATTERN_TYPE_ERE, | |
70 | GREP_PATTERN_TYPE_FIXED, | |
71 | GREP_PATTERN_TYPE_PCRE | |
72 | }; | |
73 | ||
83b5d2f5 JH |
74 | struct grep_expr { |
75 | enum grep_expr_node node; | |
0ab7befa | 76 | unsigned hit; |
83b5d2f5 JH |
77 | union { |
78 | struct grep_pat *atom; | |
79 | struct grep_expr *unary; | |
80 | struct { | |
81 | struct grep_expr *left; | |
82 | struct grep_expr *right; | |
83 | } binary; | |
84 | } u; | |
85 | }; | |
86 | ||
87 | struct grep_opt { | |
88 | struct grep_pat *pattern_list; | |
89 | struct grep_pat **pattern_tail; | |
80235ba7 JH |
90 | struct grep_pat *header_list; |
91 | struct grep_pat **header_tail; | |
83b5d2f5 | 92 | struct grep_expr *pattern_expression; |
493b7a08 | 93 | const char *prefix; |
83b5d2f5 JH |
94 | int prefix_length; |
95 | regex_t regexp; | |
3e230fa1 RS |
96 | int linenum; |
97 | int invert; | |
5183bf67 | 98 | int ignore_case; |
3e230fa1 RS |
99 | int status_only; |
100 | int name_only; | |
101 | int unmatch_name_only; | |
102 | int count; | |
103 | int word_regexp; | |
104 | int fixed; | |
105 | int all_match; | |
17bf35a3 | 106 | int debug; |
83b5d2f5 JH |
107 | #define GREP_BINARY_DEFAULT 0 |
108 | #define GREP_BINARY_NOMATCH 1 | |
109 | #define GREP_BINARY_TEXT 2 | |
3e230fa1 | 110 | int binary; |
335ec3bf | 111 | int allow_textconv; |
3e230fa1 | 112 | int extended; |
baa6378f | 113 | int use_reflog_filter; |
63e7e9d8 | 114 | int pcre; |
3e230fa1 RS |
115 | int relative; |
116 | int pathname; | |
117 | int null_following_name; | |
7e8f59d5 | 118 | int color; |
a91f453f | 119 | int max_depth; |
2944e4e6 | 120 | int funcname; |
ba8ea749 | 121 | int funcbody; |
84befcd0 S |
122 | int extended_regexp_option; |
123 | int pattern_type_option; | |
00588bb5 | 124 | char color_context[COLOR_MAXLEN]; |
55f638bd | 125 | char color_filename[COLOR_MAXLEN]; |
00588bb5 | 126 | char color_function[COLOR_MAXLEN]; |
55f638bd | 127 | char color_lineno[COLOR_MAXLEN]; |
79a77109 RS |
128 | char color_match_context[COLOR_MAXLEN]; |
129 | char color_match_selected[COLOR_MAXLEN]; | |
00588bb5 | 130 | char color_selected[COLOR_MAXLEN]; |
55f638bd | 131 | char color_sep[COLOR_MAXLEN]; |
83b5d2f5 JH |
132 | int regflags; |
133 | unsigned pre_context; | |
134 | unsigned post_context; | |
5dd06d38 | 135 | unsigned last_shown; |
046802d0 | 136 | int show_hunk_mark; |
a8f0e764 | 137 | int file_break; |
1d84f72e | 138 | int heading; |
60ecac98 | 139 | void *priv; |
5b594f45 FK |
140 | |
141 | void (*output)(struct grep_opt *opt, const void *data, size_t size); | |
142 | void *output_priv; | |
83b5d2f5 JH |
143 | }; |
144 | ||
7687a054 JH |
145 | extern void init_grep_defaults(void); |
146 | extern int grep_config(const char *var, const char *value, void *); | |
147 | extern void grep_init(struct grep_opt *, const char *prefix); | |
c5c31d33 | 148 | void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); |
7687a054 | 149 | |
ed40a095 | 150 | 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 | 151 | extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t); |
a4d7d2c6 | 152 | extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *); |
83b5d2f5 | 153 | extern void compile_grep_patterns(struct grep_opt *opt); |
b48fb5b6 | 154 | extern void free_grep_patterns(struct grep_opt *opt); |
c876d6da | 155 | extern int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size); |
83b5d2f5 | 156 | |
e1327023 JK |
157 | struct grep_source { |
158 | char *name; | |
159 | ||
160 | enum grep_source_type { | |
161 | GREP_SOURCE_SHA1, | |
162 | GREP_SOURCE_FILE, | |
163 | GREP_SOURCE_BUF, | |
164 | } type; | |
165 | void *identifier; | |
166 | ||
167 | char *buf; | |
168 | unsigned long size; | |
94ad9d9e | 169 | |
55c61688 | 170 | char *path; /* for attribute lookups */ |
94ad9d9e | 171 | struct userdiff_driver *driver; |
e1327023 JK |
172 | }; |
173 | ||
174 | void grep_source_init(struct grep_source *gs, enum grep_source_type type, | |
55c61688 NTND |
175 | const char *name, const char *path, |
176 | const void *identifier); | |
e1327023 JK |
177 | void grep_source_clear_data(struct grep_source *gs); |
178 | void grep_source_clear(struct grep_source *gs); | |
94ad9d9e | 179 | void grep_source_load_driver(struct grep_source *gs); |
07a7d656 | 180 | |
e1327023 JK |
181 | |
182 | int grep_source(struct grep_opt *opt, struct grep_source *gs); | |
183 | ||
5b594f45 FK |
184 | extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt); |
185 | extern int grep_threads_ok(const struct grep_opt *opt); | |
186 | ||
0579f91d TR |
187 | #ifndef NO_PTHREADS |
188 | /* | |
189 | * Mutex used around access to the attributes machinery if | |
190 | * opt->use_threads. Must be initialized/destroyed by callers! | |
191 | */ | |
78db6ea9 | 192 | extern int grep_use_locks; |
0579f91d | 193 | extern pthread_mutex_t grep_attr_mutex; |
b3aeb285 JK |
194 | extern pthread_mutex_t grep_read_mutex; |
195 | ||
196 | static inline void grep_read_lock(void) | |
197 | { | |
198 | if (grep_use_locks) | |
199 | pthread_mutex_lock(&grep_read_mutex); | |
200 | } | |
201 | ||
202 | static inline void grep_read_unlock(void) | |
203 | { | |
204 | if (grep_use_locks) | |
205 | pthread_mutex_unlock(&grep_read_mutex); | |
206 | } | |
207 | ||
208 | #else | |
209 | #define grep_read_lock() | |
210 | #define grep_read_unlock() | |
0579f91d TR |
211 | #endif |
212 | ||
83b5d2f5 | 213 | #endif |