Merge branch 'nd/i18n-parseopt-help'
[git/mingw.git] / grep.h
blob75afb7b10564a58f6427a03abccfb334facfea3b
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"
12 #include "userdiff.h"
14 enum grep_pat_token {
15 GREP_PATTERN,
16 GREP_PATTERN_HEAD,
17 GREP_PATTERN_BODY,
18 GREP_AND,
19 GREP_OPEN_PAREN,
20 GREP_CLOSE_PAREN,
21 GREP_NOT,
22 GREP_OR
25 enum grep_context {
26 GREP_CONTEXT_HEAD,
27 GREP_CONTEXT_BODY
30 enum grep_header_field {
31 GREP_HEADER_AUTHOR = 0,
32 GREP_HEADER_COMMITTER
34 #define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
36 struct grep_pat {
37 struct grep_pat *next;
38 const char *origin;
39 int no;
40 enum grep_pat_token token;
41 char *pattern;
42 size_t patternlen;
43 enum grep_header_field field;
44 regex_t regexp;
45 pcre *pcre_regexp;
46 pcre_extra *pcre_extra_info;
47 kwset_t kws;
48 unsigned fixed:1;
49 unsigned ignore_case:1;
50 unsigned word_regexp:1;
53 enum grep_expr_node {
54 GREP_NODE_ATOM,
55 GREP_NODE_NOT,
56 GREP_NODE_AND,
57 GREP_NODE_TRUE,
58 GREP_NODE_OR
61 enum 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
69 struct grep_expr {
70 enum grep_expr_node node;
71 unsigned hit;
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;
82 struct grep_opt {
83 struct grep_pat *pattern_list;
84 struct grep_pat **pattern_tail;
85 struct grep_pat *header_list;
86 struct grep_pat **header_tail;
87 struct grep_expr *pattern_expression;
88 const char *prefix;
89 int prefix_length;
90 regex_t regexp;
91 int linenum;
92 int invert;
93 int ignore_case;
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;
101 #define GREP_BINARY_DEFAULT 0
102 #define GREP_BINARY_NOMATCH 1
103 #define GREP_BINARY_TEXT 2
104 int binary;
105 int extended;
106 int pcre;
107 int relative;
108 int pathname;
109 int null_following_name;
110 int color;
111 int max_depth;
112 int funcname;
113 int funcbody;
114 int extended_regexp_option;
115 int pattern_type_option;
116 char color_context[COLOR_MAXLEN];
117 char color_filename[COLOR_MAXLEN];
118 char color_function[COLOR_MAXLEN];
119 char color_lineno[COLOR_MAXLEN];
120 char color_match[COLOR_MAXLEN];
121 char color_selected[COLOR_MAXLEN];
122 char color_sep[COLOR_MAXLEN];
123 int regflags;
124 unsigned pre_context;
125 unsigned post_context;
126 unsigned last_shown;
127 int show_hunk_mark;
128 int file_break;
129 int heading;
130 void *priv;
132 void (*output)(struct grep_opt *opt, const void *data, size_t size);
133 void *output_priv;
136 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);
137 extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
138 extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
139 extern void compile_grep_patterns(struct grep_opt *opt);
140 extern void free_grep_patterns(struct grep_opt *opt);
141 extern int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size);
143 struct grep_source {
144 char *name;
146 enum grep_source_type {
147 GREP_SOURCE_SHA1,
148 GREP_SOURCE_FILE,
149 GREP_SOURCE_BUF,
150 } type;
151 void *identifier;
153 char *buf;
154 unsigned long size;
156 struct userdiff_driver *driver;
159 void grep_source_init(struct grep_source *gs, enum grep_source_type type,
160 const char *name, const void *identifier);
161 int grep_source_load(struct grep_source *gs);
162 void grep_source_clear_data(struct grep_source *gs);
163 void grep_source_clear(struct grep_source *gs);
164 void grep_source_load_driver(struct grep_source *gs);
165 int grep_source_is_binary(struct grep_source *gs);
167 int grep_source(struct grep_opt *opt, struct grep_source *gs);
169 extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
170 extern int grep_threads_ok(const struct grep_opt *opt);
172 #ifndef NO_PTHREADS
174 * Mutex used around access to the attributes machinery if
175 * opt->use_threads. Must be initialized/destroyed by callers!
177 extern int grep_use_locks;
178 extern pthread_mutex_t grep_attr_mutex;
179 extern pthread_mutex_t grep_read_mutex;
181 static inline void grep_read_lock(void)
183 if (grep_use_locks)
184 pthread_mutex_lock(&grep_read_mutex);
187 static inline void grep_read_unlock(void)
189 if (grep_use_locks)
190 pthread_mutex_unlock(&grep_read_mutex);
193 #else
194 #define grep_read_lock()
195 #define grep_read_unlock()
196 #endif
198 #endif