Use fseeko module from gnulib instead of our home-grown solution.
[pspp] / src / language / stats / flip.c
index 53d9873d538f427715296b9e04e6770876549abb..3fe43eb90858993a54b0f23bb6dc2ea07265c28f 100644 (file)
@@ -21,9 +21,6 @@
 #include <float.h>
 #include <limits.h>
 #include <stdlib.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
 
 #include <data/case.h>
 #include <data/casereader.h>
@@ -36,7 +33,6 @@
 #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/assertion.h>
 #include <libpspp/message.h>
@@ -46,6 +42,7 @@
 
 #include "intprops.h"
 #include "minmax.h"
+#include "xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -62,7 +59,6 @@ struct flip_pgm
   {
     struct pool *pool;          /* Pool containing FLIP data. */
     const struct variable **var;      /* Variables to transpose. */
-    int *idx_to_fv;             /* var[]->index to compacted sink case fv. */
     size_t var_cnt;             /* Number of elements in `var'. */
     int case_cnt;               /* Pre-flip case count. */
 
@@ -101,8 +97,6 @@ cmd_flip (struct lexer *lexer, struct dataset *ds)
 
   flip = pool_create_container (struct flip_pgm, pool);
   flip->var = NULL;
-  flip->idx_to_fv = dict_get_compacted_dict_index_to_case_index (dict);
-  pool_register (flip->pool, free, flip->idx_to_fv);
   flip->var_cnt = 0;
   flip->case_cnt = 0;
   flip->new_names = NULL;
@@ -171,7 +165,6 @@ cmd_flip (struct lexer *lexer, struct dataset *ds)
   flip->case_cnt = 1;
 
   /* Read the active file into a flip_sink. */
-  proc_make_temporary_transformations_permanent (ds);
   proc_discard_output (ds);
 
   input = proc_open (ds);
@@ -318,11 +311,10 @@ write_flip_case (struct flip_pgm *flip, const struct ccase *c)
   if (flip->new_names != NULL)
     {
       struct varname *v = pool_alloc (flip->pool, sizeof *v);
-      int fv = flip->idx_to_fv[var_get_dict_index (flip->new_names)];
       v->next = NULL;
       if (var_is_numeric (flip->new_names))
         {
-          double f = case_num_idx (c, fv);
+          double f = case_num (c, flip->new_names);
 
           if (f == SYSMIS)
             strcpy (v->name, "VSYSMIS");
@@ -336,7 +328,7 @@ write_flip_case (struct flip_pgm *flip, const struct ccase *c)
       else
        {
          int width = MIN (var_get_width (flip->new_names), MAX_SHORT_STRING);
-         memcpy (v->name, case_str_idx (c, fv), width);
+         memcpy (v->name, case_str (c, flip->new_names), width);
          v->name[width] = 0;
        }
 
@@ -350,15 +342,8 @@ write_flip_case (struct flip_pgm *flip, const struct ccase *c)
   /* Write to external file. */
   for (i = 0; i < flip->var_cnt; i++)
     {
-      double out;
-
-      if (var_is_numeric (flip->var[i]))
-        {
-          int fv = flip->idx_to_fv[var_get_dict_index (flip->var[i])];
-          out = case_num_idx (c, fv);
-        }
-      else
-        out = SYSMIS;
+      const struct variable *v = flip->var[i];
+      double out = var_is_numeric (v) ? case_num (c, v) : SYSMIS;
       fwrite (&out, sizeof out, 1, flip->file);
     }
   return true;
@@ -438,14 +423,6 @@ flip_file (struct flip_pgm *flip)
          for (j = 0; j < read_cases; j++)
            output_buf[j] = input_buf[i + j * flip->var_cnt];
 
-#ifndef HAVE_FSEEKO
-#define fseeko fseek
-#endif
-
-#ifndef HAVE_OFF_T
-#define off_t long int
-#endif
-
          if (fseeko (output_file,
                       sizeof *input_buf * (case_idx
                                            + (off_t) i * flip->case_cnt),