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