Had to get last call to multipass_split_output() inside
[pspp-builds.git] / src / recode.c
index 53a8e23ad5a943516529c290ab31a3a0d45181c8..e415dcf84bbcd89d7a18cb986267322043aadf50 100644 (file)
@@ -18,7 +18,7 @@
    02111-1307, USA. */
 
 #include <config.h>
-#include <assert.h>
+#include "error.h"
 #include <ctype.h>
 #include <math.h>
 #include <stdlib.h>
 #include "magic.h"
 #include "str.h"
 #include "var.h"
-
-#include "debug-print.h"
 \f
 /* Definitions. */
 
+/* Type of source value for RECODE. */
 enum
   {
     RCD_END,                   /* sentinel value */
@@ -107,20 +106,9 @@ static int parse_src_spec (struct rcd_var * rcd, int type, size_t max_src_width)
 static trns_proc_func recode_trns_proc;
 static trns_free_func recode_trns_free;
 static double convert_to_double (char *, int);
-
-#if DEBUGGING
-static void debug_print (struct rcd_var * head);
-#endif
 \f
 /* Parser. */
 
-/* First transformation in the list.  rcd is in this list. */
-static struct rcd_var *head;
-
-/* Variables in the current part of the recoding. */
-struct variable **v;
-int nv;
-
 /* Parses the RECODE transformation. */
 int
 cmd_recode (void)
@@ -147,10 +135,16 @@ cmd_recode (void)
      rcd_var's. */
   struct recode_trns *trns;
 
-  lex_match_id ("RECODE");
+  /* First transformation in the list.  rcd is in this list. */
+  struct rcd_var *head;
+
+  /* Variables in the current part of the recoding. */
+  struct variable **v;
+  int nv;
 
   /* Parses each specification between slashes. */
   head = rcd = xmalloc (sizeof *rcd);
+  v = NULL;
   for (;;)
     {
       /* Whether we've already encountered a specification for SYSMIS. */
@@ -401,6 +395,7 @@ cmd_recode (void)
       rcd = rcd->next = xmalloc (sizeof *rcd);
 
       free (v);
+      v = NULL;
     }
 
   if (token != '.')
@@ -428,13 +423,10 @@ cmd_recode (void)
   trns->codings = head;
   add_transformation ((struct trns_header *) trns);
 
-#if DEBUGGING
-  debug_print (head);
-#endif
-
   return CMD_SUCCESS;
 
  lossage:
+  free (v);
   {
     struct recode_trns t;
 
@@ -796,6 +788,7 @@ recode_trns_proc (struct trns_header * t, struct ccase * c,
          break;
         default:
           assert (0);
+          abort ();
        }
       if (!cp)
        continue;
@@ -823,112 +816,6 @@ recode_trns_proc (struct trns_header * t, struct ccase * c,
 
   return -1;
 }
-\f
-/* Debug output. */
-
-#if DEBUGGING
-static void
-dump_dest (struct rcd_var * v, union value * c)
-{
-  if ((v->flags & RCD_DEST_MASK) == RCD_DEST_NUMERIC)
-    if (c->f == SYSMIS)
-      printf ("=SYSMIS");
-    else if (c->f == -SYSMIS)
-      printf ("=COPY");
-    else
-      printf ("=%g", c->f);
-  else if (c->c)
-    printf ("=\"%s\"", c->c);
-  else
-    printf ("=COPY");
-}
-
-static void
-debug_print (struct rcd_var * head)
-{
-  struct rcd_var *iter, *start;
-  struct coding *c;
-
-  printf ("RECODE\n");
-  for (iter = head; iter; iter = iter->next)
-    {
-      start = iter;
-      printf ("  %s%s", iter == head ? "" : "/", iter->src->name);
-      while (iter->next && (iter->next->flags & RCD_MISC_DUPLICATE))
-       {
-         iter = iter->next;
-         printf (" %s", iter->src->name);
-       }
-      if (iter->has_sysmis)
-       {
-         printf ("(SYSMIS");
-         dump_dest (iter, &iter->sysmis);
-         printf (")");
-       }
-      for (c = iter->map; c->type != RCD_END; c++)
-       {
-         printf ("(");
-         if ((iter->flags & RCD_SRC_MASK) == RCD_SRC_NUMERIC)
-           switch (c->type)
-             {
-             case RCD_END:
-               printf (_("!!END!!"));
-               break;
-             case RCD_USER:
-               printf ("MISSING");
-               break;
-             case RCD_SINGLE:
-               printf ("%g", c->f1.f);
-               break;
-             case RCD_HIGH:
-               printf ("%g THRU HIGH", c->f1.f);
-               break;
-             case RCD_LOW:
-               printf ("LOW THRU %g", c->f1.f);
-               break;
-             case RCD_RANGE:
-               printf ("%g THRU %g", c->f1.f, c->f2.f);
-               break;
-             case RCD_ELSE:
-               printf ("ELSE");
-               break;
-             default:
-               printf (_("!!ERROR!!"));
-               break;
-             }
-         else
-           switch (c->type)
-             {
-             case RCD_SINGLE:
-               printf ("\"%s\"", c->f1.c);
-               break;
-             case RCD_ELSE:
-               printf ("ELSE");
-               break;
-             case RCD_CONVERT:
-               printf ("CONVERT");
-               break;
-             default:
-               printf (_("!!ERROR!!"));
-               break;
-             }
-         if (c->type != RCD_CONVERT)
-           dump_dest (iter, &c->t);
-         printf (")");
-       }
-      printf ("\n    INTO");
-      for (;;)
-       {
-         printf (" %s",
-               start->dest_name[0] ? start->dest_name : start->dest->name);
-         if (start == iter)
-           break;
-         start = start->next;
-       }
-      printf ("\n");
-    }
-}
-#endif
 
 /* Convert NPTR to a `long int' in base 10.  Returns the long int on
    success, NOT_LONG on failure.  On success stores a pointer to the