-/* 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 = avl_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);
- avl_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 = avl_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);
-
- buf = xmalloc (len + 3);
- strcpy (&buf[1], h->fn);
- buf[0] = buf[len + 1] = '"';
- buf[len + 2] = 0;
- return buf;
- }
- return h->name;
-}