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/alloc.h>
28 #include <libpspp/message.h>
29 #include <libpspp/start-date.h>
30 #include <libpspp/version.h>
31 #include <output/output.h>
34 #define _(msgid) gettext (msgid)
36 static int get_title (struct lexer *, const char *cmd, char **title);
39 cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
41 return get_title (lexer, "TITLE", &outp_title);
45 cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED)
47 return get_title (lexer, "SUBTITLE", &outp_subtitle);
51 get_title (struct lexer *lexer, const char *cmd, char **title)
55 c = lex_look_ahead (lexer);
56 if (c == '"' || c == '\'')
59 if (!lex_force_string (lexer))
63 *title = ds_xstrdup (lex_tokstr (lexer));
65 if (lex_token (lexer) != '.')
67 msg (SE, _("%s: `.' expected after string."), cmd);
77 *title = xstrdup (lex_rest_of_line (lexer));
78 lex_discard_line (lexer);
79 for (cp = *title; *cp; cp++)
80 *cp = toupper ((unsigned char) (*cp));
85 /* Performs the FILE LABEL command. */
87 cmd_file_label (struct lexer *lexer, struct dataset *ds)
91 label = lex_rest_of_line (lexer);
92 lex_discard_line (lexer);
93 while (isspace ((unsigned char) *label))
96 dict_set_label (dataset_dict (ds), label);
101 /* Add entry date line to DICT's documents. */
103 add_document_trailer (struct dictionary *dict)
107 sprintf (buf, _(" (Entered %s)"), get_start_date ());
108 dict_add_document_line (dict, buf);
111 /* Performs the DOCUMENT command. */
113 cmd_document (struct lexer *lexer, struct dataset *ds)
115 struct dictionary *dict = dataset_dict (ds);
116 struct string line = DS_EMPTY_INITIALIZER;
121 end_dot = lex_end_dot (lexer);
122 ds_assign_string (&line, lex_entire_line_ds (lexer));
124 ds_put_char (&line, '.');
125 dict_add_document_line (dict, ds_cstr (&line));
127 lex_discard_line (lexer);
128 lex_get_line (lexer);
132 add_document_trailer (dict);
138 /* Performs the DROP DOCUMENTS command. */
140 cmd_drop_documents (struct lexer *lexer, struct dataset *ds)
142 dict_clear_documents (dataset_dict (ds));
144 return lex_end_of_command (lexer);
148 /* Performs the ADD DOCUMENTS command. */
150 cmd_add_documents (struct lexer *lexer, struct dataset *ds)
152 struct dictionary *dict = dataset_dict (ds);
154 if ( ! lex_force_string (lexer) )
157 while ( lex_is_string (lexer))
159 dict_add_document_line (dict, ds_cstr (lex_tokstr (lexer)));
163 add_document_trailer (dict);
165 return lex_end_of_command (lexer) ;