Merge branch 'maint'
[alt-git.git] / grep.h
blobc5682973eaf696099b0d0367e21df6c0a4624836
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
11 enum grep_pat_token {
12 GREP_PATTERN,
13 GREP_PATTERN_HEAD,
14 GREP_PATTERN_BODY,
15 GREP_AND,
16 GREP_OPEN_PAREN,
17 GREP_CLOSE_PAREN,
18 GREP_NOT,
19 GREP_OR
22 enum grep_context {
23 GREP_CONTEXT_HEAD,
24 GREP_CONTEXT_BODY
27 enum grep_header_field {
28 GREP_HEADER_AUTHOR = 0,
29 GREP_HEADER_COMMITTER
31 #define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
33 struct grep_pat {
34 struct grep_pat *next;
35 const char *origin;
36 int no;
37 enum grep_pat_token token;
38 const char *pattern;
39 size_t patternlen;
40 enum grep_header_field field;
41 regex_t regexp;
42 pcre *pcre_regexp;
43 pcre_extra *pcre_extra_info;
44 unsigned fixed:1;
45 unsigned ignore_case:1;
46 unsigned word_regexp:1;
49 enum grep_expr_node {
50 GREP_NODE_ATOM,
51 GREP_NODE_NOT,
52 GREP_NODE_AND,
53 GREP_NODE_TRUE,
54 GREP_NODE_OR
57 struct grep_expr {
58 enum grep_expr_node node;
59 unsigned hit;
60 union {
61 struct grep_pat *atom;
62 struct grep_expr *unary;
63 struct {
64 struct grep_expr *left;
65 struct grep_expr *right;
66 } binary;
67 } u;
70 struct grep_opt {
71 struct grep_pat *pattern_list;
72 struct grep_pat **pattern_tail;
73 struct grep_pat *header_list;
74 struct grep_pat **header_tail;
75 struct grep_expr *pattern_expression;
76 const char *prefix;
77 int prefix_length;
78 regex_t regexp;
79 int linenum;
80 int invert;
81 int ignore_case;
82 int status_only;
83 int name_only;
84 int unmatch_name_only;
85 int count;
86 int word_regexp;
87 int fixed;
88 int all_match;
89 #define GREP_BINARY_DEFAULT 0
90 #define GREP_BINARY_NOMATCH 1
91 #define GREP_BINARY_TEXT 2
92 int binary;
93 int extended;
94 int pcre;
95 int relative;
96 int pathname;
97 int null_following_name;
98 int color;
99 int max_depth;
100 int funcname;
101 char color_context[COLOR_MAXLEN];
102 char color_filename[COLOR_MAXLEN];
103 char color_function[COLOR_MAXLEN];
104 char color_lineno[COLOR_MAXLEN];
105 char color_match[COLOR_MAXLEN];
106 char color_selected[COLOR_MAXLEN];
107 char color_sep[COLOR_MAXLEN];
108 int regflags;
109 unsigned pre_context;
110 unsigned post_context;
111 unsigned last_shown;
112 int show_hunk_mark;
113 int file_break;
114 int heading;
115 void *priv;
117 void (*output)(struct grep_opt *opt, const void *data, size_t size);
118 void *output_priv;
121 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);
122 extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
123 extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
124 extern void compile_grep_patterns(struct grep_opt *opt);
125 extern void free_grep_patterns(struct grep_opt *opt);
126 extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
128 extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
129 extern int grep_threads_ok(const struct grep_opt *opt);
131 #endif