Eliminated global variable current_dataset.
[pspp-builds.git] / src / language / data-io / file-handle.q
index e44afbc73abcb9c473ebf2208004aebc0f88abfc..b3d15619e91b5957fa48a229a396c90c4d2a31d7 100644 (file)
@@ -27,6 +27,7 @@
 #include <language/command.h>
 #include <language/lexer/lexer.h>
 #include <language/line-buffer.h>
+#include <libpspp/assertion.h>
 #include <libpspp/message.h>
 #include <libpspp/magic.h>
 #include <libpspp/str.h>
@@ -50,7 +51,7 @@
 /* (functions) */
 
 int
-cmd_file_handle (void)
+cmd_file_handle (struct dataset *ds)
 {
   char handle_name[LONG_NAME_LEN + 1];
   struct fh_properties properties = *fh_default_properties ();
@@ -75,7 +76,7 @@ cmd_file_handle (void)
   if (!lex_force_match ('/'))
     return CMD_CASCADING_FAILURE;
 
-  if (!parse_file_handle (&cmd))
+  if (!parse_file_handle (ds, &cmd, NULL))
     return CMD_CASCADING_FAILURE;
 
   if (lex_end_of_command () != CMD_SUCCESS)
@@ -109,7 +110,7 @@ cmd_file_handle (void)
         properties.record_width = cmd.n_lrecl[0];
       break;
     default:
-      assert (0);
+      NOT_REACHED ();
     }
 
   if (cmd.mode != FH_SCRATCH)
@@ -126,7 +127,7 @@ cmd_file_handle (void)
 }
 
 int
-cmd_close_file_handle (void
+cmd_close_file_handle (struct dataset *ds UNUSED
 {
   struct file_handle *handle;
 
@@ -154,11 +155,11 @@ referent_name (enum fh_referent referent)
     case FH_REF_SCRATCH:
       return _("scratch file");
     default:
-      abort ();
+      NOT_REACHED ();
     }
 }
 
-/* Parses a file handle name, which may be a filename as a string
+/* Parses a file handle name, which may be a file name as a string
    or a file handle name as an identifier.  The allowed types of
    file handle are restricted to those in REFERENT_MASK.  Returns
    the file handle when successful, a null pointer on failure. */
@@ -181,14 +182,14 @@ fh_parse (enum fh_referent referent_mask)
       if (token == T_ID) 
         handle = fh_from_name (tokid);
       if (handle == NULL) 
-        handle = fh_from_filename (ds_c_str (&tokstr)); 
+        handle = fh_from_file_name (ds_cstr (&tokstr)); 
       if (handle == NULL)
         {
           if (token != T_ID || tokid[0] != '#' || get_syntax () != ENHANCED) 
             {
-              char *filename = ds_c_str (&tokstr);
-              char *handle_name = xasprintf ("\"%s\"", filename);
-              handle = fh_create_file (handle_name, filename,
+              char *file_name = ds_cstr (&tokstr);
+              char *handle_name = xasprintf ("\"%s\"", file_name);
+              handle = fh_create_file (handle_name, file_name,
                                        fh_default_properties ());
               free (handle_name);
             }