output: Make groups contain their subitems, and get rid of spv_item.
[pspp] / src / output / journal.c
index 5ace0db2164f08206dd9daf6df96da83263e44b9..4945db2ee9d831aa1fcbdb78790836a6617f3e5b 100644 (file)
@@ -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"
@@ -78,24 +77,26 @@ journal_destroy (struct output_driver *driver)
 {
   struct journal_driver *j = journal_driver_cast (driver);
 
-  if ( !j->destroyed)
+  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
@@ -103,32 +104,37 @@ journal_submit (struct output_driver *driver, const struct output_item *item)
 {
   struct journal_driver *j = journal_driver_cast (driver);
 
-  if (is_text_item (item))
-    {
-      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))
+  switch (item->type)
     {
-      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, message_item->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_PAGE_SETUP:
+    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. */