1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009, 2010, 2011 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"
29 #include "gl/xalloc.h"
30 #include "gl/xvasprintf.h"
33 #define _(msgid) gettext (msgid)
35 /* Creates and returns a new text item containing TEXT and the specified TYPE.
36 The new text item takes ownership of TEXT. */
38 text_item_create_nocopy (enum text_item_type type, char *text)
40 struct text_item *item = xzalloc (sizeof *item);
41 output_item_init (&item->output_item, &text_item_class);
47 /* Creates and returns a new text item containing a copy of TEXT and the
48 specified TYPE. The caller retains ownership of TEXT. */
50 text_item_create (enum text_item_type type, const char *text)
52 return text_item_create_nocopy (type, xstrdup (text));
55 /* Creates and returns a new text item containing a copy of FORMAT, which is
56 formatted as if by printf(), and the specified TYPE. The caller retains
57 ownership of FORMAT. */
59 text_item_create_format (enum text_item_type type, const char *format, ...)
61 struct text_item *item;
64 va_start (args, format);
65 item = text_item_create_nocopy (type, xvasprintf (format, args));
71 /* Returns ITEM's type. */
73 text_item_get_type (const struct text_item *item)
78 /* Returns ITEM's text, which the caller may not modify or free. */
80 text_item_get_text (const struct text_item *item)
85 /* Submits ITEM to the configured output drivers, and transfers ownership to
86 the output subsystem. */
88 text_item_submit (struct text_item *item)
90 output_submit (&item->output_item);
94 text_item_destroy (struct output_item *output_item)
96 struct text_item *item = to_text_item (output_item);
102 const struct output_item_class text_item_class =