From: Ben Pfaff Date: Sat, 6 May 2006 23:04:05 +0000 (+0000) Subject: Get rid of `char *c' member in union value, for cleanliness. X-Git-Tag: v0.6.0~886 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2cb4dbc3def605f171d0e5ceb3335bdf5b3e195;p=pspp-builds.git Get rid of `char *c' member in union value, for cleanliness. --- diff --git a/src/data/ChangeLog b/src/data/ChangeLog index 1b919186..8d675bcd 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,9 @@ +Sat May 6 15:58:36 2006 Ben Pfaff + + Get rid of `char *c' member in union value, for cleanliness. + + * value.h: (union value) Remove `c' member. + Sat May 6 15:36:59 2006 Ben Pfaff Make dictionary compacting functions a little more general. diff --git a/src/data/value.h b/src/data/value.h index 17f60bbd..fccd8a98 100644 --- a/src/data/value.h +++ b/src/data/value.h @@ -47,23 +47,12 @@ #define LOWEST second_lowest_value #define HIGHEST DBL_MAX -/* Describes one value, which is either a floating-point number or a - short string. */ +/* A numeric or short string value. + Multiple consecutive values represent a long string. */ union value { - /* A numeric value. */ double f; - - /* A short-string value. */ char s[MAX_SHORT_STRING]; - - /* Used by evaluate_expression() to return a string result. - As currently implemented, it's a pointer to a dynamic - buffer in the appropriate expression. - - Also used by the AGGREGATE procedure in handling string - values. */ - char *c; }; /* Maximum number of `union value's in a single number or string diff --git a/src/language/stats/ChangeLog b/src/language/stats/ChangeLog index 30ecf8aa..3d09f528 100644 --- a/src/language/stats/ChangeLog +++ b/src/language/stats/ChangeLog @@ -1,3 +1,24 @@ +Sat May 6 16:00:13 2006 Ben Pfaff + + Get rid of `char *c' member in union value, for cleanliness. + + * aggregate.c: (union agr_argument) New union. + (struct agr_var) Change element type of arg[] from union value to + union agr_argument. + (parse_aggregate_functions) Change local variable types likewise. + + * autorecode.c: (union arc_value) New union. + (struct arc_item) Change "from" from union value to union + arc_value. + (recode) Change local variable from union value to union + arc_value. + (autorecode_trns_proc) Ditto. + (compare_alpha_value) Ditto. + (hash_alpha_value) Ditto. + (compare_numeric_value) Ditto. + (hash_numeric_value) Ditto. + (autorecode_proc_func) Ditto. + Sat May 6 10:43:33 2006 Ben Pfaff Continue reforming procedure execution. In this phase, get rid of diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index 49157839..cd301170 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -48,6 +48,13 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +/* Argument for AGGREGATE function. */ +union agr_argument + { + double f; /* Numeric. */ + char *c; /* Short or long string. */ + }; + /* Specifies how to make an aggregate variable. */ struct agr_var { @@ -58,7 +65,7 @@ struct agr_var struct variable *dest; /* Target variable. */ int function; /* Function. */ int include_missing; /* 1=Include user-missing values. */ - union value arg[2]; /* Arguments. */ + union agr_argument arg[2]; /* Arguments. */ /* Accumulated during AGGREGATE execution. */ double dbl[3]; @@ -359,7 +366,7 @@ parse_aggregate_functions (struct agr_proc *agr) const struct agr_func *function; int func_index; - union value arg[2]; + union agr_argument arg[2]; struct variable **src; size_t n_src; @@ -515,7 +522,7 @@ parse_aggregate_functions (struct agr_proc *agr) || (src[0]->type == ALPHA && str_compare_rpad (arg[0].c, arg[1].c) > 0))) { - union value t = arg[0]; + union agr_argument t = arg[0]; arg[0] = arg[1]; arg[1] = t; diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index 89f546f2..560f9f99 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -40,10 +40,17 @@ /* FIXME: Implement PRINT subcommand. */ +/* An AUTORECODE variable's original value. */ +union arc_value + { + double f; /* Numeric. */ + char *c; /* Short or long string. */ + }; + /* Explains how to recode one value. `from' must be first element. */ struct arc_item { - union value from; /* Original value. */ + union arc_value from; /* Original value. */ double to; /* Recoded value. */ }; @@ -76,7 +83,7 @@ struct autorecode_pgm struct variable **src_vars; /* Source variables. */ char **dst_names; /* Target variable names. */ struct variable **dst_vars; /* Target variables. */ - struct hsh_table **src_values; /* `union value's of source vars. */ + struct hsh_table **src_values; /* `union arc_value's of source vars. */ size_t var_cnt; /* Number of variables. */ struct pool *src_values_pool; /* Pool used by src_values. */ enum direction direction; /* Sort order. */ @@ -248,7 +255,7 @@ recode (const struct autorecode_pgm *arc) for (j = 0; *p; p++, j++) { struct arc_item *item = pool_alloc (trns->pool, sizeof *item); - union value *vp = *p; + union arc_value *vp = *p; if (arc->src_vars[i]->type == NUMERIC) item->from.f = vp->f; @@ -273,7 +280,7 @@ autorecode_trns_proc (void *trns_, struct ccase *c, int case_idx UNUSED) { struct arc_spec *spec = &trns->specs[i]; struct arc_item *item; - union value v; + union arc_value v; if (spec->src->type == NUMERIC) v.f = case_num (c, spec->src->fv); @@ -304,8 +311,8 @@ autorecode_trns_free (void *trns_) static int compare_alpha_value (const void *a_, const void *b_, void *v_) { - const union value *a = a_; - const union value *b = b_; + const union arc_value *a = a_; + const union arc_value *b = b_; const struct variable *v = v_; return memcmp (a->c, b->c, v->width); @@ -314,7 +321,7 @@ compare_alpha_value (const void *a_, const void *b_, void *v_) static unsigned hash_alpha_value (const void *a_, void *v_) { - const union value *a = a_; + const union arc_value *a = a_; const struct variable *v = v_; return hsh_hash_bytes (a->c, v->width); @@ -323,8 +330,8 @@ hash_alpha_value (const void *a_, void *v_) static int compare_numeric_value (const void *a_, const void *b_, void *foo UNUSED) { - const union value *a = a_; - const union value *b = b_; + const union arc_value *a = a_; + const union arc_value *b = b_; return a->f < b->f ? -1 : a->f > b->f; } @@ -332,7 +339,7 @@ compare_numeric_value (const void *a_, const void *b_, void *foo UNUSED) static unsigned hash_numeric_value (const void *a_, void *foo UNUSED) { - const union value *a = a_; + const union arc_value *a = a_; return hsh_hash_double (a->f); } @@ -345,14 +352,14 @@ autorecode_proc_func (const struct ccase *c, void *arc_) for (i = 0; i < arc->var_cnt; i++) { - union value v, *vp, **vpp; + union arc_value v, *vp, **vpp; if (arc->src_vars[i]->type == NUMERIC) v.f = case_num (c, arc->src_vars[i]->fv); else v.c = (char *) case_str (c, arc->src_vars[i]->fv); - vpp = (union value **) hsh_probe (arc->src_values[i], &v); + vpp = (union arc_value **) hsh_probe (arc->src_values[i], &v); if (*vpp == NULL) { vp = pool_alloc (arc->src_values_pool, sizeof *vp); diff --git a/src/language/xforms/ChangeLog b/src/language/xforms/ChangeLog index b48427d5..dc3941f8 100644 --- a/src/language/xforms/ChangeLog +++ b/src/language/xforms/ChangeLog @@ -1,3 +1,13 @@ +Sat May 6 16:02:55 2006 Ben Pfaff + + Get rid of `char *c' member in union value, for cleanliness. + + * recode.c: (union recode_value) New union. + (struct map_in) Change x, y types to union recode_value. + (struct map_out) Change value type to union recode_value. + (find_src_string) Wrap data_in() call so it uses a real `union + value'. + Sat May 6 14:08:42 2006 Ben Pfaff * select-if.c (cmd_filter): Make FILTER without any further diff --git a/src/language/xforms/recode.c b/src/language/xforms/recode.c index 09eafb6a..86bd8b88 100644 --- a/src/language/xforms/recode.c +++ b/src/language/xforms/recode.c @@ -56,18 +56,25 @@ enum map_in_type MAP_CONVERT /* "123" => 123. */ }; +/* A value involved in a RECODE mapping. */ +union recode_value + { + double f; /* Numeric. */ + char *c; /* Short or long string. */ + }; + /* Describes input values to be mapped. */ struct map_in { enum map_in_type type; /* One of MAP_*. */ - union value x, y; /* Source values. */ + union recode_value x, y; /* Source values. */ }; /* Describes the value used as output from a mapping. */ struct map_out { bool copy_input; /* If true, copy input to output. */ - union value value; /* If copy_input false, recoded value. */ + union recode_value value; /* If copy_input false, recoded value. */ int width; /* If copy_input false, output value width. */ }; @@ -585,17 +592,19 @@ find_src_string (struct recode_trns *trns, const char *value, int width) break; case MAP_CONVERT: { + union value uv; struct data_in di; di.s = value; di.e = value + width; - di.v = &out->value; + di.v = &uv; di.flags = DI_IGNORE_ERROR; di.f1 = di.f2 = 0; di.format.type = FMT_F; di.format.w = width; di.format.d = 0; match = data_in (&di); + out->value.f = uv.f; break; } default: