[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
seq -0.1 0.1 2: print final number when locale's decimal point is ", "
From: |
Jim Meyering |
Subject: |
seq -0.1 0.1 2: print final number when locale's decimal point is ", " |
Date: |
Fri, 26 Sep 2008 23:42:57 +0200 |
I wrote the test, so here's the complete patch
I've just pushed into the upstream repository:
http://git.sv.gnu.org/gitweb/?p=coreutils.git
>From e13188e7ef7bbd609c1586332a335b4194b881aa Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 25 Sep 2008 20:01:24 +0200
Subject: [PATCH] seq -0.1 0.1 2: print final number when locale's decimal point
is ","
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
* src/seq.c (print_numbers): Use strtold, not c_strtold to convert
from just-formatted-using-asprintf string back to double, since
asprintf may have used something other than "." as the decimal point.
Reported by address@hidden as <http://bugzilla.redhat.com/463556>.
Thanks to Ondřej Vašík for discovering that the bug was locale-related.
$ LC_ALL=cs_CZ.UTF-8 seq -0.1 0.1 2|grep 2.0
[Exit 1]
$ seq -0.1 0.1 2|grep 2.0
2.0
* tests/check.mk (TESTS_ENVIRONMENT): Add LOCALE_FR_UTF8, for...
* tests/misc/seq [locale-dec-pt]: New test for the above.
* NEWS (bug fix): Mention it.
---
NEWS | 3 +++
src/seq.c | 2 +-
tests/check.mk | 1 +
tests/misc/seq | 15 +++++++++++++++
4 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/NEWS b/NEWS
index 2549d41..77458d6 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,9 @@ GNU coreutils NEWS -*-
outline -*-
od no longer suffers from platform bugs in printf(3). This is
probably most noticeable when using 'od -tfL' to print long doubles.
+ seq -0.1 0.1 2 now prints 2,0 when locale's decimal point is ",".
+ Before, it would mistakenly omit the final number in that example.
+
shuf honors the --zero-terminated (-z) option, even with --input-range=LO-HI
shuf --head-count is now correctly documented. The documentation
diff --git a/src/seq.c b/src/seq.c
index 55518df..b5f0651 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -306,7 +306,7 @@ print_numbers (char const *fmt, struct layout layout,
xalloc_die ();
x_str[x_strlen - layout.suffix_len] = '\0';
- if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, c_strtold)
+ if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, strtold)
&& abs_rel_diff (x_val, last) < DBL_EPSILON)
{
char *x0_str = NULL;
diff --git a/tests/check.mk b/tests/check.mk
index 03b89dc..9263c67 100644
--- a/tests/check.mk
+++ b/tests/check.mk
@@ -69,6 +69,7 @@ TESTS_ENVIRONMENT = \
}; \
export \
LOCALE_FR='$(LOCALE_FR)' \
+ LOCALE_FR_UTF8='$(LOCALE_FR_UTF8)' \
abs_top_builddir='$(abs_top_builddir)' \
abs_top_srcdir='$(abs_top_srcdir)' \
abs_srcdir='$(abs_srcdir)' \
diff --git a/tests/misc/seq b/tests/misc/seq
index f68d74c..8e76f42 100755
--- a/tests/misc/seq
+++ b/tests/misc/seq
@@ -26,6 +26,10 @@ use strict;
my $prog = 'seq';
my $try_help = "Try `$prog --help' for more information.\n";
+my $locale = $ENV{LOCALE_FR_UTF8};
+! defined $locale || $locale eq 'none'
+ and $locale = 'C';
+
my @Tests =
(
['onearg-1', qw(10), {OUT => [(1..10)]}],
@@ -88,6 +92,17 @@ my @Tests =
{ERR => "seq: no % directive in format string `'\n" . $try_help }],
['fmt-e', qw(-f %g%g 1), {EXIT => 1},
{ERR => "seq: too many % directives in format string `%g%g'\n"}],
+
+ # With coreutils-6.12 and earlier, with a UTF8 numeric locale that uses
+ # something other than "." as the decimal point, this use of seq would
+ # fail to print the "2,0" endpoint.
+ ['locale-dec-pt', qw(-0.1 0.1 2),
+ {OUT => [qw(-0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
+ 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0)]},
+
+ {ENV => "LC_ALL=$locale"},
+ {OUT_SUBST => 's/,/./g'},
+ ],
);
# Append a newline to each entry in the OUT array.
--
1.6.0.2.307.gc427
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- seq -0.1 0.1 2: print final number when locale's decimal point is ", ",
Jim Meyering <=