grep.h 2.5 KB
Newer Older
1 2
#ifndef GREP_H
#define GREP_H
R
René Scharfe 已提交
3
#include "color.h"
4 5 6

enum grep_pat_token {
	GREP_PATTERN,
7 8
	GREP_PATTERN_HEAD,
	GREP_PATTERN_BODY,
9 10 11 12 13 14 15
	GREP_AND,
	GREP_OPEN_PAREN,
	GREP_CLOSE_PAREN,
	GREP_NOT,
	GREP_OR,
};

16 17 18 19 20
enum grep_context {
	GREP_CONTEXT_HEAD,
	GREP_CONTEXT_BODY,
};

21 22 23 24 25
enum grep_header_field {
	GREP_HEADER_AUTHOR = 0,
	GREP_HEADER_COMMITTER,
};

26 27 28 29 30 31
struct grep_pat {
	struct grep_pat *next;
	const char *origin;
	int no;
	enum grep_pat_token token;
	const char *pattern;
32
	enum grep_header_field field;
33
	regex_t regexp;
34
	unsigned fixed:1;
35
	unsigned ignore_case:1;
36
	unsigned word_regexp:1;
37 38 39 40 41 42 43 44 45 46 47
};

enum grep_expr_node {
	GREP_NODE_ATOM,
	GREP_NODE_NOT,
	GREP_NODE_AND,
	GREP_NODE_OR,
};

struct grep_expr {
	enum grep_expr_node node;
J
Junio C Hamano 已提交
48
	unsigned hit;
49 50 51 52 53 54 55 56 57 58 59 60 61
	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;
62 63
	struct grep_pat *header_list;
	struct grep_pat **header_tail;
64
	struct grep_expr *pattern_expression;
65
	const char *prefix;
66 67
	int prefix_length;
	regex_t regexp;
R
René Scharfe 已提交
68 69
	int linenum;
	int invert;
70
	int ignore_case;
R
René Scharfe 已提交
71 72 73 74 75 76 77
	int status_only;
	int name_only;
	int unmatch_name_only;
	int count;
	int word_regexp;
	int fixed;
	int all_match;
78 79 80
#define GREP_BINARY_DEFAULT	0
#define GREP_BINARY_NOMATCH	1
#define GREP_BINARY_TEXT	2
R
René Scharfe 已提交
81 82 83 84 85
	int binary;
	int extended;
	int relative;
	int pathname;
	int null_following_name;
R
René Scharfe 已提交
86
	int color;
87
	int max_depth;
88
	int funcname;
89
	char color_context[COLOR_MAXLEN];
90
	char color_filename[COLOR_MAXLEN];
91
	char color_function[COLOR_MAXLEN];
92
	char color_lineno[COLOR_MAXLEN];
R
René Scharfe 已提交
93
	char color_match[COLOR_MAXLEN];
94
	char color_selected[COLOR_MAXLEN];
95
	char color_sep[COLOR_MAXLEN];
96 97 98
	int regflags;
	unsigned pre_context;
	unsigned post_context;
99
	unsigned last_shown;
100
	int show_hunk_mark;
101
	void *priv;
F
Fredrik Kuivinen 已提交
102 103 104

	void (*output)(struct grep_opt *opt, const void *data, size_t size);
	void *output_priv;
105 106 107
};

extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
108
extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
109
extern void compile_grep_patterns(struct grep_opt *opt);
110
extern void free_grep_patterns(struct grep_opt *opt);
111 112
extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);

F
Fredrik Kuivinen 已提交
113 114 115
extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
extern int grep_threads_ok(const struct grep_opt *opt);

116
#endif