Implemented the SET LOCALE='...' command.
[pspp-builds.git] / src / language / utilities / set.q
index e058aa5958330e4924f415dd60713882b8767305..e8cdf1aad89e6c0dfc3996a286698450779a1c15 100644 (file)
@@ -38,6 +38,7 @@
 #include <libpspp/float-format.h>
 #include <libpspp/integer-format.h>
 #include <libpspp/message.h>
+#include <libpspp/i18n.h>
 #include <math/random.h>
 #include <output/journal.h>
 #include <output/output.h>
@@ -86,6 +87,7 @@ int tgetnum (const char *);
      journal=custom;
      log=custom;
      length=custom;
+     locale=custom;
      listing=custom;
      lowres=lores:auto/on/off;
      lpi=integer "x>0" "%s must be greater than 0";
@@ -115,7 +117,7 @@ int tgetnum (const char *);
      wib=wib:msbfirst/lsbfirst/vax/native;
      wrb=wrb:native/isl/isb/idl/idb/vf/vd/vg/zs/zl;
      width=custom;
-     workspace=integer "x>=1024" "%s must be at least 1 MB";
+     workspace=integer "x>0" "%s must be positive";
      xsort=xsort:yes/no.
 */
 
@@ -195,7 +197,12 @@ cmd_set (struct lexer *lexer, struct dataset *ds)
   if (cmd.sbc_wrb)
     settings_set_output_float_format (stc_to_float_format (cmd.wrb));
   if (cmd.sbc_workspace)
-    settings_set_workspace (cmd.n_workspace[0] * 1024L);
+    {
+      if ( cmd.n_workspace[0] < 1024 && ! settings_get_testing_mode ())
+       msg (SE, _("WORKSPACE must be at least 1MB"));
+      else
+       settings_set_workspace (cmd.n_workspace[0] * 1024L);
+    }
 
   if (cmd.sbc_block)
     msg (SW, _("%s is obsolete."), "BLOCK");
@@ -356,6 +363,41 @@ stc_custom_length (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_se
   return 1;
 }
 
+static int
+stc_custom_locale (struct lexer *lexer, struct dataset *ds UNUSED,
+                  struct cmd_set *cmd UNUSED, void *aux UNUSED)
+{
+  const struct string *s;
+
+  lex_match (lexer, '=');
+
+  if ( !lex_force_string (lexer))
+    return 0;
+
+  s = lex_tokstr (lexer);
+
+  lex_get (lexer);
+
+  /* First try this string as an encoding name */
+  if ( valid_encoding (ds_cstr (s)))
+    set_default_encoding (ds_cstr (s));
+
+  /* Now try as a locale name (or alias) */
+  else if (set_encoding_from_locale (ds_cstr (s)))
+    {
+    }
+  else
+    {
+      msg (ME, _("%s is not a recognised encoding or locale name"),
+          ds_cstr (s));
+      return 0;
+    }
+
+  return 1;
+}
+
+
+
 static int
 stc_custom_seed (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
 {
@@ -584,6 +626,12 @@ show_length (const struct dataset *ds UNUSED)
   msg (SN, _("LENGTH is %d."), settings_get_viewlength ());
 }
 
+static void
+show_locale (const struct dataset *ds UNUSED)
+{
+  msg (SN, _("LOCALE is %s"), get_default_encoding ());
+}
+
 static void
 show_mxerrs (const struct dataset *ds UNUSED)
 {
@@ -739,6 +787,7 @@ const struct show_sbc show_table[] =
     {"ERRORS", show_errors},
     {"FORMAT", show_format},
     {"LENGTH", show_length},
+    {"LOCALE", show_locale},
     {"MXERRS", show_mxerrs},
     {"MXLOOPS", show_mxloops},
     {"MXWARNS", show_mxwarns},