From: Ben Pfaff Date: Mon, 12 Sep 2022 05:33:15 +0000 (-0700) Subject: SET: Improve error messages for SET CCx. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4f19dd9241b87b0b330daf674ed90d767b44822;p=pspp SET: Improve error messages for SET CCx. --- diff --git a/src/data/settings.c b/src/data/settings.c index c70635cec0..5db8e12e24 100644 --- a/src/data/settings.c +++ b/src/data/settings.c @@ -605,22 +605,21 @@ settings_set_syntax (enum behavior_mode mode) } -/* Sets custom currency specifier CC having name CC_NAME ('A' through - 'E') to correspond to the settings in CC_STRING. */ -bool +/* Sets custom currency specifier CC having name CC_NAME ('A' through 'E') to + correspond to the settings in CC_STRING. Returns NULL if successful, + otherwise an error message that the caller must free. */ +char * WARN_UNUSED_RESULT settings_set_cc (const char *cc_string, enum fmt_type type) { struct fmt_number_style *style = fmt_number_style_from_string (cc_string); if (!style) - { - msg (SE, _("%s: Custom currency string `%s' does not contain " - "exactly three periods or commas (or it contains both)."), - fmt_name (type), cc_string); - return false; - } + return xasprintf (_("Custom currency string `%s' for %s does not contain " + "exactly three periods or commas (or it contains " + "both)."), + fmt_name (type), cc_string); fmt_settings_set_cc (&the_settings.styles, type, style); - return true; + return NULL; } void diff --git a/src/data/settings.h b/src/data/settings.h index 6e412c4675..670c410032 100644 --- a/src/data/settings.h +++ b/src/data/settings.h @@ -155,7 +155,7 @@ void settings_set_cmd_algorithm (enum behavior_mode); void unset_cmd_algorithm (void); enum fmt_type; -bool settings_set_cc (const char *cc_string, enum fmt_type type); +char *settings_set_cc (const char *cc_string, enum fmt_type) WARN_UNUSED_RESULT; void settings_set_decimal_char (char decimal); void settings_set_include_leading_zero (bool include_leading_zero); diff --git a/src/language/utilities/set.c b/src/language/utilities/set.c index 2c867145ef..a03eae4ddd 100644 --- a/src/language/utilities/set.c +++ b/src/language/utilities/set.c @@ -315,7 +315,14 @@ parse_ccx (struct lexer *lexer, enum fmt_type ccx) if (!lex_force_string (lexer)) return false; - settings_set_cc (lex_tokcstr (lexer), ccx); + char *error = settings_set_cc (lex_tokcstr (lexer), ccx); + if (error) + { + lex_error (lexer, "%s", error); + free (error); + return false; + } + lex_get (lexer); return true; } @@ -1358,9 +1365,7 @@ cmd_show (struct lexer *lexer, struct dataset *ds) } else if (lex_token (lexer) == T_ID) { - int i; - - for (i = 0; i < sizeof settings / sizeof *settings; i++) + for (size_t i = 0; i < sizeof settings / sizeof *settings; i++) { const struct setting *s = &settings[i]; if (s->show && lex_match_id (lexer, s->name)) diff --git a/tests/language/utilities/set.at b/tests/language/utilities/set.at index 2103f2e96d..c4165dc27d 100644 --- a/tests/language/utilities/set.at +++ b/tests/language/utilities/set.at @@ -48,7 +48,11 @@ AT_DATA([set.pspp], [dnl SET CCA='xxxx'.SHGW CCA. ]) -AT_CHECK([pspp -O format=csv set.pspp], [1], [ignore]) +AT_CHECK([pspp -O format=csv set.pspp], [1], [dnl +"set.pspp:1.9-1.14: error: SET: Custom currency string `CCA' for xxxx does not contain exactly three periods or commas (or it contains both). + 1 | SET CCA='xxxx'.SHGW CCA. + | ^~~~~~" +]) AT_CLEANUP