1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2019 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "output/driver-provider.h"
23 #include "data/file-handle-def.h"
24 #include "libpspp/cast.h"
25 #include "output/cairo-chart.h"
26 #include "output/output-item.h"
27 #include "output/spv/spv-writer.h"
29 #include "gl/xalloc.h"
32 #define _(msgid) gettext (msgid)
36 struct output_driver driver;
37 struct spv_writer *writer;
38 struct file_handle *handle;
41 static const struct output_driver_class spv_driver_class;
43 static struct spv_driver *
44 spv_driver_cast (struct output_driver *driver)
46 assert (driver->class == &spv_driver_class);
47 return UP_CAST (driver, struct spv_driver, driver);
50 static struct output_driver *
51 spv_create (struct file_handle *fh, enum settings_output_devices device_type,
52 struct string_map *o UNUSED)
54 struct spv_writer *writer;
55 char *error = spv_writer_open (fh_get_file_name (fh), &writer);
58 msg (ME, "%s", error);
63 struct spv_driver *spv = xmalloc (sizeof *spv);
64 *spv = (struct spv_driver) {
66 .class = &spv_driver_class,
67 .name = xstrdup (fh_get_file_name (fh)),
68 .device_type = device_type,
77 spv_destroy (struct output_driver *driver)
79 struct spv_driver *spv = spv_driver_cast (driver);
81 char *error = spv_writer_close (spv->writer);
83 msg (ME, "%s", error);
84 fh_unref (spv->handle);
89 spv_submit (struct output_driver *driver,
90 const struct output_item *output_item)
92 struct spv_driver *spv = spv_driver_cast (driver);
94 spv_writer_write (spv->writer, output_item);
98 spv_setup (struct output_driver *driver,
99 const struct page_setup *ps)
101 struct spv_driver *spv = spv_driver_cast (driver);
103 spv_writer_set_page_setup (spv->writer, ps);
106 struct output_driver_factory spv_driver_factory =
107 { "spv", "pspp.spv", spv_create };
109 static const struct output_driver_class spv_driver_class =
112 .destroy = spv_destroy,
113 .submit = spv_submit,
115 .handles_show = true,
116 .handles_groups = true,