X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fxforms%2Frecode.c;h=694439616b0b9fb09fcddb0c0ceb4a2774eeb66f;hb=42489b63e0b4bec2e20c2f55c9791234f7b41764;hp=7da3ab3a48dde46d6c9484e0a0f7e6bbdfdd5575;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp diff --git a/src/language/xforms/recode.c b/src/language/xforms/recode.c index 7da3ab3a48..694439616b 100644 --- a/src/language/xforms/recode.c +++ b/src/language/xforms/recode.c @@ -18,22 +18,29 @@ 02110-1301, USA. */ #include -#include "message.h" + #include #include #include -#include "alloc.h" -#include "case.h" -#include "command.h" -#include "data-in.h" -#include "dictionary.h" -#include "message.h" -#include "lexer.h" -#include "magic.h" -#include "pool.h" -#include "range-parser.h" -#include "str.h" -#include "variable.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -51,18 +58,25 @@ enum map_in_type MAP_CONVERT /* "123" => 123. */ }; +/* A value involved in a RECODE mapping. */ +union recode_value + { + double f; /* Numeric. */ + char *c; /* Short or long string. */ + }; + /* Describes input values to be mapped. */ struct map_in { enum map_in_type type; /* One of MAP_*. */ - union value x, y; /* Source values. */ + union recode_value x, y; /* Source values. */ }; /* Describes the value used as output from a mapping. */ struct map_out { bool copy_input; /* If true, copy input to output. */ - union value value; /* If copy_input false, recoded value. */ + union recode_value value; /* If copy_input false, recoded value. */ int width; /* If copy_input false, output value width. */ }; @@ -138,7 +152,7 @@ cmd_recode (void) || !parse_dst_vars (trns)) { recode_trns_free (trns); - return CMD_PART_SUCCESS; + return CMD_FAILURE; } /* Ensure that all the output strings are at least as wide @@ -153,7 +167,8 @@ cmd_recode (void) create_dst_vars (trns); /* Done. */ - add_transformation (recode_trns_proc, recode_trns_free, trns); + add_transformation (current_dataset, + recode_trns_proc, recode_trns_free, trns); } while (lex_match ('/')); @@ -166,7 +181,7 @@ cmd_recode (void) static bool parse_src_vars (struct recode_trns *trns) { - if (!parse_variables (default_dict, &trns->src_vars, &trns->var_cnt, + if (!parse_variables (dataset_dict (current_dataset), &trns->src_vars, &trns->var_cnt, PV_SAME_TYPE)) return false; pool_register (trns->pool, free, trns->src_vars); @@ -427,7 +442,7 @@ parse_dst_vars (struct recode_trns *trns) for (i = 0; i < trns->var_cnt; i++) { struct variable *v; - v = trns->dst_vars[i] = dict_lookup_var (default_dict, + v = trns->dst_vars[i] = dict_lookup_var (dataset_dict (current_dataset), trns->dst_names[i]); if (v == NULL && trns->dst_type == ALPHA) { @@ -510,9 +525,9 @@ create_dst_vars (struct recode_trns *trns) struct variable **var = &trns->dst_vars[i]; const char *name = trns->dst_names[i]; - *var = dict_lookup_var (default_dict, name); + *var = dict_lookup_var (dataset_dict (current_dataset), name); if (*var == NULL) - *var = dict_create_var_assert (default_dict, name, 0); + *var = dict_create_var_assert (dataset_dict (current_dataset), name, 0); assert ((*var)->type == trns->dst_type); } } @@ -547,7 +562,7 @@ find_src_numeric (struct recode_trns *trns, double value, struct variable *v) match = true; break; default: - abort (); + NOT_REACHED (); } if (match) @@ -580,21 +595,23 @@ find_src_string (struct recode_trns *trns, const char *value, int width) break; case MAP_CONVERT: { + union value uv; struct data_in di; di.s = value; di.e = value + width; - di.v = &out->value; + di.v = &uv; di.flags = DI_IGNORE_ERROR; di.f1 = di.f2 = 0; di.format.type = FMT_F; di.format.w = width; di.format.d = 0; match = data_in (&di); + out->value.f = uv.f; break; } default: - abort (); + NOT_REACHED (); } if (match) @@ -606,7 +623,7 @@ find_src_string (struct recode_trns *trns, const char *value, int width) /* Performs RECODE transformation. */ static int -recode_trns_proc (void *trns_, struct ccase *c, int case_idx UNUSED) +recode_trns_proc (void *trns_, struct ccase *c, casenum_t case_idx UNUSED) { struct recode_trns *trns = trns_; size_t i;