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
28 #include "file-handle.h"
32 #include "value-labels.h"
35 #include "debug-print.h"
37 /* Compares A and B, which both have the given WIDTH, and returns
38 a strcmp()-type result. */
40 compare_values (const union value *a, const union value *b, int width)
43 return a->f < b->f ? -1 : a->f > b->f;
45 return memcmp (a->s, b->s, width);
48 /* Discards all the current state in preparation for a data-input
49 command like DATA LIST or GET. */
51 discard_variables (void)
53 dict_clear (default_dict);
54 default_handle = inline_file;
58 if (vfm_source != NULL)
60 if (vfm_source->class->destroy != NULL)
61 vfm_source->class->destroy (vfm_source);
66 cancel_transformations ();
70 expr_free (process_if_expr);
71 process_if_expr = NULL;
75 pgm_state = STATE_INIT;
78 /* Return nonzero only if X is a user-missing value for numeric
81 is_num_user_missing (double x, const struct variable *v)
88 return x == v->missing[0].f;
90 return x == v->missing[0].f || x == v->missing[1].f;
92 return (x == v->missing[0].f || x == v->missing[1].f
93 || x == v->missing[2].f);
95 return x >= v->missing[0].f && x <= v->missing[1].f;
97 return x <= v->missing[0].f;
99 return x >= v->missing[0].f;
100 case MISSING_RANGE_1:
101 return ((x >= v->missing[0].f && x <= v->missing[1].f)
102 || x == v->missing[2].f);
104 return x <= v->missing[0].f || x == v->missing[1].f;
106 return x >= v->missing[0].f || x == v->missing[1].f;
113 /* Return nonzero only if string S is a user-missing variable for
114 string variable V. */
116 is_str_user_missing (const unsigned char s[], const struct variable *v)
118 switch (v->miss_type)
123 return !strncmp (s, v->missing[0].s, v->width);
125 return (!strncmp (s, v->missing[0].s, v->width)
126 || !strncmp (s, v->missing[1].s, v->width));
128 return (!strncmp (s, v->missing[0].s, v->width)
129 || !strncmp (s, v->missing[1].s, v->width)
130 || !strncmp (s, v->missing[2].s, v->width));
137 /* Return nonzero only if value VAL is system-missing for variable
140 is_system_missing (const union value *val, const struct variable *v)
142 return v->type == NUMERIC && val->f == SYSMIS;
145 /* Return nonzero only if value VAL is system- or user-missing for
148 is_missing (const union value *val, const struct variable *v)
153 if (val->f == SYSMIS)
155 return is_num_user_missing (val->f, v);
157 return is_str_user_missing (val->s, v);
164 /* Return nonzero only if value VAL is user-missing for variable V. */
166 is_user_missing (const union value *val, const struct variable *v)
171 return is_num_user_missing (val->f, v);
173 return is_str_user_missing (val->s, v);
180 /* A hsh_compare_func that orders variables A and B by their
183 compare_variables (const void *a_, const void *b_, void *foo UNUSED)
185 const struct variable *a = a_;
186 const struct variable *b = b_;
188 return strcmp (a->name, b->name);
191 /* A hsh_hash_func that hashes variable V based on its name. */
193 hash_variable (const void *v_, void *foo UNUSED)
195 const struct variable *v = v_;
197 return hsh_hash_string (v->name);