From: Ben Pfaff Date: Wed, 15 Jun 2011 05:10:24 +0000 (-0700) Subject: GET DATA /TYPE=TXT: Also allow full format to be specified. X-Git-Tag: v0.7.9~283 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e87acf42e694cfae68040f62342becc7be3909a7;p=pspp-builds.git GET DATA /TYPE=TXT: Also allow full format to be specified. The implementation of fixed-format mode only allowed a format type (e.g. DOLLAR) to be specified. SPSS also allowed a full format specification (e.g. DOLLAR12.2), so this implements that feature. Reported-by: Ronaldo Baltar --- diff --git a/doc/files.texi b/doc/files.texi index 4fc92e1b..89d043f8 100644 --- a/doc/files.texi +++ b/doc/files.texi @@ -583,8 +583,9 @@ value is 1. The VARIABLES subcommand, which is required, specifies the positions at which each variable can be found. For each variable, specify its name, followed by its start and end column separated by @samp{-} -(e.g.@: @samp{0-9}), followed by the input format type (e.g.@: -@samp{F}). For this command, columns are numbered starting from 0 at +(e.g.@: @samp{0-9}), followed by an input format type (e.g.@: +@samp{F}) or a full format specification (e.g.@: @samp{DOLLAR12.2}). +For this command, columns are numbered starting from 0 at the left column. Introduce the variables in the second and later lines of a case by a slash followed by the number of the line within the case, e.g.@: @samp{/2} for the second line. diff --git a/src/language/data-io/get-data.c b/src/language/data-io/get-data.c index e3e6c5d4..47b65b44 100644 --- a/src/language/data-io/get-data.c +++ b/src/language/data-io/get-data.c @@ -520,19 +520,46 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds) if (!parse_format_specifier (lexer, &input) || !fmt_check_input (&input)) goto error; + + output = fmt_for_output_from_input (&input); } else { + char fmt_type_name[FMT_TYPE_LEN_MAX + 1]; + enum fmt_type fmt_type; + int w, d; + if (!parse_column_range (lexer, 0, &fc, &lc, NULL)) goto error; - if (!parse_format_specifier_name (lexer, &input.type)) + + /* Accept a format (e.g. F8.2) or just a type name (e.g. DOLLAR). */ + if (!parse_abstract_format_specifier (lexer, fmt_type_name, &w, &d)) goto error; + if (!fmt_from_name (fmt_type_name, &fmt_type)) + { + msg (SE, _("Unknown format type `%s'."), fmt_type_name); + goto error; + } + + /* Compose input format. */ + input.type = fmt_type; input.w = lc - fc + 1; input.d = 0; if (!fmt_check_input (&input)) goto error; + + /* Compose output format. */ + if (w != 0) + { + output.type = fmt_type; + output.w = w; + output.d = d; + if (!fmt_check_output (&output)) + goto error; + } + else + output = fmt_for_output_from_input (&input); } - output = fmt_for_output_from_input (&input); v = dict_create_var (dict, name, fmt_var_width (&input)); if (v == NULL) diff --git a/tests/language/data-io/get-data-txt.at b/tests/language/data-io/get-data-txt.at index e4c6ae37..44189747 100644 --- a/tests/language/data-io/get-data-txt.at +++ b/tests/language/data-io/get-data-txt.at @@ -113,7 +113,7 @@ AT_CLEANUP AT_SETUP([GET DATA /TYPE=TXT with multiple records per case]) AT_DATA([get-data.sps], [dnl get data /type=txt /file=inline /arrangement=fixed /fixcase=3 /variables= - /1 start 0-19 adate + /1 start 0-19 adate8 /2 end 0-19 adate /3 count 0-2 f. begin data. @@ -133,9 +133,9 @@ AT_CHECK([pspp -o pspp.csv get-data.sps]) AT_CHECK([cat pspp.csv], [0], [dnl Table: Data List start,end,count -07/22/2007,10/06/2007,321 -07/14/1789,08/26/1789,4 -01/01/1972,12/31/1999,682 +07/22/07,10/06/2007,321 +********,08/26/1789,4 +01/01/72,12/31/1999,682 ]) AT_CLEANUP