New command SHOW SYSTEM to easily print information useful in bug reports.
[pspp] / src / language / utilities / set.c
index 4b99bde6d956d37b8c677dcae6159794550028c9..08675179ab1ac63bd305f66a33bd8d78aaecae94 100644 (file)
@@ -23,9 +23,6 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "gl/ftoastr.h"
-#include "gl/vasnprintf.h"
-
 #include "data/casereader.h"
 #include "data/data-in.h"
 #include "data/data-out.h"
 #include "output/journal.h"
 #include "output/pivot-table.h"
 
+#include "gl/ftoastr.h"
 #include "gl/minmax.h"
+#include "gl/relocatable.h"
+#include "gl/vasnprintf.h"
 #include "gl/xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
+#define N_(msgid) (msgid)
 
 struct setting
   {
@@ -669,6 +670,24 @@ show_LOCALE (const struct dataset *ds UNUSED)
   return xstrdup (get_default_encoding ());
 }
 
+static bool
+parse_MDISPLAY (struct lexer *lexer)
+{
+  int mdisplay = force_parse_enum (lexer,
+                                   "TEXT", SETTINGS_MDISPLAY_TEXT,
+                                   "TABLES", SETTINGS_MDISPLAY_TABLES);
+  if (mdisplay >= 0)
+    settings_set_mdisplay (mdisplay);
+  return mdisplay >= 0;
+}
+
+static char *
+show_MDISPLAY (const struct dataset *ds UNUSED)
+{
+  return xstrdup (settings_get_mdisplay () == SETTINGS_MDISPLAY_TEXT
+                  ? "TEXT" : "TABLES");
+}
+
 static bool
 parse_MESSAGES (struct lexer *lexer)
 {
@@ -917,15 +936,21 @@ show_SMALL (const struct dataset *ds UNUSED)
 }
 
 static char *
-show_SYSTEM (const struct dataset *ds UNUSED)
+show_SUBTITLE (const struct dataset *ds UNUSED)
 {
-  return strdup (host_system);
+  return xstrdup (output_get_subtitle ());
 }
 
 static char *
 show_TEMPDIR (const struct dataset *ds UNUSED)
 {
-  return strdup (temp_dir_name ());
+  return xstrdup (temp_dir_name ());
+}
+
+static char *
+show_TITLE (const struct dataset *ds UNUSED)
+{
+  return xstrdup (output_get_title ());
 }
 
 static bool
@@ -1123,7 +1148,7 @@ static void
 do_show (const struct dataset *ds, const struct setting *s)
 {
   char *value = s->show (ds);
-  msg (SN, _("%s is %s."), s->name, value);
+  msg (SN, _("%s is %s."), s->name, value ? value : _("empty"));
   free (value);
 }
 
@@ -1138,6 +1163,36 @@ show_copying (const struct dataset *ds UNUSED)
 {
   fputs (copyleft, stdout);
 }
+
+static void
+add_row (struct pivot_table *table, const char *attribute,
+         const char *value)
+{
+  int row = pivot_category_create_leaf (table->dimensions[0]->root,
+                                        pivot_value_new_text (attribute));
+  if (value)
+    pivot_table_put1 (table, row, pivot_value_new_user_text (value, -1));
+}
+
+static void
+show_system (const struct dataset *ds UNUSED)
+{
+  struct pivot_table *table = pivot_table_create (N_("System Information"));
+  pivot_dimension_create (table, PIVOT_AXIS_ROW, N_("Attribute"));
+
+  add_row (table, N_("Version"), version);
+  add_row (table, N_("Host System"), host_system);
+  add_row (table, N_("Build System"), build_system);
+  add_row (table, N_("Locale Directory"), relocate (locale_dir));
+  add_row (table, N_("Compiler Version"),
+#ifdef __VERSION__
+           __VERSION__
+#else
+           "Unknown"
+#endif
+           );
+  pivot_table_submit (table);
+}
 \f
 static const struct setting settings[] = {
   { "BASETEXTDIRECTION", parse_BASETEXTDIRECTION, NULL },
@@ -1165,6 +1220,7 @@ static const struct setting settings[] = {
   { "JOURNAL", parse_JOURNAL, show_JOURNAL },
   { "LENGTH", parse_LENGTH, show_LENGTH },
   { "LOCALE", parse_LOCALE, show_LOCALE },
+  { "MDISPLAY", parse_MDISPLAY, show_MDISPLAY },
   { "MESSAGES", parse_MESSAGES, show_MESSAGES },
   { "MEXPAND", parse_MEXPAND, show_MEXPAND },
   { "MITERATE", parse_MITERATE, show_MITERATE },
@@ -1182,7 +1238,6 @@ static const struct setting settings[] = {
   { "SCOMPRESSION", parse_SCOMPRESSION, show_SCOMPRESSION },
   { "SEED", parse_SEED, NULL },
   { "SMALL", parse_SMALL, show_SMALL },
-  { "SYSTEM", NULL, show_SYSTEM },
   { "TEMPDIR", NULL, show_TEMPDIR },
   { "TNUMBERS", parse_TNUMBERS, show_TNUMBERS },
   { "TVARS", parse_TVARS, show_TVARS },
@@ -1262,6 +1317,18 @@ cmd_show (struct lexer *lexer, struct dataset *ds)
         show_warranty (ds);
       else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
         show_copying (ds);
+      else if (lex_match_id (lexer, "SYSTEM"))
+        show_system (ds);
+      else if (lex_match_id (lexer, "TITLE"))
+        {
+          struct setting s = { .name = "TITLE", .show = show_TITLE };
+          do_show (ds, &s);
+        }
+      else if (lex_match_id (lexer, "SUBTITLE"))
+        {
+          struct setting s = { .name = "SUBTITLE", .show = show_SUBTITLE };
+          do_show (ds, &s);
+        }
       else if (lex_token (lexer) == T_ID)
         {
           int i;
@@ -1332,9 +1399,3 @@ cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
       return CMD_FAILURE;
     }
 }
-
-/*
-   Local Variables:
-   mode: c
-   End:
-*/