SHOW: Add JOURNAL subcommand. 20121127030504/pspp 20121128030504/pspp 20121129030503/pspp 20121130030502/pspp
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 27 Nov 2012 05:15:43 +0000 (21:15 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 27 Nov 2012 05:15:43 +0000 (21:15 -0800)
Bug #35665.
Requested by Harry Thijssen.

NEWS
src/language/utilities/set.q
src/output/journal.c
src/output/journal.h

diff --git a/NEWS b/NEWS
index 5302e26542fe6beeec238473122727293a3f4767..e0910fe6e6b5c1b88b06818bf2189bcd52edff5d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -58,6 +58,9 @@ Changes from 0.6.2 to 0.7.9:
    - SET and SHOW no longer have ENDCMD, NULLINE, PROMPT, CPROMPT, and
      DPROMPT subcommands.  The defaults are now fixed values.
 
+   - SHOW now has a JOURNAL subcommand, to show the location of the
+     journal file.
+
    - VALUE LABELS can now assign value labels to long string
      variables.
 
index 243de30063c8b12332009d185ed02274c0a5bb06..e6e816a8b79ea57cfc5b21c4057efdbb458ac872 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -708,6 +708,14 @@ show_format (const struct dataset *ds UNUSED)
   return xstrdup (fmt_to_string (settings_get_format (), str));
 }
 
+static char *
+show_journal (const struct dataset *ds UNUSED)
+{
+  return (journal_is_enabled ()
+          ? xasprintf ("\"%s\"", journal_get_file_name ())
+          : xstrdup ("disabled"));
+}
+
 static char *
 show_length (const struct dataset *ds UNUSED)
 {
@@ -935,6 +943,7 @@ const struct show_sbc show_table[] =
     {"ENVIRONMENT", show_system},
     {"ERRORS", show_errors},
     {"FORMAT", show_format},
+    {"JOURNAL", show_journal},
     {"LENGTH", show_length},
     {"LOCALE", show_locale},
     {"MESSAGES", show_messages},
index 66c1b77534e98118ca7b300bb523d47b1d4b3493..2b5835052029dbfda9ecf19fb27702be354d9be8 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2010, 2012 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -87,11 +87,11 @@ journal_output (struct journal_driver *j, const char *s)
 {
   if (j->file == NULL)
     {
-      j->file = fopen (journal_file_name, "a");
+      j->file = fopen (journal_get_file_name (), "a");
       if (j->file == NULL)
         {
           error (0, errno, _("error opening output file `%s'"),
-                 journal_file_name);
+                 journal_get_file_name ());
           output_driver_destroy (&j->driver);
           return;
         }
@@ -144,13 +144,6 @@ journal_enable (void)
 {
   if (journal == NULL)
     {
-      /* If no journal file name is configured, use the default. */
-      if (journal_file_name == NULL)
-       {
-         const char *output_path = default_output_path ();
-         journal_file_name = xasprintf ("%s%s", output_path, "pspp.jnl");
-       }
-
       /* Create journal driver. */
       journal = xzalloc (sizeof *journal);
       output_driver_init (&journal->driver, &journal_class, "journal",
@@ -171,6 +164,13 @@ journal_disable (void)
     output_driver_destroy (&journal->driver);
 }
 
+/* Returns true if journaling is enabled, false otherwise. */
+bool
+journal_is_enabled (void)
+{
+  return journal != NULL;
+}
+
 /* Sets the name of the journal file to FILE_NAME. */
 void
 journal_set_file_name (const char *file_name)
@@ -179,3 +179,16 @@ journal_set_file_name (const char *file_name)
   free (journal_file_name);
   journal_file_name = xstrdup (file_name);
 }
+
+/* Returns the name of the journal file.  The caller must not modify or free
+   the returned string. */
+const char *
+journal_get_file_name (void)
+{
+  if (journal_file_name == NULL)
+    {
+      const char *output_path = default_output_path ();
+      journal_file_name = xasprintf ("%s%s", output_path, "pspp.jnl");
+    }
+  return journal_file_name;
+}
index 5051193a67ea3c7d03ed61be1fddfe0167273173..377152d5ce14cd6a3e3a82eeeb664ea5bc80f0e0 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2012 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -28,6 +28,8 @@
 
 void journal_enable (void);
 void journal_disable (void);
+bool journal_is_enabled (void);
 void journal_set_file_name (const char *);
+const char *journal_get_file_name (void);
 
 #endif /* output/journal.h */