1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <data/dictionary.h>
25 #include <data/procedure.h>
26 #include <data/variable.h>
27 #include <language/command.h>
28 #include <language/lexer/lexer.h>
29 #include <libpspp/alloc.h>
30 #include <libpspp/message.h>
31 #include <libpspp/start-date.h>
32 #include <libpspp/version.h>
33 #include <output/output.h>
36 #define _(msgid) gettext (msgid)
38 static int get_title (struct lexer *, const char *cmd, char **title);
41 cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
43 return get_title (lexer, "TITLE", &outp_title);
47 cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED)
49 return get_title (lexer, "SUBTITLE", &outp_subtitle);
53 get_title (struct lexer *lexer, const char *cmd, char **title)
57 c = lex_look_ahead (lexer);
58 if (c == '"' || c == '\'')
61 if (!lex_force_string (lexer))
65 *title = ds_xstrdup (lex_tokstr (lexer));
67 if (lex_token (lexer) != '.')
69 msg (SE, _("%s: `.' expected after string."), cmd);
79 *title = xstrdup (lex_rest_of_line (lexer));
80 lex_discard_line (lexer);
81 for (cp = *title; *cp; cp++)
82 *cp = toupper ((unsigned char) (*cp));
87 /* Performs the FILE LABEL command. */
89 cmd_file_label (struct lexer *lexer, struct dataset *ds)
93 label = lex_rest_of_line (lexer);
94 lex_discard_line (lexer);
95 while (isspace ((unsigned char) *label))
98 dict_set_label (dataset_dict (ds), label);
103 /* Add entry date line to DICT's documents. */
105 add_document_trailer (struct dictionary *dict)
109 sprintf (buf, _(" (Entered %s)"), get_start_date ());
110 dict_add_document_line (dict, buf);
113 /* Performs the DOCUMENT command. */
115 cmd_document (struct lexer *lexer, struct dataset *ds)
117 struct dictionary *dict = dataset_dict (ds);
118 struct string line = DS_EMPTY_INITIALIZER;
123 end_dot = lex_end_dot (lexer);
124 ds_assign_string (&line, lex_entire_line_ds (lexer));
126 ds_put_char (&line, '.');
127 dict_add_document_line (dict, ds_cstr (&line));
129 lex_discard_line (lexer);
130 lex_get_line (lexer);
134 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) ;