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.05 (-23 / +79 lines)
Lines 44-49 Link Here
44
static const char qgrep_rcsid[] = "$Id: qgrep.c,v 1.17 2007/03/17 20:53:23 solar Exp $";
44
static const char qgrep_rcsid[] = "$Id: qgrep.c,v 1.17 2007/03/17 20:53:23 solar Exp $";
45
#define qgrep_usage(ret) usage(ret, QGREP_FLAGS, qgrep_long_opts, qgrep_opts_help, lookup_applet_idx("qgrep"))
45
#define qgrep_usage(ret) usage(ret, QGREP_FLAGS, qgrep_long_opts, qgrep_opts_help, lookup_applet_idx("qgrep"))
46
46
47
char qgrep_name_match(const char*, const int, depend_atom**);
48
char qgrep_name_match(const char* name, const int argc, depend_atom** argv)
49
{
50
	depend_atom* atom;
51
	int i;
52
53
	if ((atom = atom_explode(name)) == NULL)
54
		return 0;
55
56
	for (i = 0; i < argc; i++) {
57
		if (argv[i] == NULL)
58
			continue;
59
		if (atom->CATEGORY && argv[i]->CATEGORY && *(argv[i]->CATEGORY)
60
				&& strcmp(atom->CATEGORY, argv[i]->CATEGORY))
61
			continue;
62
		if (atom->PN && argv[i]->PN && *(argv[i]->PN)
63
				&& strcmp(atom->PN, argv[i]->PN))
64
			continue;
65
		if (atom->PVR && argv[i]->PVR && *(argv[i]->PVR)
66
				&& strcmp(atom->PVR, argv[i]->PVR))
67
			continue;
68
		atom_implode(atom);
69
		return 1;
70
	}
71
72
	atom_implode(atom);
73
	return 0;
74
}
75
47
int qgrep_main(int argc, char **argv)
76
int qgrep_main(int argc, char **argv)
48
{
77
{
49
	int i;
78
	int i;
Lines 61-66 Link Here
61
	char invert_match = 0;
90
	char invert_match = 0;
62
	regex_t preg, skip_preg;
91
	regex_t preg, skip_preg;
63
	char *skip_pattern = NULL;
92
	char *skip_pattern = NULL;
93
	depend_atom** include_atoms = NULL;
64
94
65
	typedef char *(*FUNC) (char *, char *);
95
	typedef char *(*FUNC) (char *, char *);
66
	FUNC strfunc = (FUNC) strstr;
96
	FUNC strfunc = (FUNC) strstr;
Lines 100-105 Link Here
100
	if (do_list)
130
	if (do_list)
101
		do_count = 0;
131
		do_count = 0;
102
132
133
	if (argc > (optind + 1)) {
134
		include_atoms = xcalloc(sizeof(depend_atom*), (argc - optind - 1));
135
		for (i = (optind + 1); i < argc; i++)
136
			if ((include_atoms[i - optind - 1] = atom_explode(argv[i])) == NULL)
137
				warnf("%s: invalid atom, will be ignored", argv[i]);
138
	}
139
103
	if (do_regex) {
140
	if (do_regex) {
104
		int ret;
141
		int ret;
105
		char err[256];
142
		char err[256];
Lines 138-170 Link Here
138
				continue;
175
				continue;
139
			if (strcmp(p, ".eclass"))
176
			if (strcmp(p, ".eclass"))
140
				continue;
177
				continue;
141
		} else if ((p = strchr(ebuild, '\n')) != NULL)
178
			if (show_name || (include_atoms != NULL)) {
142
				*p = 0;
179
				/* cut ".eclass" */
180
				*p = '\0';
181
				/* and skip "eclass/" */
182
				snprintf(name, sizeof(name), "%s", ebuild + 7);
183
				/* restore the filepath */
184
				*p = '.';
185
			}
186
		} else {
187
			if ((p = strchr(ebuild, '\n')) != NULL)
188
				*p = '\0';
189
			if (show_name || (include_atoms != NULL)) {
190
				/* cut ".ebuild" */
191
				if (p == NULL)
192
					p = ebuild + strlen(ebuild);
193
				*(p-7) = '\0';
194
				/* cut "/foo/" from "cat/foo/foo-x.y" */
195
				if ((p = strchr(ebuild, '/')) == NULL)
196
					continue;
197
				*(p++) = '\0';
198
				/* find head of the ebuild basename */
199
				if ((p = strchr(p, '/')) == NULL)
200
					continue;
201
				/* find	start of the pkg name */
202
				snprintf(name, sizeof(name), "%s/%s", ebuild, (p+1));
203
				/* restore the filepath */
204
				*p = '/';
205
				*(p + strlen(p)) = '.';
206
				ebuild[strlen(ebuild)] = '/';
207
			}
208
		}
209
210
		if (include_atoms != NULL)
211
			if (!qgrep_name_match(name, (argc - optind - 1), include_atoms))
212
				continue;
213
143
		if ((newfp = fopen(ebuild, "r")) != NULL) {
214
		if ((newfp = fopen(ebuild, "r")) != NULL) {
144
			unsigned int lineno = 0;
215
			unsigned int lineno = 0;
145
			count = 0;
216
			count = 0;
146
217
147
			if (show_name) {
148
				if (do_eclass) {
149
					/* cut ".eclass" */
150
					*p = '\0';
151
					/* and skip "eclass/" */
152
					snprintf(name, sizeof(name), "%s", ebuild + 7);
153
				} else {
154
					/* cut ".ebuild" */
155
					*(p-7) = '\0';
156
					/* cut "/foo/" from "cat/foo/foo-x.y" */
157
					if ((p = strchr(ebuild, '/')) == NULL)
158
						continue;
159
					*(p++) = '\0';
160
					/* find head of the ebuild basename */
161
					if ((p = strchr(p, '/')) == NULL)
162
						continue;
163
					/* find start of the pkg name */
164
					snprintf(name, sizeof(name), "%s/%s", ebuild, ++p);
165
				}
166
			}
167
168
			while ((fgets(buf0, sizeof(buf0), newfp)) != NULL) {
218
			while ((fgets(buf0, sizeof(buf0), newfp)) != NULL) {
169
				lineno++;
219
				lineno++;
170
				if ((p = strrchr(buf0, '\n')) != NULL)
220
				if ((p = strrchr(buf0, '\n')) != NULL)
Lines 227-232 Link Here
227
		regfree(&preg);
277
		regfree(&preg);
228
	if (do_regex && skip_pattern)
278
	if (do_regex && skip_pattern)
229
		regfree(&skip_preg);
279
		regfree(&skip_preg);
280
	if (include_atoms != NULL) {
281
		for (i = 0; i < (argc - optind - 1); i++)
282
			if (include_atoms[i] != NULL)
283
				atom_implode(include_atoms[i]);
284
		free(include_atoms);
285
	}
230
	return EXIT_SUCCESS;
286
	return EXIT_SUCCESS;
231
}
287
}
232
288

Return to bug 171374