X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fautorecode.c;h=2944f91218fc07f315fa7c1a6fb5537fbecb1091;hb=9d6969686924cea36f9fd90e2d2c51309190a67f;hp=72534c76ea74cac4a7e0982dc57051be70f007b9;hpb=480a0746507ce73d26f528b56dc3ed80195096e0;p=pspp diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index 72534c76ea..2944f91218 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -57,7 +57,7 @@ struct arc_item /* Explains how to recode an AUTORECODE variable. */ struct arc_spec { - struct variable *src; /* Source variable. */ + const struct variable *src; /* Source variable. */ struct variable *dest; /* Target variable. */ struct hsh_table *items; /* Hash table of `freq's. */ }; @@ -80,7 +80,7 @@ enum direction /* AUTORECODE data. */ struct autorecode_pgm { - struct variable **src_vars; /* Source variables. */ + const struct variable **src_vars; /* Source variables. */ char **dst_names; /* Target variable names. */ struct variable **dst_vars; /* Target variables. */ struct hsh_table **src_values; /* `union arc_value's of source vars. */ @@ -92,7 +92,6 @@ struct autorecode_pgm static trns_proc_func autorecode_trns_proc; static trns_free_func autorecode_trns_free; -static bool autorecode_proc_func (const struct ccase *, void *, const struct dataset *); static hsh_compare_func compare_alpha_value, compare_numeric_value; static hsh_hash_func hash_alpha_value, hash_numeric_value; @@ -104,6 +103,7 @@ int cmd_autorecode (struct lexer *lexer, struct dataset *ds) { struct autorecode_pgm arc; + struct ccase *c; size_t dst_cnt; size_t i; bool ok; @@ -120,7 +120,8 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) lex_match_id (lexer, "VARIABLES"); lex_match (lexer, '='); - if (!parse_variables (lexer, dataset_dict (ds), &arc.src_vars, &arc.var_cnt, + if (!parse_variables_const (lexer, dataset_dict (ds), &arc.src_vars, + &arc.var_cnt, PV_NO_DUPLICATE)) goto lossage; if (!lex_force_match_id (lexer, "INTO")) @@ -177,14 +178,40 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) arc.dst_vars = xnmalloc (arc.var_cnt, sizeof *arc.dst_vars); arc.src_values = xnmalloc (arc.var_cnt, sizeof *arc.src_values); for (i = 0; i < dst_cnt; i++) + { + /* FIXME: consolodate this hsh_create */ if (var_is_alpha (arc.src_vars[i])) arc.src_values[i] = hsh_create (10, compare_alpha_value, hash_alpha_value, NULL, arc.src_vars[i]); else arc.src_values[i] = hsh_create (10, compare_numeric_value, hash_numeric_value, NULL, NULL); - - ok = procedure (ds, autorecode_proc_func, &arc); + } + + proc_open (ds); + while (proc_read (ds, &c)) + for (i = 0; i < arc.var_cnt; i++) + { + union arc_value v, *vp, **vpp; + + if (var_is_numeric (arc.src_vars[i])) + v.f = case_num (c, arc.src_vars[i]); + else + v.c = (char *) case_str (c, arc.src_vars[i]); + + vpp = (union arc_value **) hsh_probe (arc.src_values[i], &v); + if (*vpp == NULL) + { + vp = pool_alloc (arc.src_values_pool, sizeof *vp); + if (var_is_numeric (arc.src_vars[i])) + vp->f = v.f; + else + vp->c = pool_clone (arc.src_values_pool, + v.c, var_get_width (arc.src_vars[i])); + *vpp = vp; + } + } + ok = proc_close (ds); for (i = 0; i < arc.var_cnt; i++) arc.dst_vars[i] = dict_create_var_assert (dataset_dict (ds), @@ -344,33 +371,3 @@ hash_numeric_value (const void *a_, const void *aux UNUSED) return hsh_hash_double (a->f); } - -static bool -autorecode_proc_func (const struct ccase *c, void *arc_, const struct dataset *ds UNUSED) -{ - struct autorecode_pgm *arc = arc_; - size_t i; - - for (i = 0; i < arc->var_cnt; i++) - { - union arc_value v, *vp, **vpp; - - if (var_is_numeric (arc->src_vars[i])) - v.f = case_num (c, arc->src_vars[i]); - else - v.c = (char *) case_str (c, arc->src_vars[i]); - - vpp = (union arc_value **) hsh_probe (arc->src_values[i], &v); - if (*vpp == NULL) - { - vp = pool_alloc (arc->src_values_pool, sizeof *vp); - if (var_is_numeric (arc->src_vars[i])) - vp->f = v.f; - else - vp->c = pool_clone (arc->src_values_pool, - v.c, var_get_width (arc->src_vars[i])); - *vpp = vp; - } - } - return true; -}