CROSSTABS: Reimplement parser without q2c.
[pspp] / src / language / utilities / set.q
index f640bcbd65b6a5e6949eb1a1e95c26400c763a08..aa7f8b803444220802fc025e10f1829e51c27b65 100644 (file)
@@ -48,6 +48,7 @@
 #include "math/random.h"
 #include "output/driver.h"
 #include "output/journal.h"
+#include "output/pivot-table.h"
 
 #if HAVE_LIBTERMCAP
 #if HAVE_TERMCAP_H
@@ -109,10 +110,12 @@ int tgetnum (const char *);
      scompression=scompress:on/off;
      scripttab=string;
      seed=custom;
+     small=double;
      tnumbers=custom;
      tvars=custom;
      tb1=string;
      tbfonts=string;
+     tlook=custom;
      undefined=undef:warn/nowarn;
      wib=wib:msbfirst/lsbfirst/vax/native;
      wrb=wrb:native/isl/isb/idl/idb/vf/vd/vg/zs/zl;
@@ -193,6 +196,8 @@ cmd_set (struct lexer *lexer, struct dataset *ds)
     settings_set_safer_mode ();
   if (cmd.sbc_scompression)
     settings_set_scompression (cmd.scompress == STC_ON);
+  if (cmd.sbc_small)
+    settings_set_small (cmd.n_small[0]);
   if (cmd.sbc_undefined)
     settings_set_undefined (cmd.undef == STC_WARN);
   if (cmd.sbc_wib)
@@ -346,20 +351,14 @@ stc_custom_tnumbers (struct lexer *lexer,
   lex_match (lexer, T_EQUALS);
 
   if (lex_match_id (lexer, "VALUES"))
-    {
-      settings_set_value_style (SETTINGS_VAL_STYLE_VALUES);
-    }
+    settings_set_show_values (SETTINGS_VALUE_SHOW_VALUE);
   else if (lex_match_id (lexer, "LABELS"))
-    {
-      settings_set_value_style (SETTINGS_VAL_STYLE_LABELS);
-    }
+    settings_set_show_values (SETTINGS_VALUE_SHOW_LABEL);
   else if (lex_match_id (lexer, "BOTH"))
-    {
-      settings_set_value_style (SETTINGS_VAL_STYLE_BOTH);
-    }
+    settings_set_show_values (SETTINGS_VALUE_SHOW_BOTH);
   else
     {
-      lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH", NULL_SENTINEL);
+      lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH");
       return 0;
     }
 
@@ -375,26 +374,48 @@ stc_custom_tvars (struct lexer *lexer,
   lex_match (lexer, T_EQUALS);
 
   if (lex_match_id (lexer, "NAMES"))
-    {
-      settings_set_var_style (SETTINGS_VAR_STYLE_NAMES);
-    }
+    settings_set_show_variables (SETTINGS_VALUE_SHOW_VALUE);
   else if (lex_match_id (lexer, "LABELS"))
-    {
-      settings_set_var_style (SETTINGS_VAR_STYLE_LABELS);
-    }
+    settings_set_show_variables (SETTINGS_VALUE_SHOW_LABEL);
   else if (lex_match_id (lexer, "BOTH"))
-    {
-      settings_set_var_style (SETTINGS_VAR_STYLE_BOTH);
-    }
+    settings_set_show_variables (SETTINGS_VALUE_SHOW_BOTH);
   else
     {
-      lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH", NULL_SENTINEL);
+      lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH");
       return 0;
     }
 
   return 1;
 }
 
+static int
+stc_custom_tlook (struct lexer *lexer,
+                  struct dataset *ds UNUSED,
+                  struct cmd_set *cmd UNUSED, void *aux UNUSED)
+{
+  lex_match (lexer, T_EQUALS);
+
+  if (lex_match_id (lexer, "NONE"))
+    pivot_table_look_set_default (pivot_table_look_builtin_default ());
+  else if (lex_is_string (lexer))
+    {
+      struct pivot_table_look *look;
+      char *error = pivot_table_look_read (lex_tokcstr (lexer), &look);
+      lex_get (lexer);
+
+      if (error)
+        {
+          msg (SE, "%s", error);
+          free (error);
+          return 0;
+        }
+
+      pivot_table_look_set_default (look);
+      pivot_table_look_unref (look);
+    }
+
+  return 1;
+}
 
 /* Parses the EPOCH subcommand, which controls the epoch used for
    parsing 2-digit years. */
@@ -567,7 +588,7 @@ stc_custom_format (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_se
 
   if (!fmt_check_output (&fmt))
     return 0;
-  
+
   if (fmt_is_string (fmt.type))
     {
       char str[FMT_STRING_LEN_MAX + 1];
@@ -637,36 +658,11 @@ show_blanks (const struct dataset *ds UNUSED)
           : xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
 }
 
-static void
-format_cc (struct string *out, const char *in, char grouping)
-{
-  while (*in != '\0')
-    {
-      char c = *in++;
-      if (c == grouping || c == '\'')
-        ds_put_byte (out, '\'');
-      else if (c == '"')
-        ds_put_byte (out, '"');
-      ds_put_byte (out, c);
-    }
-}
-
 static char *
 show_cc (enum fmt_type type)
 {
-  const struct fmt_number_style *cc = settings_get_style (type);
-  struct string out;
-
-  ds_init_empty (&out);
-  format_cc (&out, cc->neg_prefix.s, cc->grouping);
-  ds_put_byte (&out, cc->grouping);
-  format_cc (&out, cc->prefix.s, cc->grouping);
-  ds_put_byte (&out, cc->grouping);
-  format_cc (&out, cc->suffix.s, cc->grouping);
-  ds_put_byte (&out, cc->grouping);
-  format_cc (&out, cc->neg_suffix.s, cc->grouping);
-
-  return ds_cstr (&out);
+  return fmt_number_style_to_string (fmt_settings_get_style (
+                                       settings_get_fmt_settings (), type));
 }
 
 static char *
@@ -702,7 +698,7 @@ show_cce (const struct dataset *ds UNUSED)
 static char *
 show_decimals (const struct dataset *ds UNUSED)
 {
-  return xasprintf ("`%c'", settings_get_decimal_char (FMT_F));
+  return xasprintf ("`%c'", settings_get_fmt_settings ()->decimal);
 }
 
 static char *
@@ -906,7 +902,7 @@ show_current_directory (const struct dataset *ds UNUSED)
     {
       len <<= 1;
       buf = xrealloc (buf, len);
-    } 
+    }
   while (NULL == (wd = getcwd (buf, len)));
 
   return wd;