#include "libpspp/message.h"
#include "libpspp/str.h"
#include "output/driver-provider.h"
-#include "output/message-item.h"
-#include "output/text-item.h"
+#include "output/output-item.h"
#include "gl/fwriteerror.h"
#include "gl/xalloc.h"
{
struct output_driver driver;
FILE *file;
- char *command_name;
/* Name of journal file. */
char *file_name;
{
struct journal_driver *j = journal_driver_cast (driver);
- if ( !j->destroyed)
- {
- journal_close ();
- free (j->command_name);
- }
+ if (!j->destroyed)
+ journal_close ();
j->destroyed = true;
}
static void
-journal_output (struct journal_driver *j, const char *s)
+journal_output (struct journal_driver *j, char *s)
{
- if ( j->file == NULL)
- return;
+ if (j->file)
+ {
+ fprintf (j->file, "%s\n", s);
- fprintf (j->file, "%s\n", s);
+ /* Flush the journal in case the syntax we're about to write
+ causes a crash. Having the syntax already written to disk
+ makes postmortem analysis of the problem possible. */
+ fflush (j->file);
+ }
- /* Flush the journal in case the syntax we're about to write
- causes a crash. Having the syntax already written to disk
- makes postmortem analysis of the problem possible. */
- fflush (j->file);
+ free (s);
}
static void
{
struct journal_driver *j = journal_driver_cast (driver);
- output_driver_track_current_command (item, &j->command_name);
-
- if (is_text_item (item))
+ switch (item->type)
{
- const struct text_item *text_item = to_text_item (item);
- enum text_item_type type = text_item_get_type (text_item);
-
- if (type == TEXT_ITEM_SYNTAX)
- journal_output (j, text_item_get_text (text_item));
- }
- else if (is_message_item (item))
- {
- const struct message_item *message_item = to_message_item (item);
- const struct msg *msg = message_item_get_msg (message_item);
- char *s = msg_to_string (msg, j->command_name);
- journal_output (j, s);
- free (s);
+ case OUTPUT_ITEM_MESSAGE:
+ journal_output (j, msg_to_string (item->message));
+ break;
+
+ case OUTPUT_ITEM_TEXT:
+ if (item->text.subtype == TEXT_ITEM_SYNTAX)
+ journal_output (j, text_item_get_plain_text (item));
+ break;
+
+ case OUTPUT_ITEM_GROUP:
+ for (size_t i = 0; i < item->group.n_children; i++)
+ journal_submit (driver, item->group.children[i]);
+ break;
+
+ case OUTPUT_ITEM_CHART:
+ case OUTPUT_ITEM_IMAGE:
+ case OUTPUT_ITEM_PAGE_BREAK:
+ case OUTPUT_ITEM_TABLE:
+ break;
}
}
static const struct output_driver_class journal_class =
{
- "journal",
- journal_destroy,
- journal_submit,
- NULL /* flush */
+ .name = "journal",
+ .destroy = journal_destroy,
+ .submit = journal_submit,
};
-
\f
/* Enables journaling. */
output_driver_init (&journal.driver, &journal_class, "journal",
SETTINGS_DEVICE_UNFILTERED);
journal.file = NULL;
- journal.command_name = NULL;
/* Register journal driver. */
output_driver_register (&journal.driver);