|
|
| |
#ifdef APPLET_qgrep | #ifdef APPLET_qgrep |
| |
#define QGREP_FLAGS "IiHce" COMMON_FLAGS |
#define QGREP_FLAGS "IiHceE" COMMON_FLAGS |
static struct option const qgrep_long_opts[] = { | static struct option const qgrep_long_opts[] = { |
{"invert-match", no_argument, NULL, 'I'}, | {"invert-match", no_argument, NULL, 'I'}, |
{"ignore-case", no_argument, NULL, 'i'}, | {"ignore-case", no_argument, NULL, 'i'}, |
{"with-filename", no_argument, NULL, 'H'}, | {"with-filename", no_argument, NULL, 'H'}, |
{"count", no_argument, NULL, 'c'}, | {"count", no_argument, NULL, 'c'}, |
{"regexp", no_argument, NULL, 'e'}, | {"regexp", no_argument, NULL, 'e'}, |
|
{"eclass", no_argument, NULL, 'E'}, |
COMMON_LONG_OPTS | COMMON_LONG_OPTS |
}; | }; |
static const char *qgrep_opts_help[] = { | static const char *qgrep_opts_help[] = { |
|
|
"Print the filename for each match", | "Print the filename for each match", |
"Only print a count of matching lines per FILE", | "Only print a count of matching lines per FILE", |
"Use PATTERN as a regular expression", | "Use PATTERN as a regular expression", |
|
"Search in eclasses instead of ebuilds", |
COMMON_OPTS_HELP | COMMON_OPTS_HELP |
}; | }; |
|
|
int i; | int i; |
int count = 0; | int count = 0; |
char *p; | char *p; |
char do_count, do_regex; |
char do_count, do_regex, do_eclass; |
char show_filename; | char show_filename; |
FILE *fp; |
FILE *fp = NULL; |
|
DIR *eclass_dir = NULL; |
|
struct dirent *dentry; |
char ebuild[_Q_PATH_MAX]; | char ebuild[_Q_PATH_MAX]; |
char buf0[BUFSIZ]; | char buf0[BUFSIZ]; |
int reflags = REG_NOSUB; | int reflags = REG_NOSUB; |
|
|
DBG("argc=%d argv[0]=%s argv[1]=%s", | DBG("argc=%d argv[0]=%s argv[1]=%s", |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); | argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
| |
do_count = do_regex = show_filename = 0; |
do_count = do_regex = do_eclass = show_filename = 0; |
| |
while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { | while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { |
switch (i) { | switch (i) { |
|
|
break; | break; |
case 'c': do_count = 1; break; | case 'c': do_count = 1; break; |
case 'e': do_regex = 1; break; | case 'e': do_regex = 1; break; |
|
case 'E': do_eclass = 1; break; |
case 'H': show_filename = 1; break; | case 'H': show_filename = 1; break; |
COMMON_GETOPTS_CASES(qgrep) | COMMON_GETOPTS_CASES(qgrep) |
} | } |
|
|
if (argc == optind) | if (argc == optind) |
qgrep_usage(EXIT_FAILURE); | qgrep_usage(EXIT_FAILURE); |
| |
initialize_ebuild_flat(); /* sets our pwd to $PORTDIR */ |
if (!do_eclass) { |
|
initialize_ebuild_flat(); /* sets our pwd to $PORTDIR */ |
|
if ((fp = fopen(CACHE_EBUILD_FILE, "r")) == NULL) |
|
return 1; |
|
} else { |
|
if ((chdir(portdir)) != 0) |
|
errp("chdir to PORTDIR '%s' failed", portdir); |
|
if ((eclass_dir = opendir("eclass")) == NULL) |
|
errp("opendir(\"%s/eclass\") failed", portdir); |
|
} |
| |
if ((fp = fopen(CACHE_EBUILD_FILE, "r")) == NULL) |
while (do_eclass |
return 1; |
? ((dentry = readdir(eclass_dir)) |
while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) { |
&& snprintf(ebuild, sizeof(ebuild), "eclass/%s", dentry->d_name)) |
|
: ((fgets(ebuild, sizeof(ebuild), fp)) != NULL)) { |
FILE *newfp; | FILE *newfp; |
if ((p = strchr(ebuild, '\n')) != NULL) |
if (do_eclass) { |
*p = 0; |
if ((p = strrchr(ebuild, '.')) == NULL) |
|
continue; |
|
if (strcmp(p, ".eclass")) |
|
continue; |
|
} else if ((p = strchr(ebuild, '\n')) != NULL) |
|
*p = 0; |
if ((newfp = fopen(ebuild, "r")) != NULL) { | if ((newfp = fopen(ebuild, "r")) != NULL) { |
unsigned int lineno = 0; | unsigned int lineno = 0; |
count = 0; | count = 0; |
|
|
} | } |
} | } |
} | } |
fclose(fp); |
if (do_eclass) |
|
closedir(eclass_dir); |
|
else |
|
fclose(fp); |
return EXIT_SUCCESS; | return EXIT_SUCCESS; |
} | } |
| |