From: Ben Pfaff Date: Sat, 24 Nov 2012 21:47:06 +0000 (-0800) Subject: DATA LIST FREE: Warn when a quoted string is not followed by a delimiter. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=897c1977501bad5b68f7cc6248a8b950fe15048a;p=pspp DATA LIST FREE: Warn when a quoted string is not followed by a delimiter. A field parsed by DATA LIST FREE (or LIST) is either quoted or unquoted. When it is quoted, this means that the entire field has to be quoted, that is, it is not possible to quote some initial part of the field, then leave some part of it unquoted (then possibly quote an additional part, etc.). That means that the quoted portion should be followed by a delimiter, such as white space, a comma, or end of line, but PSPP didn't warn when it was not. This commit makes PSPP warn in this situation, which makes errors in the input easier to find. Bug #26522. Reported by Pascal Barbedor . --- diff --git a/src/language/data-io/data-parser.c b/src/language/data-io/data-parser.c index 1dc7c93f77..3485f7af1b 100644 --- a/src/language/data-io/data-parser.c +++ b/src/language/data-io/data-parser.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 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 @@ -473,10 +473,18 @@ cut_field (const struct data_parser *parser, struct dfm_reader *reader, /* Skip trailing soft separator and a single hard separator if present. */ - ss_ltrim (&p, parser->soft_seps); - if (!ss_is_empty (p) - && ss_find_byte (parser->hard_seps, ss_first (p)) != SIZE_MAX) - ss_advance (&p, 1); + if (!ss_is_empty (p)) + { + size_t n_seps = ss_ltrim (&p, parser->soft_seps); + if (!ss_is_empty (p) + && ss_find_byte (parser->hard_seps, ss_first (p)) != SIZE_MAX) + { + ss_advance (&p, 1); + n_seps++; + } + if (!n_seps) + msg (SW, _("Missing delimiter following quoted string.")); + } } else { diff --git a/tests/language/data-io/data-list.at b/tests/language/data-io/data-list.at index b0582c6c47..05c1eb61a3 100644 --- a/tests/language/data-io/data-list.at +++ b/tests/language/data-io/data-list.at @@ -30,6 +30,7 @@ A,B,C ]) AT_CLEANUP + AT_SETUP([DATA LIST LIST with explicit delimiters]) AT_DATA([data-list.pspp], [dnl data list list ('|','X') /A B C D. @@ -255,3 +256,21 @@ AT_CHECK([cat write.txt], [0], [dnl 1 12 123 1234 12345 . ]) AT_CLEANUP + +AT_SETUP([DATA LIST FREE and LIST report missing delimiters]) +AT_DATA([data-list.sps], [dnl +DATA LIST FREE NOTABLE/s (a10). +LIST. +BEGIN DATA. +'y'z +END DATA. +]) +AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl +data-list.sps:4: warning: LIST: Missing delimiter following quoted string. + +Table: Data List +s +y @&t@ +z @&t@ +]) +AT_CLEANUP