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
21 #include <libpspp/message.h>
23 #include <language/command.h>
24 #include <data/dictionary.h>
25 #include <libpspp/message.h>
26 #include <language/lexer/lexer.h>
27 #include <libpspp/str.h>
28 #include <data/variable.h>
31 #define _(msgid) gettext (msgid)
33 /* Parses the NUMERIC command. */
39 /* Names of variables to create. */
43 /* Format spec for variables to create. f.type==-1 if default is to
49 if (!parse_DATA_LIST_vars (&v, &nv, PV_NONE))
52 /* Get the optional format specification. */
55 if (!parse_format_specifier (&f, 0))
57 if (formats[f.type].cat & FCAT_STRING)
59 msg (SE, _("Format type %s may not be used with a numeric "
60 "variable."), fmt_to_string (&f));
66 msg (SE, _("`)' expected after output format."));
73 /* Create each variable. */
74 for (i = 0; i < nv; i++)
76 struct variable *new_var = dict_create_var (default_dict, v[i], 0);
78 msg (SE, _("There is already a variable named %s."), v[i]);
82 new_var->print = new_var->write = f;
87 for (i = 0; i < nv; i++)
91 while (lex_match ('/'));
93 return lex_end_of_command ();
95 /* If we have an error at a point where cleanup is required,
96 flow-of-control comes here. */
98 for (i = 0; i < nv; i++)
104 /* Parses the STRING command. */
110 /* Names of variables to create. */
114 /* Format spec for variables to create. */
117 /* Width of variables to create. */
122 if (!parse_DATA_LIST_vars (&v, &nv, PV_NONE))
125 if (!lex_force_match ('(')
126 || !parse_format_specifier (&f, 0))
128 if (!(formats[f.type].cat & FCAT_STRING))
130 msg (SE, _("Format type %s may not be used with a string "
131 "variable."), fmt_to_string (&f));
135 if (!lex_match (')'))
137 msg (SE, _("`)' expected after output format."));
154 /* Create each variable. */
155 for (i = 0; i < nv; i++)
157 struct variable *new_var = dict_create_var (default_dict, v[i],
160 msg (SE, _("There is already a variable named %s."), v[i]);
162 new_var->print = new_var->write = f;
166 for (i = 0; i < nv; i++)
170 while (lex_match ('/'));
172 return lex_end_of_command ();
174 /* If we have an error at a point where cleanup is required,
175 flow-of-control comes here. */
177 for (i = 0; i < nv; i++)
183 /* Parses the LEAVE command. */
192 if (!parse_variables (default_dict, &v, &nv, PV_NONE))
193 return CMD_CASCADING_FAILURE;
194 for (i = 0; i < nv; i++)
203 return lex_end_of_command ();