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
26 #include "dictionary.h"
29 #include "file-handle.h"
33 #include "value-labels.h"
36 #include "debug-print.h"
39 var_attach_aux (struct variable *v,
40 void *aux, void (*aux_dtor) (struct variable *))
42 assert (v->aux == NULL);
45 v->aux_dtor = aux_dtor;
50 var_detach_aux (struct variable *v)
59 var_clear_aux (struct variable *v)
64 if (v->aux_dtor != NULL)
71 var_dtor_free (struct variable *v)
76 /* Compares A and B, which both have the given WIDTH, and returns
77 a strcmp()-type result. */
79 compare_values (const union value *a, const union value *b, int width)
82 return a->f < b->f ? -1 : a->f > b->f;
84 return memcmp (a->s, b->s, min(MAX_SHORT_STRING, width));
87 /* Create a hash of v */
89 hash_value(const union value *v, int width)
94 id_hash = hsh_hash_double (v->f);
96 id_hash = hsh_hash_bytes (v->s, min(MAX_SHORT_STRING, width));
103 /* Discards all the current state in preparation for a data-input
104 command like DATA LIST or GET. */
106 discard_variables (void)
108 dict_clear (default_dict);
109 default_handle = NULL;
113 if (vfm_source != NULL)
115 free_case_source (vfm_source);
119 cancel_transformations ();
123 expr_free (process_if_expr);
124 process_if_expr = NULL;
128 pgm_state = STATE_INIT;
131 /* Return nonzero only if X is a user-missing value for numeric
134 is_num_user_missing (double x, const struct variable *v)
136 switch (v->miss_type)
141 return x == v->missing[0].f;
143 return x == v->missing[0].f || x == v->missing[1].f;
145 return (x == v->missing[0].f || x == v->missing[1].f
146 || x == v->missing[2].f);
148 return x >= v->missing[0].f && x <= v->missing[1].f;
150 return x <= v->missing[0].f;
152 return x >= v->missing[0].f;
153 case MISSING_RANGE_1:
154 return ((x >= v->missing[0].f && x <= v->missing[1].f)
155 || x == v->missing[2].f);
157 return x <= v->missing[0].f || x == v->missing[1].f;
159 return x >= v->missing[0].f || x == v->missing[1].f;
166 /* Return nonzero only if string S is a user-missing variable for
167 string variable V. */
169 is_str_user_missing (const unsigned char s[], const struct variable *v)
171 switch (v->miss_type)
176 return !strncmp (s, v->missing[0].s, v->width);
178 return (!strncmp (s, v->missing[0].s, v->width)
179 || !strncmp (s, v->missing[1].s, v->width));
181 return (!strncmp (s, v->missing[0].s, v->width)
182 || !strncmp (s, v->missing[1].s, v->width)
183 || !strncmp (s, v->missing[2].s, v->width));
190 /* Return nonzero only if value VAL is system-missing for variable
193 is_system_missing (const union value *val, const struct variable *v)
195 return v->type == NUMERIC && val->f == SYSMIS;
198 /* Return nonzero only if value VAL is system- or user-missing for
201 is_missing (const union value *val, const struct variable *v)
206 if (val->f == SYSMIS)
208 return is_num_user_missing (val->f, v);
210 return is_str_user_missing (val->s, v);
217 /* Return nonzero only if value VAL is user-missing for variable V. */
219 is_user_missing (const union value *val, const struct variable *v)
224 return is_num_user_missing (val->f, v);
226 return is_str_user_missing (val->s, v);
233 /* A hsh_compare_func that orders variables A and B by their
236 compare_variables (const void *a_, const void *b_, void *foo UNUSED)
238 const struct variable *a = a_;
239 const struct variable *b = b_;
241 return strcmp (a->name, b->name);
244 /* A hsh_hash_func that hashes variable V based on its name. */
246 hash_variable (const void *v_, void *foo UNUSED)
248 const struct variable *v = v_;
250 return hsh_hash_string (v->name);