X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fformat.c;h=3a380bda45c0d960758739531289436da37f7af9;hb=2e4f99b049133c801ca4feffddb86bbf33de3978;hp=dc546af84577e41917220635a20a3c3f8fd3438a;hpb=3328de5b6568b4dc85562b25add87c068b579cda;p=pspp diff --git a/src/data/format.c b/src/data/format.c index dc546af845..3a380bda45 100644 --- a/src/data/format.c +++ b/src/data/format.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2010, 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -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" @@ -474,8 +475,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 +496,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 +586,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; @@ -881,38 +886,81 @@ fmt_usable_for_input (enum fmt_type type) return fmt_get_category (type) != FMT_CAT_CUSTOM; } -/* For time and date formats, returns a template used for input - and output. */ +/* For time and date formats, returns a template used for input and output in a + field of the given WIDTH. + + WIDTH only affects whether a 2-digit year or a 4-digit year is used, that + is, whether the returned string contains "yy" or "yyyy", and whether seconds + are include, that is, whether the returned string contains ":SS". A caller + that doesn't care whether the returned string contains "yy" or "yyyy" or + ":SS" can just specify 0 to omit them. */ const char * -fmt_date_template (enum fmt_type type) +fmt_date_template (enum fmt_type type, int width) { + const char *s1, *s2; + switch (type) { case FMT_DATE: - return "dd-mmm-yy"; + s1 = "dd-mmm-yy"; + s2 = "dd-mmm-yyyy"; + break; + case FMT_ADATE: - return "mm/dd/yy"; + s1 = "mm/dd/yy"; + s2 = "mm/dd/yyyy"; + break; + case FMT_EDATE: - return "dd.mm.yy"; + s1 = "dd.mm.yy"; + s2 = "dd.mm.yyyy"; + break; + case FMT_JDATE: - return "yyddd"; + s1 = "yyddd"; + s2 = "yyyyddd"; + break; + case FMT_SDATE: - return "yy/mm/dd"; + s1 = "yy/mm/dd"; + s2 = "yyyy/mm/dd"; + break; + case FMT_QYR: - return "q Q yy"; + s1 = "q Q yy"; + s2 = "q Q yyyy"; + break; + case FMT_MOYR: - return "mmmXyy"; + s1 = "mmm yy"; + s2 = "mmm yyyy"; + break; + case FMT_WKYR: - return "ww WK yy"; + s1 = "ww WK yy"; + s2 = "ww WK yyyy"; + break; + case FMT_DATETIME: - return "dd-mmm-yyyy HH:MM"; + s1 = "dd-mmm-yyyy HH:MM"; + s2 = "dd-mmm-yyyy HH:MM:SS"; + break; + case FMT_TIME: - return "H:MM"; + s1 = "H:MM"; + s2 = "H:MM:SS"; + break; + case FMT_DTIME: - return "D HH:MM"; + s1 = "D HH:MM"; + s2 = "D HH:MM:SS"; + break; + default: NOT_REACHED (); } + + return width >= strlen (s2) ? s2 : s1; } /* Returns a string representing the format TYPE for use in a GUI dialog. */