c0aad17d9f9bc2e0d85432e41cc4a18989f47d83
[pspp] / src / output / group-item.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2018 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18
19 #include "output/group-item.h"
20
21 #include <stdlib.h>
22
23 #include "libpspp/compiler.h"
24 #include "libpspp/str.h"
25 #include "output/driver.h"
26 #include "output/output-item-provider.h"
27
28 #include "gl/xalloc.h"
29
30 #include "gettext.h"
31 #define _(msgid) gettext (msgid)
32
33 struct group_open_item *
34 group_open_item_create (const char *command_name, const char *label)
35 {
36   return group_open_item_create_nocopy (
37     xstrdup_if_nonnull (command_name),
38     xstrdup_if_nonnull (label));
39 }
40
41 struct group_open_item *
42 group_open_item_create_nocopy (char *command_name, char *label)
43 {
44   struct group_open_item *item = xmalloc (sizeof *item);
45   *item = (struct group_open_item) {
46     .output_item = OUTPUT_ITEM_INITIALIZER (&group_open_item_class),
47     .output_item.label = label,
48     .output_item.command_name = command_name,
49   };
50   return item;
51 }
52
53 /* Submits ITEM to the configured output drivers, and transfers ownership to
54    the output subsystem. */
55 void
56 group_open_item_submit (struct group_open_item *item)
57 {
58   output_submit (&item->output_item);
59 }
60
61 static const char *
62 group_open_item_get_label (const struct output_item *output_item)
63 {
64   struct group_open_item *item = to_group_open_item (output_item);
65
66   return (item->output_item.command_name
67           ? item->output_item.command_name
68           : _("Group"));
69 }
70
71 static void
72 group_open_item_destroy (struct output_item *output_item)
73 {
74   struct group_open_item *item = to_group_open_item (output_item);
75
76   free (item);
77 }
78
79 const struct output_item_class group_open_item_class =
80   {
81     group_open_item_get_label,
82     group_open_item_destroy,
83   };
84 \f
85 struct group_close_item *
86 group_close_item_create (void)
87 {
88   struct group_close_item *item = xmalloc (sizeof *item);
89   *item = (struct group_close_item) {
90     .output_item = OUTPUT_ITEM_INITIALIZER (&group_close_item_class),
91   };
92   return item;
93 }
94
95 /* Submits ITEM to the configured output drivers, and transfers ownership to
96    the output subsystem. */
97 void
98 group_close_item_submit (struct group_close_item *item)
99 {
100   output_submit (&item->output_item);
101 }
102
103 static const char *
104 group_close_item_get_label (const struct output_item *output_item UNUSED)
105 {
106   /* Not marked for translation: user should never see it. */
107   return "Group Close";
108 }
109
110 static void
111 group_close_item_destroy (struct output_item *output_item)
112 {
113   struct group_close_item *item = to_group_close_item (output_item);
114
115   free (item);
116 }
117
118 const struct output_item_class group_close_item_class =
119   {
120     group_close_item_get_label,
121     group_close_item_destroy,
122   };