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., 51 Franklin Street, Fifth Floor, Boston, MA
32 /* Script variables. */
37 NUMERIC, /* A numeric variable. */
38 ALPHA /* A string variable. (STRING is pre-empted by lexer.h) */
41 /* Types of missing values. Order is significant, see
42 mis-val.c:parse_numeric(), sfm-read.c, sfm-write.c,
43 sysfile-info.c:cmd_sysfile_info(), mis-val.c:copy_missing_values(),
44 pfm-read.c:read_variables(), pfm-write.c:write_variables(),
45 apply-dict.c:cmd_apply_dictionary(), and more (?). */
48 MISSING_NONE, /* No user-missing values. */
49 MISSING_1, /* One user-missing value. */
50 MISSING_2, /* Two user-missing values. */
51 MISSING_3, /* Three user-missing values. */
52 MISSING_RANGE, /* [a,b]. */
53 MISSING_LOW, /* (-inf,a]. */
54 MISSING_HIGH, /* (a,+inf]. */
55 MISSING_RANGE_1, /* [a,b], c. */
56 MISSING_LOW_1, /* (-inf,a], b. */
57 MISSING_HIGH_1, /* (a,+inf), b. */
62 /* A variable's dictionary entry. */
65 char name[SHORT_NAME_LEN + 1]; /* As a string. */
66 char *longname; /* Pointer to entry in dictionary's table */
67 int index; /* Index into its dictionary's var[]. */
68 int type; /* NUMERIC or ALPHA. */
70 int width; /* Size of string variables in chars. */
71 int fv, nv; /* Index into `value's, number of values. */
72 unsigned init : 1; /* 1=VFM must init and possibly reinit. */
73 unsigned reinit : 1; /* Cases are: 1=reinitialized; 0=left. */
76 int miss_type; /* One of the MISSING_* constants. */
77 union value missing[3]; /* User-missing value. */
79 /* Display formats. */
80 struct fmt_spec print; /* Default format for PRINT. */
81 struct fmt_spec write; /* Default format for WRITE. */
84 struct val_labs *val_labs; /* Value labels. */
85 char *label; /* Variable label. */
88 /* GUI display parameters */
89 enum measure measure; /* Nominal ordinal or continuous */
90 int display_width; /* Width of data editor column */
91 enum alignment alignment; /* Alignment of data in gui */
93 /* Per-command info. */
95 void (*aux_dtor) (struct variable *);
99 /* A tuple containing short names and longnames */
100 struct name_table_entry
106 bool var_is_valid_name (const char *, bool issue_error);
107 int compare_var_names (const void *, const void *, void *);
108 unsigned hash_var_name (const void *, void *);
110 /* Destroy and free up an nte */
111 void free_nte(struct name_table_entry *nte);
114 unsigned hash_long_name (const void *e_, void *aux UNUSED) ;
115 int compare_long_names(const void *a_, const void *b_, void *aux);
118 int compare_var_ptr_names (const void *, const void *, void *);
119 unsigned hash_var_ptr_name (const void *, void *);
121 void *var_attach_aux (struct variable *,
122 void *aux, void (*aux_dtor) (struct variable *));
123 void var_clear_aux (struct variable *);
124 void *var_detach_aux (struct variable *);
125 void var_dtor_free (struct variable *);
127 /* Classes of variables. */
130 DC_ORDINARY, /* Ordinary identifier. */
131 DC_SYSTEM, /* System variable. */
132 DC_SCRATCH /* Scratch variable. */
135 enum dict_class dict_class_from_id (const char *name);
136 const char *dict_class_to_name (enum dict_class dict_class);
138 /* Vector of variables. */
141 int idx; /* Index for dict_get_vector(). */
142 char name[SHORT_NAME_LEN + 1]; /* Name. */
143 struct variable **var; /* Vector of variables. */
144 int cnt; /* Number of variables. */
148 void discard_variables (void);
150 /* This is the active file dictionary. */
151 extern struct dictionary *default_dict;
153 /* Transformation state. */
155 /* Default file handle for DATA LIST, REREAD, REPEATING DATA
157 extern struct file_handle *default_handle;
159 /* PROCESS IF expression. */
160 extern struct expression *process_if_expr;
162 /* TEMPORARY support. */
164 /* 1=TEMPORARY has been executed at some point. */
165 extern int temporary;
167 /* If temporary!=0, the saved dictionary. */
168 extern struct dictionary *temp_dict;
170 /* If temporary!=0, index into t_trns[] (declared far below) that
171 gives the point at which data should be written out. -1 means that
172 the data shouldn't be changed since all transformations are
174 extern int temp_trns;
176 /* If FILTER is active, whether it was executed before or after
178 extern int FILTER_before_TEMPORARY;
180 void cancel_temporary (void);
185 void dump_split_vars (const struct ccase *);
186 typedef int (* is_missing_func )(const union value *, const struct variable *);
188 int is_num_user_missing (double, const struct variable *);
189 int is_str_user_missing (const unsigned char[], const struct variable *);
190 int is_missing (const union value *, const struct variable *);
191 int is_system_missing (const union value *, const struct variable *);
192 int is_user_missing (const union value *, const struct variable *);
193 void copy_missing_values (struct variable *dest, const struct variable *src);
195 /* Transformations. */
198 typedef int trns_proc_func (struct trns_header *, struct ccase *, int);
199 typedef void trns_free_func (struct trns_header *);
201 /* Header for all transformations. */
204 int index; /* Index into t_trns[]. */
205 trns_proc_func *proc; /* Transformation proc. */
206 trns_free_func *free; /* Garbage collector proc. */
209 /* Array of transformations */
210 extern struct trns_header **t_trns;
212 /* Number of transformations, maximum number in array currently. */
213 extern int n_trns, m_trns;
215 /* Index of first transformation that is really a transformation. Any
216 transformations before this belong to INPUT PROGRAM. */
219 void add_transformation (struct trns_header *trns);
220 void cancel_transformations (void);
224 struct var_set *var_set_create_from_dict (const struct dictionary *d);
225 struct var_set *var_set_create_from_array (struct variable *const *var,
228 size_t var_set_get_cnt (const struct var_set *vs);
229 struct variable *var_set_get_var (const struct var_set *vs, size_t idx);
230 struct variable *var_set_lookup_var (const struct var_set *vs,
232 int var_set_lookup_var_idx (const struct var_set *vs, const char *name);
233 void var_set_destroy (struct var_set *vs);
235 /* Variable parsers. */
239 PV_NONE = 0, /* No options. */
240 PV_SINGLE = 0001, /* Restrict to a single name or TO use. */
241 PV_DUPLICATE = 0002, /* Don't merge duplicates. */
242 PV_APPEND = 0004, /* Append to existing list. */
243 PV_NO_DUPLICATE = 0010, /* Error on duplicates. */
244 PV_NUMERIC = 0020, /* Vars must be numeric. */
245 PV_STRING = 0040, /* Vars must be string. */
246 PV_SAME_TYPE = 00100, /* All vars must be the same type. */
247 PV_NO_SCRATCH = 00200 /* Disallow scratch variables. */
250 struct variable *parse_variable (void);
251 struct variable *parse_dict_variable (const struct dictionary *);
252 int parse_variables (const struct dictionary *, struct variable ***, int *,
254 int parse_var_set_vars (const struct var_set *, struct variable ***, int *,
256 int parse_DATA_LIST_vars (char ***names, int *cnt, int opts);
257 int parse_mixed_vars (char ***names, int *cnt, int opts);
261 /* Return a string representing this variable, in the form most
262 appropriate from a human factors perspective.
263 (IE: the label if it has one, otherwise the name )
265 const char * var_to_string(const struct variable *var);