X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fformat.c;h=1cf083d38f60ecbda65a22fdfb9712b99fda2ba3;hb=a12aeb43c5edf27b0ef2be5c2d7db30214a31a2b;hp=58e16d3075a4249080db940efcb1e7dd7285c938;hpb=142e33869c4c04338e6071e011b3053a28ea9173;p=pspp diff --git a/src/data/format.c b/src/data/format.c index 58e16d3075..1cf083d38f 100644 --- a/src/data/format.c +++ b/src/data/format.c @@ -33,6 +33,7 @@ #include "libpspp/misc.h" #include "libpspp/str.h" +#include "gl/c-strcase.h" #include "gl/minmax.h" #include "gl/xalloc.h" @@ -292,6 +293,16 @@ fmt_for_output_from_input (const struct fmt_spec *input) case FMT_MONTH: break; + case FMT_MTIME: + if (input->d) + output.w = MAX (input->w, input->d + 6); + break; + + case FMT_YMDHMS: + if (input->w) + output.w = MAX (input->w, input->d + 20); + break; + default: NOT_REACHED (); } @@ -474,8 +485,10 @@ fmt_equal (const struct fmt_spec *a, const struct fmt_spec *b) return a->type == b->type && a->w == b->w && a->d == b->d; } -/* Adjusts FMT to be valid for a value of the given WIDTH. */ -void +/* Adjusts FMT to be valid for a value of the given WIDTH if necessary. + If nothing needed to be changed the return value is false + */ +bool fmt_resize (struct fmt_spec *fmt, int width) { if ((width > 0) != fmt_is_string (fmt->type)) @@ -493,7 +506,9 @@ fmt_resize (struct fmt_spec *fmt, int width) else { /* Still numeric. */ + return false; } + return true; } /* Adjusts FMT's width and decimal places to be valid for USE. */ @@ -581,7 +596,7 @@ fmt_from_name (const char *name, enum fmt_type *type) int i; for (i = 0; i < FMT_NUMBER_OF_FORMATS; i++) - if (!strcasecmp (name, get_fmt_desc (i)->name)) + if (!c_strcasecmp (name, get_fmt_desc (i)->name)) { *type = i; return true; @@ -714,6 +729,14 @@ fmt_max_decimals (enum fmt_type type, int width, enum fmt_use use) max_d = width - 21; break; + case FMT_YMDHMS: + max_d = width - 20; + break; + + case FMT_MTIME: + max_d = width - 6; + break; + case FMT_TIME: max_d = width - 9; break; @@ -872,6 +895,40 @@ fmt_from_io (int io, enum fmt_type *fmt_type) } } +/* Translate U32, which is in the form found in SAV and SPV files, into a + format specification, and stores the new specification in *F. + + If LOOSE is false, checks that the format specification is appropriate as an + output format for a variable with the given WIDTH and reports an error if + not. If LOOSE is true, instead adjusts the format's width and decimals as + necessary to be suitable. + + Return true if successful, false if there was an error.. */ +bool +fmt_from_u32 (uint32_t u32, int width, bool loose, struct fmt_spec *f) +{ + uint8_t raw_type = u32 >> 16; + uint8_t w = u32 >> 8; + uint8_t d = u32; + + msg_disable (); + f->w = w; + f->d = d; + bool ok = fmt_from_io (raw_type, &f->type); + if (ok) + { + if (loose) + fmt_fix_output (f); + else + ok = fmt_check_output (f); + } + if (ok) + ok = fmt_check_width_compat (f, width); + msg_enable (); + + return ok; +} + /* Returns true if TYPE may be used as an input format, false otherwise. */ bool @@ -941,9 +998,19 @@ fmt_date_template (enum fmt_type type, int width) s2 = "dd-mmm-yyyy HH:MM:SS"; break; + case FMT_YMDHMS: + s1 = "yyyy-mm-dd HH:MM"; + s2 = "yyyy-mm-dd HH:MM:SS"; + break; + + case FMT_MTIME: + s1 = "MM"; + s2 = "MM:SS"; + break; + case FMT_TIME: - s1 = "H:MM"; - s2 = "H:MM:SS"; + s1 = "HH:MM"; + s2 = "HH:MM:SS"; break; case FMT_DTIME: @@ -985,6 +1052,8 @@ fmt_gui_name (enum fmt_type type) case FMT_MOYR: case FMT_WKYR: case FMT_DATETIME: + case FMT_YMDHMS: + case FMT_MTIME: case FMT_TIME: case FMT_DTIME: case FMT_WKDAY: @@ -1153,3 +1222,6 @@ get_fmt_desc (enum fmt_type type) } const struct fmt_spec F_8_0 = {FMT_F, 8, 0}; +const struct fmt_spec F_8_2 = {FMT_F, 8, 2}; +const struct fmt_spec F_4_3 = {FMT_F, 4, 3}; +const struct fmt_spec F_5_1 = {FMT_F, 5, 1};