From: Ben Pfaff <blp@cs.stanford.edu>
Date: Sat, 7 Dec 2019 23:54:50 +0000 (+0000)
Subject: pivot-table: Initialize subtype, command_id for pivot tables.
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9420449c40bb1307f6c31e50b61ba03825680e3a;p=pspp

pivot-table: Initialize subtype, command_id for pivot tables.
---

diff --git a/src/language/data-io/data-parser.c b/src/language/data-io/data-parser.c
index b3c4b54cbb..2ae8d6a361 100644
--- a/src/language/data-io/data-parser.c
+++ b/src/language/data-io/data-parser.c
@@ -671,7 +671,7 @@ dump_fixed_table (const struct data_parser *parser,
                                      parser->records_per_case),
                            parser->records_per_case, fh_get_name (fh));
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_user_text (title, -1));
+    pivot_value_new_user_text (title, -1), "Fixed Data Records");
   free (title);
 
   pivot_dimension_create (
@@ -717,7 +717,8 @@ dump_delimited_table (const struct data_parser *parser,
 {
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Reading free-form data from %s."),
-                                 fh_get_name (fh)));
+                                 fh_get_name (fh)),
+    "Free-Form Data Records");
 
   pivot_dimension_create (
     table, PIVOT_AXIS_COLUMN, N_("Attributes"), N_("Format"));
diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c
index 5d47725b57..66ef00bb70 100644
--- a/src/language/dictionary/sys-file-info.c
+++ b/src/language/dictionary/sys-file-info.c
@@ -1002,7 +1002,7 @@ report_encodings (const struct file_handle *h, struct pool *pool,
   /* Table of valid encodings. */
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Usable encodings for %s."),
-                                 fh_get_name (h)));
+                                 fh_get_name (h)), "Usable Encodings");
   table->caption = pivot_value_new_text_format (
     N_("Encodings that can successfully read %s (by specifying the encoding "
        "name on the GET command's ENCODING subcommand).  Encodings that "
@@ -1040,7 +1040,8 @@ report_encodings (const struct file_handle *h, struct pool *pool,
   /* Table of alternative interpretations. */
   table = pivot_table_create__ (
     pivot_value_new_text_format (N_("%s Encoded Text Strings"),
-                                 fh_get_name (h)));
+                                 fh_get_name (h)),
+    "Alternate Encoded Text Strings");
   table->caption = pivot_value_new_text (
     N_("Text strings in the file dictionary that the previously listed "
        "encodings interpret differently, along with the interpretations."));
diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c
index dcd0a14d76..c093b1e6ab 100644
--- a/src/language/stats/autorecode.c
+++ b/src/language/stats/autorecode.c
@@ -369,7 +369,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
                : pivot_value_new_text_format (N_("Recoding %s into %s."),
                                               spec->src_name,
                                               var_get_name (spec->dst)));
-          struct pivot_table *table = pivot_table_create__ (title);
+          struct pivot_table *table = pivot_table_create__ (title, "Recoding");
 
           pivot_dimension_create (
             table, PIVOT_AXIS_COLUMN, N_("Attributes"),
diff --git a/src/language/stats/chisquare.c b/src/language/stats/chisquare.c
index ccfa484621..ffb75dd3e0 100644
--- a/src/language/stats/chisquare.c
+++ b/src/language/stats/chisquare.c
@@ -176,7 +176,7 @@ chisquare_execute (const struct dataset *ds,
             }
 
           struct pivot_table *table = pivot_table_create__ (
-            pivot_value_new_variable (var));
+            pivot_value_new_variable (var), "Chisquare");
           pivot_table_set_weight_var (table, dict_get_weight (dict));
 
           pivot_dimension_create (
diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q
index 6defd2447a..a772034f64 100644
--- a/src/language/stats/crosstabs.q
+++ b/src/language/stats/crosstabs.q
@@ -1243,7 +1243,8 @@ create_crosstab_table (struct crosstabs_proc *proc, struct crosstabulation *xt,
       free (s);
     }
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_user_text_nocopy (ds_steal_cstr (&title)));
+    pivot_value_new_user_text_nocopy (ds_steal_cstr (&title)),
+    "Crosstabulation");
   pivot_table_set_weight_format (table, &proc->weight_format);
   table->omit_empty = true;
 
