]>
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" |
83b5d2f5 JH |
12 | |
13 | enum grep_pat_token { | |
14 | GREP_PATTERN, | |
480c1ca6 JH |
15 | GREP_PATTERN_HEAD, |
16 | GREP_PATTERN_BODY, | |
83b5d2f5 JH |
17 | GREP_AND, |
18 | GREP_OPEN_PAREN, | |
19 | GREP_CLOSE_PAREN, | |
20 | GREP_NOT, | |
4b05548f | 21 | GREP_OR |
83b5d2f5 JH |
22 | }; |
23 | ||
480c1ca6 JH |
24 | enum grep_context { |
25 | GREP_CONTEXT_HEAD, | |
4b05548f | 26 | GREP_CONTEXT_BODY |
480c1ca6 JH |
27 | }; |
28 | ||
a4d7d2c6 JH |
29 | enum grep_header_field { |
30 | GREP_HEADER_AUTHOR = 0, | |
4b05548f | 31 | GREP_HEADER_COMMITTER |
a4d7d2c6 | 32 | }; |
5aaeb733 | 33 | #define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1) |
a4d7d2c6 | 34 | |
83b5d2f5 JH |
35 | struct grep_pat { |
36 | struct grep_pat *next; | |
37 | const char *origin; | |
38 | int no; | |
39 | enum grep_pat_token token; | |
40 | const char *pattern; | |
ed40a095 | 41 | size_t patternlen; |
a4d7d2c6 | 42 | enum grep_header_field field; |
83b5d2f5 | 43 | regex_t regexp; |
63e7e9d8 MK |
44 | pcre *pcre_regexp; |
45 | pcre_extra *pcre_extra_info; | |
9eceddee | 46 | kwset_t kws; |
c822255c | 47 | unsigned fixed:1; |
5183bf67 | 48 | unsigned ignore_case:1; |
d7eb527d | 49 | unsigned word_regexp:1; |
83b5d2f5 JH |
50 | }; |
51 | ||
52 | enum grep_expr_node { | |
53 | GREP_NODE_ATOM, | |
54 | GREP_NODE_NOT, | |
55 | GREP_NODE_AND, | |
5aaeb733 | 56 | GREP_NODE_TRUE, |
4b05548f | 57 | GREP_NODE_OR |
83b5d2f5 JH |
58 | }; |
59 | ||
60 | struct grep_expr { | |
61 | enum grep_expr_node node; | |
0ab7befa | 62 | unsigned hit; |
83b5d2f5 JH |
63 | union { |
64 | struct grep_pat *atom; | |
65 | struct grep_expr *unary; | |
66 | struct { | |
67 | struct grep_expr *left; | |
68 | struct grep_expr *right; | |
69 | } binary; | |
70 | } u; | |
71 | }; | |
72 | ||
73 | struct grep_opt { | |
74 | struct grep_pat *pattern_list; | |
75 | struct grep_pat **pattern_tail; | |
80235ba7 JH |
76 | struct grep_pat *header_list; |
77 | struct grep_pat **header_tail; | |
83b5d2f5 | 78 | struct grep_expr *pattern_expression; |
493b7a08 | 79 | const char *prefix; |
83b5d2f5 JH |
80 | int prefix_length; |
81 | regex_t regexp; | |
3e230fa1 RS |
82 | int linenum; |
83 | int invert; | |
5183bf67 | 84 | int ignore_case; |
3e230fa1 RS |
85 | int status_only; |
86 | int name_only; | |
87 | int unmatch_name_only; | |
88 | int count; | |
89 | int word_regexp; | |
90 | int fixed; | |
91 | int all_match; | |
83b5d2f5 JH |
92 | #define GREP_BINARY_DEFAULT 0 |
93 | #define GREP_BINARY_NOMATCH 1 | |
94 | #define GREP_BINARY_TEXT 2 | |
3e230fa1 RS |
95 | int binary; |
96 | int extended; | |
63e7e9d8 | 97 | int pcre; |
3e230fa1 RS |
98 | int relative; |
99 | int pathname; | |
100 | int null_following_name; | |
7e8f59d5 | 101 | int color; |
a91f453f | 102 | int max_depth; |
2944e4e6 | 103 | int funcname; |
ba8ea749 | 104 | int funcbody; |
00588bb5 | 105 | char color_context[COLOR_MAXLEN]; |
55f638bd | 106 | char color_filename[COLOR_MAXLEN]; |
00588bb5 | 107 | char color_function[COLOR_MAXLEN]; |
55f638bd | 108 | char color_lineno[COLOR_MAXLEN]; |
7e8f59d5 | 109 | char color_match[COLOR_MAXLEN]; |
00588bb5 | 110 | char color_selected[COLOR_MAXLEN]; |
55f638bd | 111 | char color_sep[COLOR_MAXLEN]; |
83b5d2f5 JH |
112 | int regflags; |
113 | unsigned pre_context; | |
114 | unsigned post_context; | |
5dd06d38 | 115 | unsigned last_shown; |
046802d0 | 116 | int show_hunk_mark; |
a8f0e764 | 117 | int file_break; |
1d84f72e | 118 | int heading; |
0579f91d | 119 | int use_threads; |
60ecac98 | 120 | void *priv; |
5b594f45 FK |
121 | |
122 | void (*output)(struct grep_opt *opt, const void *data, size_t size); | |
123 | void *output_priv; | |
83b5d2f5 JH |
124 | }; |
125 | ||
ed40a095 | 126 | 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 | 127 | extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t); |
a4d7d2c6 | 128 | extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *); |
83b5d2f5 | 129 | extern void compile_grep_patterns(struct grep_opt *opt); |
b48fb5b6 | 130 | extern void free_grep_patterns(struct grep_opt *opt); |
83b5d2f5 JH |
131 | extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size); |
132 | ||
5b594f45 FK |
133 | extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt); |
134 | extern int grep_threads_ok(const struct grep_opt *opt); | |
135 | ||
0579f91d TR |
136 | #ifndef NO_PTHREADS |
137 | /* | |
138 | * Mutex used around access to the attributes machinery if | |
139 | * opt->use_threads. Must be initialized/destroyed by callers! | |
140 | */ | |
141 | extern pthread_mutex_t grep_attr_mutex; | |
142 | #endif | |
143 | ||
83b5d2f5 | 144 | #endif |