From 30d83ce86bca0ceeedc9362f05a07080d919ddf1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 30 Sep 2023 12:21:53 -0700 Subject: [PATCH] settings: Make PRESERVE, RESTORE, and SHOW handle TLOOK. Thanks to Frans Houweling for reporting the issue. --- src/language/commands/set.c | 29 +++++++++++--- src/output/pivot-table.c | 2 + src/output/pivot-table.h | 1 + src/output/spv/spv-table-look.c | 4 +- src/output/spv/spv-table-look.h | 1 + src/output/spv/spv.c | 2 +- tests/language/commands/set.at | 71 +++++++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 8 deletions(-) diff --git a/src/language/commands/set.c b/src/language/commands/set.c index 443862d831..a8d46e93cc 100644 --- a/src/language/commands/set.c +++ b/src/language/commands/set.c @@ -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) #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 diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 2f1c9c4bcd..fff7f8d295 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -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); diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h index 6d8466b460..12e7d61f2f 100644 --- a/src/output/pivot-table.h +++ b/src/output/pivot-table.h @@ -428,6 +428,7 @@ struct pivot_table_look int ref_cnt; char *name; /* May be null. */ + char *file_name; /* May be null. */ /* General properties. diff --git a/src/output/spv/spv-table-look.c b/src/output/spv/spv-table-look.c index 6b3c6d2345..c8703435b0 100644 --- a/src/output/spv/spv-table-look.c +++ b/src/output/spv/spv-table-look.c @@ -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); diff --git a/src/output/spv/spv-table-look.h b/src/output/spv/spv-table-look.h index 59fe420dc4..bbff488def 100644 --- a/src/output/spv/spv-table-look.h +++ b/src/output/spv/spv-table-look.h @@ -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 **) diff --git a/src/output/spv/spv.c b/src/output/spv/spv.c index 7a3dae4d3d..c6dfa6f248 100644 --- a/src/output/spv/spv.c +++ b/src/output/spv/spv.c @@ -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) { diff --git a/tests/language/commands/set.at b/tests/language/commands/set.at index 9ee8509672..c0eae42894 100644 --- a/tests/language/commands/set.at +++ b/tests/language/commands/set.at @@ -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 -- 2.30.2