diff --git a/src/language/stats/frequencies.c b/src/language/stats/frequencies.c
index c96b4eab19..ef1b7592dc 100644
--- a/src/language/stats/frequencies.c
+++ b/src/language/stats/frequencies.c
@@ -296,7 +296,7 @@ dump_freq_table (const struct var_freqs *vf, const struct variable *wv)
   const struct freq_tab *ft = &vf->tab;
 
   struct pivot_table *table = pivot_table_create__ (pivot_value_new_variable (
-                                                      vf->var));
+                                                      vf->var), "Frequencies");
   pivot_table_set_weight_var (table, wv);
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
diff --git a/src/language/stats/mcnemar.c b/src/language/stats/mcnemar.c
index 0456b909c5..ef84b77a4e 100644
--- a/src/language/stats/mcnemar.c
+++ b/src/language/stats/mcnemar.c
@@ -169,7 +169,7 @@ output_freq_table (variable_pair *vp,
 		   const struct dictionary *dict)
 {
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_user_text_nocopy (make_pair_name (vp)));
+    pivot_value_new_user_text_nocopy (make_pair_name (vp)), "Frequencies");
   pivot_table_set_weight_var (table, dict_get_weight (dict));
 
   struct pivot_dimension *vars[2];
diff --git a/src/language/stats/oneway.c b/src/language/stats/oneway.c
index 7f28b75b8a..c33d333ce4 100644
--- a/src/language/stats/oneway.c
+++ b/src/language/stats/oneway.c
@@ -1365,7 +1365,8 @@ show_comparisons (const struct oneway_spec *cmd, const struct oneway_workspace *
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_user_text_nocopy (xasprintf (
                                         _("Multiple Comparisons (%s)"),
-                                        var_to_string (cmd->vars[v]))));
+                                        var_to_string (cmd->vars[v]))),
+    "Multiple Comparisons");
   table->omit_empty = true;
 
   struct pivot_dimension *statistics = pivot_dimension_create (
diff --git a/src/language/stats/regression.c b/src/language/stats/regression.c
index 9ca056943e..28618f12b0 100644
--- a/src/language/stats/regression.c
+++ b/src/language/stats/regression.c
@@ -856,7 +856,8 @@ reg_stats_r (const struct linreg * c, const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Model Summary (%s)"),
-                                 var_to_string (var)));
+                                 var_to_string (var)),
+    "Model Summary");
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
                           N_("R"), N_("R Square"), N_("Adjusted R Square"),
@@ -886,8 +887,8 @@ reg_stats_coeff (const struct regression *cmd, const struct linreg *c,
 		 const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_text_format (N_("Coefficients (%s)"),
-                                 var_to_string (var)));
+    pivot_value_new_text_format (N_("Coefficients (%s)"), var_to_string (var)),
+    "Coefficients");
 
   struct pivot_dimension *statistics = pivot_dimension_create (
     table, PIVOT_AXIS_COLUMN, N_("Statistics"));
@@ -1011,7 +1012,8 @@ static void
 reg_stats_anova (const struct linreg * c, const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_text_format (N_("ANOVA (%s)"), var_to_string (var)));
+    pivot_value_new_text_format (N_("ANOVA (%s)"), var_to_string (var)),
+    "ANOVA");
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
                           N_("Sum of Squares"), PIVOT_RC_OTHER,
