From 55740f362a5218c87e61858a672540f4909d5e06 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 24 Nov 2012 17:26:38 -0800 Subject: [PATCH] format-parser: Improve error message when format specifier lacks width. Until now, parse_format_specifier() was willing to parse, e.g. "datetime" as a format specifier. It would then be rejected later by e.g. fmt_check_input() with a message like "Input format DATETIME0.0 specifies width 0, but DATETIME requires a width between 17 and 40," which makes no sense to the user. This commit improves the error message. --- src/language/lexer/format-parser.c | 9 ++++++++- tests/language/expressions/evaluate.at | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/language/lexer/format-parser.c b/src/language/lexer/format-parser.c index 45a0b4b1e3..78af09da31 100644 --- a/src/language/lexer/format-parser.c +++ b/src/language/lexer/format-parser.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 @@ -117,6 +117,13 @@ parse_format_specifier (struct lexer *lexer, struct fmt_spec *format) return false; } + if (format->w == 0 && !strchr (lex_tokcstr (lexer), '0')) + { + msg (SE, _("Format specifier `%s' lacks required width."), + lex_tokcstr (lexer)); + return false; + } + lex_get (lexer); return true; } diff --git a/tests/language/expressions/evaluate.at b/tests/language/expressions/evaluate.at index e56a3a457e..8fa027e622 100644 --- a/tests/language/expressions/evaluate.at +++ b/tests/language/expressions/evaluate.at @@ -487,7 +487,7 @@ ANY(string, string[, string]...).]], [[any('a', 'a ', 'b', 'c')], [true]], [[any('b ', 'a', 'b', 'c')], [true]], [[any('c ', 'a', 'b', 'c ')], [true]], - [[any(a, 'b', 'c', 'd')], [error], + [[any(a10, 'b', 'c', 'd')], [error], [error: DEBUG EVALUATE: Function invocation any(format, string, string, string) does not match any known function. Candidates are: ANY(number, number[, number]...) ANY(string, string[, string]...).]], -- 2.30.2