From: Ben Pfaff Date: Sun, 16 Apr 2006 02:42:39 +0000 (+0000) Subject: Remove last users of struct file_ext, and then get rid of struct X-Git-Tag: v0.6.0~987 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae9f5561a7fdeb23707bf355e06f3ca04824e738;p=pspp-builds.git Remove last users of struct file_ext, and then get rid of struct file_ext entirely. --- diff --git a/src/data/ChangeLog b/src/data/ChangeLog index b87a9395..ffe2b80f 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,12 @@ +Sat Apr 15 19:36:47 2006 Ben Pfaff + + Remove ill-considered file routines that are no longer used. + + * filename.c: (fn_open_ext) Removed. + (fn_close_ext) Removed. + + * filename.h: (struct file_ext) Removed. + Mon Apr 3 13:22:39 2006 Ben Pfaff * variable.c (var_is_valid_name): Move declarations before code diff --git a/src/data/filename.c b/src/data/filename.c index 323a78c5..d81dd076 100644 --- a/src/data/filename.c +++ b/src/data/filename.c @@ -782,113 +782,6 @@ fn_close (const char *fn, FILE *f) else return fclose (f); } - -/* More extensive file handling. */ - -/* File open routine that extends fn_open(). Opens or reopens a - file according to the contents of file_ext F. Returns nonzero on - success. If 0 is returned, errno is set to a sensible value. */ -int -fn_open_ext (struct file_ext *f) -{ - char *p; - - p = strstr (f->filename, "%d"); - if (p) - { - char *s = local_alloc (strlen (f->filename) - + INT_STRLEN_BOUND (int) - 1); - char *cp; - - memcpy (s, f->filename, p - f->filename); - cp = spprintf (&s[p - f->filename], "%d", *f->sequence_no); - strcpy (cp, &p[2]); - - if (f->file) - { - int error = 0; - - if (f->preclose) - if (f->preclose (f) == 0) - error = errno; - - if (EOF == fn_close (f->filename, f->file) || error) - { - f->file = NULL; - local_free (s); - - if (error) - errno = error; - - return 0; - } - - f->file = NULL; - } - - f->file = fn_open (s, f->mode); - local_free (s); - - if (f->file && f->postopen) - if (f->postopen (f) == 0) - { - int error = errno; - fn_close (f->filename, f->file); - errno = error; - - return 0; - } - - return (f->file != NULL); - } - else if (f->file) - return 1; - else - { - f->file = fn_open (f->filename, f->mode); - - if (f->file && f->postopen) - if (f->postopen (f) == 0) - { - int error = errno; - fn_close (f->filename, f->file); - errno = error; - - return 0; - } - - return (f->file != NULL); - } -} - -/* Properly closes the file associated with file_ext F, if any. - Return nonzero on success. If zero is returned, errno is set to a - sensible value. */ -int -fn_close_ext (struct file_ext *f) -{ - if (f->file) - { - int error = 0; - - if (f->preclose) - if (f->preclose (f) == 0) - error = errno; - - if (EOF == fn_close (f->filename, f->file) || error) - { - f->file = NULL; - - if (error) - errno = error; - - return 0; - } - - f->file = NULL; - } - return 1; -} #ifdef unix /* A file's identity. */ diff --git a/src/data/filename.h b/src/data/filename.h index 93fa6e2a..e7df800c 100644 --- a/src/data/filename.h +++ b/src/data/filename.h @@ -65,26 +65,5 @@ struct file_identity *fn_get_identity (const char *filename); void fn_free_identity (struct file_identity *); int fn_compare_file_identities (const struct file_identity *, const struct file_identity *); - -/* Extended file routines. */ -struct file_ext; - -typedef int (*file_callback) (struct file_ext *); - -/* File callbacks may not return zero to indicate failure unless they - set errno to a sensible value. */ -struct file_ext - { - char *filename; /* Filename. */ - const char *mode; /* Open mode, i.e, "wb". */ - FILE *file; /* File. */ - int *sequence_no; /* Page number, etc. */ - void *param; /* User data. */ - file_callback postopen; /* Called after FILE opened. */ - file_callback preclose; /* Called before FILE closed. */ - }; - -int fn_open_ext (struct file_ext *file); -int fn_close_ext (struct file_ext *file); #endif /* filename_h */ diff --git a/src/language/data-io/ChangeLog b/src/language/data-io/ChangeLog index 256cc20c..bfbe4043 100644 --- a/src/language/data-io/ChangeLog +++ b/src/language/data-io/ChangeLog @@ -1,3 +1,26 @@ +Sat Apr 15 19:38:13 2006 Ben Pfaff + + Remove last users of struct file_ext so we can get rid of it + entirely. + + * data-reader.c: (struct dfm_reader) Change file member from + struct file_ext to FILE *. Updated all references. + (dfm_close_reader) Close file with fn_close() instead of + fn_close_ext(). Also, make a copy of the file name from the file + handle before closing it, because we can't extract it after we + close the file. + (dfm_open_reader) Open file with fn_open() instead of + fn_open_ext(). + + * data-writer.c: (struct dfm_writer) Change file member + struct file_ext to FILE *. Updated all references. + (dfm_close_writer) Close file with fn_close() instead of + fn_close_ext(). Also, make a copy of the file name from the file + handle before closing it, because we can't extract it after we + close the file. + (dfm_open_writer) Open file with fn_open() instead of + fn_open_ext(). + Sat Apr 15 18:00:32 2006 Ben Pfaff * data-list.c: Add prototype to suppress warning for diff --git a/src/language/data-io/data-reader.c b/src/language/data-io/data-reader.c index 6f717fd2..0a4baf67 100644 --- a/src/language/data-io/data-reader.c +++ b/src/language/data-io/data-reader.c @@ -56,7 +56,7 @@ struct dfm_reader struct string line; /* Current line. */ struct string scratch; /* Extra line buffer. */ enum dfm_reader_flags flags; /* Zero or more of DFM_*. */ - struct file_ext file; /* Associated file. */ + FILE *file; /* Associated file. */ size_t pos; /* Offset in line of current character. */ unsigned eof_cnt; /* # of attempts to advance past EOF. */ }; @@ -67,21 +67,22 @@ dfm_close_reader (struct dfm_reader *r) { int still_open; bool is_inline; + char *file_name; if (r == NULL) return; is_inline = r->fh == fh_inline_file (); + file_name = is_inline ? NULL : xstrdup (fh_get_filename (r->fh)); still_open = fh_close (r->fh, "data file", "rs"); - if (still_open) - return; - - if (!is_inline) + if (still_open) { - fn_close_ext (&r->file); - free (r->file.filename); - r->file.filename = NULL; + free (file_name); + return; } + + if (!is_inline) + fn_close (file_name, r->file); else { /* Skip any remaining data on the inline file. */ @@ -96,6 +97,7 @@ dfm_close_reader (struct dfm_reader *r) ds_destroy (&r->line); ds_destroy (&r->scratch); free (r); + free (file_name); } /* Opens the file designated by file handle FH for reading as a @@ -125,15 +127,8 @@ dfm_open_reader (struct file_handle *fh) { r->where.filename = fh_get_filename (fh); r->where.line_number = 0; - r->file.file = NULL; - r->file.filename = xstrdup (fh_get_filename (r->fh)); - r->file.mode = "rb"; - r->file.file = NULL; - r->file.sequence_no = NULL; - r->file.param = NULL; - r->file.postopen = NULL; - r->file.preclose = NULL; - if (!fn_open_ext (&r->file)) + r->file = fn_open (fh_get_filename (fh), "rb"); + if (r->file == NULL) { msg (ME, _("Could not open \"%s\" for reading as a data file: %s."), fh_get_filename (r->fh), strerror (errno)); @@ -151,7 +146,7 @@ dfm_open_reader (struct file_handle *fh) bool dfm_reader_error (const struct dfm_reader *r) { - return fh_get_referent (r->fh) == FH_REF_FILE && ferror (r->file.file); + return fh_get_referent (r->fh) == FH_REF_FILE && ferror (r->file); } /* Reads a record from the inline file into R. @@ -200,9 +195,9 @@ read_file_record (struct dfm_reader *r) if (fh_get_mode (r->fh) == FH_MODE_TEXT) { ds_clear (&r->line); - if (!ds_gets (&r->line, r->file.file)) + if (!ds_gets (&r->line, r->file)) { - if (ferror (r->file.file)) + if (ferror (r->file)) msg (ME, _("Error reading file %s: %s."), fh_get_name (r->fh), strerror (errno)); return false; @@ -216,11 +211,10 @@ read_file_record (struct dfm_reader *r) if (ds_length (&r->line) < record_width) ds_rpad (&r->line, record_width, 0); - amt = fread (ds_c_str (&r->line), 1, record_width, - r->file.file); + amt = fread (ds_c_str (&r->line), 1, record_width, r->file); if (record_width != amt) { - if (ferror (r->file.file)) + if (ferror (r->file)) msg (ME, _("Error reading file %s: %s."), fh_get_name (r->fh), strerror (errno)); else if (amt != 0) diff --git a/src/language/data-io/data-writer.c b/src/language/data-io/data-writer.c index 57a5b9f7..eb5fe019 100644 --- a/src/language/data-io/data-writer.c +++ b/src/language/data-io/data-writer.c @@ -35,7 +35,7 @@ struct dfm_writer { struct file_handle *fh; /* File handle. */ - struct file_ext file; /* Associated file. */ + FILE *file; /* Associated file. */ char *bounce; /* Bounce buffer for fixed-size fields. */ }; @@ -54,18 +54,10 @@ dfm_open_writer (struct file_handle *fh) w = *aux = xmalloc (sizeof *w); w->fh = fh; - w->file.file = NULL; + w->file = fn_open (fh_get_filename (w->fh), "wb"); w->bounce = NULL; - w->file.filename = xstrdup (fh_get_filename (w->fh)); - w->file.mode = "wb"; - w->file.file = NULL; - w->file.sequence_no = NULL; - w->file.param = NULL; - w->file.postopen = NULL; - w->file.preclose = NULL; - - if (!fn_open_ext (&w->file)) + if (w->file == NULL) { msg (ME, _("An error occurred while opening \"%s\" for writing " "as a data file: %s."), @@ -84,7 +76,7 @@ dfm_open_writer (struct file_handle *fh) bool dfm_write_error (const struct dfm_writer *writer) { - return ferror (writer->file.file); + return ferror (writer->file); } /* Writes record REC having length LEN to the file corresponding to @@ -110,7 +102,7 @@ dfm_put_record (struct dfm_writer *w, const char *rec, size_t len) len = rec_width; } - fwrite (rec, len, 1, w->file.file); + fwrite (rec, len, 1, w->file); return !dfm_write_error (w); } @@ -118,29 +110,29 @@ dfm_put_record (struct dfm_writer *w, const char *rec, size_t len) bool dfm_close_writer (struct dfm_writer *w) { + char *file_name; bool ok; if (w == NULL) return true; + file_name = xstrdup (fh_get_name (w->fh)); if (fh_close (w->fh, "data file", "ws")) - return true; + { + free (file_name); + return true; + } ok = true; - if (w->file.file != NULL) + if (w->file != NULL) { - ok = !dfm_write_error (w); - if (!fn_close_ext (&w->file)) - ok = false; + ok = !dfm_write_error (w) && !fn_close (file_name, w->file); if (!ok) - msg (ME, _("I/O error occurred writing data file \"%s\"."), - fh_get_filename (w->fh)); - - free (w->file.filename); - w->file.filename = NULL; + msg (ME, _("I/O error occurred writing data file \"%s\"."), file_name); } free (w->bounce); free (w); + free (file_name); return ok; }