X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Flanguage%2Fstats%2Fautorecode.c;h=af9280b557c5669e4ec0033de09b8c17ca4c2e9d;hb=bd00412ff6cf29cf3b7744bf1045f53122eb46f7;hp=a84528af3c1b97fd7e9c8d3a0cc8763e606388cc;hpb=5862de297bb487c81660beb3796d5c612eeb12b7;p=pspp-builds.git
diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c
index a84528af..af9280b5 100644
--- a/src/language/stats/autorecode.c
+++ b/src/language/stats/autorecode.c
@@ -1,25 +1,24 @@
-/* PSPP - computes sample statistics.
+/* PSPP - a program for statistical analysis.
Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see . */
#include
#include
#include
+#include
#include
#include
#include
@@ -27,21 +26,21 @@
#include
#include
#include
-#include
#include
#include
#include
-#include
#include
#include
+#include "xalloc.h"
+
#include "gettext.h"
#define _(msgid) gettext (msgid)
/* FIXME: Implement PRINT subcommand. */
/* An AUTORECODE variable's original value. */
-union arc_value
+union arc_value
{
double f; /* Numeric. */
char *c; /* Short or long string. */
@@ -57,7 +56,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. */
};
@@ -71,16 +70,16 @@ struct autorecode_trns
};
/* Descending or ascending sort order. */
-enum direction
+enum direction
{
ASCENDING,
DESCENDING
};
/* AUTORECODE data. */
-struct autorecode_pgm
+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. */
@@ -103,7 +102,8 @@ int
cmd_autorecode (struct lexer *lexer, struct dataset *ds)
{
struct autorecode_pgm arc;
- struct ccase *c;
+ struct casereader *input;
+ 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"))
@@ -132,9 +133,9 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
{
size_t i;
- msg (SE, _("Source variable count (%u) does not match "
- "target variable count (%u)."),
- (unsigned) arc.var_cnt, (unsigned) dst_cnt);
+ msg (SE, _("Source variable count (%zu) does not match "
+ "target variable count (%zu)."),
+ arc.var_cnt, dst_cnt);
for (i = 0; i < dst_cnt; i++)
free (arc.dst_names[i]);
@@ -177,23 +178,26 @@ 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);
+ }
- proc_open (ds);
- while (proc_read (ds, &c))
+ input = proc_open (ds);
+ for (; casereader_read (input, &c); case_destroy (&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]);
+ v.f = case_num (&c, arc.src_vars[i]);
else
- v.c = (char *) case_str (c, arc.src_vars[i]);
+ v.c = (char *) case_str (&c, arc.src_vars[i]);
vpp = (union arc_value **) hsh_probe (arc.src_values[i], &v);
if (*vpp == NULL)
@@ -207,7 +211,8 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
*vpp = vp;
}
}
- ok = proc_close (ds);
+ ok = casereader_destroy (input);
+ ok = proc_commit (ds) && ok;
for (i = 0; i < arc.var_cnt; i++)
arc.dst_vars[i] = dict_create_var_assert (dataset_dict (ds),
@@ -223,19 +228,19 @@ lossage:
}
static void
-arc_free (struct autorecode_pgm *arc)
+arc_free (struct autorecode_pgm *arc)
{
free (arc->src_vars);
- if (arc->dst_names != NULL)
+ if (arc->dst_names != NULL)
{
size_t i;
-
+
for (i = 0; i < arc->var_cnt; i++)
free (arc->dst_names[i]);
free (arc->dst_names);
}
free (arc->dst_vars);
- if (arc->src_values != NULL)
+ if (arc->src_values != NULL)
{
size_t i;
@@ -279,7 +284,7 @@ recode (struct dataset *ds, const struct autorecode_pgm *arc)
{
struct arc_item *item = pool_alloc (trns->pool, sizeof *item);
union arc_value *vp = *p;
-
+
if (var_is_numeric (arc->src_vars[i]))
item->from.f = vp->f;
else
@@ -289,7 +294,7 @@ recode (struct dataset *ds, const struct autorecode_pgm *arc)
hsh_force_insert (spec->items, item);
}
}
- add_transformation (ds,
+ add_transformation (ds,
autorecode_trns_proc, autorecode_trns_free, trns);
}
@@ -347,7 +352,7 @@ hash_alpha_value (const void *a_, const void *v_)
{
const union arc_value *a = a_;
const struct variable *v = v_;
-
+
return hsh_hash_bytes (a->c, var_get_width (v));
}