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