*** empty log message ***
[pspp-builds.git] / src / pfm-read.c
index 99a7931ae6129679aa02cd0e08ec9c3d87010d33..ab33e700f724ab2c5c6562593be0351a673a3e17 100644 (file)
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA. */
 
-/* AIX requires this to be the first thing in the file.  */
 #include <config.h>
-#if __GNUC__
-#define alloca __builtin_alloca
-#else
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
-#pragma alloca
-#else
-#ifndef alloca                 /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#endif
-#endif
-#endif
-#endif
-
 #include "pfm.h"
-#include <assert.h>
+#include "error.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -79,7 +62,7 @@ static struct fh_ext_class pfm_r_class;
 
 static int 
 corrupt_msg (struct file_handle *h, const char *format,...)
-  __attribute__ ((format (printf, 2, 3)));
+     PRINTF_FORMAT (2, 3);
 
 /* Displays a corruption error. */
 static int
@@ -99,12 +82,14 @@ corrupt_msg (struct file_handle *h, const char *format, ...)
   {
     char *title;
     struct error e;
+    const char *filename;
 
     e.class = ME;
     getl_location (&e.where.filename, &e.where.line_number);
-    e.title = title = local_alloc (strlen (h->fn) + 80);
+    filename = handle_get_filename (h);
+    e.title = title = local_alloc (strlen (filename) + 80);
     sprintf (title, _("portable file %s corrupt at offset %ld: "),
-            h->fn, ftell (ext->file) - (82 - (long) (ext->bp - ext->buf)));
+            filename, ftell (ext->file) - (82 - (long) (ext->bp - ext->buf)));
     e.text = buf;
 
     err_vmsg (&e);
@@ -117,12 +102,13 @@ corrupt_msg (struct file_handle *h, const char *format, ...)
 
 /* Closes a portable file after we're done with it. */
 static void
-pfm_close (struct file_handle * h)
+pfm_close (struct file_handle *h)
 {
   struct pfm_fhuser_ext *ext = h->ext;
 
   if (EOF == fclose (ext->file))
-    msg (ME, _("%s: Closing portable file: %s."), h->fn, strerror (errno));
+    msg (ME, _("%s: Closing portable file: %s."),
+         handle_get_filename (h), strerror (errno));
   free (ext->vars);
   free (ext->trans);
   free (h->ext);
@@ -237,20 +223,21 @@ pfm_read_dictionary (struct file_handle *h, struct pfm_read_info *inf)
     {
       msg (ME, _("Cannot read file %s as portable file: already opened "
                 "for %s."),
-          fh_handle_name (h), h->class->name);
+          handle_get_name (h), h->class->name);
       return NULL;
     }
 
   msg (VM (1), _("%s: Opening portable-file handle %s for reading."),
-       fh_handle_filename (h), fh_handle_name (h));
+       handle_get_filename (h), handle_get_name (h));
 
   /* Open the physical disk file. */
   ext = xmalloc (sizeof (struct pfm_fhuser_ext));
-  ext->file = fopen (h->norm_fn, "rb");
+  ext->file = fopen (handle_get_filename (h), "rb");
   if (ext->file == NULL)
     {
       msg (ME, _("An error occurred while opening \"%s\" for reading "
-          "as a portable file: %s."), h->fn, strerror (errno));
+                 "as a portable file: %s."),
+           handle_get_filename (h), strerror (errno));
       err_cond_fail ();
       free (ext);
       return NULL;
@@ -634,11 +621,9 @@ static int
 convert_format (struct file_handle *h, int fmt[3], struct fmt_spec *v,
                struct variable *vv)
 {
-  if (fmt[0] < 0
-      || (size_t) fmt[0] >= sizeof translate_fmt / sizeof *translate_fmt)
-    lose ((h, _("%s: Bad format specifier byte %d."), vv->name, fmt[0]));
-
-  v->type = translate_fmt[fmt[0]];
+  v->type = translate_fmt (fmt[0]);
+  if (v->type == -1)
+    lose ((h, _("%s: Bad format specifier byte (%d)."), vv->name, fmt[0]));
   v->w = fmt[1];
   v->d = fmt[2];