blob: d252dd25f81526d9b8663b4d3c9585d69a901397 [file] [log] [blame]
Junio C Hamano83b5d2f2006-09-17 16:02:52 -07001#ifndef GREP_H
2#define GREP_H
3
4enum grep_pat_token {
5 GREP_PATTERN,
Junio C Hamano480c1ca2006-09-20 12:39:46 -07006 GREP_PATTERN_HEAD,
7 GREP_PATTERN_BODY,
Junio C Hamano83b5d2f2006-09-17 16:02:52 -07008 GREP_AND,
9 GREP_OPEN_PAREN,
10 GREP_CLOSE_PAREN,
11 GREP_NOT,
12 GREP_OR,
13};
14
Junio C Hamano480c1ca2006-09-20 12:39:46 -070015enum grep_context {
16 GREP_CONTEXT_HEAD,
17 GREP_CONTEXT_BODY,
18};
19
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070020struct grep_pat {
21 struct grep_pat *next;
22 const char *origin;
23 int no;
24 enum grep_pat_token token;
25 const char *pattern;
26 regex_t regexp;
27};
28
29enum grep_expr_node {
30 GREP_NODE_ATOM,
31 GREP_NODE_NOT,
32 GREP_NODE_AND,
33 GREP_NODE_OR,
34};
35
36struct grep_expr {
37 enum grep_expr_node node;
Junio C Hamano0ab7bef2006-09-27 17:50:52 -070038 unsigned hit;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070039 union {
40 struct grep_pat *atom;
41 struct grep_expr *unary;
42 struct {
43 struct grep_expr *left;
44 struct grep_expr *right;
45 } binary;
46 } u;
47};
48
49struct grep_opt {
50 struct grep_pat *pattern_list;
51 struct grep_pat **pattern_tail;
52 struct grep_expr *pattern_expression;
53 int prefix_length;
54 regex_t regexp;
55 unsigned linenum:1;
56 unsigned invert:1;
57 unsigned status_only:1;
58 unsigned name_only:1;
59 unsigned unmatch_name_only:1;
60 unsigned count:1;
61 unsigned word_regexp:1;
62 unsigned fixed:1;
Junio C Hamano0ab7bef2006-09-27 17:50:52 -070063 unsigned all_match:1;
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070064#define GREP_BINARY_DEFAULT 0
65#define GREP_BINARY_NOMATCH 1
66#define GREP_BINARY_TEXT 2
67 unsigned binary:2;
68 unsigned extended:1;
69 unsigned relative:1;
70 unsigned pathname:1;
71 int regflags;
72 unsigned pre_context;
73 unsigned post_context;
74};
75
76extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
77extern void compile_grep_patterns(struct grep_opt *opt);
Junio C Hamanob48fb5b2006-09-27 16:27:10 -070078extern void free_grep_patterns(struct grep_opt *opt);
Junio C Hamano83b5d2f2006-09-17 16:02:52 -070079extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
80
81#endif