1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 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, NULL));
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, NULL);
94 lex_discard_line (lexer);
95 while (isspace ((unsigned char) *label))
98 dict_set_label (dataset_dict (ds), label);
103 /* Add LINE as a line of document information to dictionary
104 indented by INDENT spaces. */
106 add_document_line (struct dictionary *dict, const char *line, int indent)
108 const char *old_documents;
112 old_documents = dict_get_documents (dict);
113 old_len = old_documents != NULL ? strlen (old_documents) : 0;
114 new_documents = xmalloc (old_len + 81);
116 memcpy (new_documents, old_documents, old_len);
117 memset (new_documents + old_len, ' ', indent);
118 buf_copy_str_rpad (new_documents + old_len + indent, 80 - indent, line);
119 new_documents[old_len + 80] = '\0';
121 dict_set_documents (dict, new_documents);
123 free (new_documents);
126 /* Performs the DOCUMENT command. */
128 cmd_document (struct lexer *lexer, struct dataset *ds)
130 struct dictionary *dict = dataset_dict (ds);
131 /* Add a few header lines for reference. */
135 if (dict && dict_get_documents (dict))
136 add_document_line (dict, "", 0);
138 sprintf (buf, _("Document entered %s by %s:"), get_start_date (), version);
139 add_document_line (dict, buf, 1);
145 const char *orig_line;
148 orig_line = lex_rest_of_line (lexer, &had_dot);
149 lex_discard_line (lexer);
150 while (isspace ((unsigned char) *orig_line))
153 copy_line = xmalloc (strlen (orig_line) + 2);
154 strcpy (copy_line, orig_line);
156 strcat (copy_line, ".");
158 add_document_line (dict, copy_line, 3);
161 lex_get_line (lexer);
169 /* Performs the DROP DOCUMENTS command. */
171 cmd_drop_documents (struct lexer *lexer, struct dataset *ds)
173 dict_set_documents (dataset_dict (ds), NULL);
175 return lex_end_of_command (lexer);