1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 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. */
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 (&v, &nv, PV_NONE))
57 /* Get the optional format specification. */
60 if (!parse_format_specifier (&f))
62 if (formats[f.type].cat & FCAT_STRING)
64 msg (SE, _("Format type %s may not be used with a numeric "
65 "variable."), fmt_to_string (&f));
71 msg (SE, _("`)' expected after output format."));
78 /* Create each variable. */
79 for (i = 0; i < nv; i++)
81 struct variable *new_var = dict_create_var (default_dict, v[i], 0);
83 msg (SE, _("There is already a variable named %s."), v[i]);
87 new_var->print = new_var->write = f;
92 for (i = 0; i < nv; i++)
96 while (lex_match ('/'));
98 return lex_end_of_command ();
100 /* If we have an error at a point where cleanup is required,
101 flow-of-control comes here. */
103 for (i = 0; i < nv; i++)
109 /* Parses the STRING command. */
115 /* Names of variables to create. */
119 /* Format spec for variables to create. */
122 /* Width of variables to create. */
127 if (!parse_DATA_LIST_vars (&v, &nv, PV_NONE))
130 if (!lex_force_match ('(') || !parse_format_specifier (&f))
132 if (!(formats[f.type].cat & FCAT_STRING))
134 msg (SE, _("Format type %s may not be used with a string "
135 "variable."), fmt_to_string (&f));
139 if (!lex_match (')'))
141 msg (SE, _("`)' expected after output format."));
157 /* Create each variable. */
158 for (i = 0; i < nv; i++)
160 struct variable *new_var = dict_create_var (default_dict, v[i],
163 msg (SE, _("There is already a variable named %s."), v[i]);
165 new_var->print = new_var->write = f;
169 for (i = 0; i < nv; i++)
173 while (lex_match ('/'));
175 return lex_end_of_command ();
177 /* If we have an error at a point where cleanup is required,
178 flow-of-control comes here. */
180 for (i = 0; i < nv; i++)
186 /* Parses the LEAVE command. */
195 if (!parse_variables (default_dict, &v, &nv, PV_NONE))
196 return CMD_CASCADING_FAILURE;
197 for (i = 0; i < nv; i++)
201 return lex_end_of_command ();