Fixed a bug causing pspp to crash when computed variables had no format
[pspp-builds.git] / src / count.c
index bbb41e55709828686c15f318331c8002086a653a..3b9a0ac098c752593f7b68f99ff9bf5955627e61 100644 (file)
@@ -21,7 +21,6 @@
 #include <assert.h>
 #include <stdlib.h>
 #include "alloc.h"
-#include "approx.h"
 #include "command.h"
 #include "error.h"
 #include "lexer.h"
@@ -56,8 +55,6 @@
    Perhaps simultaneity could be implemented as an option.  On the
    other hand, what good are the above commands?  */
 
-#undef DEBUGGING
-/*#define DEBUGGING 1*/
 #include "debug-print.h"
 \f
 /* Definitions. */
@@ -137,21 +134,6 @@ static void count_trns_free (struct trns_header *);
 static int parse_numeric_criteria (struct counting *);
 static int parse_string_criteria (struct counting *);
 
-int cmd_count (void);
-
-int
-internal_cmd_count (void)
-{
-  int code = cmd_count ();
-  if (!code)
-    {
-      struct count_trns c;
-      c.specs = head;
-      count_trns_free ((struct trns_header *) & c);
-    }
-  return code;
-}
-
 int
 cmd_count (void)
 {
@@ -181,7 +163,7 @@ cmd_count (void)
       /* Get destination struct variable, or at least its name. */
       if (!lex_force_id ())
        goto fail;
-      cnt->d = find_variable (tokid);
+      cnt->d = dict_lookup_var (default_dict, tokid);
       if (cnt->d)
        {
          if (cnt->d->type == ALPHA)
@@ -202,7 +184,8 @@ cmd_count (void)
        {
          c->next = NULL;
          c->v = NULL;
-         if (!parse_variables (NULL, &c->v, &c->n, PV_DUPLICATE | PV_SAME_TYPE))
+         if (!parse_variables (default_dict, &c->v, &c->n,
+                                PV_DUPLICATE | PV_SAME_TYPE))
            goto fail;
 
          if (!lex_force_match ('('))
@@ -232,12 +215,12 @@ cmd_count (void)
   for (cnt = head; cnt; cnt = cnt->next)
     if (!cnt->d)
       {
-       /* It's legal, though motivationally questionable, to count to
+       /* It's valid, though motivationally questionable, to count to
           the same dest var more than once. */
-       cnt->d = find_variable (cnt->n);
+       cnt->d = dict_lookup_var (default_dict, cnt->n);
 
-       if (!cnt->d)
-         cnt->d = force_create_variable (&default_dict, cnt->n, NUMERIC, 0);
+       if (cnt->d == NULL) 
+          cnt->d = dict_create_var_assert (default_dict, cnt->n, 0);
       }
 
 #if DEBUGGING
@@ -434,22 +417,22 @@ count_numeric (struct counting * cnt, struct ccase * c)
            assert (0);
            break;
          case CNT_SINGLE:
-           if (approx_ne (cmp, num->a))
+           if (cmp != num->a)
              break;
            counter++;
            goto done;
          case CNT_HIGH:
-           if (approx_lt (cmp, num->a))
+           if (cmp < num->a)
              break;
            counter++;
            goto done;
          case CNT_LOW:
-           if (approx_gt (cmp, num->a))
+           if (cmp > num->a)
              break;
            counter++;
            goto done;
          case CNT_RANGE:
-           if (approx_lt (cmp, num->a) || approx_gt (cmp, num->b))
+           if (cmp < num->a || cmp > num->b)
              break;
            counter++;
            goto done;