X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fautorecode.c;h=a84528af3c1b97fd7e9c8d3a0cc8763e606388cc;hb=11d2ffde279bad43d0c271f7fbfad383969e063f;hp=048db1191cbecffe1a8dd055e126c9ceb1e71192;hpb=338fb2a2e84df6427a2fdee6769421f57d5666d8;p=pspp diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index 048db1191c..a84528af3c 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -1,6 +1,5 @@ /* PSPP - computes sample statistics. Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -93,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; @@ -105,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; @@ -185,7 +184,30 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) 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), @@ -345,33 +367,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; -}