1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009 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/text-item.h>
25 #include <libpspp/cast.h>
26 #include <output/driver.h>
27 #include <output/output-item-provider.h>
30 #include "xvasprintf.h"
33 #define _(msgid) gettext (msgid)
35 static struct text_item *
36 allocate_text_item (enum text_item_type type, char *text)
38 struct text_item *item = xmalloc (sizeof *item);
39 output_item_init (&item->output_item, &text_item_class);
45 /* Creates and returns a new text item containing a copy of TEXT and the
46 specified TYPE. The caller retains ownership of TEXT. */
48 text_item_create (enum text_item_type type, const char *text)
50 return allocate_text_item (type, xstrdup (text));
53 /* Creates and returns a new text item containing a copy of FORMAT, which is
54 formatted as if by printf(), and the specified TYPE. The caller retains
55 ownership of FORMAT. */
57 text_item_create_format (enum text_item_type type, const char *format, ...)
59 struct text_item *item;
62 va_start (args, format);
63 item = allocate_text_item (type, xvasprintf (format, args));
69 /* Returns ITEM's type. */
71 text_item_get_type (const struct text_item *item)
76 /* Returns ITEM's text, which the caller may not modify or free. */
78 text_item_get_text (const struct text_item *item)
83 /* Submits ITEM to the configured output drivers, and transfers ownership to
84 the output subsystem. */
86 text_item_submit (struct text_item *item)
88 output_submit (&item->output_item);
92 text_item_destroy (struct output_item *output_item)
94 struct text_item *item = to_text_item (output_item);
99 const struct output_item_class text_item_class =