PERFORCE change 157128 for review
Gabor Kovesdan
gabor at FreeBSD.org
Wed Feb 4 02:24:11 PST 2009
http://perforce.freebsd.org/chv.cgi?CH=157128
Change 157128 by gabor at gabor_server on 2009/02/04 10:23:19
- Add --exclude-dir and --include-dir, options similar to
--exclude and --include but for directories
Requested by: bz
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#80 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#79 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#80 (text+ko) ====
@@ -182,8 +182,8 @@
{"colour", optional_argument, NULL, COLOR_OPT},
{"exclude", required_argument, NULL, R_EXCLUDE_OPT},
{"include", required_argument, NULL, R_INCLUDE_OPT},
-/* {"exclude-dir", required_argument, NULL, R_DEXCLUDE_OPT},
- {"include-dir", required_argument, NULL, R_DINCLUDE_OPT}, */
+ {"exclude-dir", required_argument, NULL, R_DEXCLUDE_OPT},
+ {"include-dir", required_argument, NULL, R_DINCLUDE_OPT},
{"after-context", required_argument, NULL, 'A'},
{"text", no_argument, NULL, 'a'},
{"before-context", required_argument, NULL, 'B'},
==== //depot/projects/soc2008/gabor_textproc/grep/util.c#79 (text+ko) ====
@@ -66,6 +66,7 @@
FTS *fts;
FTSENT *p;
int i, c, ok, fts_flags;
+ char *d, *dirname;
c = fts_flags = 0;
@@ -99,14 +100,30 @@
/* Check for file exclusion/inclusion */
ok = 1;
if (exclflag) {
+ d = strrchr(p->fts_path, '/');
+ dirname = grep_malloc(sizeof(char) * (d - p->fts_path + 2));
+ strlcpy(dirname, p->fts_path, (d - p->fts_path + 1));
for (i = 0; i < epatterns; ++i) {
- if (fnmatch(epattern[i].pat, basename(p->fts_path), 0) == 0) {
- if (epattern[i].mode == EXCL_PAT)
- ok = 0;
- else
- ok = 1;
+ switch(epattern[i].type) {
+ case FILE_PAT:
+ if (fnmatch(epattern[i].pat, basename(p->fts_path), 0) == 0) {
+ if (epattern[i].mode == EXCL_PAT)
+ ok = 0;
+ else
+ ok = 1;
+ }
+ break;
+ case DIR_PAT:
+ if (strstr(dirname, epattern[i].pat) != NULL) {
+ if (epattern[i].mode == EXCL_PAT)
+ ok = 0;
+ else
+ ok = 1;
+ }
+ break;
}
}
+ free(dirname);
}
if (ok)
More information about the p4-projects
mailing list