/* Performs the AUTORECODE procedure. */
int
-cmd_autorecode (struct dataset *ds)
+cmd_autorecode (struct lexer *lexer, struct dataset *ds)
{
struct autorecode_pgm arc;
size_t dst_cnt;
arc.print = 0;
dst_cnt = 0;
- lex_match_id ("VARIABLES");
- lex_match ('=');
- if (!parse_variables (dataset_dict (ds), &arc.src_vars, &arc.var_cnt,
+ lex_match_id (lexer, "VARIABLES");
+ lex_match (lexer, '=');
+ if (!parse_variables (lexer, dataset_dict (ds), &arc.src_vars, &arc.var_cnt,
PV_NO_DUPLICATE))
goto lossage;
- if (!lex_force_match_id ("INTO"))
+ if (!lex_force_match_id (lexer, "INTO"))
goto lossage;
- lex_match ('=');
- if (!parse_DATA_LIST_vars (&arc.dst_names, &dst_cnt, PV_NONE))
+ lex_match (lexer, '=');
+ if (!parse_DATA_LIST_vars (lexer, &arc.dst_names, &dst_cnt, PV_NONE))
goto lossage;
if (dst_cnt != arc.var_cnt)
{
goto lossage;
}
- while (lex_match ('/'))
- if (lex_match_id ("DESCENDING"))
+ while (lex_match (lexer, '/'))
+ if (lex_match_id (lexer, "DESCENDING"))
arc.direction = DESCENDING;
- else if (lex_match_id ("PRINT"))
+ else if (lex_match_id (lexer, "PRINT"))
arc.print = 1;
- if (token != '.')
+ if (lex_token (lexer) != '.')
{
- lex_error (_("expecting end of command"));
+ lex_error (lexer, _("expecting end of command"));
goto lossage;
}
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++)
- if (arc.src_vars[i]->type == ALPHA)
+ 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
spec->src = arc->src_vars[i];
spec->dest = arc->dst_vars[i];
- if (arc->src_vars[i]->type == ALPHA)
+ if (var_is_alpha (arc->src_vars[i]))
spec->items = hsh_create (2 * count, compare_alpha_value,
hash_alpha_value, NULL, arc->src_vars[i]);
else
struct arc_item *item = pool_alloc (trns->pool, sizeof *item);
union arc_value *vp = *p;
- if (arc->src_vars[i]->type == NUMERIC)
+ if (var_is_numeric (arc->src_vars[i]))
item->from.f = vp->f;
else
item->from.c = pool_clone (trns->pool, vp->c,
- arc->src_vars[i]->width);
+ var_get_width (arc->src_vars[i]));
item->to = arc->direction == ASCENDING ? j + 1 : count - j;
hsh_force_insert (spec->items, item);
}
struct arc_item *item;
union arc_value v;
- if (spec->src->type == NUMERIC)
+ if (var_is_numeric (spec->src))
v.f = case_num (c, spec->src->fv);
else
v.c = (char *) case_str (c, spec->src->fv);
/* AUTORECODE procedure. */
static int
-compare_alpha_value (const void *a_, const void *b_, void *v_)
+compare_alpha_value (const void *a_, const void *b_, const void *v_)
{
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);
+ return memcmp (a->c, b->c, var_get_width (v));
}
static unsigned
-hash_alpha_value (const void *a_, void *v_)
+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, v->width);
+ return hsh_hash_bytes (a->c, var_get_width (v));
}
static int
-compare_numeric_value (const void *a_, const void *b_, void *foo UNUSED)
+compare_numeric_value (const void *a_, const void *b_, const void *aux UNUSED)
{
const union arc_value *a = a_;
const union arc_value *b = b_;
}
static unsigned
-hash_numeric_value (const void *a_, void *foo UNUSED)
+hash_numeric_value (const void *a_, const void *aux UNUSED)
{
const union arc_value *a = a_;
{
union arc_value v, *vp, **vpp;
- if (arc->src_vars[i]->type == NUMERIC)
+ if (var_is_numeric (arc->src_vars[i]))
v.f = case_num (c, arc->src_vars[i]->fv);
else
v.c = (char *) case_str (c, arc->src_vars[i]->fv);
if (*vpp == NULL)
{
vp = pool_alloc (arc->src_values_pool, sizeof *vp);
- if (arc->src_vars[i]->type == NUMERIC)
+ if (var_is_numeric (arc->src_vars[i]))
vp->f = v.f;
else
vp->c = pool_clone (arc->src_values_pool,
- v.c, arc->src_vars[i]->width);
+ v.c, var_get_width (arc->src_vars[i]));
*vpp = vp;
}
}