--- qgrep.c.eclass 2007-03-13 23:05:34.000000000 +0100 +++ qgrep.c 2007-03-13 23:05:01.000000000 +0100 @@ -10,7 +10,7 @@ #ifdef APPLET_qgrep -#define QGREP_FLAGS "IiHceE" COMMON_FLAGS +#define QGREP_FLAGS "IiHceEs" COMMON_FLAGS static struct option const qgrep_long_opts[] = { {"invert-match", no_argument, NULL, 'I'}, {"ignore-case", no_argument, NULL, 'i'}, @@ -18,6 +18,7 @@ {"count", no_argument, NULL, 'c'}, {"regexp", no_argument, NULL, 'e'}, {"eclass", no_argument, NULL, 'E'}, + {"skip-comments", no_argument, NULL, 's'}, COMMON_LONG_OPTS }; static const char *qgrep_opts_help[] = { @@ -27,5 +28,6 @@ "Only print a count of matching lines per FILE", "Use PATTERN as a regular expression", "Search in eclasses instead of ebuilds", + "Skip comments lines", COMMON_OPTS_HELP }; @@ -38,7 +40,7 @@ int count = 0; char *p; char do_count, do_regex, do_eclass; - char show_filename; + char show_filename, skip_comments; FILE *fp = NULL; DIR *eclass_dir = NULL; struct dirent *dentry; @@ -54,7 +56,7 @@ DBG("argc=%d argv[0]=%s argv[1]=%s", 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) { switch (i) { @@ -67,6 +69,7 @@ case 'e': do_regex = 1; break; case 'E': do_eclass = 1; break; case 'H': show_filename = 1; break; + case 's': skip_comments = 1; break; COMMON_GETOPTS_CASES(qgrep) } } @@ -107,6 +110,12 @@ if ((p = strrchr(buf0, '\r')) != NULL) *p = 0; + if (skip_comments) { + p = buf0; + while (*p == ' ' || *p == '\t') p++; + if (*p == '#') continue; + } + if (!invert_match) { if (do_regex == 0) { if (( (FUNC *) (strfunc) (buf0, argv[optind])) == NULL) continue;