Encapsulated the static data of procedure.[ch] into a single object, to be
[pspp-builds.git] / src / language / xforms / compute.c
index 13499a067fb125754a4feff5816d97ca66fcc981..c4ea4c5a4db266958b2f20bfb78a1049f6c0f26a 100644 (file)
    02110-1301, USA. */
 
 #include <config.h>
-#include "message.h"
+
 #include <stdlib.h>
-#include "alloc.h"
-#include "case.h"
-#include "command.h"
-#include "dictionary.h"
-#include "message.h"
-#include "expressions/public.h"
-#include "lexer.h"
-#include "misc.h"
-#include "str.h"
-#include "variable.h"
+
+#include <data/case.h>
+#include <data/dictionary.h>
+#include <data/procedure.h>
+#include <data/transformations.h>
+#include <data/variable.h>
+#include <language/command.h>
+#include <language/expressions/public.h>
+#include <language/lexer/lexer.h>
+#include <libpspp/alloc.h>
+#include <libpspp/message.h>
+#include <libpspp/message.h>
+#include <libpspp/misc.h>
+#include <libpspp/str.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -90,7 +94,8 @@ cmd_compute (void)
   if (compute->rvalue == NULL)
     goto fail;
 
-  add_transformation (get_proc_func (lvalue), compute_trns_free, compute);
+  add_transformation (current_dataset, 
+                     get_proc_func (lvalue), compute_trns_free, compute);
 
   lvalue_finalize (lvalue, compute);
 
@@ -106,7 +111,7 @@ cmd_compute (void)
 
 /* Handle COMPUTE or IF with numeric target variable. */
 static int
-compute_num (void *compute_, struct ccase *c, int case_num)
+compute_num (void *compute_, struct ccase *c, casenum_t case_num)
 {
   struct compute_trns *compute = compute_;
 
@@ -121,7 +126,7 @@ compute_num (void *compute_, struct ccase *c, int case_num)
 /* Handle COMPUTE or IF with numeric vector element target
    variable. */
 static int
-compute_num_vec (void *compute_, struct ccase *c, int case_num)
+compute_num_vec (void *compute_, struct ccase *c, casenum_t case_num)
 {
   struct compute_trns *compute = compute_;
 
@@ -153,7 +158,7 @@ compute_num_vec (void *compute_, struct ccase *c, int case_num)
 
 /* Handle COMPUTE or IF with string target variable. */
 static int
-compute_str (void *compute_, struct ccase *c, int case_num)
+compute_str (void *compute_, struct ccase *c, casenum_t case_num)
 {
   struct compute_trns *compute = compute_;
 
@@ -168,7 +173,7 @@ compute_str (void *compute_, struct ccase *c, int case_num)
 /* Handle COMPUTE or IF with string vector element target
    variable. */
 static int
-compute_str_vec (void *compute_, struct ccase *c, int case_num)
+compute_str_vec (void *compute_, struct ccase *c, casenum_t case_num)
 {
   struct compute_trns *compute = compute_;
 
@@ -215,7 +220,7 @@ cmd_if (void)
   compute = compute_trns_create ();
 
   /* Test expression. */
-  compute->test = expr_parse (default_dict, EXPR_BOOLEAN);
+  compute->test = expr_parse (dataset_dict (current_dataset), EXPR_BOOLEAN);
   if (compute->test == NULL)
     goto fail;
 
@@ -231,7 +236,8 @@ cmd_if (void)
   if (compute->rvalue == NULL)
     goto fail;
 
-  add_transformation (get_proc_func (lvalue), compute_trns_free, compute);
+  add_transformation (current_dataset, 
+                     get_proc_func (lvalue), compute_trns_free, compute);
 
   lvalue_finalize (lvalue, compute);
 
@@ -263,7 +269,7 @@ parse_rvalue (const struct lvalue *lvalue)
 {
   bool is_numeric = lvalue_get_type (lvalue) == NUMERIC;
 
-  return expr_parse (default_dict, is_numeric ? EXPR_NUMBER : EXPR_STRING);
+  return expr_parse (dataset_dict (current_dataset), is_numeric ? EXPR_NUMBER : EXPR_STRING);
 }
 
 /* Returns a new struct compute_trns after initializing its fields. */
@@ -321,7 +327,7 @@ lvalue_parse (void)
   if (lex_look_ahead () == '(')
     {
       /* Vector. */
-      lvalue->vector = dict_lookup_vector (default_dict, tokid);
+      lvalue->vector = dict_lookup_vector (dataset_dict (current_dataset), tokid);
       if (lvalue->vector == NULL)
        {
          msg (SE, _("There is no vector named %s."), tokid);
@@ -332,7 +338,7 @@ lvalue_parse (void)
       lex_get ();
       if (!lex_force_match ('('))
        goto lossage;
-      lvalue->element = expr_parse (default_dict, EXPR_NUMBER);
+      lvalue->element = expr_parse (dataset_dict (current_dataset), EXPR_NUMBER);
       if (lvalue->element == NULL)
         goto lossage;
       if (!lex_force_match (')'))
@@ -358,7 +364,7 @@ lvalue_get_type (const struct lvalue *lvalue)
 {
   if (lvalue->vector == NULL) 
     {
-      struct variable *var = dict_lookup_var (default_dict, lvalue->var_name);
+      struct variable *var = dict_lookup_var (dataset_dict (current_dataset), lvalue->var_name);
       if (var == NULL)
         return NUMERIC;
       else
@@ -368,7 +374,7 @@ lvalue_get_type (const struct lvalue *lvalue)
     return lvalue->vector->var[0]->type;
 }
 
-/* Returns nonzero if LVALUE has a vector as its target. */
+/* Returns true if LVALUE has a vector as its target. */
 static bool
 lvalue_is_vector (const struct lvalue *lvalue) 
 {
@@ -382,9 +388,9 @@ lvalue_finalize (struct lvalue *lvalue, struct compute_trns *compute)
 {
   if (lvalue->vector == NULL)
     {
-      compute->variable = dict_lookup_var (default_dict, lvalue->var_name);
+      compute->variable = dict_lookup_var (dataset_dict (current_dataset), lvalue->var_name);
       if (compute->variable == NULL)
-         compute->variable = dict_create_var_assert (default_dict,
+         compute->variable = dict_create_var_assert (dataset_dict (current_dataset),
                                                      lvalue->var_name, 0);
 
       compute->fv = compute->variable->fv;
@@ -392,7 +398,7 @@ lvalue_finalize (struct lvalue *lvalue, struct compute_trns *compute)
 
       /* Goofy behavior, but compatible: Turn off LEAVE. */
       if (dict_class_from_id (compute->variable->name) != DC_SCRATCH)
-        compute->variable->reinit = 1;
+        compute->variable->leave = false;
     }
   else 
     {