- h->recform = FH_RF_VARIABLE;
- h->mode = FH_MD_CHARACTER;
- h->ext = NULL;
- h->class = NULL;
-}
-
-/* Returns the handle corresponding to FILENAME. Creates the handle
- if no handle exists for that file. All filenames are normalized
- first, so different filenames referring to the same file will
- return the same file handle. */
-struct file_handle *
-fh_get_handle_by_filename (const char *filename)
-{
- struct file_handle f, *fp;
- char *fn;
- char *name;
- int len;
-
- /* Get filename. */
- fn = fn_normalize (filename);
- len = strlen (fn);
-
- /* Create handle name with invalid identifier character to prevent
- conflicts with handles created with FILE HANDLE. */
- name = xmalloc (len + 2);
- name[0] = '*';
- strcpy (&name[1], fn);
-
- f.name = name;
- fp = hsh_find (files, &f);
- if (!fp)
- {
- fp = xmalloc (sizeof *fp);
- init_file_handle (fp);
- fp->name = name;
- fp->norm_fn = fn;
- fp->where.filename = fp->fn = xstrdup (filename);
- hsh_force_insert (files, fp);
- }
- else
- {
- free (fn);
- free (name);
- }
- return fp;
-}
-
-/* Returns the handle with identifier NAME, if it exists; otherwise
- reports error to user and returns NULL. */
-struct file_handle *
-fh_get_handle_by_name (const char name[9])
-{
- struct file_handle f, *fp;
- f.name = (char *) name;
- fp = hsh_find (files, &f);
-
- if (!fp)
- msg (SE, _("File handle `%s' has not been previously declared on "
- "FILE HANDLE."), name);
- return fp;
-}
-
-/* Returns the identifier of file HANDLE. If HANDLE was created by
- referring to a filename (i.e., DATA LIST FILE='yyy' instead of FILE
- HANDLE XXX='yyy'), returns the filename, enclosed in double quotes.
- Return value is in a static buffer.
-
- Useful for printing error messages about use of file handles. */
-const char *
-fh_handle_name (struct file_handle *h)
-{
- static char *buf = NULL;
-
- if (buf)
- {
- free (buf);
- buf = NULL;
- }
- if (!h)
- return NULL;
-
- if (h->name[0] == '*')
- {
- int len = strlen (h->fn);
+ struct file_handle *handle;
+ struct file_handle_list *list;
+
+ /* Create and initialize file handle. */
+ handle = xmalloc (sizeof *handle);
+ handle->private = xmalloc (sizeof *handle->private);
+ handle->private->name = xstrdup (handle_name);
+ handle->private->filename = xstrdup (filename);
+ handle->private->identity = fn_get_identity (filename);
+ handle->private->where.filename = handle->private->filename;
+ handle->private->where.line_number = 0;
+ handle->private->mode = MODE_TEXT;
+ handle->private->length = 1024;
+ handle->ext = NULL;
+ handle->class = NULL;
+
+ /* Add file handle to global list. */
+ list = xmalloc (sizeof *list);
+ list->handle = handle;
+ list->next = file_handles;
+ file_handles = list;