aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2013-07-04 11:40:00 +0300
committerArnold D. Robbins <arnold@skeeve.com>2013-07-04 11:40:00 +0300
commit71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6 (patch)
tree8d5d238bb671fff295f5ecee19be56153c470166
parent96cb55baaa352714943b94e73cbf94866250628d (diff)
downloadegawk-71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6.tar.gz
egawk-71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6.tar.bz2
egawk-71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6.zip
Fix for %c in multibyte locale + new tests.
-rw-r--r--ChangeLog5
-rw-r--r--builtin.c27
-rw-r--r--test/ChangeLog6
-rw-r--r--test/Makefile.am11
-rw-r--r--test/Makefile.in11
-rw-r--r--test/mbprintf4.awk32
-rw-r--r--test/mbprintf4.in3
-rw-r--r--test/mbprintf4.ok81
8 files changed, 162 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index bc49b4c0..c6a32d6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-07-04 Arnold D. Robbins <arnold@skeeve.com>
+
+ * builtin.c (format_tree): Fixes for %c with multibyte characters
+ and field width > 1. Bugs reported by Nethox <nethox@gmail.com>.
+
2013-07-02 Arnold D. Robbins <arnold@skeeve.com>
* profile.c (pp_string): Add a call to chksize and fix another.
diff --git a/builtin.c b/builtin.c
index ba1d8dcb..b8e24cb3 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1097,6 +1097,7 @@ out0:
* used to work? 6/2003.)
*/
cp = arg->stptr;
+ prec = 1;
#if MBS_SUPPORT
/*
* First character can be multiple bytes if
@@ -1108,17 +1109,14 @@ out0:
memset(& state, 0, sizeof(state));
count = mbrlen(cp, arg->stlen, & state);
- if (count == 0
- || count == (size_t)-1
- || count == (size_t)-2)
- goto out2;
- prec = count;
- goto pr_tail;
+ if (count > 0) {
+ prec = count;
+ /* may need to increase fw so that padding happens, see pr_tail code */
+ if (fw > 0)
+ fw += count - 1;
+ }
}
-out2:
- ;
#endif
- prec = 1;
goto pr_tail;
case 's':
need_format = false;
@@ -1421,9 +1419,14 @@ mpf1:
copy_count = prec;
if (fw == 0 && ! have_prec)
;
- else if (gawk_mb_cur_max > 1 && (cs1 == 's' || cs1 == 'c')) {
- assert(cp == arg->stptr || cp == cpbuf);
- copy_count = mbc_byte_count(arg->stptr, prec);
+ else if (gawk_mb_cur_max > 1) {
+ if (cs1 == 's') {
+ assert(cp == arg->stptr || cp == cpbuf);
+ copy_count = mbc_byte_count(arg->stptr, prec);
+ }
+ /* prec was set by code for %c */
+ /* else
+ copy_count = prec; */
}
bchunk(cp, copy_count);
while (fw > prec) {
diff --git a/test/ChangeLog b/test/ChangeLog
index dd71a1b5..87ad809f 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
+2013-07-04 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (mbprintf4): New test.
+ * mbprintf4.awk, mbprintf4.in, mbprintf4.ok: New files.
+ Test cases from Nethox <nethox@gmail.com>.
+
2013-06-27 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (dfamb1): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index fe6d3a59..e7c9cefd 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -493,6 +493,9 @@ EXTRA_DIST = \
mbprintf3.awk \
mbprintf3.in \
mbprintf3.ok \
+ mbprintf4.awk \
+ mbprintf4.in \
+ mbprintf4.ok \
mbstr1.awk \
mbstr1.ok \
membug1.awk \
@@ -991,7 +994,7 @@ MPFR_TESTS = mpfrnr mpfrrnd mpfrieee mpfrexprange mpfrsort mpfrbigint
LOCALE_CHARSET_TESTS = \
asort asorti fmttest fnarydel fnparydl jarebug lc_num1 mbfw1 \
- mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
+ mbprintf1 mbprintf2 mbprintf3 mbprintf4 rebt8b2 rtlenmb sort1 sprintfc
SHLIB_TESTS = \
fnmatch filefuncs fork fork2 fts functab4 inplace1 inplace2 inplace3 \
@@ -1564,6 +1567,12 @@ mbprintf3::
$(AWK) -f $(srcdir)/$@.awk $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >> _$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+mbprintf4::
+ @echo $@
+ @GAWKLOCALE=en_US.UTF-8 ; export GAWKLOCALE ; \
+ $(AWK) -f $(srcdir)/$@.awk $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >> _$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
mbfw1::
@echo $@
@GAWKLOCALE=en_US.UTF-8 ; export GAWKLOCALE ; \
diff --git a/test/Makefile.in b/test/Makefile.in
index 06946c0c..147eeaf3 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -711,6 +711,9 @@ EXTRA_DIST = \
mbprintf3.awk \
mbprintf3.in \
mbprintf3.ok \
+ mbprintf4.awk \
+ mbprintf4.in \
+ mbprintf4.ok \
mbstr1.awk \
mbstr1.ok \
membug1.awk \
@@ -1204,7 +1207,7 @@ MACHINE_TESTS = double1 double2 fmtspcl intformat
MPFR_TESTS = mpfrnr mpfrrnd mpfrieee mpfrexprange mpfrsort mpfrbigint
LOCALE_CHARSET_TESTS = \
asort asorti fmttest fnarydel fnparydl jarebug lc_num1 mbfw1 \
- mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
+ mbprintf1 mbprintf2 mbprintf3 mbprintf4 rebt8b2 rtlenmb sort1 sprintfc
SHLIB_TESTS = \
fnmatch filefuncs fork fork2 fts functab4 inplace1 inplace2 inplace3 \
@@ -1960,6 +1963,12 @@ mbprintf3::
$(AWK) -f $(srcdir)/$@.awk $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >> _$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+mbprintf4::
+ @echo $@
+ @GAWKLOCALE=en_US.UTF-8 ; export GAWKLOCALE ; \
+ $(AWK) -f $(srcdir)/$@.awk $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >> _$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
mbfw1::
@echo $@
@GAWKLOCALE=en_US.UTF-8 ; export GAWKLOCALE ; \
diff --git a/test/mbprintf4.awk b/test/mbprintf4.awk
new file mode 100644
index 00000000..a4b2a218
--- /dev/null
+++ b/test/mbprintf4.awk
@@ -0,0 +1,32 @@
+# printf with multi-byte text encoding, %c and %s, width and precision, and left-alignment.
+{
+ print "printf %c " $0
+ printf "|%c|\n", $0
+ printf "|%1c|\n", $0
+ printf "|%3c|\n", $0
+ # precision is ignored by %c.
+ printf "|%3.1c|\n", $0
+ printf "|%3.5c|\n", $0
+ print "printf %-c " $0
+ printf "|%-c|\n", $0
+ printf "|%-1c|\n", $0
+ printf "|%-3c|\n", $0
+ # precision is ignored by %c.
+ printf "|%-3.1c|\n", $0
+ printf "|%-3.5c|\n", $0
+ printf ORS
+
+ print "printf %s " $0
+ printf "|%s|\n", $0
+ printf "|%1s|\n", $0
+ printf "|%3s|\n", $0
+ printf "|%3.1s|\n", $0
+ printf "|%3.5s|\n", $0
+ print "printf %-s " $0
+ printf "|%-s|\n", $0
+ printf "|%-1s|\n", $0
+ printf "|%-3s|\n", $0
+ printf "|%-3.1s|\n", $0
+ printf "|%-3.5s|\n", $0
+ printf ORS ORS
+}
diff --git a/test/mbprintf4.in b/test/mbprintf4.in
new file mode 100644
index 00000000..c93d40de
--- /dev/null
+++ b/test/mbprintf4.in
@@ -0,0 +1,3 @@
+último
+áé
diff --git a/test/mbprintf4.ok b/test/mbprintf4.ok
new file mode 100644
index 00000000..9b9dd4e2
--- /dev/null
+++ b/test/mbprintf4.ok
@@ -0,0 +1,81 @@
+printf %c ú
+|ú|
+|ú|
+| ú|
+| ú|
+| ú|
+printf %-c ú
+|ú|
+|ú|
+|ú |
+|ú |
+|ú |
+
+printf %s ú
+|ú|
+|ú|
+| ú|
+| ú|
+| ú|
+printf %-s ú
+|ú|
+|ú|
+|ú |
+|ú |
+|ú |
+
+
+printf %c último
+|ú|
+|ú|
+| ú|
+| ú|
+| ú|
+printf %-c último
+|ú|
+|ú|
+|ú |
+|ú |
+|ú |
+
+printf %s último
+|último|
+|último|
+|último|
+| ú|
+|últim|
+printf %-s último
+|último|
+|último|
+|último|
+|ú |
+|últim|
+
+
+printf %c áé
+|á|
+|á|
+| á|
+| á|
+| á|
+printf %-c áé
+|á|
+|á|
+|á |
+|á |
+|á |
+
+printf %s áé
+|áé|
+|áé|
+| áé|
+| á|
+| áé|
+printf %-s áé
+|áé|
+|áé|
+|áé |
+|á |
+|áé |
+
+