|
|
| |
#ifdef APPLET_qgrep | #ifdef APPLET_qgrep |
| |
#define QGREP_FLAGS "IiHceE" COMMON_FLAGS |
#define QGREP_FLAGS "IiHceEs" 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'}, |
|
|
{"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'}, | {"eclass", no_argument, NULL, 'E'}, |
|
{"skip-comments", no_argument, NULL, 's'}, |
COMMON_LONG_OPTS | COMMON_LONG_OPTS |
}; | }; |
static const char *qgrep_opts_help[] = { | static const char *qgrep_opts_help[] = { |
|
|
"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", | "Search in eclasses instead of ebuilds", |
|
"Skip comments lines", |
COMMON_OPTS_HELP | COMMON_OPTS_HELP |
}; | }; |
|
|
int count = 0; | int count = 0; |
char *p; | char *p; |
char do_count, do_regex, do_eclass; | char do_count, do_regex, do_eclass; |
char show_filename; |
char show_filename, skip_comments; |
FILE *fp = NULL; | FILE *fp = NULL; |
DIR *eclass_dir = NULL; | DIR *eclass_dir = NULL; |
struct dirent *dentry; | struct dirent *dentry; |
|
|
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 = do_eclass = show_filename = 0; |
do_count = do_regex = do_eclass = show_filename = skip_comments = 0; |
| |
while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { | while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { |
switch (i) { | switch (i) { |
|
|
case 'e': do_regex = 1; break; | case 'e': do_regex = 1; break; |
case 'E': do_eclass = 1; break; | case 'E': do_eclass = 1; break; |
case 'H': show_filename = 1; break; | case 'H': show_filename = 1; break; |
|
case 's': skip_comments = 1; break; |
COMMON_GETOPTS_CASES(qgrep) | COMMON_GETOPTS_CASES(qgrep) |
} | } |
} | } |
|
|
if ((p = strrchr(buf0, '\r')) != NULL) | if ((p = strrchr(buf0, '\r')) != NULL) |
*p = 0; | *p = 0; |
| |
|
if (skip_comments) { |
|
p = buf0; |
|
while (*p == ' ' || *p == '\t') p++; |
|
if (*p == '#') continue; |
|
} |
|
|
if (!invert_match) { | if (!invert_match) { |
if (do_regex == 0) { | if (do_regex == 0) { |
if (( (FUNC *) (strfunc) (buf0, argv[optind])) == NULL) continue; | if (( (FUNC *) (strfunc) (buf0, argv[optind])) == NULL) continue; |