Implemented the recently used files menus.
[pspp] / src / language / stats / flip.c
index 594596c07550143938ae22e5ed443fe632bcb3da..5c6e77404879e1b1b340f87d60c8ad1ef8fc6fe9 100644 (file)
@@ -64,7 +64,7 @@ struct varname
 struct flip_pgm 
   {
     struct pool *pool;          /* Pool containing FLIP data. */
-    struct variable **var;      /* Variables to transpose. */
+    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. */
@@ -83,7 +83,7 @@ struct flip_pgm
   };
 
 static void destroy_flip_pgm (struct flip_pgm *);
-static struct case_sink *flip_sink_create (struct dictionary *d, struct flip_pgm *);
+static struct case_sink *flip_sink_create (struct dataset *ds, struct flip_pgm *);
 static struct case_source *flip_source_create (struct flip_pgm *);
 static bool flip_file (struct flip_pgm *);
 static int build_dictionary (struct dictionary *, struct flip_pgm *);
@@ -122,7 +122,7 @@ cmd_flip (struct lexer *lexer, struct dataset *ds)
   if (lex_match_id (lexer, "VARIABLES"))
     {
       lex_match (lexer, '=');
-      if (!parse_variables (lexer, dict, &flip->var, &flip->var_cnt,
+      if (!parse_variables_const (lexer, dict, &flip->var, &flip->var_cnt,
                             PV_NO_DUPLICATE))
        goto error;
       lex_match (lexer, '/');
@@ -158,7 +158,7 @@ cmd_flip (struct lexer *lexer, struct dataset *ds)
   /* Read the active file into a flip_sink. */
   flip->case_cnt = 0;
   proc_make_temporary_transformations_permanent (ds);
-  sink = flip_sink_create (dict, flip);
+  sink = flip_sink_create (ds, flip);
   if (sink == NULL)
     goto error;
   proc_set_sink (ds, sink);
@@ -289,7 +289,7 @@ build_dictionary (struct dictionary *dict, struct flip_pgm *flip)
      
 /* Creates a flip sink based on FLIP. */
 static struct case_sink *
-flip_sink_create (struct dictionary *dict, struct flip_pgm *flip) 
+flip_sink_create (struct dataset *ds, struct flip_pgm *flip) 
 {
   size_t i;
 
@@ -299,7 +299,8 @@ flip_sink_create (struct dictionary *dict, struct flip_pgm *flip)
   flip->file = pool_tmpfile (flip->pool);
   if (flip->file == NULL)
     {
-      msg (SE, _("Could not create temporary file for FLIP."));
+      msg (SE, _("Could not create temporary file for FLIP: %s."),
+           strerror (errno));
       return NULL;
     }
 
@@ -316,7 +317,10 @@ flip_sink_create (struct dictionary *dict, struct flip_pgm *flip)
 
   flip->case_cnt = 1;
 
-  return create_case_sink (&flip_sink_class, dict, flip);
+  return create_case_sink (&flip_sink_class,
+                          dataset_dict (ds),
+                          dataset_get_casefile_factory (ds),
+                          flip);
 }
 
 /* Writes case C to the FLIP sink.
@@ -445,7 +449,10 @@ flip_file (struct flip_pgm *flip)
 
       if (read_cases != fread (input_buf, case_bytes, read_cases, input_file)) 
         {
-          msg (SE, _("Error reading FLIP file: %s."), strerror (errno));
+          if (ferror (input_file))
+            msg (SE, _("Error reading FLIP file: %s."), strerror (errno));
+          else
+            msg (SE, _("Unexpected end of file reading FLIP file.")); 
           return false;
         }