1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 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/format-parser.h>
29 #include <language/lexer/lexer.h>
30 #include <language/lexer/variable-parser.h>
31 #include <libpspp/assertion.h>
32 #include <libpspp/message.h>
33 #include <libpspp/str.h>
36 #define _(msgid) gettext (msgid)
38 /* Parses the NUMERIC command. */
40 cmd_numeric (struct lexer *lexer, struct dataset *ds)
44 /* Names of variables to create. */
48 /* Format spec for variables to create. f.type==-1 if default is to
54 if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NONE))
57 /* Get the optional format specification. */
58 if (lex_match (lexer, '('))
60 if (!parse_format_specifier (lexer, &f))
62 if (fmt_is_string (f.type))
64 char str[FMT_STRING_LEN_MAX + 1];
65 msg (SE, _("Format type %s may not be used with a numeric "
66 "variable."), fmt_to_string (&f, str));
70 if (!lex_match (lexer, ')'))
72 msg (SE, _("`)' expected after output format."));
79 /* Create each variable. */
80 for (i = 0; i < nv; i++)
82 struct variable *new_var = dict_create_var (dataset_dict (ds), v[i], 0);
84 msg (SE, _("There is already a variable named %s."), v[i]);
88 var_set_both_formats (new_var, &f);
93 for (i = 0; i < nv; i++)
97 while (lex_match (lexer, '/'));
99 return lex_end_of_command (lexer);
101 /* If we have an error at a point where cleanup is required,
102 flow-of-control comes here. */
104 for (i = 0; i < nv; i++)
110 /* Parses the STRING command. */
112 cmd_string (struct lexer *lexer, struct dataset *ds)
116 /* Names of variables to create. */
120 /* Format spec for variables to create. */
123 /* Width of variables to create. */
128 if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NONE))
131 if (!lex_force_match (lexer, '(')
132 || !parse_format_specifier (lexer, &f)
133 || !lex_force_match (lexer, ')'))
135 if (!fmt_is_string (f.type))
137 char str[FMT_STRING_LEN_MAX + 1];
138 msg (SE, _("Format type %s may not be used with a string "
139 "variable."), fmt_to_string (&f, str));
142 if (!fmt_check_output (&f))
145 width = fmt_var_width (&f);
147 /* Create each variable. */
148 for (i = 0; i < nv; i++)
150 struct variable *new_var = dict_create_var (dataset_dict (ds), v[i],
153 msg (SE, _("There is already a variable named %s."), v[i]);
155 var_set_both_formats (new_var, &f);
159 for (i = 0; i < nv; i++)
163 while (lex_match (lexer, '/'));
165 return lex_end_of_command (lexer);
167 /* If we have an error at a point where cleanup is required,
168 flow-of-control comes here. */
170 for (i = 0; i < nv; i++)
176 /* Parses the LEAVE command. */
178 cmd_leave (struct lexer *lexer, struct dataset *ds)
185 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
186 return CMD_CASCADING_FAILURE;
187 for (i = 0; i < nv; i++)
188 var_set_leave (v[i], true);
191 return lex_end_of_command (lexer);