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

Collapse All | Expand All

(-)qgrep.c (-11 / +34 lines)
Lines 10-22 Link Here
10
10
11
#ifdef APPLET_qgrep
11
#ifdef APPLET_qgrep
12
12
13
#define QGREP_FLAGS "IiHce" COMMON_FLAGS
13
#define QGREP_FLAGS "IiHceE" 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
	{"regexp",        no_argument, NULL, 'e'},
19
	{"regexp",        no_argument, NULL, 'e'},
20
	{"eclass",        no_argument, NULL, 'E'},
20
	COMMON_LONG_OPTS
21
	COMMON_LONG_OPTS
21
};
22
};
22
static const char *qgrep_opts_help[] = {
23
static const char *qgrep_opts_help[] = {
Lines 25-29 Link Here
25
	"Print the filename for each match",
26
	"Print the filename for each match",
26
	"Only print a count of matching lines per FILE",
27
	"Only print a count of matching lines per FILE",
27
	"Use PATTERN as a regular expression",
28
	"Use PATTERN as a regular expression",
29
	"Search in eclasses instead of ebuilds",
28
	COMMON_OPTS_HELP
30
	COMMON_OPTS_HELP
29
};
31
};
Lines 35-43 Link Here
35
	int i;
37
	int i;
36
	int count = 0;
38
	int count = 0;
37
	char *p;
39
	char *p;
38
	char do_count, do_regex;
40
	char do_count, do_regex, do_eclass;
39
	char show_filename;
41
	char show_filename;
40
	FILE *fp;
42
	FILE *fp = NULL;
43
	DIR *eclass_dir = NULL;
44
	struct dirent *dentry;
41
	char ebuild[_Q_PATH_MAX];
45
	char ebuild[_Q_PATH_MAX];
42
	char buf0[BUFSIZ];
46
	char buf0[BUFSIZ];
43
	int reflags = REG_NOSUB;
47
	int reflags = REG_NOSUB;
Lines 49-55 Link Here
49
	DBG("argc=%d argv[0]=%s argv[1]=%s",
53
	DBG("argc=%d argv[0]=%s argv[1]=%s",
50
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
54
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
51
55
52
	do_count = do_regex = show_filename = 0;
56
	do_count = do_regex = do_eclass = show_filename = 0;
53
57
54
	while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) {
58
	while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) {
55
		switch (i) {
59
		switch (i) {
Lines 60-65 Link Here
60
			break;
64
			break;
61
		case 'c': do_count = 1; break;
65
		case 'c': do_count = 1; break;
62
		case 'e': do_regex = 1; break;
66
		case 'e': do_regex = 1; break;
67
		case 'E': do_eclass = 1; break;
63
		case 'H': show_filename = 1; break;
68
		case 'H': show_filename = 1; break;
64
		COMMON_GETOPTS_CASES(qgrep)
69
		COMMON_GETOPTS_CASES(qgrep)
65
		}
70
		}
Lines 67-80 Link Here
67
	if (argc == optind)
72
	if (argc == optind)
68
		qgrep_usage(EXIT_FAILURE);
73
		qgrep_usage(EXIT_FAILURE);
69
74
70
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
75
	if (!do_eclass) {
76
		initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
77
		if ((fp = fopen(CACHE_EBUILD_FILE, "r")) == NULL)
78
			return 1;
79
	} else {
80
		if ((chdir(portdir)) != 0)
81
			errp("chdir to PORTDIR '%s' failed", portdir);
82
		if ((eclass_dir = opendir("eclass")) == NULL)
83
			errp("opendir(\"%s/eclass\") failed", portdir);
84
	}
71
85
72
	if ((fp = fopen(CACHE_EBUILD_FILE, "r")) == NULL)
86
	while (do_eclass
73
		return 1;
87
			? ((dentry = readdir(eclass_dir))
74
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
88
				&& snprintf(ebuild, sizeof(ebuild), "eclass/%s", dentry->d_name))
89
			: ((fgets(ebuild, sizeof(ebuild), fp)) != NULL)) {
75
		FILE *newfp;
90
		FILE *newfp;
76
		if ((p = strchr(ebuild, '\n')) != NULL)
91
		if (do_eclass) {
77
			*p = 0;
92
			if ((p = strrchr(ebuild, '.')) == NULL)
93
				continue;
94
			if (strcmp(p, ".eclass"))
95
				continue;
96
		} else if ((p = strchr(ebuild, '\n')) != NULL)
97
				*p = 0;
78
		if ((newfp = fopen(ebuild, "r")) != NULL) {
98
		if ((newfp = fopen(ebuild, "r")) != NULL) {
79
			unsigned int lineno = 0;
99
			unsigned int lineno = 0;
80
			count = 0;
100
			count = 0;
Lines 116-122 Link Here
116
			}
136
			}
117
		}
137
		}
118
	}
138
	}
119
	fclose(fp);
139
	if (do_eclass)
140
		closedir(eclass_dir);
141
	else
142
		fclose(fp);
120
	return EXIT_SUCCESS;
143
	return EXIT_SUCCESS;
121
}
144
}
122
145

Return to bug 170795