X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata-out.c;h=c9c17a5e642fd6f14fcefe1472df9586dd44bdae;hb=0e4ef2c7099e82d8e43cf87a53c36430d1ce879f;hp=6439b607045f18e5566deec8a438b9197f88d03e;hpb=317e6b778833b5dcd5dd195c0b677835a8024b2a;p=pspp diff --git a/src/data-out.c b/src/data-out.c index 6439b60704..c9c17a5e64 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, @@ -193,10 +198,7 @@ data_out (char *s, const struct fmt_spec *fp, const union value *v) void num_to_string (double v, char *s, int w, int d) { - struct fmt_spec f; - f.type = FMT_F; - f.w = w; - f.d = d; + struct fmt_spec f = make_output_format (FMT_F, w, d); convert_F (s, &f, v); } @@ -963,7 +965,7 @@ year4 (int year) static int try_CCx (char *dst, const struct fmt_spec *fp, double number) { - const struct set_cust_currency *cc = get_cc(fp->type - FMT_CCA); + const struct custom_currency *cc = get_cc(fp->type - FMT_CCA); struct fmt_spec f; @@ -973,7 +975,7 @@ try_CCx (char *dst, const struct fmt_spec *fp, double number) /* Determine length available, decimal character for number proper. */ - f.type = cc->decimal == get_decimal() ? FMT_COMMA : FMT_DOT; + f.type = cc->decimal == get_decimal () ? FMT_COMMA : FMT_DOT; f.w = fp->w - strlen (cc->prefix) - strlen (cc->suffix); if (number < 0) f.w -= strlen (cc->neg_prefix) + strlen (cc->neg_suffix) - 1; @@ -1045,7 +1047,7 @@ try_F (char *dst, const struct fmt_spec *fp, double number) /* There are no decimal places, so there's no way that the value can be shortened. Either it fits or it doesn't. */ - char buf[40]; + char buf[41]; sprintf (buf, "%*.0f", fp->w, number); if (strlen (buf) <= fp->w) { @@ -1119,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)) @@ -1218,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; }