Beginning of VFM cleanup.
[pspp] / src / file-handle.q
index 309c409738e8f27483e71d1a872041f80928f214..77291a45e42836595c071150a754ab3691a0fa2d 100644 (file)
    02111-1307, USA. */
 
 #include <config.h>
+#include "file-handle.h"
 #include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
 #include "alloc.h"
-#include "avl.h"
 #include "filename.h"
-#include "file-handle.h"
 #include "command.h"
+#include "hash.h"
 #include "lexer.h"
 #include "getline.h"
 #include "error.h"
 #include "var.h"
 /* (headers) */
 
-#undef DEBUGGING
-/*#define DEBUGGING 1*/
 #include "debug-print.h"
 
-avl_tree *files;
+static struct hsh_table *files;
 struct file_handle *inline_file;
 
 static void init_file_handle (struct file_handle * handle);
@@ -68,7 +66,7 @@ cmd_file_handle (void)
 
   fp = NULL;
   if (files)
-    fp = avl_find (files, &handle_name_p);
+    fp = hsh_find (files, &handle_name_p);
   if (fp)
     {
       msg (SE, _("File handle %s had already been defined to refer to "
@@ -124,8 +122,9 @@ cmd_file_handle (void)
       fp->recform = FH_RF_VARIABLE;
       break;
     case FH_SPANNED:
-      msg (SE, _("/RECFORM SPANNED is not implemented, as the author doesn't "
-          "know what it is supposed to do.  Send the author a note."));
+      msg (SE, 
+          _("%s is not implemented, as the author doesn't know what it is supposed to do.  Send a note to %s.") ,
+          "/RECFORM SPANNED",PACKAGE_BUGREPORT);
       break;
     default:
       assert (0);
@@ -137,18 +136,18 @@ cmd_file_handle (void)
       fp->mode = FH_MD_CHARACTER;
       break;
     case FH_IMAGE:
-      msg (SE, _("/MODE IMAGE is not implemented, as the author doesn't know "
-          "what it is supposed to do.  Send the author a note."));
+      msg (SE, 
+          _("%s is not implemented, as the author doesn't know what it is supposed to do.  Send a note to %s.") ,
+          "/MODE IMAGE",PACKAGE_BUGREPORT);
       break;
     case FH_BINARY:
       fp->mode = FH_MD_BINARY;
       break;
     case FH_MULTIPUNCH:
-      msg (SE, _("/MODE MULTIPUNCH is not implemented.  If you care, "
-                "complain."));
+      msg (SE, _("%s is not implemented.  If you care, complain."),"/MODE MULTIPUNCH");
       break;
     case FH__360:
-      msg (SE, _("/MODE 360 is not implemented.  If you care, complain."));
+      msg (SE, _("%s is not implemented.  If you care, complain."),"/MODE 360");
       break;
     default:
       assert (0);
@@ -157,7 +156,7 @@ cmd_file_handle (void)
   fp->name = xstrdup (handle_name);
   fp->norm_fn = fn_normalize (cmd.s_name);
   fp->where.filename = fp->fn = cmd.s_name;
-  avl_force_insert (files, fp);
+  hsh_force_insert (files, fp);
 
   return CMD_SUCCESS;
 
@@ -202,7 +201,7 @@ fh_get_handle_by_filename (const char *filename)
   strcpy (&name[1], fn);
 
   f.name = name;
-  fp = avl_find (files, &f);
+  fp = hsh_find (files, &f);
   if (!fp)
     {
       fp = xmalloc (sizeof *fp);
@@ -210,7 +209,7 @@ fh_get_handle_by_filename (const char *filename)
       fp->name = name;
       fp->norm_fn = fn;
       fp->where.filename = fp->fn = xstrdup (filename);
-      avl_force_insert (files, fp);
+      hsh_force_insert (files, fp);
     }
   else
     {
@@ -227,7 +226,7 @@ fh_get_handle_by_name (const char name[9])
 {
   struct file_handle f, *fp;
   f.name = (char *) name;
-  fp = avl_find (files, &f);
+  fp = hsh_find (files, &f);
 
   if (!fp)
     msg (SE, _("File handle `%s' has not been previously declared on "
@@ -242,7 +241,7 @@ fh_get_handle_by_name (const char name[9])
 
    Useful for printing error messages about use of file handles.  */
 const char *
-fh_handle_name (struct file_handle *h)
+fh_handle_name (const struct file_handle *h)
 {
   static char *buf = NULL;
 
@@ -285,21 +284,32 @@ fh_close_handle (struct file_handle *h)
   h->ext = NULL;
 }
 
+/* Hashes the name of file handle H. */
+static unsigned
+hash_file_handle (const void *handle_, void *param UNUSED)
+{
+  const struct file_handle *handle = handle_;
+
+  return hsh_hash_string (handle->name);
+}
+
 /* Compares names of file handles A and B. */
 static int
-cmp_file_handle (const void *a, const void *b, void *foo unused)
+cmp_file_handle (const void *a_, const void *b_, void *foo UNUSED)
 {
-  return strcmp (((struct file_handle *) a)->name,
-                ((struct file_handle *) b)->name);
+  const struct file_handle *a = a_;
+  const struct file_handle *b = b_;
+
+  return strcmp (a->name, b->name);
 }
 
-/* Initialize the AVL tree of file handles; inserts the "inline file"
+/* Initialize the hash of file handles; inserts the "inline file"
    inline_file. */
 void
 fh_init_files (void)
 {
-  /* Create AVL tree. */
-  files = avl_create (NULL, cmp_file_handle, NULL);
+  /* Create hash. */
+  files = hsh_create (4, cmp_file_handle, hash_file_handle, NULL, NULL);
 
   /* Insert inline file. */
   inline_file = xmalloc (sizeof *inline_file);
@@ -308,7 +318,7 @@ fh_init_files (void)
   inline_file->where.filename
     = inline_file->fn = inline_file->norm_fn = (char *) _("<Inline File>");
   inline_file->where.line_number = 0;
-  avl_force_insert (files, inline_file);
+  hsh_force_insert (files, inline_file);
 }
 
 /* Parses a file handle name, which may be a filename as a string or