Fixed a bug causing pspp to crash when computed variables had no format
[pspp-builds.git] / src / loop.c
index b7dac89557d66109e32254edf0c8077522b6088b..e9bb674749bf9626f2dfcf0b2f3719b5e2f6a3ef 100644 (file)
 #include <config.h>
 #include <assert.h>
 #include "alloc.h"
-#include "approx.h"
 #include "command.h"
 #include "do-ifP.h"
 #include "error.h"
 #include "expr.h"
 #include "lexer.h"
+#include "misc.h"
 #include "settings.h"
 #include "str.h"
 #include "var.h"
 
-#undef DEBUGGING
-/*#define DEBUGGING 1*/
 #include "debug-print.h"
 
 /* *INDENT-OFF* */
@@ -194,7 +192,7 @@ internal_cmd_loop (void)
   /* Parse indexing clause. */
   if (token == T_ID && lex_look_ahead () == '=')
     {
-      struct variable *v = find_variable (tokid);
+      struct variable *v = dict_lookup_var (default_dict, tokid);
 
       two->flags |= LPC_INDEX;
 
@@ -254,14 +252,9 @@ internal_cmd_loop (void)
   /* Find variable; create if necessary. */
   if (name[0])
     {
-      two->index = find_variable (name);
+      two->index = dict_lookup_var (default_dict, name);
       if (!two->index)
-       {
-         two->index = force_create_variable (&default_dict, name, NUMERIC, 0);
-#if DEBUGGING
-         envector (two->index);
-#endif
-       }
+        two->index = dict_create_var (default_dict, name, 0);
     }
   
   /* Push on control stack. */
@@ -378,8 +371,7 @@ loop_1_trns_proc (struct trns_header * trns, struct ccase * c)
       c->data[two->index->fv].f = t1.f;
 
       /* Throw out various pathological cases. */
-      if (!finite (t1.f) || !finite (t2.f) || !finite (t3.f)
-         || approx_eq (t2.f, 0.0))
+      if (!finite (t1.f) || !finite (t2.f) || !finite (t3.f) || t2.f == 0.0)
        return two->loop_term;
       debug_printf (("LOOP %s=%g TO %g BY %g.\n", two->index->name,
                     t1.f, t3.f, t2.f));
@@ -389,7 +381,7 @@ loop_1_trns_proc (struct trns_header * trns, struct ccase * c)
          two->flags &= ~LPC_RINDEX;
 
          /* incr>0 but init>term */
-         if (approx_gt (t1.f, t3.f))
+         if (t1.f > t3.f)
            return two->loop_term;
        }
       else
@@ -398,7 +390,7 @@ loop_1_trns_proc (struct trns_header * trns, struct ccase * c)
          two->flags |= LPC_RINDEX;
 
          /* incr<0 but init<term */
-         if (approx_lt (t1.f, t3.f))
+         if (t1.f < t3.f)
            return two->loop_term;
        }
 
@@ -439,7 +431,7 @@ loop_2_trns_proc (struct trns_header * trns, struct ccase * c)
   if (two->flags & LPC_RINDEX)
     {
       /* Test if we're at the end of the looping. */
-      if (approx_lt (two->curr, two->term))
+      if (two->curr < two->term)
        return two->loop_term;
 
       /* Set the current value into the case. */
@@ -452,7 +444,7 @@ loop_2_trns_proc (struct trns_header * trns, struct ccase * c)
   else if (two->flags & LPC_INDEX)
     {
       /* Test if we're at the end of the looping. */
-      if (approx_gt (two->curr, two->term))
+      if (two->curr > two->term)
        return two->loop_term;
 
       /* Set the current value into the case. */
@@ -540,7 +532,7 @@ cmd_break (void)
 }
 
 static int
-break_trns_proc (struct trns_header * trns, struct ccase * c unused)
+break_trns_proc (struct trns_header * trns, struct ccase * c UNUSED)
 {
   return ((struct break_trns *) trns)->loop_term;
 }