- char *filename = ds_c_str (&tokstr);
- char *handle_name = xmalloc (strlen (filename) + 3);
- sprintf (handle_name, "\"%s\"", filename);
- handle = fh_create (handle_name, filename, fh_default_properties ());
- free (handle_name);
+ if (token != T_ID && token != T_STRING)
+ {
+ lex_error (_("expecting a file name or handle name"));
+ return NULL;
+ }
+
+ handle = NULL;
+ if (token == T_ID)
+ handle = fh_from_name (tokid);
+ if (handle == NULL)
+ handle = fh_from_filename (ds_c_str (&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,
+ fh_default_properties ());
+ free (handle_name);
+ }
+ else
+ handle = fh_create_scratch (tokid);
+ }
+ lex_get ();