From c3dd7acbbaca2931e601b6327a39a209f6cc0d9e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 24 Nov 2012 17:50:05 -0800 Subject: [PATCH] DATA LIST: Accept freefield format types without widths use minimum width. A user reported that SPSS accepts syntax such as "DATA LIST FREE/ d (DATETIME)." using a default width for the field with no specified width. This commit makes PSPP accept this syntax too, although it does not get the width exactly right (please let me know if you figure out how to do that). Bug #30690. Reported by Andreas Lappe. --- src/language/data-io/data-list.c | 25 ++++++++++++++++++++++--- tests/language/data-io/data-list.at | 13 +++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index 17c6032d25..bc295a9aed 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -429,9 +429,28 @@ parse_free (struct lexer *lexer, struct dictionary *dict, if (lex_match (lexer, T_LPAREN)) { - if (!parse_format_specifier (lexer, &input) - || !fmt_check_input (&input) - || !lex_force_match (lexer, T_RPAREN)) + char type[FMT_TYPE_LEN_MAX + 1]; + + if (!parse_abstract_format_specifier (lexer, type, &input.w, + &input.d)) + return NULL; + if (!fmt_from_name (type, &input.type)) + { + msg (SE, _("Unknown format type `%s'."), type); + return NULL; + } + + /* If no width was included, use the minimum width for the type. + This isn't quite right, because DATETIME by itself seems to become + DATETIME20 (see bug #30690), whereas this will become + DATETIME17. The correct behavior is not documented. */ + if (input.w == 0) + { + input.w = fmt_min_input_width (input.type); + input.d = 0; + } + + if (!fmt_check_input (&input) || !lex_force_match (lexer, T_RPAREN)) return NULL; /* As a special case, N format is treated as F format diff --git a/tests/language/data-io/data-list.at b/tests/language/data-io/data-list.at index ade227274c..4a59cf795a 100644 --- a/tests/language/data-io/data-list.at +++ b/tests/language/data-io/data-list.at @@ -274,3 +274,16 @@ y @&t@ z @&t@ ]) AT_CLEANUP + +AT_SETUP([DATA LIST FREE and LIST assume a width if omitted]) +AT_DATA([data-list.sps], [dnl +DATA LIST FREE TABLE/s (a) d (datetime) f (f). +]) +AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl +Table: Reading free-form data from INLINE. +Variable,Format +s,A1 +d,DATETIME17.0 +f,F1.0 +]) +AT_CLEANUP -- 2.30.2