X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata-out.c;h=d26215a9c8cb887db2b827342c18abc7f7b5000d;hb=88df4d36b881e6a7aa08612737f72c2abd63bcb4;hp=d21d2902e1e5fcfe383b0872c1dabed27ef75c88;hpb=77e400ebcde847289260797535e5be5fea3f52dd;p=pspp diff --git a/src/data-out.c b/src/data-out.c index d21d2902e1..d26215a9c8 100644 --- a/src/data-out.c +++ b/src/data-out.c @@ -34,6 +34,9 @@ #include "str.h" #include "var.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + #include "debug-print.h" /* Public functions. */ @@ -53,7 +56,7 @@ static string_converter convert_A, convert_AHEX; /* Converts binary value V into printable form in the exactly FP->W character in buffer S according to format specification FP. No null terminator is appended to the buffer. */ -void +bool data_out (char *s, const struct fmt_spec *fp, const union value *v) { int cat = formats[fp->type].cat; @@ -70,7 +73,7 @@ data_out (char *s, const struct fmt_spec *fp, const union value *v) { memset (s, ' ', fp->w); s[fp->w - fp->d - 1] = '.'; - return; + return true; } /* Handle decimal shift. */ @@ -186,6 +189,8 @@ data_out (char *s, const struct fmt_spec *fp, const union value *v) /* Error handling. */ if (!ok) strncpy (s, "ERROR", fp->w); + + return ok; } /* Converts V into S in F format with width W and D decimal places, @@ -1116,6 +1121,7 @@ format_and_round (char *dst, double number, const struct fmt_spec *fp, sprintf (buf, "%.*f", decimals, number); + /* Omit integer part if it's 0. */ if (!memcmp (buf, "0.", 2)) memmove (buf, buf + 1, strlen (buf)); else if (!memcmp (buf, "-0.", 3)) @@ -1215,6 +1221,10 @@ format_and_round (char *dst, double number, const struct fmt_spec *fp, } } + /* Omit `-' if value output is zero. */ + if (buf[0] == '-' && buf[strspn (buf, "-.0")] == '\0') + memmove (buf, buf + 1, strlen (buf)); + buf_copy_str_lpad (dst, fp->w, buf); return 1; }