X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fjournal.c;h=a07fd4a094fdc1f213e82c67f965f14eb570973a;hb=refs%2Fheads%2Fctables7;hp=84d0cd922266c0dbe1d745af84a8005fc6b7de42;hpb=f2d4cc6e7a4d5948a2c0cf70883347000a79a2b0;p=pspp diff --git a/src/output/journal.c b/src/output/journal.c index 84d0cd9222..a07fd4a094 100644 --- a/src/output/journal.c +++ b/src/output/journal.c @@ -28,8 +28,7 @@ #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" @@ -41,7 +40,6 @@ struct journal_driver { struct output_driver driver; FILE *file; - char *command_name; /* Name of journal file. */ char *file_name; @@ -79,27 +77,26 @@ journal_destroy (struct output_driver *driver) { 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 @@ -107,34 +104,36 @@ journal_submit (struct output_driver *driver, const struct output_item *item) { 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, }; - /* Enables journaling. */ @@ -145,8 +144,7 @@ journal_init (void) 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);