fbuf: New data structure for buffered file I/O.
[pspp] / src / data / por-file-writer.c
index 1cd6c6ed7a085eb83c1035c5eb8ecf9c819895d8..1853ad3a56a5877e265abbff7b2f5caa35313112 100644 (file)
@@ -32,7 +32,6 @@
 #include "data/casewriter.h"
 #include "data/dictionary.h"
 #include "data/file-handle-def.h"
-#include "data/file-name.h"
 #include "data/format.h"
 #include "data/make-file.h"
 #include "data/missing-values.h"
@@ -74,7 +73,7 @@ struct pfm_writer
 struct pfm_var
   {
     int width;                  /* 0=numeric, otherwise string var width. */
-    int fv;                     /* Starting case index. */
+    int case_index;             /* Index in case. */
   };
 
 static const struct casewriter_class por_file_casewriter_class;
@@ -131,7 +130,7 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict,
       const struct variable *dv = dict_get_var (dict, i);
       struct pfm_var *pv = &w->vars[i];
       pv->width = MIN (var_get_width (dv), MAX_POR_WIDTH);
-      pv->fv = var_get_case_index (dv);
+      pv->case_index = var_get_case_index (dv);
     }
 
   w->digits = opts.digits;
@@ -153,8 +152,7 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict,
   mode = 0444;
   if (opts.create_writeable)
     mode |= 0222;
-  w->rf = replace_file_start (fh_get_file_name (fh), "w", mode,
-                              &w->file, NULL);
+  w->rf = replace_file_start (fh, false, mode, &w->file);
   if (w->rf == NULL)
     {
       msg (ME, _("Error opening `%s' for writing as a portable file: %s."),
@@ -328,12 +326,12 @@ write_variables (struct pfm_writer *w, struct dictionary *dict)
 
   short_names_assign (dict);
 
-  if (dict_get_weight (dict) != NULL) 
+  if (dict_get_weight (dict) != NULL)
     {
       buf_write (w, "6", 1);
       write_string (w, var_get_short_name (dict_get_weight (dict), 0));
     }
-  
+
   buf_write (w, "4", 1);
   write_int (w, dict_get_var_cnt (dict));
 
@@ -458,11 +456,11 @@ por_file_casewriter_write (struct casewriter *writer, void *w_,
           struct pfm_var *v = &w->vars[i];
 
           if (v->width == 0)
-            write_float (w, case_num_idx (c, v->fv));
+            write_float (w, case_num_idx (c, v->case_index));
           else
             {
               write_int (w, v->width);
-              buf_write (w, case_str_idx (c, v->fv), v->width);
+              buf_write (w, case_str_idx (c, v->case_index), v->width);
             }
         }
     }