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 /* Create a hash of v */
50 hash_value(const union value *v, int width)
55 id_hash = hsh_hash_double (v->f);
57 id_hash = hsh_hash_bytes (v->s, width);
64 /* Discards all the current state in preparation for a data-input
65 command like DATA LIST or GET. */
67 discard_variables (void)
69 dict_clear (default_dict);
70 default_handle = inline_file;
74 if (vfm_source != NULL)
76 free_case_source (vfm_source);
80 cancel_transformations ();
84 expr_free (process_if_expr);
85 process_if_expr = NULL;
89 pgm_state = STATE_INIT;
92 /* Return nonzero only if X is a user-missing value for numeric
95 is_num_user_missing (double x, const struct variable *v)
102 return x == v->missing[0].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
107 || x == v->missing[2].f);
109 return x >= v->missing[0].f && x <= v->missing[1].f;
111 return x <= v->missing[0].f;
113 return x >= v->missing[0].f;
114 case MISSING_RANGE_1:
115 return ((x >= v->missing[0].f && x <= v->missing[1].f)
116 || x == v->missing[2].f);
118 return x <= v->missing[0].f || x == v->missing[1].f;
120 return x >= v->missing[0].f || x == v->missing[1].f;
127 /* Return nonzero only if string S is a user-missing variable for
128 string variable V. */
130 is_str_user_missing (const unsigned char s[], const struct variable *v)
132 switch (v->miss_type)
137 return !strncmp (s, v->missing[0].s, v->width);
139 return (!strncmp (s, v->missing[0].s, v->width)
140 || !strncmp (s, v->missing[1].s, v->width));
142 return (!strncmp (s, v->missing[0].s, v->width)
143 || !strncmp (s, v->missing[1].s, v->width)
144 || !strncmp (s, v->missing[2].s, v->width));
151 /* Return nonzero only if value VAL is system-missing for variable
154 is_system_missing (const union value *val, const struct variable *v)
156 return v->type == NUMERIC && val->f == SYSMIS;
159 /* Return nonzero only if value VAL is system- or user-missing for
162 is_missing (const union value *val, const struct variable *v)
167 if (val->f == SYSMIS)
169 return is_num_user_missing (val->f, v);
171 return is_str_user_missing (val->s, v);
178 /* Return nonzero only if value VAL is user-missing for variable V. */
180 is_user_missing (const union value *val, const struct variable *v)
185 return is_num_user_missing (val->f, v);
187 return is_str_user_missing (val->s, v);
194 /* A hsh_compare_func that orders variables A and B by their
197 compare_variables (const void *a_, const void *b_, void *foo UNUSED)
199 const struct variable *a = a_;
200 const struct variable *b = b_;
202 return strcmp (a->name, b->name);
205 /* A hsh_hash_func that hashes variable V based on its name. */
207 hash_variable (const void *v_, void *foo UNUSED)
209 const struct variable *v = v_;
211 return hsh_hash_string (v->name);