text-item: Merge "title" and "subtitle" items into a new "page title".
[pspp] / src / language / utilities / title.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2007, 2010, 2011 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 <ctype.h>
20 #include <stdlib.h>
21
22 #include "data/dataset.h"
23 #include "data/dictionary.h"
24 #include "data/variable.h"
25 #include "language/command.h"
26 #include "language/lexer/lexer.h"
27 #include "libpspp/message.h"
28 #include "libpspp/start-date.h"
29 #include "libpspp/version.h"
30 #include "output/driver.h"
31
32 #include "gl/xalloc.h"
33
34 #include "gettext.h"
35 #define _(msgid) gettext (msgid)
36
37 static int
38 parse_title (struct lexer *lexer, void (*set_title) (const char *))
39 {
40   if (!lex_force_string (lexer))
41     return CMD_FAILURE;
42   set_title (lex_tokcstr (lexer));
43   lex_get (lexer);
44   return CMD_SUCCESS;
45 }
46
47 int
48 cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
49 {
50   return parse_title (lexer, output_set_title);
51 }
52
53 int
54 cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED)
55 {
56   return parse_title (lexer, output_set_subtitle);
57 }
58
59 /* Performs the FILE LABEL command. */
60 int
61 cmd_file_label (struct lexer *lexer, struct dataset *ds)
62 {
63   if (!lex_force_string (lexer))
64     return CMD_FAILURE;
65
66   dict_set_label (dataset_dict (ds), lex_tokcstr (lexer));
67   lex_get (lexer);
68
69   return CMD_SUCCESS;
70 }
71
72 /* Performs the DOCUMENT command. */
73 int
74 cmd_document (struct lexer *lexer, struct dataset *ds)
75 {
76   struct dictionary *dict = dataset_dict (ds);
77   char *trailer;
78
79   if (!lex_force_string (lexer))
80     return CMD_FAILURE;
81
82   while (lex_is_string (lexer))
83     {
84       dict_add_document_line (dict, lex_tokcstr (lexer), true);
85       lex_get (lexer);
86     }
87
88   trailer = xasprintf (_("   (Entered %s)"), get_start_date ());
89   dict_add_document_line (dict, trailer, true);
90   free (trailer);
91
92   return CMD_SUCCESS;
93 }
94
95 /* Performs the ADD DOCUMENTS command. */
96 int
97 cmd_add_documents (struct lexer *lexer, struct dataset *ds)
98 {
99   return cmd_document (lexer, ds);
100 }
101
102 /* Performs the DROP DOCUMENTS command. */
103 int
104 cmd_drop_documents (struct lexer *lexer UNUSED, struct dataset *ds)
105 {
106   dict_clear_documents (dataset_dict (ds));
107   return CMD_SUCCESS;
108 }