grep.h 2.9 KB
Newer Older
1 2
#ifndef GREP_H
#define GREP_H
R
René Scharfe 已提交
3
#include "color.h"
M
Michał Kiedrowicz 已提交
4 5 6 7 8 9
#ifdef USE_LIBPCRE
#include <pcre.h>
#else
typedef int pcre;
typedef int pcre_extra;
#endif
10 11 12

enum grep_pat_token {
	GREP_PATTERN,
13 14
	GREP_PATTERN_HEAD,
	GREP_PATTERN_BODY,
15 16 17 18
	GREP_AND,
	GREP_OPEN_PAREN,
	GREP_CLOSE_PAREN,
	GREP_NOT,
19
	GREP_OR
20 21
};

22 23
enum grep_context {
	GREP_CONTEXT_HEAD,
24
	GREP_CONTEXT_BODY
25 26
};

27 28
enum grep_header_field {
	GREP_HEADER_AUTHOR = 0,
29
	GREP_HEADER_COMMITTER
30
};
31
#define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
32

33 34 35 36 37 38
struct grep_pat {
	struct grep_pat *next;
	const char *origin;
	int no;
	enum grep_pat_token token;
	const char *pattern;
39
	size_t patternlen;
40
	enum grep_header_field field;
41
	regex_t regexp;
M
Michał Kiedrowicz 已提交
42 43
	pcre *pcre_regexp;
	pcre_extra *pcre_extra_info;
44
	unsigned fixed:1;
45
	unsigned ignore_case:1;
46
	unsigned word_regexp:1;
47 48 49 50 51 52
};

enum grep_expr_node {
	GREP_NODE_ATOM,
	GREP_NODE_NOT,
	GREP_NODE_AND,
53
	GREP_NODE_TRUE,
54
	GREP_NODE_OR
55 56 57 58
};

struct grep_expr {
	enum grep_expr_node node;
J
Junio C Hamano 已提交
59
	unsigned hit;
60 61 62 63 64 65 66 67 68 69 70 71 72
	union {
		struct grep_pat *atom;
		struct grep_expr *unary;
		struct {
			struct grep_expr *left;
			struct grep_expr *right;
		} binary;
	} u;
};

struct grep_opt {
	struct grep_pat *pattern_list;
	struct grep_pat **pattern_tail;
73 74
	struct grep_pat *header_list;
	struct grep_pat **header_tail;
75
	struct grep_expr *pattern_expression;
76
	const char *prefix;
77 78
	int prefix_length;
	regex_t regexp;
R
René Scharfe 已提交
79 80
	int linenum;
	int invert;
81
	int ignore_case;
R
René Scharfe 已提交
82 83 84 85 86 87 88
	int status_only;
	int name_only;
	int unmatch_name_only;
	int count;
	int word_regexp;
	int fixed;
	int all_match;
89 90 91
#define GREP_BINARY_DEFAULT	0
#define GREP_BINARY_NOMATCH	1
#define GREP_BINARY_TEXT	2
R
René Scharfe 已提交
92 93
	int binary;
	int extended;
M
Michał Kiedrowicz 已提交
94
	int pcre;
R
René Scharfe 已提交
95 96 97
	int relative;
	int pathname;
	int null_following_name;
R
René Scharfe 已提交
98
	int color;
99
	int max_depth;
100
	int funcname;
101
	char color_context[COLOR_MAXLEN];
102
	char color_filename[COLOR_MAXLEN];
103
	char color_function[COLOR_MAXLEN];
104
	char color_lineno[COLOR_MAXLEN];
R
René Scharfe 已提交
105
	char color_match[COLOR_MAXLEN];
106
	char color_selected[COLOR_MAXLEN];
107
	char color_sep[COLOR_MAXLEN];
108 109 110
	int regflags;
	unsigned pre_context;
	unsigned post_context;
111
	unsigned last_shown;
112
	int show_hunk_mark;
R
René Scharfe 已提交
113
	int file_break;
R
René Scharfe 已提交
114
	int heading;
115
	void *priv;
F
Fredrik Kuivinen 已提交
116 117 118

	void (*output)(struct grep_opt *opt, const void *data, size_t size);
	void *output_priv;
119 120
};

121
extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
122
extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
123
extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
124
extern void compile_grep_patterns(struct grep_opt *opt);
125
extern void free_grep_patterns(struct grep_opt *opt);
126 127
extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);

F
Fredrik Kuivinen 已提交
128 129 130
extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
extern int grep_threads_ok(const struct grep_opt *opt);

131
#endif