summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2019-04-07 21:43:38 +0300
committerArnold D. Robbins <arnold@skeeve.com>2019-04-07 21:43:38 +0300
commit8ae4556cd755b7902afba7ab89313d5aa8801173 (patch)
tree2bb7041df050d8744d7fa2517ac0aca460ea7a9b
parent12a5a583e98ba7a6886407df6df74a1dbb65ae64 (diff)
downloadgawk-8ae4556cd755b7902afba7ab89313d5aa8801173.tar.gz
Single-byte locales use locale settings for ignoring case.
-rwxr-xr-xChangeLog6
-rw-r--r--NEWS5
-rw-r--r--eval.c14
-rw-r--r--main.c4
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am6
-rw-r--r--test/Makefile.in12
-rw-r--r--test/Maketests6
-rw-r--r--test/range2.awk1
-rw-r--r--test/range2.ok1
10 files changed, 48 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 37de7911..7eacd7ab 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-04-05 Arnold D. Robbins <arnold@skeeve.com>
+
+ * eval.c (load_casetable): Always use the locale's settings.
+ (set_IGNORECASE): Don't call load_casetable.
+ * main.c (main): Call load_casetable if in a single-byte locale.
+
2019-03-22 Arnold D. Robbins <arnold@skeeve.com>
* config.guess: Updated from GNULIB.
diff --git a/NEWS b/NEWS
index d87e0d5c..04965129 100644
--- a/NEWS
+++ b/NEWS
@@ -44,5 +44,8 @@ Changes from 4.2.1 to 5.0.0
gawk -e 'BEGIN {' -e 'print "hello" }'
-12. A number of bugs, some of them quite significant, have been fixed.
+12. Gawk now uses the locale settings for ignoring case in single byte
+ locales, instead of hardwiring in Latin-1.
+
+13. A number of bugs, some of them quite significant, have been fixed.
See the ChangeLog for details.
diff --git a/eval.c b/eval.c
index 4650150b..132c8509 100644
--- a/eval.c
+++ b/eval.c
@@ -104,6 +104,12 @@ char casetable[] = {
'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
/* Latin 1: */
+ /*
+ * 4/2019: This is now overridden; in single byte locales
+ * we call load_casetable from main and it fills in the values
+ * based on the current locale. In particular, we want LC_ALL=C
+ * to work correctly for values >= 0200.
+ */
C('\200'), C('\201'), C('\202'), C('\203'), C('\204'), C('\205'), C('\206'), C('\207'),
C('\210'), C('\211'), C('\212'), C('\213'), C('\214'), C('\215'), C('\216'), C('\217'),
C('\220'), C('\221'), C('\222'), C('\223'), C('\224'), C('\225'), C('\226'), C('\227'),
@@ -201,18 +207,12 @@ load_casetable(void)
{
#if defined(LC_CTYPE)
int i;
- char *cp;
static bool loaded = false;
if (loaded || do_traditional)
return;
loaded = true;
- cp = setlocale(LC_CTYPE, NULL);
-
- /* this is not per standard, but it's pretty safe */
- if (cp == NULL || strcmp(cp, "C") == 0 || strcmp(cp, "POSIX") == 0)
- return;
#ifndef USE_EBCDIC
/* use of isalpha is ok here (see is_alpha in awkgram.y) */
@@ -710,7 +710,7 @@ set_IGNORECASE()
warned = true;
lintwarn(_("`IGNORECASE' is a gawk extension"));
}
- load_casetable();
+
if (do_traditional)
IGNORECASE = false;
else
diff --git a/main.c b/main.c
index e2bcd724..d6e34266 100644
--- a/main.c
+++ b/main.c
@@ -320,6 +320,10 @@ main(int argc, char **argv)
/* init the cache for checking bytes if they're characters */
init_btowc_cache();
+ /* set up the single byte case table */
+ if (gawk_mb_cur_max == 1)
+ load_casetable();
+
if (do_nostalgia)
nostalgia();
diff --git a/test/ChangeLog b/test/ChangeLog
index de10e221..389edc9a 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-07 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): New test: range2. Needs LC_ALL=C.
+ * range2.awk, range2.ok: New files.
+
2019-03-17 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (mbprintf5): Add a minus so that the tests
diff --git a/test/Makefile.am b/test/Makefile.am
index 37d49848..57d0444c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -946,6 +946,8 @@ EXTRA_DIST = \
range1.awk \
range1.in \
range1.ok \
+ range2.awk \
+ range2.ok \
readbuf.awk \
readbuf.ok \
readdir.awk \
@@ -1301,7 +1303,7 @@ BASIC_TESTS = \
paramasfunc1 paramasfunc2 paramdup paramres paramtyp paramuninitglobal \
parse1 parsefld parseme pcntplus posix2008sub prdupval prec printf0 \
printf1 printfchar prmarscl prmreuse prt1eval prtoeval \
- rand randtest range1 readbuf rebrackloc rebt8b1 rebuild redfilnm regeq \
+ rand randtest range1 range2 readbuf rebrackloc rebt8b1 rebuild redfilnm regeq \
regexpbrack regexpbrack2 regexprange regrange reindops reparse resplit \
rri1 rs rscompat rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 rstest3 \
rstest4 rstest5 rswhite \
@@ -1422,7 +1424,7 @@ CHECK_MPFR = \
# Lists of tests that need particular locales
NEED_LOCALE_C = \
- clos1way gsubtst6
+ clos1way gsubtst6 range2
NEED_LOCALE_EN = \
backbigs1 backsmalls1 backsmalls2 concat4 dfamb1 ignrcas2 lc_num1 \
diff --git a/test/Makefile.in b/test/Makefile.in
index b4c62c15..fea54584 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1205,6 +1205,8 @@ EXTRA_DIST = \
range1.awk \
range1.in \
range1.ok \
+ range2.awk \
+ range2.ok \
readbuf.awk \
readbuf.ok \
readdir.awk \
@@ -1560,7 +1562,7 @@ BASIC_TESTS = \
paramasfunc1 paramasfunc2 paramdup paramres paramtyp paramuninitglobal \
parse1 parsefld parseme pcntplus posix2008sub prdupval prec printf0 \
printf1 printfchar prmarscl prmreuse prt1eval prtoeval \
- rand randtest range1 readbuf rebrackloc rebt8b1 rebuild redfilnm regeq \
+ rand randtest range1 range2 readbuf rebrackloc rebt8b1 rebuild redfilnm regeq \
regexpbrack regexpbrack2 regexprange regrange reindops reparse resplit \
rri1 rs rscompat rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 rstest3 \
rstest4 rstest5 rswhite \
@@ -1683,7 +1685,7 @@ CHECK_MPFR = \
# Lists of tests that need particular locales
NEED_LOCALE_C = \
- clos1way gsubtst6
+ clos1way gsubtst6 range2
NEED_LOCALE_EN = \
backbigs1 backsmalls1 backsmalls2 concat4 dfamb1 ignrcas2 lc_num1 \
@@ -3584,6 +3586,12 @@ range1:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+range2:
+ @echo $@
+ @[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=C; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
readbuf:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 48b24333..e557cb2b 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -850,6 +850,12 @@ range1:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+range2:
+ @echo $@
+ @[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=C; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
readbuf:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/range2.awk b/test/range2.awk
new file mode 100644
index 00000000..c4f11eaa
--- /dev/null
+++ b/test/range2.awk
@@ -0,0 +1 @@
+BEGIN { print("a" ~ /^[\300-\337]/) }
diff --git a/test/range2.ok b/test/range2.ok
new file mode 100644
index 00000000..573541ac
--- /dev/null
+++ b/test/range2.ok
@@ -0,0 +1 @@
+0