page-eject-item: Factor out of text_item.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 6 Dec 2020 21:08:24 +0000 (13:08 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 19 Dec 2020 05:17:35 +0000 (21:17 -0800)
These really don't have much in common.

15 files changed:
src/language/data-io/print.c
src/output/ascii.c
src/output/automake.mk
src/output/cairo.c
src/output/csv.c
src/output/html.c
src/output/page-eject-item.c [new file with mode: 0644]
src/output/page-eject-item.h [new file with mode: 0644]
src/output/pivot-output.c
src/output/spv-driver.c
src/output/spv/spv-writer.c
src/output/spv/spv-writer.h
src/output/tex.c
src/output/text-item.c
src/output/text-item.h

index 3b34dfcd8767ab09214d8edf9f9ed36f738d1639..0cb337d42879f6c3703ff73c8d99d78f9f09274d 100644 (file)
@@ -42,6 +42,7 @@
 #include "libpspp/u8-line.h"
 #include "output/pivot-table.h"
 #include "output/table.h"
+#include "output/page-eject-item.h"
 #include "output/text-item.h"
 
 #include "gl/xalloc.h"
@@ -555,7 +556,7 @@ print_text_flush_records (struct print_trns *trns, struct u8_line *line,
         {
           *eject = false;
           if (trns->writer == NULL)
-            text_item_submit (text_item_create (TEXT_ITEM_EJECT_PAGE, ""));
+            page_eject_item_submit (page_eject_item_create ());
           else
             leader = '1';
         }
index 011c6946c5a6461f2815b6e519648a0e82add8d7..3d857fdeb056d1ffbfc5cead0cda3906140fed33 100644 (file)
@@ -518,7 +518,7 @@ ascii_submit (struct output_driver *driver,
       const struct text_item *text_item = to_text_item (output_item);
       enum text_item_type type = text_item_get_type (text_item);
 
-      if (type != TEXT_ITEM_PAGE_TITLE && type != TEXT_ITEM_EJECT_PAGE)
+      if (type != TEXT_ITEM_PAGE_TITLE)
         ascii_output_table_item_unref (
           a, text_item_to_table_item (text_item_ref (text_item)));
     }
index eb1b438a535f56efcb9d1b811fe0b49ad3d37d61..5b4390f9b29707a7a8fc872197dc4ce08f0a5174 100644 (file)
@@ -71,6 +71,8 @@ src_output_liboutput_la_SOURCES = \
        src/output/output-item-provider.h \
        src/output/output-item.c \
        src/output/output-item.h \
+       src/output/page-eject-item.c \
+       src/output/page-eject-item.h \
        src/output/page-setup-item.c \
        src/output/page-setup-item.h \
        src/output/pivot-output.c \
index c7b14ff68c6baf496f5e1d961402d30f8b014142..078464c26f3813e4bb9fc3cf51896bcf7b9cf325 100644 (file)
@@ -43,6 +43,7 @@
 #include "output/group-item.h"
 #include "output/message-item.h"
 #include "output/options.h"
+#include "output/page-eject-item.h"
 #include "output/page-setup-item.h"
 #include "output/render.h"
 #include "output/table-item.h"
@@ -1961,11 +1962,6 @@ xr_render_text (struct xr_driver *xr, const struct text_item *text_item)
     case TEXT_ITEM_PAGE_TITLE:
       break;
 
-    case TEXT_ITEM_EJECT_PAGE:
-      if (xr->y > 0)
-        return xr_render_eject ();
-      break;
-
     default:
       return xr_render_table (
         xr, text_item_to_table_item (text_item_ref (text_item)));
@@ -1994,6 +1990,8 @@ xr_render_output_item (struct xr_driver *xr,
     return xr_render_chart (to_chart_item (output_item));
   else if (is_text_item (output_item))
     return xr_render_text (xr, to_text_item (output_item));
+  else if (is_page_eject_item (output_item))
+    return xr->y > 0 ? xr_render_eject () : NULL;
   else if (is_message_item (output_item))
     return xr_render_message (xr, to_message_item (output_item));
   else
index 1c6662793fc3fafd5c40f83d3a668f700e32bc8d..e2c97a64cd479b3ad5b5e921f6e27ef9d8979bca 100644 (file)
@@ -30,6 +30,7 @@
 #include "output/driver-provider.h"
 #include "output/options.h"
 #include "output/message-item.h"
+#include "output/page-eject-item.h"
 #include "output/table-item.h"
 #include "output/table-provider.h"
 
@@ -298,6 +299,11 @@ csv_submit (struct output_driver *driver,
       else
         csv_output_lines (csv, text);
     }
+  else if (is_page_eject_item (output_item))
+    {
+      csv_put_separator (csv);
+      csv_output_lines (csv, "");
+    }
   else if (is_message_item (output_item))
     {
       const struct message_item *message_item = to_message_item (output_item);
index 85defc9ab2d55aa7b2fca9d1f6c30d8b1d37d3fc..9498561a54b3d843c3ed33c7e50ef1e1542708ef 100644 (file)
@@ -305,10 +305,6 @@ html_submit (struct output_driver *driver,
         case TEXT_ITEM_LOG:
           print_title_tag (html->file, "pre", s); /* should be <P><TT> */
           break;
-
-        case TEXT_ITEM_EJECT_PAGE:
-          /* Nothing to do. */
-          break;
         }
     }
   else if (is_message_item (output_item))
diff --git a/src/output/page-eject-item.c b/src/output/page-eject-item.c
new file mode 100644 (file)
index 0000000..5d108f9
--- /dev/null
@@ -0,0 +1,54 @@
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2020 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/page-eject-item.h"
+
+#include <stdlib.h>
+
+#include "output/driver-provider.h"
+#include "output/output-item-provider.h"
+
+#include "gl/xalloc.h"
+
+struct page_eject_item *
+page_eject_item_create (void)
+{
+  struct page_eject_item *item = xmalloc (sizeof *item);
+  output_item_init (&item->output_item, &page_eject_item_class);
+  return item;
+}
+
+/* Submits ITEM to the configured output drivers, and transfers ownership to
+   the output subsystem. */
+void
+page_eject_item_submit (struct page_eject_item *item)
+{
+  output_submit (&item->output_item);
+}
+
+static void
+page_eject_item_destroy (struct output_item *output_item)
+{
+  free (to_page_eject_item (output_item));
+}
+
+const struct output_item_class page_eject_item_class =
+  {
+    "page_eject",
+    page_eject_item_destroy,
+  };
diff --git a/src/output/page-eject-item.h b/src/output/page-eject-item.h
new file mode 100644 (file)
index 0000000..b9cd675
--- /dev/null
@@ -0,0 +1,91 @@
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2020 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/>. */
+
+#ifndef OUTPUT_PAGE_EJECT_ITEM_H
+#define OUTPUT_PAGE_EJECT_ITEM_H 1
+
+/* Page eject items.
+
+   This ejects the page (for output devices that have pages). */
+
+#include <stdbool.h>
+#include "output/output-item.h"
+
+/* A page eject item. */
+struct page_eject_item
+  {
+    struct output_item output_item;
+  };
+
+struct page_eject_item *page_eject_item_create (void);
+\f
+/* This boilerplate for page_eject_item, a subclass of output_item, was
+   autogenerated by mk-class-boilerplate. */
+
+#include <assert.h>
+#include "libpspp/cast.h"
+
+extern const struct output_item_class page_eject_item_class;
+
+/* Returns true if SUPER is a page_eject_item, otherwise false. */
+static inline bool
+is_page_eject_item (const struct output_item *super)
+{
+  return super->class == &page_eject_item_class;
+}
+
+/* Returns SUPER converted to page_eject_item.  SUPER must be a page_eject_item, as
+   reported by is_page_eject_item. */
+static inline struct page_eject_item *
+to_page_eject_item (const struct output_item *super)
+{
+  assert (is_page_eject_item (super));
+  return UP_CAST (super, struct page_eject_item, output_item);
+}
+
+/* Returns INSTANCE converted to output_item. */
+static inline struct output_item *
+page_eject_item_super (const struct page_eject_item *instance)
+{
+  return CONST_CAST (struct output_item *, &instance->output_item);
+}
+
+/* Increments INSTANCE's reference count and returns INSTANCE. */
+static inline struct page_eject_item *
+page_eject_item_ref (const struct page_eject_item *instance)
+{
+  return to_page_eject_item (output_item_ref (&instance->output_item));
+}
+
+/* Decrements INSTANCE's reference count, then destroys INSTANCE if
+   the reference count is now zero. */
+static inline void
+page_eject_item_unref (struct page_eject_item *instance)
+{
+  output_item_unref (&instance->output_item);
+}
+
+/* Returns true if INSTANCE's reference count is greater than 1,
+   false otherwise. */
+static inline bool
+page_eject_item_is_shared (const struct page_eject_item *instance)
+{
+  return output_item_is_shared (&instance->output_item);
+}
+
+void page_eject_item_submit (struct page_eject_item *);
+\f
+#endif /* output/page-eject-item.h */
index 8ca3601cfcbaf0882dbd903ad2fa47929712bcce..e469afb08150cf6e33121f25c8417c0a3113e55d 100644 (file)
@@ -24,6 +24,7 @@
 #include "libpspp/assertion.h"
 #include "libpspp/pool.h"
 #include "output/table.h"
+#include "output/page-eject-item.h"
 #include "output/table-item.h"
 #include "output/text-item.h"
 #include "output/table-provider.h"
@@ -532,7 +533,7 @@ pivot_table_submit (struct pivot_table *pt)
       PIVOT_AXIS_FOR_EACH (layer_indexes, &pt->axes[PIVOT_AXIS_LAYER])
         {
           if (pt->look.paginate_layers)
-            text_item_submit (text_item_create (TEXT_ITEM_EJECT_PAGE, ""));
+            page_eject_item_submit (page_eject_item_create ());
           pivot_table_submit_layer (pt, layer_indexes);
         }
     }
index 3990ab2041e991ba8c2a03cc7e7d7c8a03140a0a..fed7db75759c0affe80321f90ffcc74494eb9250 100644 (file)
@@ -23,6 +23,7 @@
 #include "data/file-handle-def.h"
 #include "libpspp/cast.h"
 #include "output/group-item.h"
+#include "output/page-eject-item.h"
 #include "output/page-setup-item.h"
 #include "output/table-item.h"
 #include "output/text-item.h"
@@ -109,6 +110,8 @@ spv_submit (struct output_driver *driver,
   else if (is_text_item (output_item))
     spv_writer_put_text (spv->writer, to_text_item (output_item),
                          output_get_command_name ());
+  else if (is_page_eject_item (output_item))
+    spv_writer_eject_page (spv->writer);
   else if (is_page_setup_item (output_item))
     spv_writer_set_page_setup (spv->writer,
                                to_page_setup_item (output_item)->page_setup);
index 4883ebf5ba36477cff3fa7bcf90a696a93a74d5f..12f3ec70dff5bcff23cf6be7c4b54c09e362f367 100644 (file)
@@ -294,9 +294,6 @@ void
 spv_writer_put_text (struct spv_writer *w, const struct text_item *text,
                      const char *command_id)
 {
-  if (text->type == TEXT_ITEM_EJECT_PAGE)
-    w->need_page_break = true;
-
   bool initial_depth = w->heading_depth;
   if (!initial_depth)
     spv_writer_open_file (w);
@@ -325,6 +322,12 @@ spv_writer_put_text (struct spv_writer *w, const struct text_item *text,
   if (!initial_depth)
     spv_writer_close_file (w, "");
 }
+
+void
+spv_writer_eject_page (struct spv_writer *w)
+{
+  w->need_page_break = true;
+}
 \f
 #define H TABLE_HORZ
 #define V TABLE_VERT
index 1d891213ea52428ac0c24e21bb041ad04553951b..05604d521980baf3c7a857efc7fc0754fff95ca3 100644 (file)
@@ -40,4 +40,6 @@ void spv_writer_put_text (struct spv_writer *, const struct text_item *,
                           const char *command_id);
 void spv_writer_put_table (struct spv_writer *, const struct pivot_table *);
 
+void spv_writer_eject_page (struct spv_writer *);
+
 #endif /* output/spv/spv-writer.h */
index 70518285d173f2dab475c27d6e629765a3c5fde5..01a5a2816cb373669df2490b964671bf983cfdd3 100644 (file)
@@ -353,10 +353,6 @@ tex_submit (struct output_driver *driver,
           shipout (&tex->token_list, "}\\par\n\n");
           break;
 
-        case TEXT_ITEM_EJECT_PAGE:
-          /* Nothing to do. */
-          break;
-
         case TEXT_ITEM_SYNTAX:
           /* So far as I'm aware, this can never happen.  */
         default:
index f892e9277453a1fd406b8f3f447bce6190bc984a..95bb7723c84147043a2e429489f29f8ca50d1626 100644 (file)
@@ -50,9 +50,6 @@ text_item_type_to_string (enum text_item_type type)
     case TEXT_ITEM_LOG:
       return _("Log");
 
-    case TEXT_ITEM_EJECT_PAGE:
-      return _("Page Break");
-
     default:
       return _("Text");
     }
index 95bfc0826fb7548de4870e90a99f2d241059d31a..554d478f7407df186d726df8ae6c497db0e456d4 100644 (file)
@@ -34,7 +34,6 @@ enum text_item_type
     TEXT_ITEM_TITLE,            /* Title. */
     TEXT_ITEM_SYNTAX,           /* Syntax printback logging. */
     TEXT_ITEM_LOG,              /* Other logging. */
-    TEXT_ITEM_EJECT_PAGE        /* Eject page. */
   };
 
 const char *text_item_type_to_string (enum text_item_type);