grep: Extract compile_regexp_failed() from compile_regexp()
[git/git.git] / grep.h
CommitLineData
83b5d2f5
JH
1#ifndef GREP_H
2#define GREP_H
7e8f59d5 3#include "color.h"
83b5d2f5
JH
4
5enum grep_pat_token {
6 GREP_PATTERN,
480c1ca6
JH
7 GREP_PATTERN_HEAD,
8 GREP_PATTERN_BODY,
83b5d2f5
JH
9 GREP_AND,
10 GREP_OPEN_PAREN,
11 GREP_CLOSE_PAREN,
12 GREP_NOT,
4b05548f 13 GREP_OR
83b5d2f5
JH
14};
15
480c1ca6
JH
16enum grep_context {
17 GREP_CONTEXT_HEAD,
4b05548f 18 GREP_CONTEXT_BODY
480c1ca6
JH
19};
20
a4d7d2c6
JH
21enum grep_header_field {
22 GREP_HEADER_AUTHOR = 0,
4b05548f 23 GREP_HEADER_COMMITTER
a4d7d2c6 24};
5aaeb733 25#define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
a4d7d2c6 26
83b5d2f5
JH
27struct grep_pat {
28 struct grep_pat *next;
29 const char *origin;
30 int no;
31 enum grep_pat_token token;
32 const char *pattern;
ed40a095 33 size_t patternlen;
a4d7d2c6 34 enum grep_header_field field;
83b5d2f5 35 regex_t regexp;
c822255c 36 unsigned fixed:1;
5183bf67 37 unsigned ignore_case:1;
d7eb527d 38 unsigned word_regexp:1;
83b5d2f5
JH
39};
40
41enum grep_expr_node {
42 GREP_NODE_ATOM,
43 GREP_NODE_NOT,
44 GREP_NODE_AND,
5aaeb733 45 GREP_NODE_TRUE,
4b05548f 46 GREP_NODE_OR
83b5d2f5
JH
47};
48
49struct grep_expr {
50 enum grep_expr_node node;
0ab7befa 51 unsigned hit;
83b5d2f5
JH
52 union {
53 struct grep_pat *atom;
54 struct grep_expr *unary;
55 struct {
56 struct grep_expr *left;
57 struct grep_expr *right;
58 } binary;
59 } u;
60};
61
62struct grep_opt {
63 struct grep_pat *pattern_list;
64 struct grep_pat **pattern_tail;
80235ba7
JH
65 struct grep_pat *header_list;
66 struct grep_pat **header_tail;
83b5d2f5 67 struct grep_expr *pattern_expression;
493b7a08 68 const char *prefix;
83b5d2f5
JH
69 int prefix_length;
70 regex_t regexp;
3e230fa1
RS
71 int linenum;
72 int invert;
5183bf67 73 int ignore_case;
3e230fa1
RS
74 int status_only;
75 int name_only;
76 int unmatch_name_only;
77 int count;
78 int word_regexp;
79 int fixed;
80 int all_match;
83b5d2f5
JH
81#define GREP_BINARY_DEFAULT 0
82#define GREP_BINARY_NOMATCH 1
83#define GREP_BINARY_TEXT 2
3e230fa1
RS
84 int binary;
85 int extended;
86 int relative;
87 int pathname;
88 int null_following_name;
7e8f59d5 89 int color;
a91f453f 90 int max_depth;
2944e4e6 91 int funcname;
00588bb5 92 char color_context[COLOR_MAXLEN];
55f638bd 93 char color_filename[COLOR_MAXLEN];
00588bb5 94 char color_function[COLOR_MAXLEN];
55f638bd 95 char color_lineno[COLOR_MAXLEN];
7e8f59d5 96 char color_match[COLOR_MAXLEN];
00588bb5 97 char color_selected[COLOR_MAXLEN];
55f638bd 98 char color_sep[COLOR_MAXLEN];
83b5d2f5
JH
99 int regflags;
100 unsigned pre_context;
101 unsigned post_context;
5dd06d38 102 unsigned last_shown;
046802d0 103 int show_hunk_mark;
60ecac98 104 void *priv;
5b594f45
FK
105
106 void (*output)(struct grep_opt *opt, const void *data, size_t size);
107 void *output_priv;
83b5d2f5
JH
108};
109
ed40a095 110extern 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 111extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
a4d7d2c6 112extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
83b5d2f5 113extern void compile_grep_patterns(struct grep_opt *opt);
b48fb5b6 114extern void free_grep_patterns(struct grep_opt *opt);
83b5d2f5
JH
115extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
116
5b594f45
FK
117extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
118extern int grep_threads_ok(const struct grep_opt *opt);
119
83b5d2f5 120#endif