SYSFILE INFO: Display documents too.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 23 Feb 2019 02:24:01 +0000 (18:24 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 23 Feb 2019 02:31:38 +0000 (18:31 -0800)
The documentation says that SYSFILE INFO displays the documents but it
didn't actually do it.

Reported by Nolan Void <nolvoa@hanakami.com>.

src/language/dictionary/sys-file-info.c
tests/language/dictionary/sys-file-info.at

index 80fa903b066ca704f05d5e1572c2b42270707760..10ee6c8073d4b418fee2cf952c0e2047233020dd 100644 (file)
@@ -89,6 +89,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)
@@ -239,6 +241,10 @@ 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_line_cnt (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);
@@ -398,6 +404,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 +426,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);
index 11f5d4e9f82c8ca0b6ea562a7512adfeab81a2ee..50bf224b63f49ad584ed377b8b59b07e589d224c 100644 (file)
@@ -24,6 +24,7 @@ BEGIN DATA
 2 two
 3 three
 END DATA.
+DOCUMENT A document.
 SAVE OUTFILE='pro.sav'.
 
 sysfile info file='pro.sav'.
@@ -34,7 +35,8 @@ AT_CHECK(
        -e '/^Endian,/d' \
        -e '/^Integer Format,/d' \
        -e '/^Real Format,/d' \
-       -e '/^Encoding,/d' pspp.csv],
+       -e '/^Encoding,/d' \
+       -e 's/(Entered.*)/(Entered <date>)/' pspp.csv],
   [0], [dnl
 Table: Reading free-form data from INLINE.
 Variable,Format
@@ -49,6 +51,8 @@ Cases,3
 Type,SPSS System File
 Weight,Not weighted
 Compression,SAV
+Documents,"DOCUMENT A document.
+   (Entered <date>)"
 
 Table: Variables
 Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values