1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2007, 2010 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/>. */
22 #include <data/dictionary.h>
23 #include <data/procedure.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/text-item.h>
35 #define _(msgid) gettext (msgid)
37 static int parse_title (struct lexer *, enum text_item_type);
38 static void set_title (const char *title, enum text_item_type);
41 cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
43 return parse_title (lexer, TEXT_ITEM_TITLE);
47 cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED)
49 return parse_title (lexer, TEXT_ITEM_SUBTITLE);
53 parse_title (struct lexer *lexer, enum text_item_type type)
55 if (lex_look_ahead (lexer) == T_STRING)
58 if (!lex_force_string (lexer))
60 set_title (lex_tokcstr (lexer), type);
62 return lex_end_of_command (lexer);
66 set_title (lex_rest_of_line (lexer), type);
67 lex_discard_line (lexer);
73 set_title (const char *title, enum text_item_type type)
75 text_item_submit (text_item_create (type, title));
78 /* Performs the FILE LABEL command. */
80 cmd_file_label (struct lexer *lexer, struct dataset *ds)
84 label = lex_rest_of_line (lexer);
85 lex_discard_line (lexer);
86 while (isspace ((unsigned char) *label))
89 dict_set_label (dataset_dict (ds), label);
94 /* Add entry date line to DICT's documents. */
96 add_document_trailer (struct dictionary *dict)
100 sprintf (buf, _(" (Entered %s)"), get_start_date ());
101 dict_add_document_line (dict, buf);
104 /* Performs the DOCUMENT command. */
106 cmd_document (struct lexer *lexer, struct dataset *ds)
108 struct dictionary *dict = dataset_dict (ds);
109 struct string line = DS_EMPTY_INITIALIZER;
114 end_dot = lex_end_dot (lexer);
115 ds_assign_string (&line, lex_entire_line_ds (lexer));
117 ds_put_byte (&line, '.');
118 dict_add_document_line (dict, ds_cstr (&line));
120 lex_discard_line (lexer);
121 lex_get_line (lexer);
125 add_document_trailer (dict);
131 /* Performs the DROP DOCUMENTS command. */
133 cmd_drop_documents (struct lexer *lexer, struct dataset *ds)
135 dict_clear_documents (dataset_dict (ds));
137 return lex_end_of_command (lexer);
141 /* Performs the ADD DOCUMENTS command. */
143 cmd_add_documents (struct lexer *lexer, struct dataset *ds)
145 struct dictionary *dict = dataset_dict (ds);
147 if ( ! lex_force_string (lexer) )
150 while ( lex_is_string (lexer))
152 dict_add_document_line (dict, lex_tokcstr (lexer));
156 add_document_trailer (dict);
158 return lex_end_of_command (lexer) ;