X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fctables.c;h=461007c555db92673236ba5beb192d59862ee2e2;hb=e4c6d9fad9dfac0e7fae4323e1c2aaa3642acf94;hp=64c399bcbcd27a70634c398cd58ce554abb8e88f;hpb=e9c5e5844109cf683c69f3eea296d7b23fdad839;p=pspp diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 64c399bcbc..461007c555 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -4358,6 +4358,37 @@ ctables_cell_calculate_postcompute (const struct ctables_section *s, return ctables_pcexpr_evaluate (&ctx, pc->expr); } +static char * +ctables_format (double d, const struct fmt_spec *format, + const struct fmt_settings *settings) +{ + const union value v = { .f = d }; + char *s = data_out_stretchy (&v, "UTF-8", format, settings, NULL); + + /* The custom-currency specifications for NEQUAL, PAREN, and PCTPAREN don't + produce the results we want for negative numbers, putting the negative + sign in the wrong spot, before the prefix instead of after it. We can't, + in fact, produce the desired results using a custom-currency + specification. Instead, we postprocess the output, moving the negative + sign into place: + + NEQUAL: "-N=3" => "N=-3" + PAREN: "-(3)" => "(-3)" + PCTPAREN: "-(3%)" => "(-3%)" + + This transformation doesn't affect NEGPAREN. */ + char *minus_src = strchr (s, '-'); + if (minus_src && (minus_src == s || minus_src[-1] != 'E')) + { + char *n_equals = strstr (s, "N="); + char *lparen = strchr (s, '('); + char *minus_dst = n_equals ? n_equals + 1 : lparen; + if (minus_dst) + move_element (s, minus_dst - s + 1, 1, minus_src - s, minus_dst - s); + } + return s; +} + static void ctables_table_output (struct ctables *ct, struct ctables_table *t) { @@ -4684,12 +4715,8 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t) else if (d == SYSMIS && ct->missing) value = pivot_value_new_user_text (ct->missing, SIZE_MAX); else if (is_ctables_format) - { - char *s = data_out_stretchy (&(union value) { .f = d }, - "UTF-8", &format, - &ct->ctables_formats, NULL); - value = pivot_value_new_user_text_nocopy (s); - } + value = pivot_value_new_user_text_nocopy ( + ctables_format (d, &format, &ct->ctables_formats)); else { value = pivot_value_new_number (d);