1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006 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/>. */
21 #include <data/dictionary.h>
22 #include <data/procedure.h>
23 #include <data/variable.h>
24 #include <language/command.h>
25 #include <language/lexer/format-parser.h>
26 #include <language/lexer/lexer.h>
27 #include <language/lexer/variable-parser.h>
28 #include <libpspp/assertion.h>
29 #include <libpspp/message.h>
30 #include <libpspp/str.h>
33 #define _(msgid) gettext (msgid)
35 /* Parses the NUMERIC command. */
37 cmd_numeric (struct lexer *lexer, struct dataset *ds)
41 /* Names of variables to create. */
45 /* Format spec for variables to create. f.type==-1 if default is to
51 if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NONE))
54 /* Get the optional format specification. */
55 if (lex_match (lexer, '('))
57 if (!parse_format_specifier (lexer, &f))
59 if (fmt_is_string (f.type))
61 char str[FMT_STRING_LEN_MAX + 1];
62 msg (SE, _("Format type %s may not be used with a numeric "
63 "variable."), fmt_to_string (&f, str));
67 if (!lex_match (lexer, ')'))
69 msg (SE, _("`)' expected after output format."));
76 /* Create each variable. */
77 for (i = 0; i < nv; i++)
79 struct variable *new_var = dict_create_var (dataset_dict (ds), v[i], 0);
81 msg (SE, _("There is already a variable named %s."), v[i]);
85 var_set_both_formats (new_var, &f);
90 for (i = 0; i < nv; i++)
94 while (lex_match (lexer, '/'));
96 return lex_end_of_command (lexer);
98 /* If we have an error at a point where cleanup is required,
99 flow-of-control comes here. */
101 for (i = 0; i < nv; i++)
107 /* Parses the STRING command. */
109 cmd_string (struct lexer *lexer, struct dataset *ds)
113 /* Names of variables to create. */
117 /* Format spec for variables to create. */
120 /* Width of variables to create. */
125 if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NONE))
128 if (!lex_force_match (lexer, '(')
129 || !parse_format_specifier (lexer, &f)
130 || !lex_force_match (lexer, ')'))
132 if (!fmt_is_string (f.type))
134 char str[FMT_STRING_LEN_MAX + 1];
135 msg (SE, _("Format type %s may not be used with a string "
136 "variable."), fmt_to_string (&f, str));
139 if (!fmt_check_output (&f))
142 width = fmt_var_width (&f);
144 /* Create each variable. */
145 for (i = 0; i < nv; i++)
147 struct variable *new_var = dict_create_var (dataset_dict (ds), v[i],
150 msg (SE, _("There is already a variable named %s."), v[i]);
152 var_set_both_formats (new_var, &f);
156 for (i = 0; i < nv; i++)
160 while (lex_match (lexer, '/'));
162 return lex_end_of_command (lexer);
164 /* If we have an error at a point where cleanup is required,
165 flow-of-control comes here. */
167 for (i = 0; i < nv; i++)
173 /* Parses the LEAVE command. */
175 cmd_leave (struct lexer *lexer, struct dataset *ds)
182 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
183 return CMD_CASCADING_FAILURE;
184 for (i = 0; i < nv; i++)
185 var_set_leave (v[i], true);
188 return lex_end_of_command (lexer);