1#ifndef GREP_H
2#define GREP_H
3#include "color.h"
4#ifdef USE_LIBPCRE
5#include <pcre.h>
6#else
7typedef int pcre;
8typedef int pcre_extra;
9#endif
10
11enum 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
20};
21
22enum grep_context {
23 GREP_CONTEXT_HEAD,
24 GREP_CONTEXT_BODY
25};
26
27enum grep_header_field {
28 GREP_HEADER_AUTHOR = 0,
29 GREP_HEADER_COMMITTER
30};
31#define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
32
33struct 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;
47};
48
49enum grep_expr_node {
50 GREP_NODE_ATOM,
51 GREP_NODE_NOT,
52 GREP_NODE_AND,
53 GREP_NODE_TRUE,
54 GREP_NODE_OR
55};
56
57struct 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;
68};
69
70struct 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 int funcbody;
102 char color_context[COLOR_MAXLEN];
103 char color_filename[COLOR_MAXLEN];
104 char color_function[COLOR_MAXLEN];
105 char color_lineno[COLOR_MAXLEN];
106 char color_match[COLOR_MAXLEN];
107 char color_selected[COLOR_MAXLEN];
108 char color_sep[COLOR_MAXLEN];
109 int regflags;
110 unsigned pre_context;
111 unsigned post_context;
112 unsigned last_shown;
113 int show_hunk_mark;
114 int file_break;
115 int heading;
116 void *priv;
117
118 void (*output)(struct grep_opt *opt, const void *data, size_t size);
119 void *output_priv;
120};
121
122extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
123extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
124extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
125extern void compile_grep_patterns(struct grep_opt *opt);
126extern void free_grep_patterns(struct grep_opt *opt);
127extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
128
129extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
130extern int grep_threads_ok(const struct grep_opt *opt);
131
132#endif