blob: f6eecc62c038f212fa4efc8648f13f61bf937452 [file] [log] [blame]
Junio C Hamano83b5d2f2006-09-17 16:02:52 -07001#ifndef GREP_H
2#define GREP_H
René Scharfe7e8f59d2009-03-07 13:32:32 +01003#include "color.h"
Junio C Hamano83b5d2f2006-09-17 16:02:52 -07004
5enum grep_pat_token {
6 GREP_PATTERN,
Junio C Hamano480c1ca2006-09-20 12:39:46 -07007 GREP_PATTERN_HEAD,
8 GREP_PATTERN_BODY,
Junio C Hamano83b5d2f2006-09-17 16:02:52 -07009 GREP_AND,
10 GREP_OPEN_PAREN,
11 GREP_CLOSE_PAREN,
12 GREP_NOT,
13 GREP_OR,
14};
15
Junio C Hamano480c1ca2006-09-20 12:39:46 -070016enum grep_context {
17 GREP_CONTEXT_HEAD,
18 GREP_CONTEXT_BODY,
19};
20
Junio C Hamanoa4d7d2c2008-09-04 22:15:02 -070021enum grep_header_field {
22 GREP_HEADER_AUTHOR = 0,
23 GREP_HEADER_COMMITTER,
24};
25
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070026struct grep_pat {
27 struct grep_pat *next;
28 const char *origin;
29 int no;
30 enum grep_pat_token token;
31 const char *pattern;
Junio C Hamanoa4d7d2c2008-09-04 22:15:02 -070032 enum grep_header_field field;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070033 regex_t regexp;
René Scharfec8222552009-01-10 00:18:34 +010034 unsigned fixed:1;
René Scharfed7eb5272009-03-07 13:28:40 +010035 unsigned word_regexp:1;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070036};
37
38enum grep_expr_node {
39 GREP_NODE_ATOM,
40 GREP_NODE_NOT,
41 GREP_NODE_AND,
42 GREP_NODE_OR,
43};
44
45struct grep_expr {
46 enum grep_expr_node node;
Junio C Hamano0ab7bef2006-09-27 17:50:52 -070047 unsigned hit;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070048 union {
49 struct grep_pat *atom;
50 struct grep_expr *unary;
51 struct {
52 struct grep_expr *left;
53 struct grep_expr *right;
54 } binary;
55 } u;
56};
57
58struct grep_opt {
59 struct grep_pat *pattern_list;
60 struct grep_pat **pattern_tail;
61 struct grep_expr *pattern_expression;
Clemens Buchacher493b7a02009-09-05 14:31:17 +020062 const char *prefix;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070063 int prefix_length;
64 regex_t regexp;
René Scharfe3e230fa2009-05-07 21:46:48 +020065 int linenum;
66 int invert;
67 int status_only;
68 int name_only;
69 int unmatch_name_only;
70 int count;
71 int word_regexp;
72 int fixed;
73 int all_match;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070074#define GREP_BINARY_DEFAULT 0
75#define GREP_BINARY_NOMATCH 1
76#define GREP_BINARY_TEXT 2
René Scharfe3e230fa2009-05-07 21:46:48 +020077 int binary;
78 int extended;
79 int relative;
80 int pathname;
81 int null_following_name;
René Scharfe7e8f59d2009-03-07 13:32:32 +010082 int color;
Michał Kiedrowicza91f4532009-07-22 19:52:15 +020083 int max_depth;
René Scharfe2944e4e2009-07-02 00:06:34 +020084 int funcname;
René Scharfe7e8f59d2009-03-07 13:32:32 +010085 char color_match[COLOR_MAXLEN];
René Scharfea94982e2009-03-07 13:34:46 +010086 const char *color_external;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070087 int regflags;
88 unsigned pre_context;
89 unsigned post_context;
René Scharfe5dd06d32009-07-02 00:02:38 +020090 unsigned last_shown;
René Scharfe046802d2009-07-02 00:03:44 +020091 int show_hunk_mark;
René Scharfe60ecac92009-07-02 00:07:24 +020092 void *priv;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070093};
94
95extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
Junio C Hamanoa4d7d2c2008-09-04 22:15:02 -070096extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070097extern void compile_grep_patterns(struct grep_opt *opt);
Junio C Hamanob48fb5b2006-09-27 16:27:10 -070098extern void free_grep_patterns(struct grep_opt *opt);
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070099extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
100
101#endif