pivot-table: New functions for setting captions, etc.
[pspp] / src / language / dictionary / sys-file-info.c
index 80fa903b066ca704f05d5e1572c2b42270707760..7f5216134c8e1d869700ce3437db2ea7e7209845 100644 (file)
@@ -43,8 +43,7 @@
 #include "libpspp/pool.h"
 #include "libpspp/string-array.h"
 #include "output/pivot-table.h"
-#include "output/text-item.h"
-#include "output/table-item.h"
+#include "output/output-item.h"
 
 #include "gl/count-one-bits.h"
 #include "gl/localcharset.h"
@@ -89,6 +88,8 @@ static void report_encodings (const struct file_handle *, struct pool *,
                               char **titles, bool *ids,
                               char **strings, size_t n_strings);
 
+static char *get_documents_as_string (const struct dictionary *);
+
 static void
 add_row (struct pivot_table *table, const char *attribute,
          struct pivot_value *value)
@@ -101,7 +102,7 @@ add_row (struct pivot_table *table, const char *attribute,
 
 /* SYSFILE INFO utility. */
 int
-cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
+cmd_sysfile_info (struct lexer *lexer, struct dataset *ds)
 {
   struct any_reader *any_reader;
   struct file_handle *h;
@@ -214,12 +215,12 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
              : N_("Unknown")));
 
   add_row (table, N_("Variables"),
-           pivot_value_new_integer (dict_get_var_cnt (d)));
+           pivot_value_new_integer (dict_get_n_vars (d)));
 
   add_row (table, N_("Cases"),
-           (info.case_cnt == -1
+           (info.n_cases == -1
             ? pivot_value_new_text (N_("Unknown"))
-            : pivot_value_new_integer (info.case_cnt)));
+            : pivot_value_new_integer (info.n_cases)));
 
   add_row (table, N_("Type"),
            pivot_value_new_text (info.klass->name));
@@ -239,11 +240,15 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
   add_row (table, N_("Encoding"),
            pivot_value_new_user_text (dict_get_encoding (d), -1));
 
+  if (dict_get_document_n_lines (d) > 0)
+    add_row (table, N_("Documents"),
+             pivot_value_new_user_text_nocopy (get_documents_as_string (d)));
+
   pivot_table_submit (table);
 
-  size_t n_vars = dict_get_var_cnt (d);
+  size_t n_vars = dict_get_n_vars (d);
   const struct variable **vars = xnmalloc (n_vars, sizeof *vars);
-  for (size_t i = 0; i < dict_get_var_cnt (d); i++)
+  for (size_t i = 0; i < dict_get_n_vars (d); i++)
     vars[i] = dict_get_var (d, i);
   display_variables (vars, n_vars, DF_ALL_VARIABLE);
   display_value_labels (vars, n_vars);
@@ -398,6 +403,20 @@ display_macros (void)
   msg (SW, _("Macros not supported."));
 }
 
+static char *
+get_documents_as_string (const struct dictionary *dict)
+{
+  const struct string_array *documents = dict_get_documents (dict);
+  struct string s = DS_EMPTY_INITIALIZER;
+  for (size_t i = 0; i < documents->n; i++)
+    {
+      if (i)
+        ds_put_byte (&s, '\n');
+      ds_put_cstr (&s, documents->strings[i]);
+    }
+  return ds_steal_cstr (&s);
+}
+
 static void
 display_documents (const struct dictionary *dict)
 {
@@ -406,20 +425,12 @@ display_documents (const struct dictionary *dict)
     table, PIVOT_AXIS_COLUMN, N_("Documents"), N_("Document"));
   d->hide_all_labels = true;
 
-  const struct string_array *documents = dict_get_documents (dict);
-  if (!documents->n)
+  if (!dict_get_documents (dict)->n)
     pivot_table_put1 (table, 0, pivot_value_new_text (N_("(none)")));
   else
     {
-      struct string s = DS_EMPTY_INITIALIZER;
-      for (size_t i = 0; i < documents->n; i++)
-        {
-          if (i)
-            ds_put_byte (&s, '\n');
-          ds_put_cstr (&s, documents->strings[i]);
-        }
-      pivot_table_put1 (table, 0,
-                        pivot_value_new_user_text_nocopy (ds_steal_cstr (&s)));
+      char *docs = get_documents_as_string (dict);
+      pivot_table_put1 (table, 0, pivot_value_new_user_text_nocopy (docs));
     }
 
   pivot_table_submit (table);
@@ -585,7 +596,7 @@ display_value_labels (const struct variable **vars, size_t n_vars)
             value->numeric.show = SETTINGS_VALUE_SHOW_VALUE;
           else
             value->string.show = SETTINGS_VALUE_SHOW_VALUE;
-          if (var_is_value_missing (vars[i], &vl->value, MV_USER))
+          if (var_is_value_missing (vars[i], &vl->value) == MV_USER)
             pivot_value_add_footnote (value, missing_footnote);
           int row = pivot_category_create_leaf (group, value);
 
@@ -694,7 +705,7 @@ display_attributes (const struct attrset *dict_attrset,
                      var_get_attributes (vars[i]), flags);
 
   if (pivot_table_is_empty (table))
-    pivot_table_destroy (table);
+    pivot_table_unref (table);
   else
     pivot_table_submit (table);
 }
@@ -704,7 +715,7 @@ display_attributes (const struct attrset *dict_attrset,
 static void
 display_vectors (const struct dictionary *dict, int sorted)
 {
-  size_t n_vectors = dict_get_vector_cnt (dict);
+  size_t n_vectors = dict_get_n_vectors (dict);
   if (n_vectors == 0)
     {
       msg (SW, _("No vectors defined."));
@@ -732,7 +743,7 @@ display_vectors (const struct dictionary *dict, int sorted)
         vector_dim->root, pivot_value_new_user_text (
           vector_get_name (vectors[i]), -1));
 
-      for (size_t j = 0; j < vector_get_var_cnt (vec); j++)
+      for (size_t j = 0; j < vector_get_n_vars (vec); j++)
         {
           struct variable *var = vector_get_var (vec, j);
 
@@ -990,12 +1001,13 @@ 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)));
-  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 "
-       "yield identical text are listed together."),
-    fh_get_name (h));
+                                 fh_get_name (h)), "Usable Encodings");
+  pivot_table_set_caption (
+    table, 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 "
+         "yield identical text are listed together."),
+      fh_get_name (h)));
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Encodings"),
                           N_("Encodings"));
@@ -1028,10 +1040,12 @@ 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)));
-  table->caption = pivot_value_new_text (
-    N_("Text strings in the file dictionary that the previously listed "
-       "encodings interpret differently, along with the interpretations."));
+                                 fh_get_name (h)),
+    "Alternate Encoded Text Strings");
+  pivot_table_set_caption (
+    table, pivot_value_new_text (
+      N_("Text strings in the file dictionary that the previously listed "
+         "encodings interpret differently, along with the interpretations.")));
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Text"), N_("Text"));