@@ -1066,7 +1068,8 @@ reg_stats_bcov (const struct linreg * c, const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Coefficient Correlations (%s)"),
-                                 var_to_string (var)));
+                                 var_to_string (var)),
+    "Coefficient Correlations");
 
   for (size_t i = 0; i < 2; i++)
     {
diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c
index 057df4ef02..ff45226e64 100644
--- a/src/output/pivot-table.c
+++ b/src/output/pivot-table.c
@@ -26,6 +26,7 @@
 #include "data/variable.h"
 #include "libpspp/hash-functions.h"
 #include "libpspp/i18n.h"
+#include "output/driver.h"
 
 #include "gl/c-ctype.h"
 #include "gl/intprops.h"
@@ -655,7 +656,8 @@ pivot_result_class_change (const char *s_, const struct fmt_spec *format)
 
 /* Creates and returns a new pivot table with the given TITLE.  TITLE should be
    a text string marked for translation but not actually translated yet,
-   e.g. N_("Descriptive Statistics").
+   e.g. N_("Descriptive Statistics").  The un-translated text string is used as
+   the pivot table's subtype.
 
    Operations commonly performed on the new pivot_table:
 
@@ -667,18 +669,22 @@ pivot_result_class_change (const char *s_, const struct fmt_spec *format)
 
    This function is a shortcut for pivot_table_create__() for the most common
    case.  Use pivot_table_create__() directly if the title should be some kind
-   of value other than an ordinary text string.
+   of value other than an ordinary text string, or if the subtype should be
+different from the title.
 
    See the large comment at the top of pivot-table.h for general advice on
    creating pivot tables. */
 struct pivot_table *
 pivot_table_create (const char *title)
 {
-  return pivot_table_create__ (pivot_value_new_text (title));
+  return pivot_table_create__ (pivot_value_new_text (title), title);
 }
 
 /* Creates and returns a new pivot table with the given TITLE, and takes
-   ownership of TITLE.
+   ownership of TITLE.  The new pivot table's subtype is SUBTYPE, which
+   should be an untranslated English string that describes the contents of
+   the table at a high level without being specific about the variables or
+   other context involved.
 
    Operations commonly performed on the new pivot_table:
 
@@ -691,12 +697,16 @@ pivot_table_create (const char *title)
    See the large comment at the top of pivot-table.h for general advice on
    creating pivot tables. */
 struct pivot_table *
-pivot_table_create__ (struct pivot_value *title)
+pivot_table_create__ (struct pivot_value *title, const char *subtype)
 {
   struct pivot_table *table = xzalloc (sizeof *table);
   table->ref_cnt = 1;
   table->weight_format = (struct fmt_spec) { FMT_F, 40, 0 };
   table->title = title;
+  table->subtype = pivot_value_new_text (subtype);
+
+  const char *command_id = output_get_command_name ();
+  table->command_c = command_id ? xstrdup (command_id) : NULL;
 
   table->sizing[TABLE_HORZ].range[0] = 50;
   table->sizing[TABLE_HORZ].range[1] = 72;
@@ -748,7 +758,7 @@ struct pivot_table *
 pivot_table_create_for_text (struct pivot_value *title,
                              struct pivot_value *content)
 {
-  struct pivot_table *table = pivot_table_create__ (title);
+  struct pivot_table *table = pivot_table_create__ (title, "Error");
 
   struct pivot_dimension *d = pivot_dimension_create (
     table, PIVOT_AXIS_ROW, N_("Error"));
diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h
index 99308c9e44..c11874da2e 100644
--- a/src/output/pivot-table.h
+++ b/src/output/pivot-table.h
@@ -432,7 +432,7 @@ struct pivot_table
 
     /* Titles. */
     struct pivot_value *title;
-    struct pivot_value *subtype;  /* Same as pivot_item's subtype. */
+    struct pivot_value *subtype;  /* Same as spv_item's subtype. */
     struct pivot_value *corner_text;
     struct pivot_value *caption;
     char *notes;
@@ -453,7 +453,8 @@ struct pivot_table
 
 /* Creating and destroy pivot tables. */
 struct pivot_table *pivot_table_create (const char *title);
-struct pivot_table *pivot_table_create__ (struct pivot_value *title);
+struct pivot_table *pivot_table_create__ (struct pivot_value *title,
+                                          const char *subtype);
 struct pivot_table *pivot_table_create_for_text (struct pivot_value *title,
                                                  struct pivot_value *content);