X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fformat.c;h=3c407f4a85f3c0bb842e41a3cca37098b1a5850a;hb=e5c4ada5c7675c8a54edf71c1a89fa88e1762a6f;hp=95e87a0daa7e7f32fc6b8bc7f7bd1d9bbcc19868;hpb=4e8257086ffc71bc5a1785fd86610921be677887;p=pspp-builds.git diff --git a/src/data/format.c b/src/data/format.c index 95e87a0d..3c407f4a 100644 --- a/src/data/format.c +++ b/src/data/format.c @@ -500,6 +500,7 @@ fmt_resize (struct fmt_spec *fmt, int width) void fmt_fix (struct fmt_spec *fmt, bool for_input) { + unsigned int step; int min_w, max_w; int max_d; @@ -511,18 +512,19 @@ fmt_fix (struct fmt_spec *fmt, bool for_input) else if (fmt->w > max_w) fmt->w = max_w; - /* First, if FMT has more decimal places than allowed, attempt - to increase FMT's width until that number of decimal places - can be achieved. */ - if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, for_input)) + /* Round width to step. */ + step = fmt_step_width (fmt->type); + fmt->w = ROUND_DOWN (fmt->w, step); + + /* If FMT has more decimal places than allowed, attempt to increase FMT's + width until that number of decimal places can be achieved. */ + if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, for_input) + && fmt_takes_decimals (fmt->type)) { - int w; - for (w = fmt->w; w <= max_w; w++) - if (fmt_max_decimals (fmt->type, w, for_input) >= fmt->d) - { - fmt->w = w; - break; - } + int max_w = fmt_max_width (fmt->type, for_input); + for (; fmt->w < max_w; fmt->w++) + if (fmt->d <= fmt_max_decimals (fmt->type, fmt->w, for_input)) + break; } /* Clamp decimals to those allowed by format and width. */ @@ -912,6 +914,56 @@ fmt_date_template (enum fmt_type type) } } +/* Returns a string representing the format TYPE for use in a GUI dialog. */ +const char * +fmt_gui_name (enum fmt_type type) +{ + switch (type) + { + case FMT_F: + return _("Numeric"); + + case FMT_COMMA: + return _("Comma"); + + case FMT_DOT: + return _("Dot"); + + case FMT_E: + return _("Scientific"); + + case FMT_DATE: + case FMT_EDATE: + case FMT_SDATE: + case FMT_ADATE: + case FMT_JDATE: + case FMT_QYR: + case FMT_MOYR: + case FMT_WKYR: + case FMT_DATETIME: + case FMT_TIME: + case FMT_DTIME: + case FMT_WKDAY: + case FMT_MONTH: + return _("Date"); + + case FMT_DOLLAR: + return _("Dollar"); + + case FMT_CCA: + case FMT_CCB: + case FMT_CCC: + case FMT_CCD: + case FMT_CCE: + return _("Custom"); + + case FMT_A: + return _("String"); + + default: + return fmt_name (type); + } +} /* Returns true if TYPE is a valid format type, false otherwise. */