X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmeans.q;h=483b6dc6d45a1f3b5e9888e81672349e91395f40;hb=2c9a5954d98d4dd508d8fbf2496f2bb819527a46;hp=99432a35ef3667c30483c065feed6944b73f9f29;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp diff --git a/src/means.q b/src/means.q index 99432a35ef..483b6dc6d4 100644 --- a/src/means.q +++ b/src/means.q @@ -20,18 +20,16 @@ #include #include #include -#include +#include "error.h" #include "alloc.h" -#include "avl.h" #include "command.h" +#include "hash.h" #include "lexer.h" #include "error.h" #include "magic.h" #include "var.h" /* (headers) */ -#undef DEBUGGING -#define DEBUGGING 1 #include "debug-print.h" /* (specification) @@ -50,10 +48,6 @@ /* (declarations) */ /* (functions) */ -#if DEBUGGING -static void debug_print (struct cmd_means *cmd); -#endif - /* TABLES: Variable lists for each dimension. */ int n_dim; /* Number of dimensions. */ int *nv_dim; /* Number of variables in each dimension. */ @@ -75,7 +69,6 @@ cmd_means (void) v_dim = NULL; v_var = NULL; - lex_match_id ("MEANS"); if (!parse_means (&cmd)) goto free; @@ -109,10 +102,6 @@ cmd_means (void) goto free; } -#if DEBUGGING - debug_print (&cmd); -#endif - success = CMD_SUCCESS; free: @@ -129,23 +118,14 @@ free: return success; } -/* Returns nonzero only if value V is valid as an endpoint for a - dependent variable in integer mode. */ -int -validate_dependent_endpoint (double V) -{ - return V == (int) V && V != LOWEST && V != HIGHEST; -} - /* Parses the TABLES subcommand. */ static int mns_custom_tables (struct cmd_means *cmd) { - struct dictionary *dict; - struct dictionary temp_dict; + struct var_set *var_set; if (!lex_match_id ("TABLES") - && (token != T_ID || !is_varname (tokid)) + && (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL) && token != T_ALL) return 2; lex_match ('='); @@ -157,30 +137,20 @@ mns_custom_tables (struct cmd_means *cmd) return 0; } - if (cmd->sbc_variables) - { - dict = &temp_dict; - temp_dict.var = v_var; - temp_dict.nvar = n_var; - - { - int i; - - temp_dict.var_by_name = avl_create (NULL, cmp_variable, NULL); - for (i = 0; i < temp_dict.nvar; i++) - avl_force_insert (temp_dict.var_by_name, temp_dict.var[i]); - } - } + if (cmd->sbc_variables) + var_set = var_set_create_from_array (v_var, n_var); else - dict = &default_dict; + var_set = var_set_create_from_dict (default_dict); + assert (var_set != NULL); do { int nvl; struct variable **vl; - - if (!parse_variables (dict, &vl, &nvl, PV_NO_DUPLICATE | PV_NO_SCRATCH)) - return 0; + + if (!parse_var_set_vars (var_set, &vl, &nvl, + PV_NO_DUPLICATE | PV_NO_SCRATCH)) + goto lossage; n_dim++; nv_dim = xrealloc (nv_dim, n_dim * sizeof (int)); @@ -203,7 +173,7 @@ mns_custom_tables (struct cmd_means *cmd) "CROSSBREAK, but not specified on " "VARIABLES."), v_dim[0][i]->name); - return 0; + goto lossage; } if (n_dim == 1) @@ -216,7 +186,7 @@ mns_custom_tables (struct cmd_means *cmd) msg (SE, _("LOWEST and HIGHEST may not be used " "for independent variables (%s)."), v_dim[0][i]->name); - return 0; + goto lossage; } if (v_inf->min != (int) v_inf->min || v_inf->max != (int) v_inf->max) @@ -225,7 +195,7 @@ mns_custom_tables (struct cmd_means *cmd) "have noninteger endpoints in their " "ranges."), v_dim[0][i]->name); - return 0; + goto lossage; } } } @@ -233,26 +203,12 @@ mns_custom_tables (struct cmd_means *cmd) } while (lex_match (T_BY)); - /* Check for duplicates. */ - { - int i; - - for (i = 0; i < default_dict.nvar; i++) - default_dict.var[i]->foo = 0; - for (i = 0; i < dict->nvar; i++) - if (dict->var[i]->foo++) - { - msg (SE, _("Variable %s is multiply specified on TABLES " - "or CROSSBREAK."), - dict->var[i]->name); - return 0; - } - } - - if (cmd->sbc_variables) - avl_destroy (temp_dict.var_by_name, NULL); - + var_set_destroy (var_set); return 1; + + lossage: + var_set_destroy (var_set); + return 0; } /* Parse CROSSBREAK subcommand. */ @@ -276,8 +232,8 @@ mns_custom_variables (struct cmd_means *cmd) { int i; - for (i = 0; i < default_dict.nvar; i++) - default_dict.var[i]->p.mns.min = SYSMIS; + for (i = 0; i < dict_get_var_cnt (default_dict); i++) + dict_get_var (default_dict, i)->p.mns.min = SYSMIS; } do @@ -286,7 +242,7 @@ mns_custom_variables (struct cmd_means *cmd) double min, max; - if (!parse_variables (&default_dict, &v_var, &n_var, + if (!parse_variables (default_dict, &v_var, &n_var, PV_APPEND | PV_NO_DUPLICATE | PV_NO_SCRATCH)) return 0; @@ -347,61 +303,6 @@ mns_custom_variables (struct cmd_means *cmd) return 1; } -#if DEBUGGING -static void -debug_print (struct cmd_means *cmd) -{ - int i; - - printf ("MEANS"); - - if (cmd->sbc_variables) - { - int j = 0; - - printf (" VARIABLES="); - for (i = 0; i < default_dict.nvar; i++) - { - struct variable *v = default_dict.var[i]; - - if (v->p.mns.min == SYSMIS) - continue; - if (j++) - printf (" "); - printf ("%s(", v->name); - if (v->p.mns.min == LOWEST) - printf ("LO"); - else - printf ("%g", v->p.mns.min); - printf (","); - if (v->p.mns.max == HIGHEST) - printf ("HI"); - else - printf ("%g", v->p.mns.max); - printf (")"); - } - printf ("\n"); - } - - printf (" TABLES="); - for (i = 0; i < n_dim; i++) - { - int j; - - if (i) - printf (" BY"); - - for (j = 0; j < nv_dim[i]; j++) - { - if (i || j) - printf (" "); - printf (v_dim[i][j]->name); - } - } - printf ("\n"); -} -#endif /* DEBUGGING */ - /* Local Variables: mode: c