@table @asis
@item JOURNAL
-@item LOG
-Not currently used.
+@itemx LOG
+These subcommands, which are synonyms, control the journal. The
+default is ON, which causes commands entered interactively to be
+written to the journal file. Commands included from syntax files that
+are included interactively and error messages printed by PSPP are also
+written to the journal file, prefixed by @samp{>}. OFF disables use
+of the journal.
+
+The journal is named @file{pspp.jnl} by default. A different name may
+be specified.
@end table
System file subcommands affect the default format of system files
+2007-08-16 Ben Pfaff <blp@gnu.org>
+
+ Implement journaling. Bug #17240.
+
+ * lexer.c (lex_get_line_raw): Pass the line read to journal_write.
+
2007-06-03 Ben Pfaff <blp@gnu.org>
Implement missing functions for subcommand integer lists.
#include <data/settings.h>
#include <libpspp/getl.h>
#include <libpspp/str.h>
+#include <output/journal.h>
#include "size_max.h"
lex_get_line_raw (struct lexer *lexer, enum getl_syntax *syntax)
{
enum getl_syntax dummy;
- bool ok = getl_read_line (lexer->ss, &lexer->line_buffer,
- syntax != NULL ? syntax : &dummy);
+ bool ok;
+
+ if (syntax == NULL)
+ syntax = &dummy;
+ ok = getl_read_line (lexer->ss, &lexer->line_buffer, syntax);
+ journal_write (*syntax == GETL_BATCH, ds_cstr (&lexer->line_buffer));
+
return ok;
}
+2007-08-16 Ben Pfaff <blp@gnu.org>
+
+ Implement journaling. Bug #17240.
+
+ * set.q: Add LOG subcommand as synonym for JOURNAL.
+ (stc_custom_journal): Implement.
+ (stc_custom_log): New function.
+
2007-05-06 Ben Pfaff <blp@gnu.org>
Abstract the documents within a dictionary a little better.
#include <libpspp/magic.h>
#include <libpspp/message.h>
#include <math/random.h>
+#include <output/journal.h>
#include <output/output.h>
#if HAVE_LIBTERMCAP
histogram=string "x==1" "one character long";
include=inc:on/off;
journal=custom;
+ log=custom;
length=custom;
listing=custom;
lowres=lores:auto/on/off;
stc_custom_journal (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
lex_match (lexer, '=');
- if (!lex_match_id (lexer, "ON") && !lex_match_id (lexer, "OFF"))
+ if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "YES"))
+ journal_enable ();
+ else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NO"))
+ journal_disable ();
+ else if (lex_token (lexer) == T_STRING || lex_token (lexer) == T_ID)
{
- if (lex_token (lexer) == T_STRING)
- lex_get (lexer);
- else
- {
- lex_error (lexer, NULL);
- return 0;
- }
+ journal_set_file_name (ds_cstr (lex_tokstr (lexer)));
+ lex_get (lexer);
+ }
+ else
+ {
+ lex_error (lexer, NULL);
+ return 0;
}
return 1;
}
+static int
+stc_custom_log (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
+{
+ return stc_custom_journal (lexer, ds, cmd, aux);
+}
+
static int
stc_custom_listing (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
+2007-08-23 Ben Pfaff <blp@gnu.org>
+
+ Implement journaling. Bug #17240.
+
+ * automake.mk (output_sources): Add journal.c, journal.h.
+
+ * journal.c: New file.
+
+ * journal.h: New file.
+
2007-08-16 Ben Pfaff <blp@gnu.org>
* output.c output.h: export function outp_configure_driver_line.
src/output/ascii.c \
src/output/html.c \
src/output/htmlP.h \
+ src/output/journal.c \
+ src/output/journal.h \
src/output/output.c \
src/output/output.h \
src/output/postscript.c \
--- /dev/null
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 2007 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <output/journal.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libpspp/str.h>
+
+#include "fwriteerror.h"
+#include "error.h"
+#include "xalloc.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+/* Journaling enabled? */
+static bool journal_enabled = false;
+
+/* Name of the journal file. */
+static char *journal_file_name = NULL;
+
+/* Journal file. */
+static FILE *journal_file = NULL;
+
+/* Enables journaling. */
+void
+journal_enable (void)
+{
+ journal_enabled = true;
+}
+
+/* Disables journaling. */
+void
+journal_disable (void)
+{
+ journal_enabled = false;
+ if (journal_file != NULL)
+ fflush (journal_file);
+}
+
+/* Sets the name of the journal file to FILE_NAME. */
+void
+journal_set_file_name (const char *file_name)
+{
+ assert (file_name != NULL);
+
+ if (journal_file != NULL)
+ {
+ if (fwriteerror (journal_file))
+ error (0, errno, _("error writing \"%s\""), journal_file_name);
+ }
+
+ free (journal_file_name);
+ journal_file_name = xstrdup (file_name);
+}
+
+/* Writes LINE to the journal file (if journaling is enabled).
+ If PREFIX is non-null, the line will be prefixed by "> ". */
+void
+journal_write (bool prefix, const char *line)
+{
+ if (!journal_enabled)
+ return;
+
+ if (journal_file == NULL)
+ {
+ if (journal_file_name == NULL)
+ journal_file_name = xstrdup ("pspp.jnl");
+ journal_file = fopen (journal_file_name, "w");
+ if (journal_file == NULL)
+ {
+ error (0, errno, _("error creating \"%s\""), journal_file_name);
+ journal_enabled = false;
+ return;
+ }
+ }
+
+ if (prefix)
+ fputs ("> ", journal_file);
+ fputs (line, journal_file);
+ if (strchr (line, '\n') == NULL)
+ putc ('\n', journal_file);
+}
--- /dev/null
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 2007 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Journal for commands and errors.
+
+ The journal file records the commands entered interactively
+ during a PSPP session. It also records, prefixed by "> ",
+ commands from files included with interactive commands and
+ errors. */
+
+#ifndef OUTPUT_JOURNAL_H
+#define OUTPUT_JOURNAL_H 1
+
+#include <stdbool.h>
+
+void journal_enable (void);
+void journal_disable (void);
+void journal_set_file_name (const char *);
+void journal_write (bool prefix, const char *);
+
+#endif /* output/journal.h */
+2007-08-23 Ben Pfaff <blp@gnu.org>
+
+ Implement journaling. Bug #17240.
+
+ * msg-ui.c (handle_msg): Send message to write_journal function
+ as well as msg_file.
+ (dump_message): Change interface so that it takes a function
+ pointer instead of a FILE.
+ (write_stream): New function.
+ (write_journal): New function.
+
+ * read-line.c (welcome): Call journal_enable, so that the journal
+ is enabled by default.
+
2007-07-25 Ben Pfaff <blp@gnu.org>
Make interactive output go to the terminal (bug #17213), by
#include <data/settings.h>
#include <libpspp/message.h>
#include <libpspp/str.h>
+#include <output/journal.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
return error_count > 0;
}
\f
-static void dump_message (char *msg, unsigned width, unsigned indent, FILE *);
-static void dump_line (int line_indent, const char *line, size_t length,
- FILE *);
+typedef void write_line_func (int indent, struct substring line, void *aux);
+static void dump_message (char *msg, unsigned width, unsigned indent,
+ write_line_func *, void *aux);
+static write_line_func write_stream;
+static write_line_func write_journal;
static void
handle_msg (const struct msg *m)
ds_put_cstr (&string, m->text);
if (msg_file != stdout || get_error_routing_to_terminal ())
- dump_message (ds_cstr (&string), get_viewwidth (), 8, msg_file);
+ dump_message (ds_cstr (&string), get_viewwidth (), 8,
+ write_stream, msg_file);
+
+ dump_message (ds_cstr (&string), 78, 0, write_journal, NULL);
ds_destroy (&string);
}
/* Divides MSG into lines of WIDTH width for the first line and
WIDTH - INDENT width for each succeeding line, and writes the
- lines to STREAM. */
+ lines by calling DUMP_LINE for each line, passing AUX as
+ auxiliary data. */
static void
-dump_message (char *msg, unsigned width, unsigned indent, FILE *stream)
+dump_message (char *msg, unsigned width, unsigned indent,
+ write_line_func *dump_line, void *aux)
{
size_t length = strlen (msg);
char *string, *breaks;
{
free (string);
free (breaks);
- fputs (msg, stream);
- putc ('\n', stream);
+ dump_line (0, ss_cstr (msg), aux);
return;
}
line_start = 0;
line_indent = 0;
for (i = 0; i < length; i++)
- switch (breaks[i])
+ if (breaks[i] == UC_BREAK_POSSIBLE || breaks[i] == UC_BREAK_MANDATORY)
{
- case UC_BREAK_POSSIBLE:
- /* Break before this character,
- and include this character in the next line. */
- dump_line (line_indent, &string[line_start], i - line_start, stream);
- line_start = i;
- line_indent = indent;
- break;
- case UC_BREAK_MANDATORY:
- /* Break before this character,
- but don't include this character in the next line
- (because it'string a new-line). */
- dump_line (line_indent, &string[line_start], i - line_start, stream);
- line_start = i + 1;
+ dump_line (line_indent,
+ ss_buffer (string + line_start, i - line_start), aux);
line_indent = indent;
- break;
- default:
- break;
+
+ /* UC_BREAK_POSSIBLE means that a line break can be
+ inserted, and that the character should be included
+ in the next line.
+ UC_BREAK_MANDATORY means that this character is a line
+ break, so it should not be included in the next line. */
+ line_start = i + (breaks[i] == UC_BREAK_MANDATORY);
}
if (line_start < length)
- dump_line (line_indent, &string[line_start], length - line_start, stream);
+ dump_line (line_indent,
+ ss_buffer (string + line_start, length - line_start), aux);
free (string);
free (breaks);
}
-/* Write LINE_INDENT spaces, the LENGTH characters in LINE, then
- a new-line to STREAM. */
+/* Write LINE_INDENT spaces, LINE, then a new-line to STREAM. */
static void
-dump_line (int line_indent, const char *line, size_t length, FILE *stream)
+write_stream (int line_indent, struct substring line, void *stream_)
{
+ FILE *stream = stream_;
int i;
for (i = 0; i < line_indent; i++)
putc (' ', stream);
- fwrite (line, 1, length, stream);
+ fwrite (ss_data (line), 1, ss_length (line), stream);
putc ('\n', stream);
}
+/* Writes LINE to the journal. */
+static void
+write_journal (int line_indent, struct substring line, void *unused UNUSED)
+{
+ char *s = xstrndup (ss_data (line), ss_length (line));
+ journal_write (true, s);
+ free (s);
+}
#include <libpspp/str.h>
#include <libpspp/version.h>
#include <language/prompt.h>
+#include <output/journal.h>
#include <output/manager.h>
#include "xalloc.h"
"warranty.\" for details.\n", stdout);
puts (stat_version);
readln_initialize ();
+ journal_enable ();
}
/* Gets a line from the user and stores it into LINE.