1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 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
23 #include <data/dictionary.h>
24 #include <data/procedure.h>
25 #include <data/variable.h>
26 #include <language/command.h>
27 #include <language/lexer/format-parser.h>
28 #include <language/lexer/lexer.h>
29 #include <language/lexer/variable-parser.h>
30 #include <libpspp/assertion.h>
31 #include <libpspp/message.h>
32 #include <libpspp/str.h>
35 #define _(msgid) gettext (msgid)
37 /* Parses the NUMERIC command. */
39 cmd_numeric (struct lexer *lexer, struct dataset *ds)
43 /* Names of variables to create. */
47 /* Format spec for variables to create. f.type==-1 if default is to
53 if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NONE))
56 /* Get the optional format specification. */
57 if (lex_match (lexer, '('))
59 if (!parse_format_specifier (lexer, &f))
61 if (fmt_is_string (f.type))
63 char str[FMT_STRING_LEN_MAX + 1];
64 msg (SE, _("Format type %s may not be used with a numeric "
65 "variable."), fmt_to_string (&f, str));
69 if (!lex_match (lexer, ')'))
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 (dataset_dict (ds), v[i], 0);
83 msg (SE, _("There is already a variable named %s."), v[i]);
87 var_set_both_formats (new_var, &f);
92 for (i = 0; i < nv; i++)
96 while (lex_match (lexer, '/'));
98 return lex_end_of_command (lexer);
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. */
111 cmd_string (struct lexer *lexer, struct dataset *ds)
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 (lexer, &v, &nv, PV_NONE))
130 if (!lex_force_match (lexer, '(')
131 || !parse_format_specifier (lexer, &f)
132 || !lex_force_match (lexer, ')'))
134 if (!fmt_is_string (f.type))
136 char str[FMT_STRING_LEN_MAX + 1];
137 msg (SE, _("Format type %s may not be used with a string "
138 "variable."), fmt_to_string (&f, str));
141 if (!fmt_check_output (&f))
144 width = fmt_var_width (&f);
146 /* Create each variable. */
147 for (i = 0; i < nv; i++)
149 struct variable *new_var = dict_create_var (dataset_dict (ds), v[i],
152 msg (SE, _("There is already a variable named %s."), v[i]);
154 var_set_both_formats (new_var, &f);
158 for (i = 0; i < nv; i++)
162 while (lex_match (lexer, '/'));
164 return lex_end_of_command (lexer);
166 /* If we have an error at a point where cleanup is required,
167 flow-of-control comes here. */
169 for (i = 0; i < nv; i++)
175 /* Parses the LEAVE command. */
177 cmd_leave (struct lexer *lexer, struct dataset *ds)
184 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
185 return CMD_CASCADING_FAILURE;
186 for (i = 0; i < nv; i++)
187 var_set_leave (v[i], true);
190 return lex_end_of_command (lexer);