From a5a978da36eb6b8247e55075a7d4c87cb67c3eaf Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 7 Nov 1994 03:00:26 +0000 Subject: [PATCH] WRITE ALL about halfway done. --- monitor.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/monitor.c b/monitor.c index 5e4f9c8..7727467 100644 --- 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 -- 2.43.0