1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2007 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/output.h>
35 #define _(msgid) gettext (msgid)
37 static int get_title (struct lexer *, const char *cmd, char **title);
40 cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
42 return get_title (lexer, "TITLE", &outp_title);
46 cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED)
48 return get_title (lexer, "SUBTITLE", &outp_subtitle);
52 get_title (struct lexer *lexer, const char *cmd, char **title)
56 c = lex_look_ahead (lexer);
57 if (c == '"' || c == '\'')
60 if (!lex_force_string (lexer))
64 *title = ds_xstrdup (lex_tokstr (lexer));
66 if (lex_token (lexer) != '.')
68 msg (SE, _("%s: `.' expected after string."), cmd);
78 *title = xstrdup (lex_rest_of_line (lexer));
79 lex_discard_line (lexer);
80 for (cp = *title; *cp; cp++)
81 *cp = toupper ((unsigned char) (*cp));
86 /* Performs the FILE LABEL command. */
88 cmd_file_label (struct lexer *lexer, struct dataset *ds)
92 label = lex_rest_of_line (lexer);
93 lex_discard_line (lexer);
94 while (isspace ((unsigned char) *label))
97 dict_set_label (dataset_dict (ds), label);
102 /* Add entry date line to DICT's documents. */
104 add_document_trailer (struct dictionary *dict)
108 sprintf (buf, _(" (Entered %s)"), get_start_date ());
109 dict_add_document_line (dict, buf);
112 /* Performs the DOCUMENT command. */
114 cmd_document (struct lexer *lexer, struct dataset *ds)
116 struct dictionary *dict = dataset_dict (ds);
117 struct string line = DS_EMPTY_INITIALIZER;
122 end_dot = lex_end_dot (lexer);
123 ds_assign_string (&line, lex_entire_line_ds (lexer));
125 ds_put_char (&line, '.');
126 dict_add_document_line (dict, ds_cstr (&line));
128 lex_discard_line (lexer);
129 lex_get_line (lexer);
133 add_document_trailer (dict);
139 /* Performs the DROP DOCUMENTS command. */
141 cmd_drop_documents (struct lexer *lexer, struct dataset *ds)
143 dict_clear_documents (dataset_dict (ds));
145 return lex_end_of_command (lexer);
149 /* Performs the ADD DOCUMENTS command. */
151 cmd_add_documents (struct lexer *lexer, struct dataset *ds)
153 struct dictionary *dict = dataset_dict (ds);
155 if ( ! lex_force_string (lexer) )
158 while ( lex_is_string (lexer))
160 dict_add_document_line (dict, ds_cstr (lex_tokstr (lexer)));
164 add_document_trailer (dict);
166 return lex_end_of_command (lexer) ;