Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 171374 | Differences between
and this patch

Collapse All | Expand All

(-)qgrep.c.02 (-3 / +23 lines)
Lines 10-16 Link Here
10
10
11
#ifdef APPLET_qgrep
11
#ifdef APPLET_qgrep
12
12
13
#define QGREP_FLAGS "IiHclLeEs" COMMON_FLAGS
13
#define QGREP_FLAGS "IiHclLeEsS:" COMMON_FLAGS
14
static struct option const qgrep_long_opts[] = {
14
static struct option const qgrep_long_opts[] = {
15
	{"invert-match",  no_argument, NULL, 'I'},
15
	{"invert-match",  no_argument, NULL, 'I'},
16
	{"ignore-case",   no_argument, NULL, 'i'},
16
	{"ignore-case",   no_argument, NULL, 'i'},
Lines 21-26 Link Here
21
	{"regexp",        no_argument, NULL, 'e'},
21
	{"regexp",        no_argument, NULL, 'e'},
22
	{"eclass",        no_argument, NULL, 'E'},
22
	{"eclass",        no_argument, NULL, 'E'},
23
	{"skip-comments", no_argument, NULL, 's'},
23
	{"skip-comments", no_argument, NULL, 's'},
24
	{"skip",           a_argument, NULL, 'S'},
24
	COMMON_LONG_OPTS
25
	COMMON_LONG_OPTS
25
};
26
};
26
static const char *qgrep_opts_help[] = {
27
static const char *qgrep_opts_help[] = {
Lines 33-38 Link Here
33
	"Use PATTERN as a regular expression",
34
	"Use PATTERN as a regular expression",
34
	"Search in eclasses instead of ebuilds",
35
	"Search in eclasses instead of ebuilds",
35
	"Skip comments lines",
36
	"Skip comments lines",
37
	"Skip lines matching <arg>",
36
	COMMON_OPTS_HELP
38
	COMMON_OPTS_HELP
37
};
39
};
38
static const char qgrep_rcsid[] = "$Id: qgrep.c,v 1.17 2007/03/17 20:53:23 solar Exp $";
40
static const char qgrep_rcsid[] = "$Id: qgrep.c,v 1.17 2007/03/17 20:53:23 solar Exp $";
Lines 52-58 Link Here
52
	char buf0[BUFSIZ];
54
	char buf0[BUFSIZ];
53
	int reflags = REG_NOSUB;
55
	int reflags = REG_NOSUB;
54
	char invert_match = 0;
56
	char invert_match = 0;
55
	regex_t preg;
57
	regex_t preg, skip_preg;
58
	char *skip_pattern = NULL;
56
59
57
	typedef char *(*FUNC) (char *, char *);
60
	typedef char *(*FUNC) (char *, char *);
58
	FUNC strfunc = (FUNC) strstr;
61
	FUNC strfunc = (FUNC) strstr;
Lines 77-82 Link Here
77
		case 'E': do_eclass = 1; break;
80
		case 'E': do_eclass = 1; break;
78
		case 'H': show_filename = 1; break;
81
		case 'H': show_filename = 1; break;
79
		case 's': skip_comments = 1; break;
82
		case 's': skip_comments = 1; break;
83
		case 'S': skip_pattern = optarg; break;
80
		COMMON_GETOPTS_CASES(qgrep)
84
		COMMON_GETOPTS_CASES(qgrep)
81
		}
85
		}
82
	}
86
	}
Lines 88-100 Link Here
88
92
89
	if (do_regex) {
93
	if (do_regex) {
90
		int ret;
94
		int ret;
95
		char err[256];
91
		if ((ret = regcomp(&preg, argv[optind], reflags))) {
96
		if ((ret = regcomp(&preg, argv[optind], reflags))) {
92
			char err[256];
93
			if (regerror(ret, &preg, err, sizeof(err)))
97
			if (regerror(ret, &preg, err, sizeof(err)))
94
				errf("regcomp failed: %s", err);
98
				errf("regcomp failed: %s", err);
95
			else
99
			else
96
				err("regcomp failed");
100
				err("regcomp failed");
97
		}
101
		}
102
		if (skip_pattern && (ret = regcomp(&skip_preg, skip_pattern, reflags))) {
103
			if (regerror(ret, &skip_preg, err, sizeof(err)))
104
				errf("regcomp failed for --skip pattern: %s", err);
105
			else
106
				err("regcomp failed for --skip pattern");
107
		}
98
	}
108
	}
99
109
100
	if (!do_eclass) {
110
	if (!do_eclass) {
Lines 136-141 Link Here
136
					if (*p == '#') continue;
146
					if (*p == '#') continue;
137
				}
147
				}
138
148
149
				if (skip_pattern) {
150
					if (!do_regex) {
151
						if (( (FUNC *) (strfunc) (buf0, skip_pattern)) != NULL) continue;
152
					} else {
153
						if (regexec(&skip_preg, buf0, 0, NULL, 0) == 0) continue;
154
					}
155
				}
156
139
				if (!invert_match) {
157
				if (!invert_match) {
140
					if (do_regex == 0) {
158
					if (do_regex == 0) {
141
						if (( (FUNC *) (strfunc) (buf0, argv[optind])) == NULL) continue;
159
						if (( (FUNC *) (strfunc) (buf0, argv[optind])) == NULL) continue;
Lines 174-179 Link Here
174
		fclose(fp);
192
		fclose(fp);
175
	if (do_regex)
193
	if (do_regex)
176
		regfree(&preg);
194
		regfree(&preg);
195
	if (do_regex && skip_pattern)
196
		regfree(&skip_preg);
177
	return EXIT_SUCCESS;
197
	return EXIT_SUCCESS;
178
}
198
}
179
199

Return to bug 171374