From 60947ec119c619fc2076ad264d0843aaab3917d3 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 24 Dec 2012 08:57:46 +0100 Subject: [PATCH] New wrapper function c_dtoastr. This function wraps dtoastr (from gnulib) replacing the first occurance of , by . Thanks to Ben Pfaff for this suggested implementation. --- src/libpspp/misc.c | 21 +++++++++++++++++++++ src/libpspp/misc.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/libpspp/misc.c b/src/libpspp/misc.c index de1ce3f5d5..c0120df82b 100644 --- a/src/libpspp/misc.c +++ b/src/libpspp/misc.c @@ -16,6 +16,7 @@ #include #include "misc.h" +#include /* Returns the number of digits in X. */ int @@ -33,3 +34,23 @@ intlog10 (unsigned x) return digits; } + +/* A locale independent version of dtoastr (from gnulib) */ +int +c_dtoastr (char *buf, size_t bufsize, int flags, int width, double x) +{ + int i; + int result = dtoastr (buf, bufsize, flags, width, x); + + /* Replace the first , (if any) by a . */ + for (i = 0; i < result; ++i) + { + if (buf[i] == ',') + { + buf[i] = '.'; + break; + } + } + + return result; +} diff --git a/src/libpspp/misc.h b/src/libpspp/misc.h index c2f865d90c..1698297dc4 100644 --- a/src/libpspp/misc.h +++ b/src/libpspp/misc.h @@ -17,6 +17,7 @@ #if !libpspp_misc_h #define libpspp_misc_h 1 +#include #include #include @@ -95,5 +96,7 @@ maximize_int (int *dest, int src) *dest = src; } +int c_dtoastr (char *buf, size_t bufsize, int flags, int width, double x); + #endif /* libpspp/misc.h */ -- 2.30.2