X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fweight.c;h=f1326f09d25fc6a70e99670b9ab68266f6c826f2;hb=92fb12eb06716d14c05b781f5d9dcde956d77c30;hp=1d7fe9eb306f35bbecb3f041d7626ce8e42b4d06;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp diff --git a/src/weight.c b/src/weight.c index 1d7fe9eb30..f1326f09d2 100644 --- a/src/weight.c +++ b/src/weight.c @@ -14,40 +14,27 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include -#include +#include "error.h" #include #include "command.h" +#include "dictionary.h" #include "error.h" #include "lexer.h" #include "str.h" #include "var.h" -/* Notes: - - If the weighting variable is deleted somehow (for instance by - end-of-scope of TEMPORARY), weighting must be canceled. - - Scratch vars may not be used for weighting. */ - -/* WEIGHT transformation. */ -struct weight_trns - { - struct trns_header h; - int src; /* `value' index of weighting variable. */ - int dest; /* `value' index of $WEIGHT. */ - }; +#include "gettext.h" +#define _(msgid) gettext (msgid) int cmd_weight (void) { - lex_match_id ("WEIGHT"); - if (lex_match_id ("OFF")) - default_dict.weight_var[0] = 0; + dict_set_weight (default_dict, NULL); else { struct variable *v; @@ -61,61 +48,14 @@ cmd_weight (void) msg (SE, _("The weighting variable must be numeric.")); return CMD_FAILURE; } - if (v->name[0] == '#') + if (dict_class_from_id (v->name) == DC_SCRATCH) { msg (SE, _("The weighting variable may not be scratch.")); return CMD_FAILURE; } - strcpy (default_dict.weight_var, v->name); + dict_set_weight (default_dict, v); } return lex_end_of_command (); } - -#if 0 /* FIXME: dead code. */ -static int -weight_trns_proc (any_trns * pt, ccase * c) -{ - weight_trns *t = (weight_trns *) pt; - - c->data[t->dest].f = c->data[t->src].f; - return -1; -} -#endif - -/* Global functions. */ - -/* Sets the weight_index member of dictionary D to an appropriate - value for the value of weight_var, and returns the weighting - variable if any or NULL if none. */ -struct variable * -update_weighting (struct dictionary * d) -{ - if (d->weight_var[0]) - { - struct variable *v = find_dict_variable (d, d->weight_var); - if (v && v->type == NUMERIC) - { - d->weight_index = v->fv; - return v; - } - else - { -#if GLOBAL_DEBUGGING - printf (_("bad weighting variable, canceling\n")); -#endif - d->weight_var[0] = 0; - } - } - - d->weight_index = -1; - return NULL; -} - -/* Turns off case weighting for dictionary D. */ -void -stop_weighting (struct dictionary * d) -{ - d->weight_var[0] = 0; -}