Revision: 422
http://vcs.pcre.org/viewvc?view=rev&revision=422
Author: ph10
Date: 2009-08-14 17:42:55 +0100 (Fri, 14 Aug 2009)
Log Message:
-----------
Fix --regex(p)=pattern not working in pcregrep.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/RunGrepTest
code/trunk/pcregrep.c
code/trunk/testdata/grepoutput
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2009-08-14 15:43:27 UTC (rev 421)
+++ code/trunk/ChangeLog 2009-08-14 16:42:55 UTC (rev 422)
@@ -26,6 +26,11 @@
but it seems right to fix it, and I didn't think it was worth preserving
the old behaviour.
+5. The command line items --regex=pattern and --regexp=pattern were not
+ recognized by pcregrep, which required --regex pattern or --regexp pattern
+ (with a space rather than an '='). The man page documented the '=' forms,
+ which are compatible with GNU grep; these now work.
+
Version 7.9 11-Apr-09
---------------------
Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest 2009-08-14 15:43:27 UTC (rev 421)
+++ code/trunk/RunGrepTest 2009-08-14 16:42:55 UTC (rev 422)
@@ -179,13 +179,13 @@
(cd $srcdir; $valgrind $pcregrep -on 'before|zero|after' ./testdata/grepinput) >>testtry
echo "---------------------------- Test 43 ------------------------------" >>testtry
-(cd $srcdir; $valgrind $pcregrep -on -e before -e zero -e after ./testdata/grepinput) >>testtry
+(cd $srcdir; $valgrind $pcregrep -on -e before -ezero -e after ./testdata/grepinput) >>testtry
echo "---------------------------- Test 44 ------------------------------" >>testtry
(cd $srcdir; $valgrind $pcregrep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtry
echo "---------------------------- Test 45 ------------------------------" >>testtry
-(cd $srcdir; $valgrind $pcregrep -e abc -e '(unclosed' ./testdata/grepinput) 2>>testtry >>testtry
+(cd $srcdir; $valgrind $pcregrep -eabc -e '(unclosed' ./testdata/grepinput) 2>>testtry >>testtry
echo "---------------------------- Test 46 ------------------------------" >>testtry
(cd $srcdir; $valgrind $pcregrep -Fx "AB.VE
@@ -223,6 +223,18 @@
echo "---------------------------- Test 56 -----------------------------" >>testtry
(cd $srcdir; $valgrind $pcregrep -c -l lazy ./testdata/grepinput*) >>testtry
+echo "---------------------------- Test 57 -----------------------------" >>testtry
+(cd $srcdir; $valgrind $pcregrep --regex=PATTERN ./testdata/grepinput) >>testtry
+
+echo "---------------------------- Test 58 -----------------------------" >>testtry
+(cd $srcdir; $valgrind $pcregrep --regexp=PATTERN ./testdata/grepinput) >>testtry
+
+echo "---------------------------- Test 59 -----------------------------" >>testtry
+(cd $srcdir; $valgrind $pcregrep --regex PATTERN ./testdata/grepinput) >>testtry
+
+echo "---------------------------- Test 60 -----------------------------" >>testtry
+(cd $srcdir; $valgrind $pcregrep --regexp PATTERN ./testdata/grepinput) >>testtry
+
# Now compare the results.
$cf $srcdir/testdata/grepoutput testtry
Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c 2009-08-14 15:43:27 UTC (rev 421)
+++ code/trunk/pcregrep.c 2009-08-14 16:42:55 UTC (rev 422)
@@ -210,7 +210,7 @@
{ OP_OP_STRING, N_COLOUR, &colour_option, "colour=option", "matched text colour option" },
{ OP_STRING, 'D', &DEE_option, "devices=action","how to handle devices, FIFOs, and sockets" },
{ OP_STRING, 'd', &dee_option, "directories=action", "how to handle directories" },
- { OP_PATLIST, 'e', NULL, "regex(p)", "specify pattern (may be used more than once)" },
+ { OP_PATLIST, 'e', NULL, "regex(p)=pattern", "specify pattern (may be used more than once)" },
{ OP_NODATA, 'F', NULL, "fixed-strings", "patterns are sets of newline-separated strings" },
{ OP_STRING, 'f', &pattern_filename, "file=path", "read patterns from file" },
{ OP_NODATA, N_FOFFSETS, NULL, "file-offsets", "output file offsets, not text" },
@@ -1929,14 +1929,17 @@
Some options have variations in the long name spelling: specifically, we
allow "regexp" because GNU grep allows it, though I personally go along
with Jeffrey Friedl and Larry Wall in preferring "regex" without the "p".
- These options are entered in the table as "regex(p)". No option is in both
- these categories, fortunately. */
+ These options are entered in the table as "regex(p)". Options can be in
+ both these categories. */
for (op = optionlist; op->one_char != 0; op++)
{
char *opbra = strchr(op->long_name, '(');
char *equals = strchr(op->long_name, '=');
- if (opbra == NULL) /* Not a (p) case */
+
+ /* Handle options with only one spelling of the name */
+
+ if (opbra == NULL) /* Does not contain '(' */
{
if (equals == NULL) /* Not thing=data case */
{
@@ -1958,16 +1961,36 @@
}
}
}
- else /* Special case xxxx(p) */
+
+ /* Handle options with an alternate spelling of the name */
+
+ else
{
char buff1[24];
char buff2[24];
+
int baselen = opbra - op->long_name;
+ int fulllen = strchr(op->long_name, ')') - op->long_name + 1;
+ int arglen = (argequals == NULL || equals == NULL)?
+ (int)strlen(arg) : argequals - arg;
+
sprintf(buff1, "%.*s", baselen, op->long_name);
- sprintf(buff2, "%s%.*s", buff1,
- (int)strlen(op->long_name) - baselen - 2, opbra + 1);
- if (strcmp(arg, buff1) == 0 || strcmp(arg, buff2) == 0)
+ sprintf(buff2, "%s%.*s", buff1, fulllen - baselen - 2, opbra + 1);
+
+ if (strncmp(arg, buff1, arglen) == 0 ||
+ strncmp(arg, buff2, arglen) == 0)
+ {
+ if (equals != NULL && argequals != NULL)
+ {
+ option_data = argequals;
+ if (*option_data == '=')
+ {
+ option_data++;
+ longopwasequals = TRUE;
+ }
+ }
break;
+ }
}
}
@@ -1978,7 +2001,6 @@
}
}
-
/* Jeffrey Friedl's debugging harness uses these additional options which
are not in the right form for putting in the option table because they use
only one hyphen, yet are more than one character long. By putting them
Modified: code/trunk/testdata/grepoutput
===================================================================
--- code/trunk/testdata/grepoutput 2009-08-14 15:43:27 UTC (rev 421)
+++ code/trunk/testdata/grepoutput 2009-08-14 16:42:55 UTC (rev 422)
@@ -431,3 +431,19 @@
---------------------------- Test 56 -----------------------------
./testdata/grepinput:456
./testdata/grepinputv:1
+---------------------------- Test 57 -----------------------------
+PATTERN at the start of a line.
+In the middle of a line, PATTERN appears.
+Check up on PATTERN near the end.
+---------------------------- Test 58 -----------------------------
+PATTERN at the start of a line.
+In the middle of a line, PATTERN appears.
+Check up on PATTERN near the end.
+---------------------------- Test 59 -----------------------------
+PATTERN at the start of a line.
+In the middle of a line, PATTERN appears.
+Check up on PATTERN near the end.
+---------------------------- Test 60 -----------------------------
+PATTERN at the start of a line.
+In the middle of a line, PATTERN appears.
+Check up on PATTERN near the end.