PERFORCE change 144904 for review
Gabor Kovesdan
gabor at FreeBSD.org
Tue Jul 8 18:58:04 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=144904
Change 144904 by gabor at gabor_server on 2008/07/08 18:57:23
- Change --exclude and --include to use fnmatch() for GNU compatibility
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#61 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#52 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#61 (text+ko) ====
@@ -88,7 +88,6 @@
/* Filename exclusion/inclusion patterns */
int epatterns, epattern_sz;
char **epattern;
-regex_t *er_pattern;
/* For regex errors */
char re_error[RE_ERROR_BUF + 1];
@@ -258,10 +257,8 @@
}
if (len > 0 && pat[len - 1] == '\n')
--len;
- /* pat may not be NUL-terminated */
epattern[epatterns] = grep_malloc(len + 1);
memcpy(epattern[epatterns], pat, len);
- epattern[epatterns][len] = '\0';
++epatterns;
}
@@ -568,15 +565,6 @@
errx(2, "%s", re_error);
}
}
- er_pattern = grep_calloc(epatterns, sizeof(*er_pattern));
- for (i = 0; i < epatterns; ++i) {
- c = regcomp(&er_pattern[i], epattern[i], REG_EXTENDED);
- if (c != 0) {
- regerror(c, &er_pattern[i], re_error,
- RE_ERROR_BUF);
- errx(2, "%s", re_error);
- }
- }
if (lbflag)
setlinebuf(stdout);
==== //depot/projects/soc2008/gabor_textproc/grep/util.c#52 (text+ko) ====
@@ -40,6 +40,7 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fnmatch.h>
#include <fts.h>
#include <stdio.h>
#include <stdlib.h>
@@ -93,23 +94,16 @@
break;
default:
if (exclflag) {
- regmatch_t pmatch;
-
ok = 1;
- pmatch.rm_so = 0;
- pmatch.rm_eo = strlen(p->fts_path);
- for (i = 0; i < epatterns; i++)
- if (regexec(&er_pattern[i], p->fts_path, 0, &pmatch, eflags) == 0) {
+ for (i = 0; i < epatterns; ++i)
+ if (fnmatch(epattern[i], p->fts_path, 0) == 0) {
ok = 0;
break;
}
} else if (inclflag) {
- regmatch_t pmatch;
ok = 0;
- pmatch.rm_so = 0;
- pmatch.rm_eo = strlen(p->fts_path);
for (i = 0; i < epatterns; i++)
- if (regexec(&er_pattern[i], p->fts_path, 0, &pmatch, eflags) == 0) {
+ if (fnmatch(epattern[i], p->fts_path, 0) == 0) {
ok = 1;
break;
}
More information about the p4-projects
mailing list