SET: Improve error messages for SET CCx.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 05:33:15 +0000 (22:33 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 05:36:40 +0000 (22:36 -0700)
src/data/settings.c
src/data/settings.h
src/language/utilities/set.c
tests/language/utilities/set.at

index c70635cec03fc06da0dd7c472a8da626e2010fd6..5db8e12e249d51e5537ab12e9f909e6c0c6c2919 100644 (file)
@@ -605,22 +605,21 @@ settings_set_syntax (enum behavior_mode mode)
 }
 
 \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
index 6e412c4675925e7389f2958c879a70e506575a1b..670c41003236f3891e7246bdcde64188892f6286 100644 (file)
@@ -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);
index 2c867145efd9c412925953ddf59d6fd6efe74c23..a03eae4ddd94e2dc3792efee76f83af4dd84c775 100644 (file)
@@ -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))
index 2103f2e96d5de3bfe24a5daed42f10792170bb27..c4165dc27d340bbff86718669c40091d313b059c 100644 (file)
@@ -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