projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
parsing works, at least the basics
[pspp]
/
src
/
language
/
stats
/
autorecode.c
diff --git
a/src/language/stats/autorecode.c
b/src/language/stats/autorecode.c
index 91fffcf27a07158b8f78ffa9bc1833fb2e428aba..499f149d22a14c4003f2d2ae1a9a42d368202798 100644
(file)
--- a/
src/language/stats/autorecode.c
+++ b/
src/language/stats/autorecode.c
@@
-1,5
+1,6
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2009, 2010, 2012, 2013, 2014 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009, 2010, 2012, 2013, 2014
+ 2021, 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
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
@@
-95,8
+96,7
@@
struct autorecode_pgm
bool blank_valid;
};
bool blank_valid;
};
-static trns_proc_func autorecode_trns_proc;
-static trns_free_func autorecode_trns_free;
+static const struct trns_class autorecode_trns_class;
static int compare_arc_items (const void *, const void *, const void *aux);
static void arc_free (struct autorecode_pgm *);
static int compare_arc_items (const void *, const void *, const void *aux);
static void arc_free (struct autorecode_pgm *);
@@
-131,7
+131,7
@@
cmd_autorecode (struct lexer *lexer, struct dataset *ds)
bool print = false;
/* Create procedure. */
bool print = false;
/* Create procedure. */
- struct autorecode_pgm *arc =
xzalloc (sizeof *arc
);
+ struct autorecode_pgm *arc =
XZALLOC (struct autorecode_pgm
);
arc->blank_valid = true;
/* Parse variable lists. */
arc->blank_valid = true;
/* Parse variable lists. */
@@
-245,7
+245,7
@@
cmd_autorecode (struct lexer *lexer, struct dataset *ds)
spec->format = *var_get_print_format (src_vars[i]);
const char *label = var_get_label (src_vars[i]);
spec->format = *var_get_print_format (src_vars[i]);
const char *label = var_get_label (src_vars[i]);
- spec->label =
label ? xstrdup (label) : NULL
;
+ spec->label =
xstrdup_if_nonnull (label)
;
if (group && i > 0)
spec->items = arc->specs[0].items;
if (group && i > 0)
spec->items = arc->specs[0].items;
@@
-311,8
+311,8
@@
cmd_autorecode (struct lexer *lexer, struct dataset *ds)
struct arc_item *item = xmalloc (sizeof *item);
item->width = width;
value_clone (&item->from, value, width);
struct arc_item *item = xmalloc (sizeof *item);
item->width = width;
value_clone (&item->from, value, width);
- item->missing = mv_is_value_missing_varwidth (&spec->mv, value,
spec->width,
-
MV_ANY
);
+ item->missing = mv_is_value_missing_varwidth (&spec->mv, value,
+
spec->width
);
item->value_label = ds_steal_cstr (&value_label);
hmap_insert (&spec->items->ht, &item->hmap_node, hash);
item->value_label = ds_steal_cstr (&value_label);
hmap_insert (&spec->items->ht, &item->hmap_node, hash);
@@
-386,7
+386,7
@@
cmd_autorecode (struct lexer *lexer, struct dataset *ds)
old_values->root, pivot_value_new_value (
&item->from, item->width,
(item->width
old_values->root, pivot_value_new_value (
&item->from, item->width,
(item->width
- ? &(struct fmt_spec) {
FMT_F, item->width, 0
}
+ ? &(struct fmt_spec) {
.type = FMT_F, .w = item->width
}
: &spec->format),
dict_get_encoding (dict)));
pivot_table_put2 (table, 0, old_value_idx,
: &spec->format),
dict_get_encoding (dict)));
pivot_table_put2 (table, 0, old_value_idx,
@@
-428,7
+428,7
@@
cmd_autorecode (struct lexer *lexer, struct dataset *ds)
mv_init (&mv, 0);
if (n_missing > 3)
mv_add_range (&mv, lo, hi);
mv_init (&mv, 0);
if (n_missing > 3)
mv_add_range (&mv, lo, hi);
- else
if (n_missing > 0)
+ else
for (size_t k = 0; k < n_missing; k++)
mv_add_num (&mv, lo + k);
var_set_missing_values (spec->dst, &mv);
for (size_t k = 0; k < n_missing; k++)
mv_add_num (&mv, lo + k);
var_set_missing_values (spec->dst, &mv);
@@
-449,7
+449,7
@@
cmd_autorecode (struct lexer *lexer, struct dataset *ds)
/* Free array. */
free (items);
}
/* Free array. */
free (items);
}
- add_transformation (ds,
autorecode_trns_proc, autorecode_trns_free
, arc);
+ add_transformation (ds,
&autorecode_trns_class
, arc);
for (size_t i = 0; i < n_dsts; i++)
free (dst_names[i]);
for (size_t i = 0; i < n_dsts; i++)
free (dst_names[i]);
@@
-552,7
+552,7
@@
compare_arc_items (const void *a_, const void *b_, const void *direction_)
return direction == ASCENDING ? cmp : -cmp;
}
return direction == ASCENDING ? cmp : -cmp;
}
-static
in
t
+static
enum trns_resul
t
autorecode_trns_proc (void *arc_, struct ccase **c,
casenumber case_idx UNUSED)
{
autorecode_trns_proc (void *arc_, struct ccase **c,
casenumber case_idx UNUSED)
{
@@
-567,7
+567,7
@@
autorecode_trns_proc (void *arc_, struct ccase **c,
size_t hash = value_hash (value, width, 0);
const struct arc_item *item = find_arc_item (spec->items, value, width,
hash);
size_t hash = value_hash (value, width, 0);
const struct arc_item *item = find_arc_item (spec->items, value, width,
hash);
-
case_data_rw (*c, spec->dst)->f
= item ? item->to : SYSMIS;
+
*case_num_rw (*c, spec->dst)
= item ? item->to : SYSMIS;
}
return TRNS_CONTINUE;
}
return TRNS_CONTINUE;
@@
-581,3
+581,9
@@
autorecode_trns_free (void *arc_)
arc_free (arc);
return true;
}
arc_free (arc);
return true;
}
+
+static const struct trns_class autorecode_trns_class = {
+ .name = "AUTORECODE",
+ .execute = autorecode_trns_proc,
+ .destroy = autorecode_trns_free,
+};