Junio C Hamano | 83b5d2f | 2006-09-17 16:02:52 -0700 | [diff] [blame] | 1 | #ifndef GREP_H |
| 2 | #define GREP_H |
| 3 | |
| 4 | enum grep_pat_token { |
| 5 | GREP_PATTERN, |
Junio C Hamano | 480c1ca | 2006-09-20 12:39:46 -0700 | [diff] [blame] | 6 | GREP_PATTERN_HEAD, |
| 7 | GREP_PATTERN_BODY, |
Junio C Hamano | 83b5d2f | 2006-09-17 16:02:52 -0700 | [diff] [blame] | 8 | GREP_AND, |
| 9 | GREP_OPEN_PAREN, |
| 10 | GREP_CLOSE_PAREN, |
| 11 | GREP_NOT, |
| 12 | GREP_OR, |
| 13 | }; |
| 14 | |
Junio C Hamano | 480c1ca | 2006-09-20 12:39:46 -0700 | [diff] [blame] | 15 | enum grep_context { |
| 16 | GREP_CONTEXT_HEAD, |
| 17 | GREP_CONTEXT_BODY, |
| 18 | }; |
| 19 | |
Junio C Hamano | 83b5d2f | 2006-09-17 16:02:52 -0700 | [diff] [blame] | 20 | struct 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 | |
| 29 | enum grep_expr_node { |
| 30 | GREP_NODE_ATOM, |
| 31 | GREP_NODE_NOT, |
| 32 | GREP_NODE_AND, |
| 33 | GREP_NODE_OR, |
| 34 | }; |
| 35 | |
| 36 | struct grep_expr { |
| 37 | enum grep_expr_node node; |
Junio C Hamano | 0ab7bef | 2006-09-27 17:50:52 -0700 | [diff] [blame] | 38 | unsigned hit; |
Junio C Hamano | 83b5d2f | 2006-09-17 16:02:52 -0700 | [diff] [blame] | 39 | 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 | |
| 49 | struct 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 Hamano | 0ab7bef | 2006-09-27 17:50:52 -0700 | [diff] [blame] | 63 | unsigned all_match:1; |
Junio C Hamano | 83b5d2f | 2006-09-17 16:02:52 -0700 | [diff] [blame] | 64 | #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 | |
| 76 | extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t); |
| 77 | extern void compile_grep_patterns(struct grep_opt *opt); |
Junio C Hamano | b48fb5b | 2006-09-27 16:27:10 -0700 | [diff] [blame] | 78 | extern void free_grep_patterns(struct grep_opt *opt); |
Junio C Hamano | 83b5d2f | 2006-09-17 16:02:52 -0700 | [diff] [blame] | 79 | extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size); |
| 80 | |
| 81 | #endif |