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/data-in.h>
25 #include <libpspp/message.h>
26 #include <language/lexer/lexer.h>
27 #include <libpspp/magic.h>
28 #include <language/lexer/range-parser.h>
29 #include <libpspp/str.h>
30 #include <data/variable.h>
33 #define _(msgid) gettext (msgid)
36 cmd_missing_values (void)
41 int retval = CMD_FAILURE;
42 bool deferred_errors = false;
48 if (!parse_variables (default_dict, &v, &nv, PV_NONE))
53 lex_error (_("expecting `('"));
57 for (i = 0; i < nv; i++)
58 mv_init (&v[i]->miss, v[i]->width);
62 struct missing_values mv;
64 for (i = 0; i < nv; i++)
65 if (v[i]->type != v[0]->type)
67 const struct variable *n = v[0]->type == NUMERIC ? v[0] : v[i];
68 const struct variable *s = v[0]->type == NUMERIC ? v[i] : v[0];
69 msg (SE, _("Cannot mix numeric variables (e.g. %s) and "
70 "string variables (e.g. %s) within a single list."),
75 if (v[0]->type == NUMERIC)
78 while (!lex_match (')'))
83 if (!parse_num_range (&x, &y, &v[0]->print))
88 : mv_add_num_range (&mv, x, y));
90 deferred_errors = true;
97 mv_init (&mv, MAX_SHORT_STRING);
98 while (!lex_match (')'))
100 if (!lex_force_string ())
102 deferred_errors = true;
106 if (ds_length (&tokstr) > MAX_SHORT_STRING)
108 ds_truncate (&tokstr, MAX_SHORT_STRING);
109 msg (SE, _("Truncating missing value to short string "
110 "length (%d characters)."),
114 ds_rpad (&tokstr, MAX_SHORT_STRING, ' ');
116 if (!mv_add_str (&mv, ds_data (&tokstr)))
117 deferred_errors = true;
124 for (i = 0; i < nv; i++)
126 if (!mv_is_resizable (&mv, v[i]->width))
128 msg (SE, _("Missing values provided are too long to assign "
129 "to variable of width %d."),
131 deferred_errors = true;
135 mv_copy (&v[i]->miss, &mv);
136 mv_resize (&v[i]->miss, v[i]->width);
145 retval = lex_end_of_command ();
150 retval = CMD_FAILURE;