summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2022-04-27 21:48:14 +0300
committerArnold D. Robbins <arnold@skeeve.com>2022-04-27 21:48:14 +0300
commit0171cdeb5ce6f0d43bc41b0a69d706d367370bd0 (patch)
tree52c5c474a5d623e6714e4054c2eb0aa13cb579c8
parentcb970456a0cc9e9b024afc5664d27ba486e60715 (diff)
downloadgawk-0171cdeb5ce6f0d43bc41b0a69d706d367370bd0.tar.gz
Update handling of [...---...] and add test.
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst6
-rw-r--r--support/ChangeLog5
-rw-r--r--support/regcomp.c30
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am3
-rw-r--r--test/Makefile.in8
-rw-r--r--test/Maketests5
-rw-r--r--test/regex3minus.awk3
-rw-r--r--test/regex3minus.ok1
10 files changed, 53 insertions, 17 deletions
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 132b6e1c..814eee19 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2022-04-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Regenerated.
+
2022-04-21 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Regenerated.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 2ea1822c..03081946 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -169,6 +169,7 @@ BASIC_TESTS = \
posix2008sub prdupval prec printf0 printf1 printfchar prmarscl \
prmreuse prt1eval prtoeval rand randtest range1 range2 readbuf \
rebrackloc rebt8b1 rebuild redfilnm regeq regexpbrack regexpbrack2 \
+ regex3minus \
regexprange regrange reindops reparse resplit rri1 rs rscompat \
rsnul1nl rsnulbig rsnulbig2 rsnullre rsnulw rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite scalar sclforin sclifin setrec0 \
@@ -2173,6 +2174,11 @@ regexpbrack2:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+regex3minus:
+ @echo $@
+ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regexprange:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/support/ChangeLog b/support/ChangeLog
index 26acdf24..4948abe8 100644
--- a/support/ChangeLog
+++ b/support/ChangeLog
@@ -1,3 +1,8 @@
+2022-04-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * regcomp.c (peek_token_bracket): Sync to version from GNULIB
+ that fixes the "---" issue.
+
2022-04-21 Arnold D. Robbins <arnold@skeeve.com>
* regcomp.c (peek_token_bracket): Allow "---" to be a range
diff --git a/support/regcomp.c b/support/regcomp.c
index adfe28e2..122c3de5 100644
--- a/support/regcomp.c
+++ b/support/regcomp.c
@@ -2038,29 +2038,25 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
}
switch (c)
{
- case '-':
- // Special case. V7 Unix grep and Unix awk and mawk allow
- // [...---...] (3 minus signs in a bracket expression) to represent
- // a single minus sign. Let's try to support that without breaking
- // anything else.
- if (re_string_peek_byte (input, 1) == '-' && re_string_peek_byte (input, 2) == '-')
- {
- // advance past the minus signs
- (void) re_string_fetch_byte (input);
- (void) re_string_fetch_byte (input);
-
- token->type = CHARACTER;
- token->opr.c = '-';
- }
- else
- token->type = OP_CHARSET_RANGE;
- break;
case ']':
token->type = OP_CLOSE_BRACKET;
break;
case '^':
token->type = OP_NON_MATCH_LIST;
break;
+ case '-':
+ /* In V7 Unix grep and Unix awk and mawk, [...---...]
+ (3 adjacent minus signs) stands for a single minus sign.
+ Support that without breaking anything else. */
+ if (! (re_string_cur_idx (input) + 2 < re_string_length (input)
+ && re_string_peek_byte (input, 1) == '-'
+ && re_string_peek_byte (input, 2) == '-'))
+ {
+ token->type = OP_CHARSET_RANGE;
+ break;
+ }
+ re_string_skip_bytes (input, 2);
+ FALLTHROUGH;
default:
token->type = CHARACTER;
}
diff --git a/test/ChangeLog b/test/ChangeLog
index 4edcbf69..91ed0ece 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2022-04-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): regex3minus, new test.
+ * regex3minus.awk, regex3minus.ok: New files.
+
2022-04-21 Arnold D. Robbins <arnold@skeeve.com>
* profile5.ok, profile10.ok, profile11.ok: Updated after code changes.
diff --git a/test/Makefile.am b/test/Makefile.am
index 04394b3c..3c949a49 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1065,6 +1065,8 @@ EXTRA_DIST = \
regeq.awk \
regeq.in \
regeq.ok \
+ regex3minus.awk \
+ regex3minus.ok \
regexpbrack.awk \
regexpbrack.in \
regexpbrack.ok \
@@ -1430,6 +1432,7 @@ BASIC_TESTS = \
posix2008sub prdupval prec printf0 printf1 printfchar prmarscl \
prmreuse prt1eval prtoeval rand randtest range1 range2 readbuf \
rebrackloc rebt8b1 rebuild redfilnm regeq regexpbrack regexpbrack2 \
+ regex3minus \
regexprange regrange reindops reparse resplit rri1 rs rscompat \
rsnul1nl rsnulbig rsnulbig2 rsnullre rsnulw rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite scalar sclforin sclifin setrec0 \
diff --git a/test/Makefile.in b/test/Makefile.in
index 7e39f325..ac649b34 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1331,6 +1331,8 @@ EXTRA_DIST = \
regeq.awk \
regeq.in \
regeq.ok \
+ regex3minus.awk \
+ regex3minus.ok \
regexpbrack.awk \
regexpbrack.in \
regexpbrack.ok \
@@ -1696,6 +1698,7 @@ BASIC_TESTS = \
posix2008sub prdupval prec printf0 printf1 printfchar prmarscl \
prmreuse prt1eval prtoeval rand randtest range1 range2 readbuf \
rebrackloc rebt8b1 rebuild redfilnm regeq regexpbrack regexpbrack2 \
+ regex3minus \
regexprange regrange reindops reparse resplit rri1 rs rscompat \
rsnul1nl rsnulbig rsnulbig2 rsnullre rsnulw rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite scalar sclforin sclifin setrec0 \
@@ -3881,6 +3884,11 @@ regexpbrack2:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+regex3minus:
+ @echo $@
+ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regexprange:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index efc168b5..6af82092 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -924,6 +924,11 @@ regexpbrack2:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+regex3minus:
+ @echo $@
+ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regexprange:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/regex3minus.awk b/test/regex3minus.awk
new file mode 100644
index 00000000..bb23cad8
--- /dev/null
+++ b/test/regex3minus.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ print match("abc-def", /[qrs---tuv]/)
+}
diff --git a/test/regex3minus.ok b/test/regex3minus.ok
new file mode 100644
index 00000000..b8626c4c
--- /dev/null
+++ b/test/regex3minus.ok
@@ -0,0 +1 @@
+4