diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rwxr-xr-x | RunGrepTest | 16 | ||||
-rw-r--r-- | pcregrep.c | 40 | ||||
-rw-r--r-- | testdata/grepoutput | 16 |
4 files changed, 66 insertions, 11 deletions
@@ -26,6 +26,11 @@ Version 8.00 ??-???-?? 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 --------------------- diff --git a/RunGrepTest b/RunGrepTest index aba5ffe..1872e9c 100755 --- a/RunGrepTest +++ b/RunGrepTest @@ -179,13 +179,13 @@ echo "---------------------------- Test 42 ------------------------------" >>tes (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 55 -----------------------------" >>test 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 @@ -210,7 +210,7 @@ static option_item optionlist[] = { { 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 @@ for (i = 1; i < argc; i++) 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 @@ for (i = 1; i < argc; i++) } } } - 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 @@ for (i = 1; i < argc; i++) } } - /* 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 diff --git a/testdata/grepoutput b/testdata/grepoutput index ecc5a53..da7a370 100644 --- a/testdata/grepoutput +++ b/testdata/grepoutput @@ -431,3 +431,19 @@ This line contains [1;31mpattern[00m not on a [1;31mline by itself[00m. ---------------------------- 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. |