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., 59 Temple Place - Suite 330, Boston, MA
29 #include "file-handle.h"
33 #include "value-labels.h"
36 #include "debug-print.h"
38 /* Discards all the current state in preparation for a data-input
39 command like DATA LIST or GET. */
41 discard_variables (void)
43 dict_clear (default_dict);
44 default_handle = inline_file;
50 vfm_source->destroy_source ();
54 cancel_transformations ();
58 expr_free (process_if_expr);
59 process_if_expr = NULL;
63 pgm_state = STATE_INIT;
66 /* Return nonzero only if X is a user-missing value for numeric
69 is_num_user_missing (double x, const struct variable *v)
76 return approx_eq (x, v->missing[0].f);
78 return (approx_eq (x, v->missing[0].f)
79 || approx_eq (x, v->missing[1].f));
81 return (approx_eq (x, v->missing[0].f)
82 || approx_eq (x, v->missing[1].f)
83 || approx_eq (x, v->missing[2].f));
85 return (approx_ge (x, v->missing[0].f)
86 && approx_le (x, v->missing[1].f));
88 return approx_le (x, v->missing[0].f);
90 return approx_ge (x, v->missing[0].f);
92 return ((approx_ge (x, v->missing[0].f)
93 && approx_le (x, v->missing[1].f))
94 || approx_eq (x, v->missing[2].f));
96 return (approx_le (x, v->missing[0].f)
97 || approx_eq (x, v->missing[1].f));
99 return (approx_ge (x, v->missing[0].f)
100 || approx_eq (x, v->missing[1].f));
107 /* Return nonzero only if string S is a user-missing variable for
108 string variable V. */
110 is_str_user_missing (const unsigned char s[], const struct variable *v)
112 switch (v->miss_type)
117 return !strncmp (s, v->missing[0].s, v->width);
119 return (!strncmp (s, v->missing[0].s, v->width)
120 || !strncmp (s, v->missing[1].s, v->width));
122 return (!strncmp (s, v->missing[0].s, v->width)
123 || !strncmp (s, v->missing[1].s, v->width)
124 || !strncmp (s, v->missing[2].s, v->width));
131 /* Return nonzero only if value VAL is system-missing for variable
134 is_system_missing (const union value *val, const struct variable *v)
136 return v->type == NUMERIC && val->f == SYSMIS;
139 /* Return nonzero only if value VAL is system- or user-missing for
142 is_missing (const union value *val, const struct variable *v)
147 if (val->f == SYSMIS)
149 return is_num_user_missing (val->f, v);
151 return is_str_user_missing (val->s, v);
158 /* Return nonzero only if value VAL is user-missing for variable V. */
160 is_user_missing (const union value *val, const struct variable *v)
165 return is_num_user_missing (val->f, v);
167 return is_str_user_missing (val->s, v);
174 /* A hsh_compare_func that orders variables A and B by their
177 compare_variables (const void *a_, const void *b_, void *foo unused)
179 const struct variable *a = a_;
180 const struct variable *b = b_;
182 return strcmp (a->name, b->name);
185 /* A hsh_hash_func that hashes variable V based on its name. */
187 hash_variable (const void *v_, void *foo unused)
189 const struct variable *v = v_;
191 return hsh_hash_string (v->name);