SHOW: Display settings in pivot table.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 01:30:51 +0000 (18:30 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 01:37:44 +0000 (18:37 -0700)
src/language/utilities/set.c
tests/data/data-out.at
tests/language/control/define.at
tests/language/utilities/set.at
tests/language/utilities/show.at
tests/language/utilities/title.at
tests/perl-module.at

index a547e5104afbe67d26cc80bcf75279038fc6a215..43adaf6da3c7fb6c6240895425808107494b8d4f 100644 (file)
@@ -1151,11 +1151,24 @@ show_N (const struct dataset *ds)
 }
 
 static void
-do_show (const struct dataset *ds, const struct setting *s)
+do_show (const struct dataset *ds, const struct setting *s,
+         struct pivot_table **ptp)
 {
-  char *value = s->show (ds);
-  msg (SN, _("%s is %s."), s->name, value ? value : _("empty"));
-  free (value);
+  struct pivot_table *pt = *ptp;
+  if (!pt)
+    {
+      pt = *ptp = pivot_table_create (N_("Settings"));
+      pivot_dimension_create (pt, PIVOT_AXIS_ROW, N_("Setting"));
+    }
+
+  struct pivot_value *name = pivot_value_new_user_text (s->name, SIZE_MAX);
+  char *text = s->show (ds);
+  if (!text)
+    text = xstrdup("empty");
+  struct pivot_value *value = pivot_value_new_user_text_nocopy (text);
+
+  int row = pivot_category_create_leaf (pt->dimensions[0]->root, name);
+  pivot_table_put1 (pt, row, value);
 }
 
 static void
@@ -1287,39 +1300,41 @@ cmd_set (struct lexer *lexer, struct dataset *ds UNUSED)
 }
 
 static void
-show_all (const struct dataset *ds)
+show_all (const struct dataset *ds, struct pivot_table **ptp)
 {
   for (size_t i = 0; i < sizeof settings / sizeof *settings; i++)
     if (settings[i].show)
-      do_show (ds, &settings[i]);
+      do_show (ds, &settings[i], ptp);
 }
 
 static void
-show_all_cc (const struct dataset *ds)
+show_all_cc (const struct dataset *ds, struct pivot_table **ptp)
 {
   for (size_t i = 0; i < sizeof settings / sizeof *settings; i++)
     {
       const struct setting *s = &settings[i];
       if (s->show && !strncmp (s->name, "CC", 2))
-        do_show (ds, s);
+        do_show (ds, s, ptp);
     }
 }
 
 int
 cmd_show (struct lexer *lexer, struct dataset *ds)
 {
+  struct pivot_table *pt = NULL;
   if (lex_token (lexer) == T_ENDCMD)
     {
-      show_all (ds);
+      show_all (ds, &pt);
+      pivot_table_submit (pt);
       return CMD_SUCCESS;
     }
 
   do
     {
       if (lex_match (lexer, T_ALL))
-        show_all (ds);
+        show_all (ds, &pt);
       else if (lex_match_id (lexer, "CC"))
-        show_all_cc (ds);
+        show_all_cc (ds, &pt);
       else if (lex_match_id (lexer, "WARRANTY"))
         show_warranty (ds);
       else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
@@ -1329,12 +1344,12 @@ cmd_show (struct lexer *lexer, struct dataset *ds)
       else if (lex_match_id (lexer, "TITLE"))
         {
           struct setting s = { .name = "TITLE", .show = show_TITLE };
-          do_show (ds, &s);
+          do_show (ds, &s, &pt);
         }
       else if (lex_match_id (lexer, "SUBTITLE"))
         {
           struct setting s = { .name = "SUBTITLE", .show = show_SUBTITLE };
-          do_show (ds, &s);
+          do_show (ds, &s, &pt);
         }
       else if (lex_token (lexer) == T_ID)
         {
@@ -1345,7 +1360,7 @@ cmd_show (struct lexer *lexer, struct dataset *ds)
               const struct setting *s = &settings[i];
               if (s->show && lex_match_id (lexer, s->name))
                 {
-                  do_show (ds, s);
+                  do_show (ds, s, &pt);
                   goto found;
                 }
               }
@@ -1364,6 +1379,9 @@ cmd_show (struct lexer *lexer, struct dataset *ds)
     }
   while (lex_token (lexer) != T_ENDCMD);
 
+  if (pt)
+    pivot_table_submit (pt);
+
   return CMD_SUCCESS;
 }
 \f
