New wrapper function c_dtoastr.
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 24 Dec 2012 07:57:46 +0000 (08:57 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 24 Dec 2012 08:34:49 +0000 (09:34 +0100)
This function wraps dtoastr (from gnulib) replacing the first occurance of
, by .   Thanks to Ben Pfaff for this suggested implementation.

src/libpspp/misc.c
src/libpspp/misc.h

index de1ce3f5d51cf92a2632d694a1c53fd56c940daa..c0120df82bfe60d35dbb06c1f64a7095eaf98062 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <config.h>
 #include "misc.h"
+#include <gl/ftoastr.h>
 
 /* 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;
+}
index c2f865d90c95512d7ec4d3517c68dff96e0181d4..1698297dc4cc51a2694f55d831c740d4eb601694 100644 (file)
@@ -17,6 +17,7 @@
 #if !libpspp_misc_h
 #define libpspp_misc_h 1
 
+#include <stddef.h>
 #include <float.h>
 #include <math.h>
 
@@ -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 */