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 lexer *lexer, struct dataset *ds)
45 int retval = CMD_FAILURE;
46 bool deferred_errors = false;
48 while (lex_token (lexer) != '.')
52 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
55 if (!lex_match (lexer, '('))
57 lex_error (lexer, _("expecting `('"));
61 for (i = 0; i < nv; i++)
62 var_clear_missing_values (v[i]);
64 if (!lex_match (lexer, ')'))
66 struct missing_values mv;
68 for (i = 0; i < nv; i++)
69 if (var_get_type (v[i]) != var_get_type (v[0]))
71 const struct variable *n = var_is_numeric (v[0]) ? v[0] : v[i];
72 const struct variable *s = var_is_numeric (v[0]) ? 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."),
75 var_get_name (n), var_get_name (s));
79 if (var_is_numeric (v[0]))
82 while (!lex_match (lexer, ')'))
84 enum fmt_type type = var_get_print_format (v[0])->type;
88 if (!parse_num_range (lexer, &x, &y, &type))
93 : mv_add_num_range (&mv, x, y));
95 deferred_errors = true;
97 lex_match (lexer, ',');
104 mv_init (&mv, MAX_SHORT_STRING);
105 while (!lex_match (lexer, ')'))
107 if (!lex_force_string (lexer))
109 deferred_errors = true;
113 ds_init_string (&value, lex_tokstr (lexer));
115 if (ds_length (&value) > MAX_SHORT_STRING)
117 ds_truncate (&value, MAX_SHORT_STRING);
118 msg (SE, _("Truncating missing value to short string "
119 "length (%d characters)."),
123 ds_rpad (&value, MAX_SHORT_STRING, ' ');
125 if (!mv_add_str (&mv, ds_data (&value)))
126 deferred_errors = true;
130 lex_match (lexer, ',');
134 for (i = 0; i < nv; i++)
136 if (!mv_is_resizable (&mv, var_get_width (v[i])))
138 msg (SE, _("Missing values provided are too long to assign "
139 "to variable of width %d."),
140 var_get_width (v[i]));
141 deferred_errors = true;
145 struct missing_values tmp;
147 mv_resize (&tmp, var_get_width (v[i]));
148 var_set_missing_values (v[i], &tmp);
153 lex_match (lexer, '/');
157 retval = lex_end_of_command (lexer);
162 retval = CMD_FAILURE;