1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <output/journal.h>
25 #include <libpspp/str.h>
27 #include "fwriteerror.h"
32 #define _(msgid) gettext (msgid)
34 /* Journaling enabled? */
35 static bool journal_enabled = false;
37 /* Name of the journal file. */
38 static char *journal_file_name = NULL;
41 static FILE *journal_file = NULL;
43 /* Enables journaling. */
47 journal_enabled = true;
50 /* Disables journaling. */
52 journal_disable (void)
54 journal_enabled = false;
55 if (journal_file != NULL)
56 fflush (journal_file);
59 /* Sets the name of the journal file to FILE_NAME. */
61 journal_set_file_name (const char *file_name)
63 assert (file_name != NULL);
65 if (journal_file != NULL)
67 if (fwriteerror (journal_file))
68 error (0, errno, _("error writing \"%s\""), journal_file_name);
71 free (journal_file_name);
72 journal_file_name = xstrdup (file_name);
75 /* Writes LINE to the journal file (if journaling is enabled).
76 If PREFIX is non-null, the line will be prefixed by "> ". */
78 journal_write (bool prefix, const char *line)
83 if (journal_file == NULL)
85 if (journal_file_name == NULL)
86 journal_file_name = xstrdup ("pspp.jnl");
87 journal_file = fopen (journal_file_name, "w");
88 if (journal_file == NULL)
90 error (0, errno, _("error creating \"%s\""), journal_file_name);
91 journal_enabled = false;
97 fputs ("> ", journal_file);
98 fputs (line, journal_file);
99 if (strchr (line, '\n') == NULL)
100 putc ('\n', journal_file);
101 fflush (journal_file);