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
32 #define _(msgid) gettext (msgid)
34 #include "debug-print.h"
36 static bool parse_number (double *, const struct fmt_spec *);
39 cmd_missing_values (void)
44 int retval = CMD_PART_SUCCESS_MAYBE;
45 bool deferred_errors = false;
52 if (!parse_variables (default_dict, &v, &nv, PV_NONE))
57 lex_error (_("expecting `('"));
61 for (i = 0; i < nv; i++)
62 mv_init (&v[i]->miss, v[i]->width);
66 struct missing_values mv;
68 for (i = 0; i < nv; i++)
69 if (v[i]->type != v[0]->type)
71 const struct variable *n = v[0]->type == NUMERIC ? v[0] : v[i];
72 const struct variable *s = v[0]->type == NUMERIC ? v[i] : v[0];
73 msg (SE, _("Cannot mix numeric variables (e.g. %s) and "
74 "string variables (e.g. %s) within a single list."),
79 if (v[0]->type == NUMERIC)
82 while (!lex_match (')'))
86 if (lex_match_id ("LO") || lex_match_id ("LOWEST"))
88 else if (!parse_number (&x, &v[0]->print))
91 if (lex_match_id ("THRU"))
95 if (lex_match_id ("HI") || lex_match_id ("HIGHEST"))
97 else if (!parse_number (&y, &v[0]->print))
100 if (x == LOWEST && y == HIGHEST)
102 msg (SE, _("LO THRU HI is an invalid range."));
103 deferred_errors = true;
105 else if (!mv_add_num_range (&mv, x, y))
106 deferred_errors = true;
112 msg (SE, _("LO or LOWEST must be part of a range."));
113 deferred_errors = true;
115 else if (!mv_add_num (&mv, x))
116 deferred_errors = true;
124 mv_init (&mv, MAX_SHORT_STRING);
125 while (!lex_match (')'))
127 if (!lex_force_string ())
129 deferred_errors = true;
133 if (ds_length (&tokstr) > MAX_SHORT_STRING)
135 ds_truncate (&tokstr, MAX_SHORT_STRING);
136 msg (SE, _("Truncating missing value to short string "
137 "length (%d characters)."),
141 ds_rpad (&tokstr, MAX_SHORT_STRING, ' ');
143 if (!mv_add_str (&mv, ds_data (&tokstr)))
144 deferred_errors = true;
151 for (i = 0; i < nv; i++)
153 if (!mv_is_resizable (&mv, v[i]->width))
155 msg (SE, _("Missing values provided are too long to assign "
156 "to variable of width %d."),
158 deferred_errors = true;
162 mv_copy (&v[i]->miss, &mv);
163 mv_resize (&v[i]->miss, v[i]->width);
172 retval = lex_end_of_command ();
177 retval = CMD_PART_SUCCESS_MAYBE;
182 parse_number (double *x, const struct fmt_spec *f)
184 if (lex_is_number ())
190 else if (token == T_STRING)
194 di.s = ds_data (&tokstr);
195 di.e = ds_end (&tokstr);
199 di.f2 = ds_length (&tokstr);
208 lex_error (_("expecting number or data string"));