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 /* Compares A and B, which both have the given WIDTH, and returns
39 a strcmp()-type result. */
41 compare_values (union value *a, union value *b, int width)
44 return a->f < b->f ? -1 : a->f > b->f;
46 return memcmp (a->s, b->s, width);
49 /* Discards all the current state in preparation for a data-input
50 command like DATA LIST or GET. */
52 discard_variables (void)
54 dict_clear (default_dict);
55 default_handle = inline_file;
61 vfm_source->destroy_source ();
65 cancel_transformations ();
69 expr_free (process_if_expr);
70 process_if_expr = NULL;
74 pgm_state = STATE_INIT;
77 /* Return nonzero only if X is a user-missing value for numeric
80 is_num_user_missing (double x, const struct variable *v)
87 return approx_eq (x, v->missing[0].f);
89 return (approx_eq (x, v->missing[0].f)
90 || approx_eq (x, v->missing[1].f));
92 return (approx_eq (x, v->missing[0].f)
93 || approx_eq (x, v->missing[1].f)
94 || approx_eq (x, v->missing[2].f));
96 return (approx_ge (x, v->missing[0].f)
97 && approx_le (x, v->missing[1].f));
99 return approx_le (x, v->missing[0].f);
101 return approx_ge (x, v->missing[0].f);
102 case MISSING_RANGE_1:
103 return ((approx_ge (x, v->missing[0].f)
104 && approx_le (x, v->missing[1].f))
105 || approx_eq (x, v->missing[2].f));
107 return (approx_le (x, v->missing[0].f)
108 || approx_eq (x, v->missing[1].f));
110 return (approx_ge (x, v->missing[0].f)
111 || approx_eq (x, v->missing[1].f));
118 /* Return nonzero only if string S is a user-missing variable for
119 string variable V. */
121 is_str_user_missing (const unsigned char s[], const struct variable *v)
123 switch (v->miss_type)
128 return !strncmp (s, v->missing[0].s, v->width);
130 return (!strncmp (s, v->missing[0].s, v->width)
131 || !strncmp (s, v->missing[1].s, v->width));
133 return (!strncmp (s, v->missing[0].s, v->width)
134 || !strncmp (s, v->missing[1].s, v->width)
135 || !strncmp (s, v->missing[2].s, v->width));
142 /* Return nonzero only if value VAL is system-missing for variable
145 is_system_missing (const union value *val, const struct variable *v)
147 return v->type == NUMERIC && val->f == SYSMIS;
150 /* Return nonzero only if value VAL is system- or user-missing for
153 is_missing (const union value *val, const struct variable *v)
158 if (val->f == SYSMIS)
160 return is_num_user_missing (val->f, v);
162 return is_str_user_missing (val->s, v);
169 /* Return nonzero only if value VAL is user-missing for variable V. */
171 is_user_missing (const union value *val, const struct variable *v)
176 return is_num_user_missing (val->f, v);
178 return is_str_user_missing (val->s, v);
185 /* A hsh_compare_func that orders variables A and B by their
188 compare_variables (const void *a_, const void *b_, void *foo UNUSED)
190 const struct variable *a = a_;
191 const struct variable *b = b_;
193 return strcmp (a->name, b->name);
196 /* A hsh_hash_func that hashes variable V based on its name. */
198 hash_variable (const void *v_, void *foo UNUSED)
200 const struct variable *v = v_;
202 return hsh_hash_string (v->name);