chiark / gitweb /
New hex encoding stuff. Rename test programs.
[mLib] / dputf.c
diff --git a/dputf.c b/dputf.c
index d78851ffbd10ab1e072c3f9013d5884cdf69fc4e..bb0641ca45182c23b9992858abfc4370e70b59fa 100644 (file)
--- a/dputf.c
+++ b/dputf.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: dputf.c,v 1.2 2000/08/15 21:26:45 mdw Exp $
+ * $Id: dputf.c,v 1.4 2001/06/22 19:35:29 mdw Exp $
  *
  * `printf'-style formatting for dynamic strings
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: dputf.c,v $
+ * Revision 1.4  2001/06/22 19:35:29  mdw
+ * Find out whether @<float.h>@ exists (hack for uC-Linux).
+ *
+ * Revision 1.3  2001/01/20 12:06:01  mdw
+ * Define flags with macros, to ensure unsignedness.
+ *
  * Revision 1.2  2000/08/15 21:26:45  mdw
  * (dstr_vputf): Don't try calling @va_arg@ on things @char@-sized.
  *
 /*----- Header files ------------------------------------------------------*/
 
 #include <ctype.h>
-#include <float.h>
 #include <math.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef HAVE_FLOAT_H
+#  include <float.h>
+#endif
+
 #include "dstr.h"
 
 /*----- Tunable constants -------------------------------------------------*/
@@ -84,13 +93,11 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
     unsigned f;
     int wd, prec;
 
-    enum {
-      f_short = 1,
-      f_long = 2,
-      f_Long = 4,
-      f_wd = 8,
-      f_prec = 16
-    };
+#define f_short 1u
+#define f_long 2u
+#define f_Long 4u
+#define f_wd 8u
+#define f_prec 16u
 
     /* --- Most stuff gets passed on through --- */
 
@@ -191,6 +198,7 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
          goto formatted;
 
        case 'e': case 'E': case 'f': case 'F': case 'g': case 'G':
+#ifdef HAVE_FLOAT_H
          DPUTC(&dd, *p);
          DPUTZ(&dd);
          if (*p == 'f') {
@@ -198,9 +206,9 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
            if (mx > sz)
              sz = mx;
          }
-         if ((f & f_prec) == 0)
+         if (!(f & f_prec))
            prec = 6;
-         if ((f & f_prec))
+         else
            sz += prec + 16;        
          if ((f & f_wd) && wd + 1 > sz)
            sz = wd + 1;
@@ -212,6 +220,9 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
            d->len += sprintf(d->buf + d->len, dd.buf,
                              va_arg(ap, double));
          goto formatted;
+#else
+         DPUTS(d, "<no float support>");
+#endif
 
        case 'c':
          DPUTC(&dd, *p);
@@ -270,6 +281,12 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
   formatted:
     DRESET(&dd);
     q = ++p;
+
+#undef f_short
+#undef f_long
+#undef f_Long
+#undef f_wd
+#undef f_prec
   }
 
   DPUTM(d, q, p - q);