X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpfm-read.c;h=7be8ea05472d3defb3143c7675fac4ecb6b57e4f;hb=d2f8593a1f1d39a3264682af0da898a3d67b68cf;hp=0a13086281c757ecc4733fa764e6a679436731a7;hpb=55dee937e22a49d01794ef772076d9f9d84199e9;p=pspp diff --git a/src/pfm-read.c b/src/pfm-read.c index 0a13086281..7be8ea0547 100644 --- a/src/pfm-read.c +++ b/src/pfm-read.c @@ -19,7 +19,7 @@ #include #include "pfm.h" -#include +#include "error.h" #include #include #include @@ -27,6 +27,7 @@ #include #include #include "alloc.h" +#include "case.h" #include "file-handle.h" #include "format.h" #include "getline.h" @@ -62,7 +63,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 @@ -82,12 +83,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); @@ -100,12 +103,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); @@ -220,20 +224,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; @@ -270,9 +275,6 @@ pfm_read_dictionary (struct file_handle *h, struct pfm_read_info *inf) msg (VM (2), _("Read portable-file dictionary successfully.")); -#if DEBUGGING - dump_dictionary (ext->dict); -#endif return ext->dict; lossage: @@ -617,11 +619,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) + v->type = translate_fmt (fmt[0]); + if (v->type == -1) lose ((h, _("%s: Bad format specifier byte (%d)."), vv->name, fmt[0])); - - v->type = translate_fmt[fmt[0]]; v->w = fmt[1]; v->d = fmt[2]; @@ -970,12 +970,13 @@ read_value_label (struct file_handle *h) return 0; } -/* Reads one case from portable file H into the value array PERM +/* Reads one case from portable file H into PERM according to the instuctions given in associated dictionary DICT, which must have the get.fv elements appropriately set. Returns nonzero only if successful. */ int -pfm_read_case (struct file_handle *h, union value *perm, struct dictionary *dict) +pfm_read_case (struct file_handle *h, struct ccase *perm, + struct dictionary *dict) { struct pfm_fhuser_ext *ext = h->ext; @@ -1019,9 +1020,9 @@ pfm_read_case (struct file_handle *h, union value *perm, struct dictionary *dict continue; if (v->type == NUMERIC) - perm[v->fv].f = temp[v->get.fv].f; + case_data_rw (perm, v->fv)->f = temp[v->get.fv].f; else - memcpy (&perm[v->fv].s, &temp[v->get.fv], v->width); + memcpy (case_data_rw (perm, v->fv)->s, &temp[v->get.fv], v->width); } local_free (temp);