1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 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/data-in.h>
25 #include <data/procedure.h>
26 #include <data/variable.h>
27 #include <language/command.h>
28 #include <language/lexer/lexer.h>
29 #include <language/lexer/variable-parser.h>
30 #include <language/lexer/range-parser.h>
31 #include <libpspp/magic.h>
32 #include <libpspp/message.h>
33 #include <libpspp/message.h>
34 #include <libpspp/str.h>
37 #define _(msgid) gettext (msgid)
40 cmd_missing_values (struct dataset *ds)
45 int retval = CMD_FAILURE;
46 bool deferred_errors = false;
52 if (!parse_variables (dataset_dict (ds), &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 (')'))
87 if (!parse_num_range (&x, &y, &v[0]->print))
92 : mv_add_num_range (&mv, x, y));
94 deferred_errors = true;
101 mv_init (&mv, MAX_SHORT_STRING);
102 while (!lex_match (')'))
104 if (!lex_force_string ())
106 deferred_errors = true;
110 if (ds_length (&tokstr) > MAX_SHORT_STRING)
112 ds_truncate (&tokstr, MAX_SHORT_STRING);
113 msg (SE, _("Truncating missing value to short string "
114 "length (%d characters)."),
118 ds_rpad (&tokstr, MAX_SHORT_STRING, ' ');
120 if (!mv_add_str (&mv, ds_data (&tokstr)))
121 deferred_errors = true;
128 for (i = 0; i < nv; i++)
130 if (!mv_is_resizable (&mv, v[i]->width))
132 msg (SE, _("Missing values provided are too long to assign "
133 "to variable of width %d."),
135 deferred_errors = true;
139 mv_copy (&v[i]->miss, &mv);
140 mv_resize (&v[i]->miss, v[i]->width);
149 retval = lex_end_of_command ();
154 retval = CMD_FAILURE;