]> thyrsus.com Git - cupl.git/commitdiff
WRITE ALL about halfway done.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 7 Nov 1994 03:00:26 +0000 (03:00 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 7 Nov 1994 03:00:26 +0000 (03:00 +0000)
monitor.c

index 5e4f9c89e35191497830921a461798bb997ee778..77274678d35026603863c635fe2089b0199c71b8 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -11,6 +11,11 @@ SYNOPSIS
     void copy_value(value v);
     void deallocate_value(value *v)
 
+    void cupl_reset_write()
+    void cupl_eol_write()
+    void cupl_scalar_write(char *name, scalar quant)
+    void cupl_string_write(char *s)
+
     value cupl_add(value, value)
     value cupl_multiply(value, value)
     value cupl_subtract(value, value)
@@ -106,6 +111,61 @@ void deallocate_value(value *v)
     (void) free(v->elements);
 }
 
+/****************************************************************************
+ *
+ * Output support
+ *
+ ****************************************************************************/
+
+static int used;
+
+void cupl_reset_write()
+{
+    used = 0;
+}
+
+void cupl_eol_write(void)
+{
+    if (used != linewidth)
+       (void) putchar('\n');
+}
+
+static void needspace(int w)
+/* emit a LF if there are not more than w spaces left on the line */
+{
+    if (used + w >= linewidth)
+    {
+       (void) putchar('\n');
+       used = 0;
+    }
+    else
+       used += w;
+}
+
+void cupl_scalar_write(char *name, scalar quant)
+/* write a numeric or skip a field in CUPL style */
+{
+    if (name)
+    {
+       needspace(2 * fieldwidth);
+       (void) printf("%*s = ", fieldwidth - 3, name);
+    }
+    else
+       needspace(fieldwidth);
+
+    if (0.001 < fabs(quant) && abs(quant) < 100000)
+       (void) printf("%*f", fieldwidth, quant);
+    else
+       (void) printf("%*E", fieldwidth, quant);
+}
+
+void cupl_string_write(char *s)
+/* write a string, or just skip the field */
+{
+    needspace(fieldwidth);
+    (void) printf("%-*s", fieldwidth, s);
+}
+
 /****************************************************************************
  *
  * Functions for arithmetic intrinsics