Move var_set and variable parsing declarations into new header.
[pspp-builds.git] / src / language / stats / flip.c
index f3286107ea525b1744aa3c7a7645cd2019dce9d6..0e9b56c5c87ecf7962db9cacd7083d9c29c8f2b8 100644 (file)
 #include <data/case-source.h>
 #include <data/case.h>
 #include <data/dictionary.h>
+#include <data/procedure.h>
 #include <data/settings.h>
 #include <data/value.h>
 #include <data/variable.h>
 #include <language/command.h>
 #include <language/lexer/lexer.h>
+#include <language/lexer/variable-parser.h>
 #include <libpspp/alloc.h>
 #include <libpspp/array.h>
 #include <libpspp/message.h>
@@ -44,7 +46,6 @@
 #include <libpspp/misc.h>
 #include <libpspp/pool.h>
 #include <libpspp/str.h>
-#include <procedure.h>
 
 #include "intprops.h"
 
@@ -91,14 +92,12 @@ int
 cmd_flip (void)
 {
   struct flip_pgm *flip;
+  struct case_sink *sink;
   bool ok;
 
-  if (temporary != 0)
-    {
-      msg (SW, _("FLIP ignores TEMPORARY.  "
-                 "Temporary transformations will be made permanent."));
-      cancel_temporary (); 
-    }
+  if (proc_make_temporary_transformations_permanent ())
+    msg (SW, _("FLIP ignores TEMPORARY.  "
+               "Temporary transformations will be made permanent."));
 
   flip = pool_create_container (struct flip_pgm, pool);
   flip->var = NULL;
@@ -150,10 +149,11 @@ cmd_flip (void)
 
   /* Read the active file into a flip_sink. */
   flip->case_cnt = 0;
-  temp_trns = temporary = 0;
-  vfm_sink = flip_sink_create (flip);
-  if (vfm_sink == NULL)
+  proc_make_temporary_transformations_permanent ();
+  sink = flip_sink_create (flip);
+  if (sink == NULL)
     goto error;
+  proc_set_sink (sink);
   flip->new_names_tail = NULL;
   ok = procedure (NULL, NULL);
 
@@ -174,7 +174,7 @@ cmd_flip (void)
   flip->case_size = dict_get_case_size (default_dict);
 
   /* Set up flipped data for reading. */
-  vfm_source = flip_source_create (flip);
+  proc_set_source (flip_source_create (flip));
 
   return ok ? lex_end_of_command () : CMD_CASCADING_FAILURE;
 
@@ -475,7 +475,11 @@ flip_file (struct flip_pgm *flip)
       case_idx += read_cases;
     }
 
-  pool_fclose (flip->pool, input_file);
+  if (pool_fclose (flip->pool, input_file) == EOF)
+    {
+      msg (SE, _("Error closing FLIP source file: %s."), strerror (errno));
+      return false;
+    }
   pool_unregister (flip->pool, input_buf);
   free (input_buf);