settings: Make PRESERVE, RESTORE, and SHOW handle TLOOK.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 30 Sep 2023 19:21:53 +0000 (12:21 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 30 Sep 2023 19:21:53 +0000 (12:21 -0700)
Thanks to Frans Houweling for reporting the issue.

src/language/commands/set.c
src/output/pivot-table.c
src/output/pivot-table.h
src/output/spv/spv-table-look.c
src/output/spv/spv-table-look.h
src/output/spv/spv.c
tests/language/commands/set.at

index 443862d831cf7ec2c6d56622e8eb9beedb15fbb9..a8d46e93ccc22a70500b9726213c6f549b38d7dc 100644 (file)
@@ -1105,6 +1105,13 @@ parse_TLOOK (struct lexer *lexer)
   return true;
 }
 
+static char *
+show_TLOOK (const struct dataset *ds UNUSED)
+{
+  const struct pivot_table_look *look = pivot_table_look_get_default ();
+  return xstrdup (look->file_name ? look->file_name : "NONE");
+}
+
 static bool
 parse_UNDEFINED (struct lexer *lexer)
 {
@@ -1346,7 +1353,7 @@ static const struct setting settings[] = {
   { "TEMPDIR", NULL, show_TEMPDIR },
   { "TNUMBERS", parse_TNUMBERS, show_TNUMBERS },
   { "TVARS", parse_TVARS, show_TVARS },
-  { "TLOOK", parse_TLOOK, NULL },
+  { "TLOOK", parse_TLOOK, show_TLOOK },
   { "UNDEFINED", parse_UNDEFINED, show_UNDEFINED },
   { "VERSION", NULL, show_VERSION },
   { "WEIGHT", NULL, show_WEIGHT },
@@ -1499,7 +1506,13 @@ cmd_show (struct lexer *lexer, struct dataset *ds)
 \f
 #define MAX_SAVED_SETTINGS 5
 
-static struct settings *saved_settings[MAX_SAVED_SETTINGS];
+struct preserved_settings
+  {
+    struct settings *settings;
+    struct pivot_table_look *look;
+  };
+
+static struct preserved_settings saved_settings[MAX_SAVED_SETTINGS];
 static int n_saved_settings;
 
 int
@@ -1507,7 +1520,9 @@ cmd_preserve (struct lexer *lexer, struct dataset *ds UNUSED)
 {
   if (n_saved_settings < MAX_SAVED_SETTINGS)
     {
-      saved_settings[n_saved_settings++] = settings_get ();
+      struct preserved_settings *ps = &saved_settings[n_saved_settings++];
+      ps->settings = settings_get ();
+      ps->look = pivot_table_look_ref (pivot_table_look_get_default ());
       return CMD_SUCCESS;
     }
   else
@@ -1526,9 +1541,11 @@ cmd_restore (struct lexer *lexer, struct dataset *ds UNUSED)
 {
   if (n_saved_settings > 0)
     {
-      struct settings *s = saved_settings[--n_saved_settings];
-      settings_set (s);
-      settings_destroy (s);
+      struct preserved_settings *ps = &saved_settings[--n_saved_settings];
+      settings_set (ps->settings);
+      settings_destroy (ps->settings);
+      pivot_table_look_set_default (ps->look);
+      pivot_table_look_unref (ps->look);
       return CMD_SUCCESS;
     }
   else
index 2f1c9c4bcd2271d101e8625818d18583489bb362..fff7f8d295b74ba85abf92b1f0ade4c3f0625f80 100644 (file)
@@ -311,6 +311,7 @@ pivot_table_look_unshare (struct pivot_table_look *old)
   struct pivot_table_look *new = xmemdup (old, sizeof *old);
   new->ref_cnt = 1;
   new->name = xstrdup_if_nonempty (old->name);
+  new->file_name = xstrdup_if_nonempty (old->name);
   for (size_t i = 0; i < PIVOT_N_AREAS; i++)
     table_area_style_copy (NULL, &new->areas[i], &old->areas[i]);
   new->continuation = xstrdup_if_nonempty (old->continuation);
@@ -327,6 +328,7 @@ pivot_table_look_unref (struct pivot_table_look *look)
       if (!--look->ref_cnt)
         {
           free (look->name);
+          free (look->file_name);
           for (size_t i = 0; i < PIVOT_N_AREAS; i++)
             table_area_style_uninit (&look->areas[i]);
           free (look->continuation);
index 6d8466b4601736659400d51bc1270bd5075afe18..12e7d61f2f10f44898e21875096f9c75aaef93b3 100644 (file)
@@ -428,6 +428,7 @@ struct pivot_table_look
     int ref_cnt;
 
     char *name;                 /* May be null. */
+    char *file_name;            /* May be null. */
 
     /* General properties.
 
index 6b3c6d23459c34d8b09c7065a6c37a029a6fc95e..c8703435b06c81edcb5a3fc4927a488b5cab0d15 100644 (file)
@@ -125,12 +125,14 @@ pivot_border_from_name (const char *name)
 
 char * WARN_UNUSED_RESULT
 spv_table_look_decode (const struct spvsx_table_properties *in,
+                       const char *file_name,
                        struct pivot_table_look **outp)
 {
   struct pivot_table_look *out = pivot_table_look_new_builtin_default ();
   char *error = NULL;
 
   out->name = xstrdup_if_nonnull (in->name);
+  out->file_name = xstrdup_if_nonnull (file_name);
 
   const struct spvsx_general_properties *g = in->general_properties;
   out->omit_empty = g->hide_empty_rows != 0;
@@ -529,7 +531,7 @@ spv_table_look_read (const char *filename, struct pivot_table_look **outp)
       char *error = spvxml_context_finish (&ctx, &tp->node_);
 
       if (!error)
-        error = spv_table_look_decode (tp, outp);
+        error = spv_table_look_decode (tp, filename, outp);
 
       spvsx_free_table_properties (tp);
       xmlFreeDoc (doc);
index 59fe420dc4e8f97398094da048b4aa30adb8b0ca..bbff488defa1b87758dcd439f333e7a33a86dfe2 100644 (file)
@@ -31,6 +31,7 @@ struct pivot_table_look;
 struct spvsx_table_properties;
 
 char *spv_table_look_decode (const struct spvsx_table_properties *,
+                             const char *file_name,
                              struct pivot_table_look **)
   WARN_UNUSED_RESULT;
 char *spv_table_look_read (const char *, struct pivot_table_look **)
index 7a3dae4d3d4a733834bf534534a1483b9ae9772e..c6dfa6f2487f613f1414ce879462baeaf9c13bf8 100644 (file)
@@ -519,7 +519,7 @@ spv_read_table_item (struct zip_reader *zip,
     {
       struct pivot_table_look *look;
       error = (table->table_properties
-               ? spv_table_look_decode (table->table_properties, &look)
+               ? spv_table_look_decode (table->table_properties, NULL, &look)
                : xstrdup ("Legacy table lacks tableProperties"));
       if (!error)
         {
index 9ee8509672ee4b6d2f2f4f7840d2fb77455613c0..c0eae428944a28f88d72e50d1f15bb513bf1892c 100644 (file)
@@ -443,3 +443,74 @@ Table: Settings
 FORMAT,F8.2
 ])
 AT_CLEANUP
+
+AT_SETUP([PRESERVE and SHOW of TLOOK])
+cp $srcdir/output/look.stt lines.stt
+sed 's/solid/none/g
+s/thick/none/g' lines.stt > no-lines.stt
+AT_DATA([set.pspp], [dnl
+DATA LIST LIST NOTABLE/x.
+BEGIN DATA.
+1
+2
+3
+END DATA.
+
+SHOW TLOOK.
+SET TLOOK='lines.stt'.
+SHOW TLOOK.
+DESCRIPTIVES/x.
+
+PRESERVE.
+SET TLOOK='no-lines.stt'.
+SHOW TLOOK.
+DESCRIPTIVES/x.
+RESTORE.
+
+SHOW TLOOK.
+DESCRIPTIVES/x.
+])
+AT_CHECK([pspp -O box=unicode set.pspp], [0], [dnl
+  Settings
+╭─────┬────╮
+│TLOOK│NONE│
+╰─────┴────╯
+
+Settings
+╭─────┬─────────╮
+│TLOOK│lines.stt│
+╰─────┴─────────╯
+
+Descriptive Statistics
+╭────────────────────┬─┬────┬───────┬───────┬───────╮
+│                    │N│Mean│Std Dev│Minimum│Maximum│
+├────────────────────┼─┼────┼───────┼───────┼───────┤
+│x                   │3│2.00│   1.00│   1.00│   3.00│
+│Valid N (listwise)  │3│    │       │       │       │
+│Missing N (listwise)│0│    │       │       │       │
+╰────────────────────┴─┴────┴───────┴───────┴───────╯
+
+Settings
+TLOOK no-lines.stt
+
+Descriptive Statistics
+                     N Mean Std Dev Minimum Maximum
+x                    3 2.00    1.00    1.00    3.00
+Valid N (listwise)   3
+Missing N (listwise) 0
+
+Settings
+╭─────┬─────────╮
+│TLOOK│lines.stt│
+╰─────┴─────────╯
+
+Descriptive Statistics
+╭────────────────────┬─┬────┬───────┬───────┬───────╮
+│                    │N│Mean│Std Dev│Minimum│Maximum│
+├────────────────────┼─┼────┼───────┼───────┼───────┤
+│x                   │3│2.00│   1.00│   1.00│   3.00│
+│Valid N (listwise)  │3│    │       │       │       │
+│Missing N (listwise)│0│    │       │       │       │
+╰────────────────────┴─┴────┴───────┴───────┴───────╯
+])
+AT_CLEANUP
\ No newline at end of file