index a96bf32c788f069e0aba6509018a306bad61b22f..1942144ede2c6ba74a9c64019456a239c20d2ce6 100644 (file)
@@ -309,7 +309,8 @@ BEGIN DATA.
 END DATA.
 ])
 AT_CHECK([pspp -O format=csv data-out.sps], [0], [dnl
-"data-out.sps:2: note: SHOW: CCA is «,¥,€,»."
+Table: Settings
+CCA,"«,¥,€,»"
 
 1.00   ¥1.00€ @&t@
 
index b3896b1aca4bc4027d1a1d82aa1ab4c61347989e..fb66b01378429a2984e717d945d1b5e07ab18513 100644 (file)
@@ -1737,7 +1737,8 @@ $command prefix !paste foo bar suffix.
 SHOW $command.
 EOF
     cat >expout <<EOF
-title.sps:5: note: SHOW: $command is prefix foobar suffix.
+Table: Settings
+$command,prefix foobar suffix
 EOF
     AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
 done
index 04ef900c5ea66a62337473463288ef25cc24986a..f93ac1301243c6f1fb456635d489da00b1b81dc6 100644 (file)
@@ -131,29 +131,23 @@ restore.
 show mexpand mprint miterate mnest.
 ])
 AT_CHECK([pspp -O format=csv set-macro.sps], [0], [dnl
-set-macro.sps:1: note: SHOW: MEXPAND is ON.
-
-set-macro.sps:1: note: SHOW: MPRINT is OFF.
-
-set-macro.sps:1: note: SHOW: MITERATE is 1000.
-
-set-macro.sps:1: note: SHOW: MNEST is 50.
-
-set-macro.sps:4: note: SHOW: MEXPAND is OFF.
-
-set-macro.sps:4: note: SHOW: MPRINT is ON.
-
-set-macro.sps:4: note: SHOW: MITERATE is 10.
-
-set-macro.sps:4: note: SHOW: MNEST is 11.
-
-set-macro.sps:6: note: SHOW: MEXPAND is ON.
-
-set-macro.sps:6: note: SHOW: MPRINT is OFF.
-
-set-macro.sps:6: note: SHOW: MITERATE is 1000.
-
-set-macro.sps:6: note: SHOW: MNEST is 50.
+Table: Settings
+MEXPAND,ON
+MPRINT,OFF
+MITERATE,1000
+MNEST,50
+
+Table: Settings
+MEXPAND,OFF
+MPRINT,ON
+MITERATE,10
+MNEST,11
+
+Table: Settings
+MEXPAND,ON
+MPRINT,OFF
+MITERATE,1000
+MNEST,50
 ])
 AT_CLEANUP
 \f
@@ -169,10 +163,13 @@ RESTORE.
 SHOW FORMAT.
 ])
 AT_CHECK([pspp -O format=csv set.pspp], [0], [dnl
-set.pspp:1: note: SHOW: FORMAT is F8.2.
+Table: Settings
+FORMAT,F8.2
 
-set.pspp:5: note: SHOW: FORMAT is F10.0.
+Table: Settings
+FORMAT,F10.0
 
-set.pspp:6: note: SHOW: FORMAT is F8.2.
+Table: Settings
+FORMAT,F8.2
 ])
 AT_CLEANUP
index 05426ee0f525b36db25ba72ae980c92351a8a34a..02c8ee1f94f3759173fdd86f9cdb9f9e4e45b19b 100644 (file)
@@ -30,7 +30,8 @@ SHOW N.
 ])
 
 AT_CHECK([pspp -O format=csv show.sps], [0], [dnl
-show.sps:8: note: SHOW: N is 3.
+Table: Settings
+N,3
 ])
 
 AT_CLEANUP
@@ -43,7 +44,8 @@ SHOW N.
 ])
 
 AT_CHECK([pspp -O format=csv shown-empty.sps], [0], [dnl
-shown-empty.sps:1: note: SHOW: N is Unknown.
+Table: Settings
+N,Unknown
 ])
 
 AT_CLEANUP
index 61be72222c7d01a515d7e5ca5c6286b71063f547..ed20ccafd4b02773df0829ece39e2e2a14832eb5 100644 (file)
@@ -138,9 +138,11 @@ $command 'foo bar baz quux'.
 SHOW $command.
 EOF
     cat >expout <<EOF
-title.sps:2: note: SHOW: $command is foo  bar.
+Table: Settings
+$command,foo  bar
 
-title.sps:5: note: SHOW: $command is foo bar baz quux.
+Table: Settings
+$command,foo bar baz quux
 EOF
     AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
 done
index b40fc26b02924c601f41336a0e83f88ac3be5ea1..291634204ed605f95bbefa17ca002a1f0df16fb7 100644 (file)
@@ -102,7 +102,8 @@ Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
 legal,1,Scale,Input,8,Right,F9.2,F9.2
 money,2,Scale,Input,8,Right,DOLLAR6.2,DOLLAR6.2
 
-dump-dict.sps:5: note: SHOW: WEIGHT is money.
+Table: Settings
+WEIGHT,money
 ])
 AT_CLEANUP