}
\f
-/* 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
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);
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;
}
}
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))
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