summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-03-10 22:35:01 +0200
committerArnold D. Robbins <arnold@skeeve.com>2014-03-10 22:35:01 +0200
commit379f62687358dfda19694dea92389e092372fc2c (patch)
tree017d84cf05b1a66dec69eb1c8721a0a6b46b3032
parent295bee08215e33ec82e34978cecc593b698c9ad9 (diff)
downloadgawk-379f62687358dfda19694dea92389e092372fc2c.tar.gz
Fix thousands separator problems and update doc.
-rw-r--r--NEWS5
-rw-r--r--builtin.c30
-rw-r--r--doc/ChangeLog5
-rw-r--r--doc/awkcard.in5
-rw-r--r--doc/gawk.111
5 files changed, 46 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 50b88a97..063386bd 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,11 @@ extension facility only works on Alpha and Itanium.
realloc() and free(), to insure that the same memory allocation
functions are always used. This bumps the minor version by one.
+13. The printf quote flag now works correctly in locales with a different
+decimal point character but without a thousands separator character.
+If the thousands separator is a string, it will be correctly added
+to decimal numbers.
+
XXX. A number of bugs have been fixed. See the ChangeLog.
Changes from 4.0.2 to 4.1.0
diff --git a/builtin.c b/builtin.c
index ffc303ab..7a6bfc62 100644
--- a/builtin.c
+++ b/builtin.c
@@ -994,9 +994,7 @@ check_pos:
goto check_pos;
case '\'':
#if defined(HAVE_LOCALE_H)
- /* allow quote_flag if there is a thousands separator. */
- if (loc.thousands_sep[0] != '\0')
- quote_flag = true;
+ quote_flag = true;
goto check_pos;
#else
goto retry;
@@ -1196,6 +1194,9 @@ out0:
}
if (i < 1)
goto out_of_range;
+#if defined(HAVE_LOCALE_H)
+ quote_flag = (quote_flag && loc.thousands_sep[0] != 0);
+#endif
chp = &cpbufs[1].buf[i-1];
ii = jj = 0;
do {
@@ -1203,8 +1204,14 @@ out0:
chp--; i--;
#if defined(HAVE_LOCALE_H)
if (quote_flag && loc.grouping[ii] && ++jj == loc.grouping[ii]) {
- if (i) /* only add if more digits coming */
- PREPEND(loc.thousands_sep[0]); /* XXX - assumption it's one char */
+ if (i) { /* only add if more digits coming */
+ int k;
+ const char *ts = loc.thousands_sep;
+
+ for (k = strlen(ts) - 1; k >= 0; k--) {
+ PREPEND(ts[k]);
+ }
+ }
if (loc.grouping[ii+1] == 0)
jj = 0; /* keep using current val in loc.grouping[ii] */
else if (loc.grouping[ii+1] == CHAR_MAX)
@@ -1360,6 +1367,9 @@ mpf1:
#ifdef HAVE_MPFR
int0:
#endif
+#if defined(HAVE_LOCALE_H)
+ quote_flag = (quote_flag && loc.thousands_sep[0] != 0);
+#endif
/*
* When to fill with zeroes is of course not simple.
* First: No zero fill if left-justifying.
@@ -1378,8 +1388,14 @@ mpf1:
uval /= base;
#if defined(HAVE_LOCALE_H)
if (base == 10 && quote_flag && loc.grouping[ii] && ++jj == loc.grouping[ii]) {
- if (uval) /* only add if more digits coming */
- PREPEND(loc.thousands_sep[0]); /* XXX --- assumption it's one char */
+ if (uval) { /* only add if more digits coming */
+ int k;
+ const char *ts = loc.thousands_sep;
+
+ for (k = strlen(ts) - 1; k >= 0; k--) {
+ PREPEND(ts[k]);
+ }
+ }
if (loc.grouping[ii+1] == 0)
jj = 0; /* keep using current val in loc.grouping[ii] */
else if (loc.grouping[ii+1] == CHAR_MAX)
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 6bb4e9c0..15e6d958 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -2,6 +2,11 @@
* gawktexi.in: Finish indexing improvements. (For now, anyway.)
+ Unrelated:
+
+ * gawk.1: Document the quote flag! (Better late than never.)
+ * awkcard.in: Update documentation of quote flag.
+
2014-03-08 Arnold D. Robbins <arnold@skeeve.com>
* gawktexi.in: Minor edits to the discussion of the memory allocation
diff --git a/doc/awkcard.in b/doc/awkcard.in
index 610032b7..5f3a9735 100644
--- a/doc/awkcard.in
+++ b/doc/awkcard.in
@@ -1,7 +1,7 @@
.\" AWK Reference Card --- Arnold Robbins, arnold@skeeve.com
.\"
.\" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-.\" 2003, 2004, 2005, 2007, 2009, 2010, 2011, 2012, 2013
+.\" 2003, 2004, 2005, 2007, 2009, 2010, 2011, 2012, 2013, 2014
.\" Free Software Foundation, Inc.
.\"
.\" Permission is granted to make and distribute verbatim copies of
@@ -1493,7 +1493,8 @@ Only has an effect when the field width is wider
than the value to be printed.
T}
\*(CB\*(FC'\*(FR T{
-Use the locale's thousands separator for \*(FC%d\fP, \*(FC%i\fP, and \*(FC%u\fP.\*(CD
+Use the locale's thousands separator and decimal
+point characters.\*(CD
T}
\*(FIwidth\fP T{
Pad the field to this width. The field is normally
diff --git a/doc/gawk.1 b/doc/gawk.1
index f88c707c..97ad9776 100644
--- a/doc/gawk.1
+++ b/doc/gawk.1
@@ -13,7 +13,7 @@
. if \w'\(rq' .ds rq "\(rq
. \}
.\}
-.TH GAWK 1 "Jan 28 2014" "Free Software Foundation" "Utility Commands"
+.TH GAWK 1 "Mar 08 2014" "Free Software Foundation" "Utility Commands"
.SH NAME
gawk \- pattern scanning and processing language
.SH SYNOPSIS
@@ -2448,6 +2448,15 @@ This applies only to the numeric output formats.
This flag only has an effect when the field width is wider than the
value to be printed.
.TP
+.B '
+A single quote character instructs
+.I gawk
+to insert the locale's thousands-separator character
+into decimal numbers, and to also use the locale's
+decimal point character with floating point formats.
+This requires correct locale support in the C library
+and in the definition of the current locale.
+.TP
.I width
The field should be padded to this width. The field is normally padded
with spaces. With the