X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fapply-dict.c;h=4cc8c10379644585db7b33f358854e9d6be59c05;hb=ed7bce25787929340a3f264f00dde7c979e571a9;hp=76820b7f9c41d2f0e717d7658ef65a48fa3d30f1;hpb=2bfc3a138f308ffb38634a92b23bdc7b62592324;p=pspp diff --git a/src/apply-dict.c b/src/apply-dict.c index 76820b7f9c..4cc8c10379 100644 --- a/src/apply-dict.c +++ b/src/apply-dict.c @@ -20,11 +20,12 @@ #include #include #include "command.h" +#include "dictionary.h" #include "error.h" #include "file-handle.h" #include "hash.h" #include "lexer.h" -#include "sfm.h" +#include "sfm-read.h" #include "str.h" #include "value-labels.h" #include "var.h" @@ -36,29 +37,28 @@ int cmd_apply_dictionary (void) { struct file_handle *handle; + struct sfm_reader *reader; struct dictionary *dict; int n_matched = 0; int i; - lex_match_id ("APPLY"); - lex_match_id ("DICTIONARY"); - lex_match_id ("FROM"); lex_match ('='); - handle = fh_parse_file_handle (); + handle = fh_parse (); if (!handle) return CMD_FAILURE; - dict = sfm_read_dictionary (handle, NULL); + reader = sfm_open_reader (handle, &dict, NULL); if (dict == NULL) return CMD_FAILURE; + sfm_close_reader (reader); - for (i = 0; i < dict->nvar; i++) + for (i = 0; i < dict_get_var_cnt (dict); i++) { - struct variable *s = dict->var[i]; - struct variable *t = find_variable (s->name); + struct variable *s = dict_get_var (dict, i); + struct variable *t = dict_lookup_var (default_dict, s->name); if (t == NULL) continue; @@ -150,6 +150,7 @@ cmd_apply_dictionary (void) t->miss_type = s->miss_type; memcpy (t->missing, s->missing, sizeof s->missing); } + skip_missing_values: ; if (s->type == NUMERIC) { @@ -163,31 +164,16 @@ cmd_apply_dictionary (void) "and target files.")); /* Weighting. */ - { - const int tfw = find_variable (default_dict.weight_var) != 0; - const int sfw = dict->weight_var[0] != 0; - struct variable *w; - - switch (10 * tfw + sfw) - { - case 10: - /* The working file retains its weighting variable. */ - break; - - case 00: - case 01: - /* Fall through to case 11. */ - - case 11: - w = find_variable (dict->weight_var); - if (w) - strcpy (default_dict.weight_var, dict->weight_var); - break; - } - } - skip_missing_values: ; + if (dict_get_weight (dict) != NULL) + { + struct variable *new_weight + = dict_lookup_var (default_dict, dict_get_weight (dict)->name); + + if (new_weight != NULL) + dict_set_weight (default_dict, new_weight); + } - sfm_maybe_close (handle); + sfm_close_reader (reader); return lex_end_of_command (); }