summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2023-09-13 18:07:49 -0700
committerArnold D. Robbins <arnold@skeeve.com>2023-09-13 18:07:49 -0700
commite5ac3346f9eee4618270125f14891a0a7f4e44b4 (patch)
tree57de841e52d707b873daec8651d10c916ba897dc
parente70cb3411ee699fbd97a39d6012f133c32ef8890 (diff)
parent017a941d413df307c3c31ddb0262ff70fdc4e88c (diff)
downloadgawk-e5ac3346f9eee4618270125f14891a0a7f4e44b4.tar.gz
Merge branch 'master' into feature/cpp-compile
-rw-r--r--ChangeLog9
-rw-r--r--builtin.c18
-rwxr-xr-xdoc/it/ChangeLog4
-rwxr-xr-xdoc/it/gawktexi.in46
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst12
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am8
-rw-r--r--test/Makefile.in14
-rw-r--r--test/Maketests6
-rw-r--r--test/gsubnulli18n.awk5
-rw-r--r--test/gsubnulli18n.ok1
12 files changed, 110 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index bfee4b8..f7c83e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-09-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ Fix handling of zero length matching in multibyte locales
+ with sub/gsub. Thanks again to Ed Morton for the report.
+
+ * builtin.c (do_sub): When the match is empty and we copy in
+ the subsequent character, check gawk_mb_cur_max to know whether
+ to copy one byte or multiple bytes.
+
2023-09-11 Arnold D. Robbins <arnold@skeeve.com>
* field.c (do_split): Fix some whitespace.
diff --git a/builtin.c b/builtin.c
index 06392ca..171e5e3 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2957,6 +2957,8 @@ do_match(int nargs)
*
* 7/2011: Reverted backslash handling to what it used to be. It was in
* gawk for too long. Should have known better.
+ *
+ * 9/2023: Update for matches of null strings around multibyte characters.
*/
/*
@@ -3259,8 +3261,20 @@ do_sub(int nargs, unsigned int flags)
empty:
/* catch the case of gsub(//, "blah", whatever), i.e. empty regexp */
if (matchstart == matchend && matchend < text + textlen) {
- *bp++ = *matchend;
- matchend++;
+ // copy in regular text
+ if (gawk_mb_cur_max == 1) {
+ *bp++ = *matchend;
+ matchend++;
+ } else {
+ mbstate_t mbs;
+ size_t i, j;
+
+ memset(& mbs, 0, sizeof(mbs));
+ j = mbrlen(matchend, (target->stptr + target->stlen) - matchend, & mbs);
+ // FIXME: Error checking on the value of `j' would be a good idea....
+ for (i = 0; i < j; i++)
+ *bp++ = *matchend++;
+ }
}
textlen = text + textlen - matchend;
text = matchend;
diff --git a/doc/it/ChangeLog b/doc/it/ChangeLog
index 9c9743c..ea83bf1 100755
--- a/doc/it/ChangeLog
+++ b/doc/it/ChangeLog
@@ -1,3 +1,7 @@
+2023-09-12 Antonio Giovanni Colombo <azc100@gmail.com>
+
+ * gawktexi.in: Updated.
+
2023-08-29 Antonio Giovanni Colombo <azc100@gmail.com>
* texinfo.tex: Updated.
diff --git a/doc/it/gawktexi.in b/doc/it/gawktexi.in
index ec7dd95..5e79ffc 100755
--- a/doc/it/gawktexi.in
+++ b/doc/it/gawktexi.in
@@ -3643,7 +3643,7 @@ Stampare la lunghezza della riga pi@`u lunga in @file{data}:
@example
expand data | awk '@{ if (x < length($0)) x = length($0) @}
- END @{ print "la lunghezza massima di una riga @`e" x @}'
+ END @{ print "lunghezza massima di riga @`e" x @}'
@end example
Questo esempio @`e leggermente diverso da quello precedente:
@@ -8616,7 +8616,7 @@ I campi nei file CSV sono separati da virgola. Per consentire la
presenza di una virgola all'interno di un campo (p.es. come parte
di un dato), il campo pu@`o essere racchiuso fra doppi apici.
Per consentire un doppio apice all'interno di un campo racchiuso fra
-doppi apici, il campo stesso @empf{deve} essere racchiuso fra doppi apici
+doppi apici, il campo stesso @emph{deve} essere racchiuso fra doppi apici
e due doppi apici rappresentano un singolo doppio apice.
Il doppio apice che segnala l'inizio del campo dev'essere
il primo carattere dopo la virgola [che segna l'inizio del campo].
@@ -8897,10 +8897,6 @@ Il valore di @code{FS} @`e ignorato.
I campi sono separati da uno o pi@`u spazi vuoti. Gli spazi vuoti iniziali
e finali sono ignorati. Questo @`e il comportamento di default.
-@item FS == ","
-I campi sono separati da virgola, con regole speciali per inserire in un
-campo virgole e/o doppi apici.
-
@item FS == @var{qualsiasi altro carattere singolo}
I campi sono separati da ogni ricorrenza del carattere. Ricorrenze
successive multiple delimitano campi vuoti, e lo stesso fanno le ricorrenze
@@ -9202,9 +9198,11 @@ per un esempio di tale funzione).
@node Separazione in base al contenuto
@section Definire i campi in base al contenuto
-@strong{FIXME}: Quest'intera sezione dev'essere riscritta
+@quotation NOTA
+Quest'intera sezione dev'essere riscritta
dopo che in @command{gawk} @`e stata introdotta la capacit@`a di analizzare
file di tipo CSV. Ahim@`e.
+@end quotation
@menu
* Ancora CSV:: Ancora sui file CSV.
@@ -9325,7 +9323,7 @@ questo tipo:
@example
if (substr($i, 1, 1) == "\"") @{
len = length($i)
- $i = substr($i, 2, len - 2) # Ottiene il testo tra doppi apici
+ $i = substr($i, 2, len - 2) # Ottiene testo tra doppi apici
@}
@end example
@@ -42380,23 +42378,33 @@ se le opzioni della riga di comando corrispondenti sono state specificate
quando @command{gawk} @`e stato chiamato. Le variabili sono:
@table @code
+@item do_csv
+Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato
+con l'opzione @option{--csv}.
+
@item do_debug
-Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato con l'opzione @option{--debug}.
+Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato
+con l'opzione @option{--debug}.
@item do_lint
-Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato con l'opzione @option{--lint}.
+Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato
+con l'opzione @option{--lint}.
@item do_mpfr
-Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato con l'opzione @option{--bignum}.
+Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato
+con l'opzione @option{--bignum}.
@item do_profile
-Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato con l'opzione @option{--profile}.
+Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato
+con l'opzione @option{--profile}.
@item do_sandbox
-Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato con l'opzione @option{--sandbox}.
+Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato
+con l'opzione @option{--sandbox}.
@item do_traditional
-Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato con l'opzione @option{--traditional}.
+Questa variabile @`e @dfn{true} se @command{gawk} @`e stato invocato
+con l'opzione @option{--traditional}.
@end table
Il valore di @code{do_lint} pu@`o cambiare se il codice @command{awk}
@@ -46137,9 +46145,19 @@ La versione 5.3 ha aggiunto le seguenti funzionalit@`a:
@itemize
@item
Divisione in campi per file di tipo CSV (Campi separati da virgola)
+e l'opzione da riga di comando @option{--csv}
(@pxref{Campi separati da virgola}).
@item
+L'elemento di vettore @code{PROCINFO["CSV"]} esiste se @command{gawk}
+@`e stato invocato con l'opzione @option{--csv}
+(@pxref{Variabili auto-assegnate}).
+
+@item
+La variabile informativa per l'API @code{do_csv}
+(@pxref{Variabili informative di estens. API}).
+
+@item
La possibilit@`a che @command{gawk} bufferizzi l'output a @dfn{pipe}
(@pxref{Noflush}).
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 4e9904d..8e62133 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2023-09-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Regenerated.
+
2023-09-01 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Regenerated.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 79fa1a6..e89ce36 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -159,7 +159,8 @@ BASIC_TESTS = \
fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \
fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \
getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \
- getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
+ getnr2tm gsubasgn gsubnulli18n \
+ gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \
intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \
math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \
@@ -314,7 +315,8 @@ NEED_LOCALE_C = \
clos1way gsubtst6 range2
NEED_LOCALE_EN = \
- backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \
+ backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \
+ gsubnulli18n ignrcas2 lc_num1 \
mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \
mtchi18n2 posix_compare \
printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \
@@ -1796,6 +1798,12 @@ gsubasgn:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+gsubnulli18n:
+ @echo $@
+ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=ENU_USA.1252; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
gsubtest:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/ChangeLog b/test/ChangeLog
index 6fcd5f6..2e9b0d4 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2023-09-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): New test, gsubnulli18n.
+ * gsubnulli18n.awk, gsubnulli18n.ok: New files.
+
2023-09-05 Arnold D. Robbins <arnold@skeeve.com>
* mtchi18n2.awk: Change to use \u in the regexp instead of
diff --git a/test/Makefile.am b/test/Makefile.am
index 4876ce5..7c7f9ae 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -545,6 +545,8 @@ EXTRA_DIST = \
gsubasgn.ok \
gsubind.awk \
gsubind.ok \
+ gsubnulli18n.awk \
+ gsubnulli18n.ok \
gsubtest.awk \
gsubtest.ok \
gsubtst2.awk \
@@ -1498,7 +1500,8 @@ BASIC_TESTS = \
fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \
fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \
getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \
- getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
+ getnr2tm gsubasgn gsubnulli18n \
+ gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \
intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \
math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \
@@ -1652,7 +1655,8 @@ NEED_LOCALE_C = \
clos1way gsubtst6 range2
NEED_LOCALE_EN = \
- backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \
+ backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \
+ gsubnulli18n ignrcas2 lc_num1 \
mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \
mtchi18n2 posix_compare \
printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \
diff --git a/test/Makefile.in b/test/Makefile.in
index ed83c6e..9fafbe1 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -809,6 +809,8 @@ EXTRA_DIST = \
gsubasgn.ok \
gsubind.awk \
gsubind.ok \
+ gsubnulli18n.awk \
+ gsubnulli18n.ok \
gsubtest.awk \
gsubtest.ok \
gsubtst2.awk \
@@ -1762,7 +1764,8 @@ BASIC_TESTS = \
fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \
fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \
getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \
- getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
+ getnr2tm gsubasgn gsubnulli18n \
+ gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \
intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \
math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \
@@ -1917,7 +1920,8 @@ NEED_LOCALE_C = \
clos1way gsubtst6 range2
NEED_LOCALE_EN = \
- backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \
+ backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \
+ gsubnulli18n ignrcas2 lc_num1 \
mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \
mtchi18n2 posix_compare \
printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \
@@ -3587,6 +3591,12 @@ gsubasgn:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+gsubnulli18n:
+ @echo $@
+ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
gsubtest:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 84d1881..f6f9e91 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -482,6 +482,12 @@ gsubasgn:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+gsubnulli18n:
+ @echo $@
+ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
gsubtest:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/gsubnulli18n.awk b/test/gsubnulli18n.awk
new file mode 100644
index 0000000..874586e
--- /dev/null
+++ b/test/gsubnulli18n.awk
@@ -0,0 +1,5 @@
+BEGIN {
+ str = "אבג"
+ n = gsub(//, "x", str)
+ print n, str
+}
diff --git a/test/gsubnulli18n.ok b/test/gsubnulli18n.ok
new file mode 100644
index 0000000..7099c3f
--- /dev/null
+++ b/test/gsubnulli18n.ok
@@ -0,0 +1 @@
+4 xאxבxגx