Lines 10-20
Link Here
|
10 |
|
10 |
|
11 |
#ifdef APPLET_qgrep |
11 |
#ifdef APPLET_qgrep |
12 |
|
12 |
|
13 |
#define QGREP_FLAGS "IiHclLeEsS:" COMMON_FLAGS |
13 |
#define QGREP_FLAGS "IiHNclLeEsS:" 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 |
{"with-name", no_argument, NULL, 'N'}, |
18 |
{"count", no_argument, NULL, 'c'}, |
19 |
{"count", no_argument, NULL, 'c'}, |
19 |
{"list", no_argument, NULL, 'l'}, |
20 |
{"list", no_argument, NULL, 'l'}, |
20 |
{"invert-list", no_argument, NULL, 'L'}, |
21 |
{"invert-list", no_argument, NULL, 'L'}, |
Lines 28-33
Link Here
|
28 |
"Select non-matching lines", |
29 |
"Select non-matching lines", |
29 |
"Ignore case distinctions", |
30 |
"Ignore case distinctions", |
30 |
"Print the filename for each match", |
31 |
"Print the filename for each match", |
|
|
32 |
"Print the package or eclass name for each match", |
31 |
"Only print a count of matching lines per FILE", |
33 |
"Only print a count of matching lines per FILE", |
32 |
"Only print FILE names containing matches", |
34 |
"Only print FILE names containing matches", |
33 |
"Only print FILE names containing no match", |
35 |
"Only print FILE names containing no match", |
Lines 46-56
Link Here
|
46 |
int count = 0; |
48 |
int count = 0; |
47 |
char *p; |
49 |
char *p; |
48 |
char do_count, do_regex, do_eclass, do_list; |
50 |
char do_count, do_regex, do_eclass, do_list; |
49 |
char show_filename, skip_comments, invert_list; |
51 |
char show_filename, skip_comments, invert_list, show_name; |
50 |
FILE *fp = NULL; |
52 |
FILE *fp = NULL; |
51 |
DIR *eclass_dir = NULL; |
53 |
DIR *eclass_dir = NULL; |
52 |
struct dirent *dentry; |
54 |
struct dirent *dentry; |
53 |
char ebuild[_Q_PATH_MAX]; |
55 |
char ebuild[_Q_PATH_MAX]; |
|
|
56 |
char name[_Q_PATH_MAX]; |
54 |
char buf0[BUFSIZ]; |
57 |
char buf0[BUFSIZ]; |
55 |
int reflags = REG_NOSUB; |
58 |
int reflags = REG_NOSUB; |
56 |
char invert_match = 0; |
59 |
char invert_match = 0; |
Lines 64-70
Link Here
|
64 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
67 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
65 |
|
68 |
|
66 |
do_count = do_regex = do_eclass = do_list = 0; |
69 |
do_count = do_regex = do_eclass = do_list = 0; |
67 |
show_filename = skip_comments = invert_list = 0; |
70 |
show_filename = skip_comments = invert_list = show_name = 0; |
68 |
|
71 |
|
69 |
while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { |
72 |
while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { |
70 |
switch (i) { |
73 |
switch (i) { |
Lines 79-84
Link Here
|
79 |
case 'e': do_regex = 1; break; |
82 |
case 'e': do_regex = 1; break; |
80 |
case 'E': do_eclass = 1; break; |
83 |
case 'E': do_eclass = 1; break; |
81 |
case 'H': show_filename = 1; break; |
84 |
case 'H': show_filename = 1; break; |
|
|
85 |
case 'N': show_name = 1; break; |
82 |
case 's': skip_comments = 1; break; |
86 |
case 's': skip_comments = 1; break; |
83 |
case 'S': skip_pattern = optarg; break; |
87 |
case 'S': skip_pattern = optarg; break; |
84 |
COMMON_GETOPTS_CASES(qgrep) |
88 |
COMMON_GETOPTS_CASES(qgrep) |
Lines 133-138
Link Here
|
133 |
if ((newfp = fopen(ebuild, "r")) != NULL) { |
137 |
if ((newfp = fopen(ebuild, "r")) != NULL) { |
134 |
unsigned int lineno = 0; |
138 |
unsigned int lineno = 0; |
135 |
count = 0; |
139 |
count = 0; |
|
|
140 |
|
141 |
if (show_name) { |
142 |
if (do_eclass) { |
143 |
/* cut ".eclass" */ |
144 |
*p = '\0'; |
145 |
/* and skip "eclass/" */ |
146 |
snprintf(name, sizeof(name), "%s", ebuild + 7); |
147 |
} else { |
148 |
/* cut ".ebuild" */ |
149 |
*(p-7) = '\0'; |
150 |
/* cut "/foo/" from "cat/foo/foo-x.y" */ |
151 |
if ((p = strchr(ebuild, '/')) == NULL) |
152 |
continue; |
153 |
*(p++) = '\0'; |
154 |
/* find head of the ebuild basename */ |
155 |
if ((p = strchr(p, '/')) == NULL) |
156 |
continue; |
157 |
/* find start of the pkg name */ |
158 |
snprintf(name, sizeof(name), "%s/%s", ebuild, ++p); |
159 |
} |
160 |
} |
161 |
|
136 |
while ((fgets(buf0, sizeof(buf0), newfp)) != NULL) { |
162 |
while ((fgets(buf0, sizeof(buf0), newfp)) != NULL) { |
137 |
lineno++; |
163 |
lineno++; |
138 |
if ((p = strrchr(buf0, '\n')) != NULL) |
164 |
if ((p = strrchr(buf0, '\n')) != NULL) |
Lines 170-177
Link Here
|
170 |
|
196 |
|
171 |
count++; |
197 |
count++; |
172 |
if (do_count || do_list) continue; |
198 |
if (do_count || do_list) continue; |
173 |
if (verbose || show_filename) { |
199 |
if (verbose || show_filename || show_name) { |
174 |
printf("%s:", ebuild); |
200 |
printf("%s:", (show_name ? name : ebuild)); |
175 |
if (verbose > 1) printf("%d:", lineno); |
201 |
if (verbose > 1) printf("%d:", lineno); |
176 |
printf(" "); |
202 |
printf(" "); |
177 |
} |
203 |
} |
Lines 179-189
Link Here
|
179 |
} |
205 |
} |
180 |
fclose(newfp); |
206 |
fclose(newfp); |
181 |
if (do_count && count) { |
207 |
if (do_count && count) { |
182 |
if (verbose || show_filename) printf("%s:", ebuild); |
208 |
if (verbose || show_filename || show_name) |
|
|
209 |
printf("%s:", (show_name ? name : ebuild)); |
183 |
printf("%d", count); |
210 |
printf("%d", count); |
184 |
puts(""); |
211 |
puts(""); |
185 |
} else if (do_list && ((count && !invert_list) || (!count && invert_list))) |
212 |
} else if (do_list && ((count && !invert_list) || (!count && invert_list))) |
186 |
printf("%s\n", ebuild); |
213 |
printf("%s\n", (show_name ? name : ebuild)); |
187 |
} |
214 |
} |
188 |
} |
215 |
} |
189 |
if (do_eclass) |
216 |
if (do_eclass) |