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.01 (-6 / +17 lines)
Lines 10-21 Link Here
10
10
11
#ifdef APPLET_qgrep
11
#ifdef APPLET_qgrep
12
12
13
#define QGREP_FLAGS "IiHceEs" COMMON_FLAGS
13
#define QGREP_FLAGS "IiHclLeEs" 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'},
17
	{"with-filename", no_argument, NULL, 'H'},
17
	{"with-filename", no_argument, NULL, 'H'},
18
	{"count",         no_argument, NULL, 'c'},
18
	{"count",         no_argument, NULL, 'c'},
19
	{"list",          no_argument, NULL, 'l'},
20
	{"invert-list",   no_argument, NULL, 'L'},
19
	{"regexp",        no_argument, NULL, 'e'},
21
	{"regexp",        no_argument, NULL, 'e'},
20
	{"eclass",        no_argument, NULL, 'E'},
22
	{"eclass",        no_argument, NULL, 'E'},
21
	{"skip-comments", no_argument, NULL, 's'},
23
	{"skip-comments", no_argument, NULL, 's'},
Lines 26-31 Link Here
26
	"Ignore case distinctions",
28
	"Ignore case distinctions",
27
	"Print the filename for each match",
29
	"Print the filename for each match",
28
	"Only print a count of matching lines per FILE",
30
	"Only print a count of matching lines per FILE",
31
	"Only print FILE names containing matches",
32
	"Only print FILE names containing no match",
29
	"Use PATTERN as a regular expression",
33
	"Use PATTERN as a regular expression",
30
	"Search in eclasses instead of ebuilds",
34
	"Search in eclasses instead of ebuilds",
31
	"Skip comments lines",
35
	"Skip comments lines",
Lines 39-46 Link Here
39
	int i;
43
	int i;
40
	int count = 0;
44
	int count = 0;
41
	char *p;
45
	char *p;
42
	char do_count, do_regex, do_eclass;
46
	char do_count, do_regex, do_eclass, do_list;
43
	char show_filename, skip_comments;
47
	char show_filename, skip_comments, invert_list;
44
	FILE *fp = NULL;
48
	FILE *fp = NULL;
45
	DIR *eclass_dir = NULL;
49
	DIR *eclass_dir = NULL;
46
	struct dirent *dentry;
50
	struct dirent *dentry;
Lines 56-62 Link Here
56
	DBG("argc=%d argv[0]=%s argv[1]=%s",
60
	DBG("argc=%d argv[0]=%s argv[1]=%s",
57
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
61
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
58
62
59
	do_count = do_regex = do_eclass = show_filename = skip_comments = 0;
63
	do_count = do_regex = do_eclass = do_list = 0;
64
	show_filename = skip_comments = invert_list = 0;
60
65
61
	while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) {
66
	while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) {
62
		switch (i) {
67
		switch (i) {
Lines 66-71 Link Here
66
			reflags |= REG_ICASE;
71
			reflags |= REG_ICASE;
67
			break;
72
			break;
68
		case 'c': do_count = 1; break;
73
		case 'c': do_count = 1; break;
74
		case 'l': do_list = 1; break;
75
		case 'L': do_list = invert_list = 1; break;
69
		case 'e': do_regex = 1; break;
76
		case 'e': do_regex = 1; break;
70
		case 'E': do_eclass = 1; break;
77
		case 'E': do_eclass = 1; break;
71
		case 'H': show_filename = 1; break;
78
		case 'H': show_filename = 1; break;
Lines 76-81 Link Here
76
	if (argc == optind)
83
	if (argc == optind)
77
		qgrep_usage(EXIT_FAILURE);
84
		qgrep_usage(EXIT_FAILURE);
78
85
86
	if (do_list)
87
		do_count = 0;
88
79
	if (do_regex) {
89
	if (do_regex) {
80
		int ret;
90
		int ret;
81
		if ((ret = regcomp(&preg, argv[optind], reflags))) {
91
		if ((ret = regcomp(&preg, argv[optind], reflags))) {
Lines 141-147 Link Here
141
				}
151
				}
142
152
143
				count++;
153
				count++;
144
				if (do_count) continue;
154
				if (do_count || do_list) continue;
145
				if (verbose || show_filename) {
155
				if (verbose || show_filename) {
146
					printf("%s:", ebuild);
156
					printf("%s:", ebuild);
147
					if (verbose > 1) printf("%d:", lineno);
157
					if (verbose > 1) printf("%d:", lineno);
Lines 154-160 Link Here
154
				if (verbose || show_filename) printf("%s:", ebuild);
164
				if (verbose || show_filename) printf("%s:", ebuild);
155
				printf("%d", count);
165
				printf("%d", count);
156
				puts("");
166
				puts("");
157
			}
167
			} else if (do_list && ((count && !invert_list) || (!count && invert_list)))
168
				printf("%s\n", ebuild);
158
		}
169
		}
159
	}
170
	}
160
	if (do_eclass)
171
	if (do_eclass)

Return to bug 171374