PERFORCE change 144879 for review
Gabor Kovesdan
gabor at FreeBSD.org
Tue Jul 8 12:48:28 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=144879
Change 144879 by gabor at gabor_server on 2008/07/08 12:47:41
- Add some code for an upcoming optional Perl regexp support
- Rename -P (skip links) to -p because the Perl regexp support
should be -P
- Better code for the regexp type
- Fix comment
- Remove some unnecessary header inclusions
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/Makefile#11 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.1#12 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#60 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.h#35 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/Makefile#11 (text+ko) ====
@@ -20,6 +20,12 @@
LDADD= -lz -lbz2
DPADD= ${LIBZ} ${LIBBZ2}
+.if defined(WITH_PCRE)
+CFLAGS+= WITH_PCRE=yes
+LDADD+= -lpcre
+DPADD= /usr/local/lib/libpcre.a
+.endif
+
.if !defined(WITHOUT_NLS)
NLS= hu_HU.ISO8859-2
NLS+= pt_BR.ISO8859-1
==== //depot/projects/soc2008/gabor_textproc/grep/grep.1#12 (text+ko) ====
@@ -29,7 +29,7 @@
.\"
.\" @(#)grep.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd 16 Jun, 2008
+.Dd 8 Jul, 2008
.Dt GREP 1
.Os
.Sh NAME
@@ -39,7 +39,7 @@
.Sh SYNOPSIS
.Nm grep
.Bk -words
-.Op Fl abcdDEFGHhIiJLlmnOoPqRSsUVvwxZ
+.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZ
.Op Fl A Ar num
.Op Fl B Ar num
.Op Fl C Ns Op Ar num
@@ -281,7 +281,7 @@
The default is not to follow symbolic links.
.It Fl o, Fl Fl only-matching
Prints only the matching part of the lines.
-.It Fl P
+.It Fl p
If
.Fl R
is specified, no symbolic links are followed.
==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#60 (text+ko) ====
@@ -85,7 +85,7 @@
char **pattern;
regex_t *r_pattern;
-/* Filename exclusion patterns */
+/* Filename exclusion/inclusion patterns */
int epatterns, epattern_sz;
char **epattern;
regex_t *er_pattern;
@@ -96,9 +96,6 @@
/* Command-line flags */
unsigned long long Aflag; /* -A x: print x lines trailing each match */
unsigned long long Bflag; /* -B x: print x lines leading each match */
-int Eflag; /* -E: interpret pattern as extended regexp */
-int Fflag; /* -F: interpret pattern as list of fixed strings */
-int Gflag; /* -G: interpret pattern as basic regexp */
int Hflag; /* -H: always print file name */
int Jflag; /* -J: grep in bzipped file */
int Lflag; /* -L: only show names of files with no matches */
@@ -124,6 +121,7 @@
char *color; /* --color */
unsigned long long mcount; /* count for -m */
+int grepbehave = GREP_BASIC;
int binbehave = BINFILE_BIN;
int devbehave = DEV_GREP;
int dirbehave = DIR_GREP;
@@ -160,7 +158,7 @@
exit(2);
}
-static char *optstr = "0123456789A:B:C:D:EFGHIJLOPSRUVZabcd:e:f:hilm:noqrsuvwxy";
+static char *optstr = "0123456789A:B:C:D:EFGHIJLOPSRUVZabcd:e:f:hilm:nopqrsuvwxy";
struct option long_options[] =
{
@@ -196,6 +194,7 @@
{"max-count", required_argument, NULL, 'm'},
{"line-number", no_argument, NULL, 'n'},
{"only-matching", no_argument, NULL, 'o'},
+ {"perl-regexp", no_argument, NULL, 'P'},
{"quiet", no_argument, NULL, 'q'},
{"silent", no_argument, NULL, 'q'},
{"recursive", no_argument, NULL, 'r'},
@@ -226,20 +225,20 @@
if (len > 0 && pat[len - 1] == '\n')
--len;
/* pat may not be NUL-terminated */
- if (wflag && !Fflag) {
+ if (wflag && !(grepbehave == GREP_FIXED)) {
int bol = 0, eol = 0, extra;
if (pat[0] == '^')
bol = 1;
if (len > 0 && pat[len - 1] == '$')
eol = 1;
- extra = Eflag ? 2 : 4;
+ extra = (grepbehave == GREP_EXTENDED) ? 2 : 4;
pattern[patterns] = grep_malloc(len + 15 + extra);
snprintf(pattern[patterns], len + 15 + extra,
"%s[[:<:]]%s%.*s%s[[:>:]]%s",
bol ? "^" : "",
- Eflag ? "(" : "\\(",
+ (grepbehave == GREP_EXTENDED) ? "(" : "\\(",
(int)len - bol - eol, pat + bol,
- Eflag ? ")" : "\\)",
+ (grepbehave == GREP_EXTENDED) ? ")" : "\\)",
eol ? "$" : "");
len += 14 + extra;
} else {
@@ -297,25 +296,25 @@
switch (__progname[0]) {
case 'e':
- Eflag++;
+ grepbehave = GREP_EXTENDED;
break;
case 'f':
- Fflag++;
+ grepbehave = GREP_FIXED;
break;
case 'g':
- Gflag++;
+ grepbehave = GREP_BASIC;
break;
case 'z':
Zflag++;
switch(__progname[1]) {
case 'e':
- Eflag++;
+ grepbehave = GREP_EXTENDED;
break;
case 'f':
- Fflag++;
+ grepbehave = GREP_FIXED;
break;
case 'g':
- Gflag++;
+ grepbehave = GREP_BASIC;
break;
}
break;
@@ -377,24 +376,21 @@
errx(2, getstr(13));
break;
case 'E':
- Fflag = Gflag = 0;
- Eflag++;
+ grepbehave = GREP_EXTENDED;
break;
case 'e':
add_pattern(optarg, strlen(optarg));
needpattern = 0;
break;
case 'F':
- Eflag = Gflag = 0;
- Fflag++;
+ grepbehave = GREP_FIXED;
break;
case 'f':
read_patterns(optarg);
needpattern = 0;
break;
case 'G':
- Eflag = Fflag = 0;
- Gflag++;
+ grepbehave = GREP_BASIC;
break;
case 'H':
Hflag++;
@@ -439,6 +435,9 @@
oflag++;
break;
case 'P':
+ grepbehave = GREP_PERL;
+ break;
+ case 'p':
linkbehave = LINK_SKIP;
break;
case 'q':
@@ -543,12 +542,23 @@
++argv;
}
- if (Fflag)
- cflags |= REG_NOSPEC;
- else if (Gflag)
- cflags |= REG_BASIC;
- else if (Eflag)
- cflags |= REG_EXTENDED;
+ switch (grepbehave) {
+ case GREP_FIXED:
+ cflags |= REG_NOSPEC;
+ break;
+ case GREP_BASIC:
+ cflags |= REG_BASIC;
+ break;
+ case GREP_EXTENDED:
+ cflags |= REG_EXTENDED;
+ break;
+ case GREP_PERL:
+ errx(2, "Not yet implemented");
+ break;
+ default:
+ /* NOTREACHED */
+ usage();
+ }
r_pattern = grep_calloc(patterns, sizeof(*r_pattern));
for (i = 0; i < patterns; ++i) {
c = regcomp(&r_pattern[i], pattern[i], cflags);
==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#35 (text+ko) ====
@@ -26,12 +26,13 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <sys/limits.h>
-
#include <regex.h>
#include <stdio.h>
+#if defined(WITH_PCRE)
+#include <pcre.h>
+#endif
+
#ifdef WITHOUT_NLS
#define getstr(n) errstr[n]
#else
@@ -45,6 +46,11 @@
#define VERSION "2.5.1-FreeBSD"
+#define GREP_FIXED 0
+#define GREP_BASIC 1
+#define GREP_EXTENDED 2
+#define GREP_PERL 3
+
#define BINFILE_BIN 0
#define BINFILE_SKIP 1
#define BINFILE_TEXT 2
More information about the p4-projects
mailing list