From: Ben Pfaff Date: Sun, 6 Dec 2020 21:08:24 +0000 (-0800) Subject: page-eject-item: Factor out of text_item. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccd1837ed5df23149584f88f6cc907cda0faaea9;p=pspp page-eject-item: Factor out of text_item. These really don't have much in common. --- diff --git a/src/language/data-io/print.c b/src/language/data-io/print.c index 3b34dfcd87..0cb337d428 100644 --- a/src/language/data-io/print.c +++ b/src/language/data-io/print.c @@ -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'; } diff --git a/src/output/ascii.c b/src/output/ascii.c index 011c6946c5..3d857fdeb0 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -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))); } diff --git a/src/output/automake.mk b/src/output/automake.mk index eb1b438a53..5b4390f9b2 100644 --- a/src/output/automake.mk +++ b/src/output/automake.mk @@ -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 \ diff --git a/src/output/cairo.c b/src/output/cairo.c index c7b14ff68c..078464c26f 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -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 diff --git a/src/output/csv.c b/src/output/csv.c index 1c6662793f..e2c97a64cd 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -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); diff --git a/src/output/html.c b/src/output/html.c index 85defc9ab2..9498561a54 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -305,10 +305,6 @@ html_submit (struct output_driver *driver, case TEXT_ITEM_LOG: print_title_tag (html->file, "pre", s); /* should be

*/ 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 index 0000000000..5d108f9890 --- /dev/null +++ b/src/output/page-eject-item.c @@ -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 . */ + +#include + +#include "output/page-eject-item.h" + +#include + +#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 index 0000000000..b9cd67511c --- /dev/null +++ b/src/output/page-eject-item.h @@ -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 . */ + +#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 +#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); + +/* This boilerplate for page_eject_item, a subclass of output_item, was + autogenerated by mk-class-boilerplate. */ + +#include +#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 *); + +#endif /* output/page-eject-item.h */ diff --git a/src/output/pivot-output.c b/src/output/pivot-output.c index 8ca3601cfc..e469afb081 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -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); } } diff --git a/src/output/spv-driver.c b/src/output/spv-driver.c index 3990ab2041..fed7db7575 100644 --- a/src/output/spv-driver.c +++ b/src/output/spv-driver.c @@ -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); diff --git a/src/output/spv/spv-writer.c b/src/output/spv/spv-writer.c index 4883ebf5ba..12f3ec70df 100644 --- a/src/output/spv/spv-writer.c +++ b/src/output/spv/spv-writer.c @@ -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; +} #define H TABLE_HORZ #define V TABLE_VERT diff --git a/src/output/spv/spv-writer.h b/src/output/spv/spv-writer.h index 1d891213ea..05604d5219 100644 --- a/src/output/spv/spv-writer.h +++ b/src/output/spv/spv-writer.h @@ -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 */ diff --git a/src/output/tex.c b/src/output/tex.c index 70518285d1..01a5a2816c 100644 --- a/src/output/tex.c +++ b/src/output/tex.c @@ -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: diff --git a/src/output/text-item.c b/src/output/text-item.c index f892e92774..95bb7723c8 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -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"); } diff --git a/src/output/text-item.h b/src/output/text-item.h index 95bfc0826f..554d478f74 100644 --- a/src/output/text-item.h +++ b/src/output/text-item.h @@ -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);