Added new files resulting from directory restructuring.
[pspp-builds.git] / src / language / dictionary / weight.c
diff --git a/src/language/dictionary/weight.c b/src/language/dictionary/weight.c
new file mode 100644 (file)
index 0000000..b6d63c9
--- /dev/null
@@ -0,0 +1,61 @@
+/* PSPP - computes sample statistics.
+   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   Written by Ben Pfaff <blp@gnu.org>.
+
+   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 the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
+
+#include <config.h>
+#include "message.h"
+#include <stdio.h>
+#include "command.h"
+#include "dictionary.h"
+#include "message.h"
+#include "lexer.h"
+#include "str.h"
+#include "variable.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+int
+cmd_weight (void)
+{
+  if (lex_match_id ("OFF"))
+    dict_set_weight (default_dict, NULL);
+  else
+    {
+      struct variable *v;
+
+      lex_match (T_BY);
+      v = parse_variable ();
+      if (!v)
+       return CMD_CASCADING_FAILURE;
+      if (v->type == ALPHA)
+       {
+         msg (SE, _("The weighting variable must be numeric."));
+         return CMD_CASCADING_FAILURE;
+       }
+      if (dict_class_from_id (v->name) == DC_SCRATCH)
+       {
+         msg (SE, _("The weighting variable may not be scratch."));
+         return CMD_CASCADING_FAILURE;
+       }
+
+      dict_set_weight (default_dict, v);
+    }
+
+  return lex_end_of_command ();
+}