about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2014-11-22 18:41:45 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2014-11-22 18:41:45 +0000
commitf3316d36985ad16f1d82aea44eddc311cb739d6d (patch)
tree82f3a6c450ec8394baa9b588962d4497e7a704a4 /lib
parent09bcfca6b8a98a40a1895ae8a66dd3fc1344a966 (diff)
downloadnetpbm-mirror-f3316d36985ad16f1d82aea44eddc311cb739d6d.tar.gz
netpbm-mirror-f3316d36985ad16f1d82aea44eddc311cb739d6d.tar.xz
netpbm-mirror-f3316d36985ad16f1d82aea44eddc311cb739d6d.zip
Fix %g for platform without vasprintf (but scores of %f still exist)
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2320 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libpm.c13
-rw-r--r--lib/pm.h5
-rw-r--r--lib/util/matrix.c12
-rw-r--r--lib/util/nstring.h3
-rw-r--r--lib/util/vasprintf.c13
5 files changed, 42 insertions, 4 deletions
diff --git a/lib/libpm.c b/lib/libpm.c
index 228f42c6..fa8ae4db 100644
--- a/lib/libpm.c
+++ b/lib/libpm.c
@@ -278,6 +278,19 @@ pm_error(const char format[], ...) {
 
 
 
+bool
+pm_have_float_format(void) {
+/*----------------------------------------------------------------------------
+  Return true iff %f, %e, and %g work in format strings for pm_message, etc.
+
+  Where they don't "work," that means the specifier just appears itself in
+  the formatted strings, e.g. "the number is g".
+-----------------------------------------------------------------------------*/
+    return pm_vasprintf_knows_float();
+}
+
+
+
 static void *
 mallocz(size_t const size) {
 
diff --git a/lib/pm.h b/lib/pm.h
index 72ecc919..a24ea7bb 100644
--- a/lib/pm.h
+++ b/lib/pm.h
@@ -23,6 +23,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#include "pm_c_util.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -219,6 +221,9 @@ pm_errormsg(const char format[], ...);
 void PM_GNU_PRINTF_ATTR(1,2)
 pm_error (const char reason[], ...);       
 
+bool
+pm_have_float_format(void);
+
 /* Obsolete - use shhopt and user's manual instead */
 void 
 pm_usage (const char usage[]);             
diff --git a/lib/util/matrix.c b/lib/util/matrix.c
index 5101f2c3..e9456e93 100644
--- a/lib/util/matrix.c
+++ b/lib/util/matrix.c
@@ -106,10 +106,14 @@ findLargestIthCoeff(unsigned int   const n,
             maxSoFar = thisA;
         }
     }
-    if (maxSoFar < epsilon)
-        pm_asprintf(errorP, "Matrix equation has no unique solution.  "
-                    "(debug: coeff %u %e < %e)", i, maxSoFar, epsilon);
-    else {
+    if (maxSoFar < epsilon) {
+        const char * const baseMsg = "Matrix equation has no unique solution";
+        if (pm_have_float_format())
+            pm_asprintf(errorP, "%s.  (debug: coeff %u %e < %e)",
+                        baseMsg, i, maxSoFar, epsilon);
+        else
+            pm_asprintf(errorP, "%s", baseMsg);
+    } else {
         *istarP = maxIdx;
         *errorP = NULL;
     }
diff --git a/lib/util/nstring.h b/lib/util/nstring.h
index 28adda94..7238a76e 100644
--- a/lib/util/nstring.h
+++ b/lib/util/nstring.h
@@ -175,6 +175,9 @@ pm_vasprintf(const char ** const resultP,
              const char *  const format,
              va_list             args);
 
+bool
+pm_vasprintf_knows_float(void);
+
 void 
 pm_strfree(const char * const string);
 
diff --git a/lib/util/vasprintf.c b/lib/util/vasprintf.c
index e38252fa..b294763a 100644
--- a/lib/util/vasprintf.c
+++ b/lib/util/vasprintf.c
@@ -6,6 +6,8 @@
 #include <string.h>
 
 #include "pm_config.h"
+#include "pm_c_util.h"
+
 #include "nstring.h"
 
 
@@ -56,3 +58,14 @@ pm_vasprintf(const char ** const resultP,
     }
 #endif
 }
+
+
+
+bool
+pm_vasprintf_knows_float(void) {
+#if HAVE_VASPRINTF
+    return true;
+#else
+    return false;
+#endif
+}