From 1e06be73a426544652cdd7d73f001c962bac1a34 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 12 Jan 2006 03:39:01 +0000 Subject: [PATCH] Clean up file handle code in preparation to add temporary file handles. --- src/ChangeLog | 39 +++++++++++++ src/data-list.c | 8 +-- src/dfm-read.c | 26 ++++----- src/dfm-write.c | 12 ++-- src/file-handle-def.c | 104 +++++++++++++++++---------------- src/file-handle-def.h | 95 ++++++++++-------------------- src/file-handle.h | 13 ----- src/file-handle.q | 72 ++++++----------------- src/get.c | 4 +- src/main.c | 2 +- src/pfm-read.c | 8 +-- src/pfm-write.c | 8 +-- src/print.c | 4 +- src/regression.q | 2 +- src/sfm-read.c | 130 +++++++++++++++++++++--------------------- src/sfm-write.c | 8 +-- src/sysfile-info.c | 2 +- 17 files changed, 251 insertions(+), 286 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 24247c14a6..bc4527fb98 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,42 @@ +Wed Jan 11 19:28:39 2006 Ben Pfaff + + Clean up file handle code in preparation to add temporary file + handles. + + * file-handle-def.c: Lots of formatting cleanup. Added function + comments. + (struct file_handle) Renamed `length' member + to `record_width'. All references updated. + (fh_init) New function. Moved here from file-handle.q. + (fh_done) New function. Moved here from file-handle.q and + rewrote. + (get_handle_with_name) Renamed fh_from_name(). + (get_handle_for_filename) Renamed fh_from_filename(). + (create_file_handle) Renamed fh_create(). Changed to take a + `struct fh_properties' instead of discrete values. Updated all + references. + (create_file_handle_with_defaults) Removed. Updated all + references to use fh_create() with fh_default_properties(). + (fh_default_properties) New function. + (destroy_file_handle) Removed. The code is now in fh_done(). + (handle_get_name) Renamed fh_get_name(). + (handle_get_filename) Renamed fh_get_filename(). + (handle_get_record_width) Renamed fh_get_record_width(). + (handle_get_tab_width) Renamed fh_get_tab_width(). + + * file-handle-def.h: Formatting, comment fixes. + (enum file_handle_mode) Renamed struct fh_mode. + (struct fh_properties) New structure. + (fh_init) Move prototype here from file-handle.h. + (fh_done) Ditto. + (fh_close) Ditto. + + * file-handle.q: (static var handle_list) Removed. + (fh_parse) Don't add handle to handle_list, because + file-handle-def.c has its own list. + (fh_init) Moved to file-handle-def.c. + (fh_done) Ditto. + Sun Jan 9 01:09 Jason Stover * regression.q: (run_regression) Moved coefficient initialization diff --git a/src/data-list.c b/src/data-list.c index ab166f0d65..7ac36a1a5b 100644 --- a/src/data-list.c +++ b/src/data-list.c @@ -798,7 +798,7 @@ dump_fixed_table (const struct dls_var_spec *specs, if (fh != NULL) tab_title (t, 1, ngettext ("Reading %d record from file %s.", "Reading %d records from file %s.", rec_cnt), - rec_cnt, handle_get_filename (fh)); + rec_cnt, fh_get_filename (fh)); else tab_title (t, 1, ngettext ("Reading %d record from the command file.", "Reading %d records from the command file.", @@ -919,7 +919,7 @@ dump_free_table (const struct data_list_pgm *dls, if (fh != NULL) tab_title (t, 1, _("Reading free-form data from file %s."), - handle_get_filename (fh)); + fh_get_filename (fh)); else tab_title (t, 1, _("Reading free-form data from the command file.")); @@ -1585,7 +1585,7 @@ cmd_repeating_data (void) /* Calculate and check starts_end, cont_end if necessary. */ if (rpd->starts_end.num == 0 && rpd->starts_end.var == NULL) { - rpd->starts_end.num = fh != NULL ? handle_get_record_width (fh) : 80; + rpd->starts_end.num = fh != NULL ? fh_get_record_width (fh) : 80; if (rpd->starts_beg.num != 0 && rpd->starts_beg.num > rpd->starts_end.num) { @@ -1598,7 +1598,7 @@ cmd_repeating_data (void) } if (rpd->cont_end.num == 0 && rpd->cont_end.var == NULL) { - rpd->cont_end.num = fh != NULL ? handle_get_record_width (fh) : 80; + rpd->cont_end.num = fh != NULL ? fh_get_record_width (fh) : 80; if (rpd->cont_beg.num != 0 && rpd->cont_beg.num > rpd->cont_end.num) { diff --git a/src/dfm-read.c b/src/dfm-read.c index 6d173cf3e9..a739b5c32f 100644 --- a/src/dfm-read.c +++ b/src/dfm-read.c @@ -136,7 +136,7 @@ dfm_open_reader (struct file_handle *fh) r->fh = fh; if (fh != NULL) { - r->where.filename = handle_get_filename (fh); + r->where.filename = fh_get_filename (fh); r->where.line_number = 0; } r->file.file = NULL; @@ -146,7 +146,7 @@ dfm_open_reader (struct file_handle *fh) if (fh != NULL) { - r->file.filename = xstrdup (handle_get_filename (r->fh)); + r->file.filename = xstrdup (fh_get_filename (r->fh)); r->file.mode = "rb"; r->file.file = NULL; r->file.sequence_no = NULL; @@ -157,7 +157,7 @@ dfm_open_reader (struct file_handle *fh) { msg (ME, _("Could not open \"%s\" for reading " "as a data file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); err_cond_fail (); fh_close (fh,"data file", "rs"); free (r); @@ -241,7 +241,7 @@ static int read_file_record (struct dfm_reader *r) { assert (r->fh != NULL); - if (handle_get_mode (r->fh) == MODE_TEXT) + if (fh_get_mode (r->fh) == MODE_TEXT) { ds_clear (&r->line); if (!ds_gets (&r->line, r->file.file)) @@ -249,15 +249,15 @@ read_file_record (struct dfm_reader *r) if (ferror (r->file.file)) { msg (ME, _("Error reading file %s: %s."), - handle_get_name (r->fh), strerror (errno)); + fh_get_name (r->fh), strerror (errno)); err_cond_fail (); } return 0; } } - else if (handle_get_mode (r->fh) == MODE_BINARY) + else if (fh_get_mode (r->fh) == MODE_BINARY) { - size_t record_width = handle_get_record_width (r->fh); + size_t record_width = fh_get_record_width (r->fh); size_t amt; if (ds_length (&r->line) < record_width) @@ -269,10 +269,10 @@ read_file_record (struct dfm_reader *r) { if (ferror (r->file.file)) msg (ME, _("Error reading file %s: %s."), - handle_get_name (r->fh), strerror (errno)); + fh_get_name (r->fh), strerror (errno)); else if (amt != 0) msg (ME, _("%s: Partial record at end of file."), - handle_get_name (r->fh)); + fh_get_name (r->fh)); else return 0; @@ -315,7 +315,7 @@ dfm_eof (struct dfm_reader *r) { if (r->fh != NULL) msg (SE, _("Attempt to read beyond end-of-file on file %s."), - handle_get_name (r->fh)); + fh_get_name (r->fh)); else msg (SE, _("Attempt to read beyond END DATA.")); err_cond_fail (); @@ -360,14 +360,14 @@ dfm_expand_tabs (struct dfm_reader *r) r->flags |= DFM_TABS_EXPANDED; if (r->fh != NULL - && (handle_get_mode (r->fh) == MODE_BINARY - || handle_get_tab_width (r->fh) == 0 + && (fh_get_mode (r->fh) == MODE_BINARY + || fh_get_tab_width (r->fh) == 0 || memchr (ds_c_str (&r->line), '\t', ds_length (&r->line)) == NULL)) return; /* Expand tabs from r->line into r->scratch, and figure out new value for r->pos. */ - tab_width = r->fh != NULL ? handle_get_tab_width (r->fh) : 8; + tab_width = r->fh != NULL ? fh_get_tab_width (r->fh) : 8; ds_clear (&r->scratch); new_pos = 0; for (ofs = 0; ofs < ds_length (&r->line); ofs++) diff --git a/src/dfm-write.c b/src/dfm-write.c index 2bf3f15674..465e04ebd2 100644 --- a/src/dfm-write.c +++ b/src/dfm-write.c @@ -57,7 +57,7 @@ dfm_open_writer (struct file_handle *fh) w->file.file = NULL; w->bounce = NULL; - w->file.filename = xstrdup (handle_get_filename (w->fh)); + w->file.filename = xstrdup (fh_get_filename (w->fh)); w->file.mode = "wb"; w->file.file = NULL; w->file.sequence_no = NULL; @@ -69,7 +69,7 @@ dfm_open_writer (struct file_handle *fh) { msg (ME, _("An error occurred while opening \"%s\" for writing " "as a data file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); goto error; } @@ -89,10 +89,10 @@ dfm_put_record (struct dfm_writer *w, const char *rec, size_t len) { assert (w != NULL); - if (handle_get_mode (w->fh) == MODE_BINARY - && len < handle_get_record_width (w->fh)) + if (fh_get_mode (w->fh) == MODE_BINARY + && len < fh_get_record_width (w->fh)) { - size_t rec_width = handle_get_record_width (w->fh); + size_t rec_width = fh_get_record_width (w->fh); if (w->bounce == NULL) w->bounce = xmalloc (rec_width); memcpy (w->bounce, rec, len); @@ -104,7 +104,7 @@ dfm_put_record (struct dfm_writer *w, const char *rec, size_t len) if (fwrite (rec, len, 1, w->file.file) != 1) { msg (ME, _("Error writing file %s: %s."), - handle_get_name (w->fh), strerror (errno)); + fh_get_name (w->fh), strerror (errno)); err_cond_fail (); return 0; } diff --git a/src/file-handle-def.c b/src/file-handle-def.c index 6cf572b305..412c3e7aa8 100644 --- a/src/file-handle-def.c +++ b/src/file-handle-def.c @@ -47,8 +47,8 @@ struct file_handle char *filename; /* Filename as provided by user. */ struct file_identity *identity; /* For checking file identity. */ struct file_locator where; /* Used for reporting error messages. */ - enum file_handle_mode mode; /* File mode. */ - size_t length; /* Length of fixed-format records. */ + enum fh_mode mode; /* File mode. */ + size_t record_width; /* Length of fixed-format records. */ size_t tab_width; /* Tab width, 0=do not expand tabs. */ int open_cnt; /* 0=not open, otherwise # of openers. */ @@ -57,12 +57,36 @@ struct file_handle void *aux; /* Aux data pointer for owner if any. */ }; - static struct file_handle *file_handles; +/* File handle initialization routine. */ +void +fh_init (void) +{ + /* Currently nothing to do. */ +} + +/* Frees all the file handles. */ +void +fh_done (void) +{ + struct file_handle *fh, *next; + + for (fh = file_handles; fh != NULL; fh = next) + { + next = fh->next; + free (fh->name); + free (fh->filename); + fn_free_identity (fh->identity); + free (fh); + } + file_handles = NULL; +} +/* Returns the handle named HANDLE_NAME, or a null pointer if + there is none. */ struct file_handle * -get_handle_with_name (const char *handle_name) +fh_from_name (const char *handle_name) { struct file_handle *iter; @@ -72,8 +96,12 @@ get_handle_with_name (const char *handle_name) return NULL; } +/* Returns the handle for the file named FILENAME, + or a null pointer if none exists. + Different names for the same file (e.g. "x" and "./x") are + considered equivalent. */ struct file_handle * -get_handle_for_filename (const char *filename) +fh_from_filename (const char *filename) { struct file_identity *identity; struct file_handle *iter; @@ -100,27 +128,12 @@ get_handle_for_filename (const char *filename) return NULL; } - -/* File handle functions. */ - -struct file_handle * -create_file_handle_with_defaults (const char *handle_name, - const char *filename) -{ - return create_file_handle (handle_name, filename, - MODE_TEXT,1024, 4); -} - - /* Creates and returns a new file handle with the given values and defaults for other values. Adds the created file handle to the global list. */ struct file_handle * -create_file_handle (const char *handle_name, const char *filename, - enum file_handle_mode mode, - size_t length, - size_t tab_width - ) +fh_create (const char *handle_name, const char *filename, + const struct fh_properties *properties) { struct file_handle *handle; @@ -132,9 +145,9 @@ create_file_handle (const char *handle_name, const char *filename, handle->identity = fn_get_identity (filename); handle->where.filename = handle->filename; handle->where.line_number = 0; - handle->mode = mode; - handle->length = length; - handle->tab_width = tab_width; + handle->mode = properties->mode; + handle->record_width = properties->record_width; + handle->tab_width = properties->tab_width; handle->open_cnt = 0; handle->type = NULL; handle->aux = NULL; @@ -143,16 +156,16 @@ create_file_handle (const char *handle_name, const char *filename, return handle; } -void -destroy_file_handle(void *fh_, void *aux UNUSED) +/* Returns a set of default properties for a file handle. */ +const struct fh_properties * +fh_default_properties (void) { - struct file_handle *fh = fh_; - free (fh->name); - free (fh->filename); - fn_free_identity (fh->identity); - free (fh); + static const struct fh_properties default_properties = {MODE_TEXT, 1024, 4}; + return &default_properties; } +/* Returns an English description of MODE, + which is in the format of the MODE argument to fh_open(). */ static const char * mode_name (const char *mode) { @@ -162,7 +175,6 @@ mode_name (const char *mode) return mode[0] == 'r' ? "reading" : "writing"; } - /* Tries to open handle H with the given TYPE and MODE. TYPE is the sort of file, e.g. "system file". Only one given @@ -198,21 +210,21 @@ fh_open (struct file_handle *h, const char *type, const char *mode) { msg (SE, _("Can't open %s as a %s because it is " "already open as a %s"), - handle_get_name (h), type, h->type); + fh_get_name (h), type, h->type); return NULL; } else if (strcmp (h->open_mode, mode)) { msg (SE, _("Can't open %s as a %s for %s because it is " "already open for %s"), - handle_get_name (h), type, - mode_name (mode), mode_name (h->open_mode)); + fh_get_name (h), type, mode_name (mode), + mode_name (h->open_mode)); return NULL; } else if (h->open_mode[1] == 'e') { msg (SE, _("Can't re-open %s as a %s for %s"), - handle_get_name (h), type, mode_name (mode)); + fh_get_name (h), type, mode_name (mode)); return NULL; } } @@ -250,9 +262,6 @@ fh_close (struct file_handle *h, const char *type, const char *mode) return h->open_cnt; } - - - /* Returns the identifier of file HANDLE. If HANDLE was created by referring to a filename instead of a handle name, returns the filename, enclosed in double quotes. Return value is @@ -260,7 +269,7 @@ fh_close (struct file_handle *h, const char *type, const char *mode) Useful for printing error messages about use of file handles. */ const char * -handle_get_name (const struct file_handle *handle) +fh_get_name (const struct file_handle *handle) { assert (handle != NULL); return handle->name; @@ -268,15 +277,15 @@ handle_get_name (const struct file_handle *handle) /* Returns the name of the file associated with HANDLE. */ const char * -handle_get_filename (const struct file_handle *handle) +fh_get_filename (const struct file_handle *handle) { assert (handle != NULL); return handle->filename; } /* Returns the mode of HANDLE. */ -enum file_handle_mode -handle_get_mode (const struct file_handle *handle) +enum fh_mode +fh_get_mode (const struct file_handle *handle) { assert (handle != NULL); return handle->mode; @@ -284,19 +293,18 @@ handle_get_mode (const struct file_handle *handle) /* Returns the width of a logical record on HANDLE. */ size_t -handle_get_record_width (const struct file_handle *handle) +fh_get_record_width (const struct file_handle *handle) { assert (handle != NULL); - return handle->length; + return handle->record_width; } /* Returns the number of characters per tab stop for HANDLE, or zero if tabs are not to be expanded. Applicable only to MODE_TEXT files. */ size_t -handle_get_tab_width (const struct file_handle *handle) +fh_get_tab_width (const struct file_handle *handle) { assert (handle != NULL); return handle->tab_width; } - diff --git a/src/file-handle-def.h b/src/file-handle-def.h index 930477a917..f654e6632e 100644 --- a/src/file-handle-def.h +++ b/src/file-handle-def.h @@ -23,75 +23,42 @@ #include /* File modes. */ -enum file_handle_mode +enum fh_mode { MODE_TEXT, /* New-line delimited lines. */ MODE_BINARY /* Fixed-length records. */ }; -struct file_handle *create_file_handle_with_defaults (const char *handle_name, - const char *filename); - -struct file_handle *create_file_handle (const char *handle_name, - const char *filename, - enum file_handle_mode mode, - size_t length, - size_t tab_width - ); - - - -struct file_handle * -get_handle_with_name (const char *handle_name) ; - -struct file_handle * -get_handle_for_filename (const char *filename); - -const char *handle_get_name (const struct file_handle *handle); - -/* Returns the name of the file associated with HANDLE. */ -const char *handle_get_filename (const struct file_handle *handle) ; - - - -/* Returns the mode of HANDLE. */ -enum file_handle_mode handle_get_mode (const struct file_handle *handle) ; - -/* Returns the width of a logical record on HANDLE. */ -size_t handle_get_record_width (const struct file_handle *handle); - - -/* Returns the number of characters per tab stop for HANDLE, or - zero if tabs are not to be expanded. Applicable only to - MODE_TEXT files. */ -size_t handle_get_tab_width (const struct file_handle *handle); - - - -void destroy_file_handle(void *fh_, void *aux UNUSED); - - -/* Tries to open handle H with the given TYPE and MODE. - - TYPE is the sort of file, e.g. "system file". Only one given - type of access is allowed on a given file handle at once. - - MODE combines the read or write mode with the sharing mode. - The first character is 'r' for read, 'w' for write. The - second character is 's' to permit sharing, 'e' to require - exclusive access. - - Returns the address of a void * that the caller can use for - data specific to the file handle if successful, or a null - pointer on failure. For exclusive access modes the void * - will always be a null pointer at return. In shared access - modes the void * will necessarily be null only if no other - sharers are active. - - If successful, a reference to type is retained, so it should - probably be a string literal. */ - -void ** fh_open (struct file_handle *h, const char *type, const char *mode) ; +/* Properties of a file handle. */ +struct fh_properties + { + enum fh_mode mode; /* File mode. */ + size_t record_width; /* Length of fixed-format records. */ + size_t tab_width; /* Tab width, 0=do not expand tabs. */ + }; +void fh_init (void); +void fh_done (void); + +/* Creating file handles. */ +struct file_handle *fh_create (const char *handle_name, + const char *filename, + const struct fh_properties *); +const struct fh_properties *fh_default_properties (void); + +/* Finding file handles, based on handle name or filename. */ +struct file_handle *fh_from_name (const char *handle_name); +struct file_handle *fh_from_filename (const char *filename); + +/* Querying properties of file handles. */ +const char *fh_get_name (const struct file_handle *); +const char *fh_get_filename (const struct file_handle *); +enum fh_mode fh_get_mode (const struct file_handle *) ; +size_t fh_get_record_width (const struct file_handle *); +size_t fh_get_tab_width (const struct file_handle *); + +/* Opening and closing file handles. */ +void **fh_open (struct file_handle *, const char *type, const char *mode); +int fh_close (struct file_handle *, const char *type, const char *mode); #endif diff --git a/src/file-handle.h b/src/file-handle.h index eab80521a2..52cf8f121f 100644 --- a/src/file-handle.h +++ b/src/file-handle.h @@ -25,19 +25,6 @@ #include #include "file-handle-def.h" - - -void fh_init(void); -void fh_done(void); - - -/* Parsing handles. */ struct file_handle *fh_parse (void); - -/* Opening and closing handles. */ -void **fh_open (struct file_handle *, const char *type, const char *mode); -int fh_close (struct file_handle *, const char *type, const char *mode); - - #endif /* !file_handle.h */ diff --git a/src/file-handle.q b/src/file-handle.q index 24a91a9fed..0eb1373f7d 100644 --- a/src/file-handle.q +++ b/src/file-handle.q @@ -49,14 +49,11 @@ /* (declarations) */ /* (functions) */ - int cmd_file_handle (void) { char handle_name[LONG_NAME_LEN + 1]; - enum file_handle_mode mode = MODE_TEXT; - size_t length = 1024; - size_t tab_width = 4; + struct fh_properties properties = *fh_default_properties (); struct cmd_file_handle cmd; struct file_handle *handle; @@ -65,12 +62,12 @@ cmd_file_handle (void) return CMD_FAILURE; str_copy_trunc (handle_name, sizeof handle_name, tokid); - handle = get_handle_with_name (handle_name); + handle = fh_from_name (handle_name); if (handle != NULL) { msg (SE, _("File handle %s already refers to file %s. " "File handles cannot be redefined within a session."), - handle_name, handle_get_filename(handle)); + handle_name, fh_get_filename(handle)); return CMD_FAILURE; } @@ -97,36 +94,29 @@ cmd_file_handle (void) switch (cmd.mode) { case FH_CHARACTER: - mode = MODE_TEXT; + properties.mode = MODE_TEXT; if (cmd.sbc_tabwidth) - tab_width = cmd.n_tabwidth[0]; - else - tab_width = 4; + properties.tab_width = cmd.n_tabwidth[0]; break; case FH_IMAGE: - mode = MODE_BINARY; + properties.mode = MODE_BINARY; if (cmd.n_lrecl[0] == NOT_LONG) - { - msg (SE, _("Fixed-length records were specified on /RECFORM, but " - "record length was not specified on /LRECL. " - "Assuming 1024-character records.")); - length = 1024; - } + msg (SE, _("Fixed-length records were specified on /RECFORM, but " + "record length was not specified on /LRECL. " + "Assuming %d-character records."), + properties.record_width); else if (cmd.n_lrecl[0] < 1) - { - msg (SE, _("Record length (%ld) must be at least one byte. " - "1-character records will be assumed."), cmd.n_lrecl[0]); - length = 1; - } + msg (SE, _("Record length (%ld) must be at least one byte. " + "Assuming %d-character records."), + cmd.n_lrecl[0], properties.record_width); else - length = cmd.n_lrecl[0]; + properties.record_width = cmd.n_lrecl[0]; break; default: assert (0); } - handle = create_file_handle (handle_name, cmd.s_name, - mode, length, tab_width); + handle = fh_create (handle_name, cmd.s_name, &properties); free_file_handle (&cmd); return CMD_SUCCESS; @@ -136,11 +126,6 @@ cmd_file_handle (void) return CMD_FAILURE; } - - -static struct linked_list *handle_list; - - /* Parses a file handle name, which may be a filename as a string or a file handle name as an identifier. Returns the file handle or NULL on failure. */ @@ -158,44 +143,23 @@ fh_parse (void) /* Check for named handles first, then go by filename. */ handle = NULL; if (token == T_ID) - handle = get_handle_with_name (tokid); + handle = fh_from_name (tokid); if (handle == NULL) - handle = get_handle_for_filename (ds_c_str (&tokstr)); + handle = fh_from_filename (ds_c_str (&tokstr)); if (handle == NULL) { char *filename = ds_c_str (&tokstr); char *handle_name = xmalloc (strlen (filename) + 3); sprintf (handle_name, "\"%s\"", filename); - handle = create_file_handle_with_defaults (handle_name, filename); - ll_push_front(handle_list, handle); + handle = fh_create (handle_name, filename, fh_default_properties ()); free (handle_name); } lex_get (); - return handle; } - - -void -fh_init(void) -{ - handle_list = ll_create(destroy_file_handle,0); -} - -void -fh_done(void) -{ - if ( handle_list ) - { - ll_destroy(handle_list); - handle_list = 0; - } -} - - /* Local variables: mode: c diff --git a/src/get.c b/src/get.c index e47850c364..0b3c131c8d 100644 --- a/src/get.c +++ b/src/get.c @@ -928,7 +928,7 @@ cmd_match_files (void) if (iter->by[i] == NULL) { msg (SE, _("File %s lacks BY variable %s."), - iter->handle ? handle_get_name (iter->handle) : "*", + iter->handle ? fh_get_name (iter->handle) : "*", by[i]->name); free (by); goto error; @@ -1461,7 +1461,7 @@ mtf_merge_dictionary (struct dictionary *const m, struct mtf_file *f) msg (SE, _("Variable %s in file %s (%s) has different " "type or width from the same variable in " "earlier file (%s)."), - dv->name, handle_get_name (f->handle), + dv->name, fh_get_name (f->handle), var_type_description (dv), var_type_description (mv)); return 0; } diff --git a/src/main.c b/src/main.c index be22605b82..d52741d1bd 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,7 @@ #include "command.h" #include "dictionary.h" #include "error.h" -#include "file-handle.h" +#include "file-handle-def.h" #include "filename.h" #include "getl.h" #include "glob.h" diff --git a/src/pfm-read.c b/src/pfm-read.c index a1ee055095..3dd939ddae 100644 --- a/src/pfm-read.c +++ b/src/pfm-read.c @@ -82,7 +82,7 @@ error (struct pfm_reader *r, const char *msg, ...) e.class = ME; getl_location (&e.where.filename, &e.where.line_number); - filename = handle_get_filename (r->fh); + filename = fh_get_filename (r->fh); e.title = title = pool_alloc (r->pool, strlen (filename) + 80); sprintf (title, _("portable file %s corrupt at offset %ld: "), filename, ftell (r->file)); @@ -159,7 +159,7 @@ pfm_open_reader (struct file_handle *fh, struct dictionary **dict, if (setjmp (r->bail_out)) goto error; r->fh = fh; - r->file = pool_fopen (r->pool, handle_get_filename (r->fh), "rb"); + r->file = pool_fopen (r->pool, fh_get_filename (r->fh), "rb"); r->weight_index = -1; r->trans = NULL; r->var_cnt = 0; @@ -171,7 +171,7 @@ pfm_open_reader (struct file_handle *fh, struct dictionary **dict, { msg (ME, _("An error occurred while opening \"%s\" for reading " "as a portable file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); err_cond_fail (); goto error; } @@ -400,7 +400,7 @@ read_header (struct pfm_reader *r) for (i = 0; i < 8; i++) if (!match (r, "SPSSPORT"[i])) { - msg (SE, _("%s: Not a portable file."), handle_get_filename (r->fh)); + msg (SE, _("%s: Not a portable file."), fh_get_filename (r->fh)); longjmp (r->bail_out, 1); } } diff --git a/src/pfm-write.c b/src/pfm-write.c index c3562f34c4..ef94831e6f 100644 --- a/src/pfm-write.c +++ b/src/pfm-write.c @@ -106,7 +106,7 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict, mode = S_IRUSR | S_IRGRP | S_IROTH; if (opts.create_writeable) mode |= S_IWUSR | S_IWGRP | S_IWOTH; - fd = open (handle_get_filename (fh), O_WRONLY | O_CREAT | O_TRUNC, mode); + fd = open (fh_get_filename (fh), O_WRONLY | O_CREAT | O_TRUNC, mode); if (fd < 0) goto open_error; @@ -163,7 +163,7 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict, open_error: msg (ME, _("An error occurred while opening \"%s\" for writing " "as a portable file: %s."), - handle_get_filename (fh), strerror (errno)); + fh_get_filename (fh), strerror (errno)); err_cond_fail (); goto error; } @@ -199,7 +199,7 @@ buf_write (struct pfm_writer *w, const void *buf_, size_t nbytes) error: msg (ME, _("%s: Writing portable file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); return 0; } @@ -466,7 +466,7 @@ pfm_close_writer (struct pfm_writer *w) if (fclose (w->file) == EOF) msg (ME, _("%s: Closing portable file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); } free (w->vars); diff --git a/src/print.c b/src/print.c index 0376fa1cbb..ce14d6618b 100644 --- a/src/print.c +++ b/src/print.c @@ -191,7 +191,7 @@ internal_cmd_print (int f) if (prt.writer == NULL) goto error; - if (handle_get_mode (fh) == MODE_BINARY) + if (fh_get_mode (fh) == MODE_BINARY) prt.options |= PRT_BINARY; } @@ -837,7 +837,7 @@ dump_table (const struct file_handle *fh) if (fh != NULL) tab_title (t, 1, _("Writing %d record(s) to file %s."), - recno, handle_get_filename (fh)); + recno, fh_get_filename (fh)); else tab_title (t, 1, _("Writing %d record(s) to the listing file."), recno); tab_submit (t); diff --git a/src/regression.q b/src/regression.q index 68469e4428..29224be479 100644 --- a/src/regression.q +++ b/src/regression.q @@ -611,7 +611,7 @@ subcommand_export (int export, pspp_linreg_cache * c) assert (c != NULL); assert (model_file != NULL); assert (fp != NULL); - fp = fopen (handle_get_filename (model_file), "w"); + fp = fopen (fh_get_filename (model_file), "w"); fprintf (fp, "%s", reg_preamble); reg_print_getvar (fp, c); reg_print_categorical_encoding (fp, c); diff --git a/src/sfm-read.c b/src/sfm-read.c index 109c9a1a5a..9e25f74135 100644 --- a/src/sfm-read.c +++ b/src/sfm-read.c @@ -147,9 +147,9 @@ sfm_close_reader (struct sfm_reader *r) fh_close (r->fh, "system file", "rs"); if ( r->file ) { - if (fn_close (handle_get_filename (r->fh), r->file) == EOF) + if (fn_close (fh_get_filename (r->fh), r->file) == EOF) msg (ME, _("%s: Closing system file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); r->file = NULL; } free (r->vars); @@ -212,7 +212,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, /* Create and initialize reader. */ r = xmalloc (sizeof *r); r->fh = fh; - r->file = fn_open (handle_get_filename (fh), "rb"); + r->file = fn_open (fh_get_filename (fh), "rb"); r->reverse_endian = 0; r->fix_specials = 0; @@ -236,7 +236,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, { msg (ME, _("An error occurred while opening \"%s\" for reading " "as a system file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); err_cond_fail (); goto error; } @@ -254,7 +254,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, if (r->weight_idx < 0 || r->weight_idx >= r->value_cnt) lose ((ME, _("%s: Index of weighting variable (%d) is not between 0 " "and number of elements per case (%d)."), - handle_get_filename (r->fh), r->weight_idx, r->value_cnt)); + fh_get_filename (r->fh), r->weight_idx, r->value_cnt)); weight_var = var_by_idx[r->weight_idx]; @@ -262,10 +262,10 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, if (weight_var == NULL) lose ((ME, _("%s: Weighting variable may not be a continuation of " - "a long string variable."), handle_get_filename (fh))); + "a long string variable."), fh_get_filename (fh))); else if (weight_var->type == ALPHA) lose ((ME, _("%s: Weighting variable may not be a string variable."), - handle_get_filename (fh))); + fh_get_filename (fh))); dict_set_weight (*dict, weight_var); } @@ -292,7 +292,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, lose ((ME, _("%s: Orphaned variable index record (type 4). Type 4 " "records must always immediately follow type 3 " "records."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); case 6: if (!read_documents (r, *dict)) @@ -322,7 +322,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, bytes = data.size * data.count; if (bytes < data.size || bytes < data.count) lose ((ME, "%s: Record type %d subtype %d too large.", - handle_get_filename (r->fh), rec_type, data.subtype)); + fh_get_filename (r->fh), rec_type, data.subtype)); switch (data.subtype) { @@ -349,7 +349,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, { msg (MW, _("%s: Invalid subrecord length. " "Record: 7; Subrecord: 11"), - handle_get_filename (r->fh)); + fh_get_filename (r->fh)); skip = 1; } @@ -403,14 +403,14 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, { msg (MW, _("%s: Trailing garbage in long variable " "name map."), - handle_get_filename (r->fh)); + fh_get_filename (r->fh)); break; } if (!var_is_valid_name (long_name, false)) { msg (MW, _("%s: Long variable mapping to invalid " "variable name `%s'."), - handle_get_filename (r->fh), long_name); + fh_get_filename (r->fh), long_name); break; } @@ -420,7 +420,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, { msg (MW, _("%s: Long variable mapping for " "nonexistent variable %s."), - handle_get_filename (r->fh), short_name); + fh_get_filename (r->fh), short_name); break; } @@ -430,7 +430,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, { lose ((ME, _("%s: Duplicate long variable name `%s' " "within system file."), - handle_get_filename (r->fh), long_name)); + fh_get_filename (r->fh), long_name)); break; } @@ -458,7 +458,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, default: msg (MW, _("%s: Unrecognized record type 7, subtype %d " "encountered in system file."), - handle_get_filename (r->fh), data.subtype); + fh_get_filename (r->fh), data.subtype); skip = 1; } @@ -482,7 +482,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, default: corrupt_msg(MW, _("%s: Unrecognized record type %d."), - handle_get_filename (r->fh), rec_type); + fh_get_filename (r->fh), rec_type); } } @@ -515,7 +515,7 @@ read_machine_int32_info (struct sfm_reader *r, int size, int count) if (size != sizeof (int32) || count != 8) lose ((ME, _("%s: Bad size (%d) or count (%d) field on record type 7, " "subtype 3. Expected size %d, count 8."), - handle_get_filename (r->fh), size, count, sizeof (int32))); + fh_get_filename (r->fh), size, count, sizeof (int32))); assertive_buf_read (r, data, sizeof data, 0); if (r->reverse_endian) @@ -527,7 +527,7 @@ read_machine_int32_info (struct sfm_reader *r, int size, int count) lose ((ME, _("%s: Floating-point representation in system file is not " "IEEE-754. PSPP cannot convert between floating-point " "formats."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); #else #error Add support for your floating-point format. #endif @@ -542,7 +542,7 @@ read_machine_int32_info (struct sfm_reader *r, int size, int count) if (file_bigendian ^ (data[6] == 1)) lose ((ME, _("%s: File-indicated endianness (%s) does not match " "endianness intuited from file header (%s)."), - handle_get_filename (r->fh), + fh_get_filename (r->fh), file_bigendian ? _("big-endian") : _("little-endian"), data[6] == 1 ? _("big-endian") : (data[6] == 2 ? _("little-endian") : _("unknown")))); @@ -551,7 +551,7 @@ read_machine_int32_info (struct sfm_reader *r, int size, int count) if (data[7] != 2 && data[7] != 3) lose ((ME, _("%s: File-indicated character representation code (%s) is " "not ASCII."), - handle_get_filename (r->fh), + fh_get_filename (r->fh), (data[7] == 1 ? "EBCDIC" : (data[7] == 4 ? _("DEC Kanji") : _("Unknown"))))); @@ -571,7 +571,7 @@ read_machine_flt64_info (struct sfm_reader *r, int size, int count) if (size != sizeof (flt64) || count != 3) lose ((ME, _("%s: Bad size (%d) or count (%d) field on record type 7, " "subtype 4. Expected size %d, count 8."), - handle_get_filename (r->fh), size, count, sizeof (flt64))); + fh_get_filename (r->fh), size, count, sizeof (flt64))); assertive_buf_read (r, data, sizeof data, 0); if (r->reverse_endian) @@ -588,7 +588,7 @@ read_machine_flt64_info (struct sfm_reader *r, int size, int count) "for at least one of the three system values. SYSMIS: " "indicated %g, expected %g; HIGHEST: %g, %g; LOWEST: " "%g, %g."), - handle_get_filename (r->fh), (double) data[0], (double) SYSMIS, + fh_get_filename (r->fh), (double) data[0], (double) SYSMIS, (double) data[1], (double) FLT64_MAX, (double) data[2], (double) second_lowest_flt64); } @@ -613,7 +613,7 @@ read_header (struct sfm_reader *r, if (strncmp ("$FL2", hdr.rec_type, 4) != 0) lose ((ME, _("%s: Bad magic. Proper system files begin with " "the four characters `$FL2'. This file will not be read."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); /* Check eye-catcher string. */ memcpy (prod_name, hdr.prod_name, sizeof hdr.prod_name); @@ -655,7 +655,7 @@ read_header (struct sfm_reader *r, if (hdr.layout_code != 2) lose ((ME, _("%s: File layout code has unexpected value %d. Value " "should be 2, in big-endian or little-endian format."), - handle_get_filename (r->fh), hdr.layout_code)); + fh_get_filename (r->fh), hdr.layout_code)); r->reverse_endian = 1; bswap_int32 (&hdr.case_size); @@ -682,13 +682,13 @@ read_header (struct sfm_reader *r, if (r->case_cnt < -1 || r->case_cnt > INT_MAX / 2) lose ((ME, _("%s: Number of cases in file (%ld) is not between -1 and %d."), - handle_get_filename (r->fh), (long) r->case_cnt, INT_MAX / 2)); + fh_get_filename (r->fh), (long) r->case_cnt, INT_MAX / 2)); r->bias = hdr.bias; if (r->bias != 100.0) corrupt_msg (MW, _("%s: Compression bias (%g) is not the usual " "value of 100."), - handle_get_filename (r->fh), r->bias); + fh_get_filename (r->fh), r->bias); /* Make a file label only on the condition that the given label is not all spaces or nulls. */ @@ -811,7 +811,7 @@ read_variables (struct sfm_reader *r, if (sv.type != -1) lose ((ME, _("%s: position %d: String variable does not have " "proper number of continuation records."), - handle_get_filename (r->fh), i)); + fh_get_filename (r->fh), i)); r->vars[i].width = -1; @@ -822,35 +822,35 @@ read_variables (struct sfm_reader *r, else if (sv.type == -1) lose ((ME, _("%s: position %d: Superfluous long string continuation " "record."), - handle_get_filename (r->fh), i)); + fh_get_filename (r->fh), i)); /* Check fields for validity. */ if (sv.type < 0 || sv.type > 255) lose ((ME, _("%s: position %d: Bad variable type code %d."), - handle_get_filename (r->fh), i, sv.type)); + fh_get_filename (r->fh), i, sv.type)); if (sv.has_var_label != 0 && sv.has_var_label != 1) lose ((ME, _("%s: position %d: Variable label indicator field is not " - "0 or 1."), handle_get_filename (r->fh), i)); + "0 or 1."), fh_get_filename (r->fh), i)); if (sv.n_missing_values < -3 || sv.n_missing_values > 3 || sv.n_missing_values == -1) lose ((ME, _("%s: position %d: Missing value indicator field is not " - "-3, -2, 0, 1, 2, or 3."), handle_get_filename (r->fh), i)); + "-3, -2, 0, 1, 2, or 3."), fh_get_filename (r->fh), i)); /* Copy first character of variable name. */ if (!isalpha ((unsigned char) sv.name[0]) && sv.name[0] != '@' && sv.name[0] != '#') lose ((ME, _("%s: position %d: Variable name begins with invalid " "character."), - handle_get_filename (r->fh), i)); + fh_get_filename (r->fh), i)); if (islower ((unsigned char) sv.name[0])) msg (MW, _("%s: position %d: Variable name begins with lowercase letter " "%c."), - handle_get_filename (r->fh), i, sv.name[0]); + fh_get_filename (r->fh), i, sv.name[0]); if (sv.name[0] == '#') msg (MW, _("%s: position %d: Variable name begins with octothorpe " "(`#'). Scratch variables should not appear in system " "files."), - handle_get_filename (r->fh), i); + fh_get_filename (r->fh), i); name[0] = toupper ((unsigned char) (sv.name[0])); /* Copy remaining characters of variable name. */ @@ -864,7 +864,7 @@ read_variables (struct sfm_reader *r, { msg (MW, _("%s: position %d: Variable name character %d is " "lowercase letter %c."), - handle_get_filename (r->fh), i, j + 1, sv.name[j]); + fh_get_filename (r->fh), i, j + 1, sv.name[j]); name[j] = toupper ((unsigned char) (c)); } else if (isalnum (c) || c == '.' || c == '@' @@ -873,20 +873,20 @@ read_variables (struct sfm_reader *r, else lose ((ME, _("%s: position %d: character `\\%03o' (%c) is not valid in a " "variable name."), - handle_get_filename (r->fh), i, c, c)); + fh_get_filename (r->fh), i, c, c)); } name[j] = 0; if ( ! var_is_valid_name(name, false) ) lose ((ME, _("%s: Invalid variable name `%s' within system file."), - handle_get_filename (r->fh), name)); + fh_get_filename (r->fh), name)); /* Create variable. */ vv = (*var_by_idx)[i] = dict_create_var (dict, name, sv.type); if (vv == NULL) lose ((ME, _("%s: Duplicate variable name `%s' within system file."), - handle_get_filename (r->fh), name)); + fh_get_filename (r->fh), name)); var_set_short_name (vv, vv->name); @@ -910,7 +910,7 @@ read_variables (struct sfm_reader *r, if (len < 0 || len > 255) lose ((ME, _("%s: Variable %s indicates variable label of invalid " "length %d."), - handle_get_filename (r->fh), vv->name, len)); + fh_get_filename (r->fh), vv->name, len)); if ( len != 0 ) { @@ -931,7 +931,7 @@ read_variables (struct sfm_reader *r, if (vv->width > MAX_SHORT_STRING) lose ((ME, _("%s: Long string variable %s may not have missing " "values."), - handle_get_filename (r->fh), vv->name)); + fh_get_filename (r->fh), vv->name)); assertive_buf_read (r, mv, sizeof *mv * mv_cnt, 0); @@ -952,7 +952,7 @@ read_variables (struct sfm_reader *r, if (vv->type == ALPHA) lose ((ME, _("%s: String variable %s may not have missing " "values specified as a range."), - handle_get_filename (r->fh), vv->name)); + fh_get_filename (r->fh), vv->name)); if (mv[0] == r->lowest) mv_add_num_range (&vv->miss, LOWEST, mv[1]); @@ -979,12 +979,12 @@ read_variables (struct sfm_reader *r, if (long_string_count != 0) lose ((ME, _("%s: Long string continuation records omitted at end of " "dictionary."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); if (next_value != r->value_cnt) corrupt_msg(MW, _("%s: System file header indicates %d variable positions but " "%d were read from file."), - handle_get_filename (r->fh), r->value_cnt, next_value); + fh_get_filename (r->fh), r->value_cnt, next_value); return 1; @@ -1002,13 +1002,13 @@ parse_format_spec (struct sfm_reader *r, int32 s, f->type = translate_fmt ((s >> 16) & 0xff); if (f->type == -1) lose ((ME, _("%s: Bad format specifier byte (%d)."), - handle_get_filename (r->fh), (s >> 16) & 0xff)); + fh_get_filename (r->fh), (s >> 16) & 0xff)); f->w = (s >> 8) & 0xff; f->d = s & 0xff; if ((v->type == ALPHA) ^ ((formats[f->type].cat & FCAT_STRING) != 0)) lose ((ME, _("%s: %s variable %s has %s format specifier %s."), - handle_get_filename (r->fh), + fh_get_filename (r->fh), v->type == ALPHA ? _("String") : _("Numeric"), v->name, formats[f->type].cat & FCAT_STRING ? _("string") : _("numeric"), @@ -1061,7 +1061,7 @@ read_value_labels (struct sfm_reader *r, if ( n_labels >= ((int32) ~0) / sizeof *labels) { corrupt_msg(MW, _("%s: Invalid number of labels: %d. Ignoring labels."), - handle_get_filename (r->fh), n_labels); + fh_get_filename (r->fh), n_labels); n_labels = 0; } @@ -1104,7 +1104,7 @@ read_value_labels (struct sfm_reader *r, if (rec_type != 4) lose ((ME, _("%s: Variable index record (type 4) does not immediately " "follow value label record (type 3) as it should."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); } /* Read number of variables associated with value label from type 4 @@ -1115,7 +1115,7 @@ read_value_labels (struct sfm_reader *r, if (n_vars < 1 || n_vars > dict_get_var_cnt (dict)) lose ((ME, _("%s: Number of variables associated with a value label (%d) " "is not between 1 and the number of variables (%d)."), - handle_get_filename (r->fh), n_vars, dict_get_var_cnt (dict))); + fh_get_filename (r->fh), n_vars, dict_get_var_cnt (dict))); /* Read the list of variables. */ var = xnmalloc (n_vars, sizeof *var); @@ -1131,7 +1131,7 @@ read_value_labels (struct sfm_reader *r, if (var_idx < 1 || var_idx > r->value_cnt) lose ((ME, _("%s: Variable index associated with value label (%d) is " "not between 1 and the number of values (%d)."), - handle_get_filename (r->fh), var_idx, r->value_cnt)); + fh_get_filename (r->fh), var_idx, r->value_cnt)); /* Make sure it's a real variable. */ v = var_by_idx[var_idx - 1]; @@ -1139,11 +1139,11 @@ read_value_labels (struct sfm_reader *r, lose ((ME, _("%s: Variable index associated with value label (%d) " "refers to a continuation of a string variable, not to " "an actual variable."), - handle_get_filename (r->fh), var_idx)); + fh_get_filename (r->fh), var_idx)); if (v->type == ALPHA && v->width > MAX_SHORT_STRING) lose ((ME, _("%s: Value labels are not allowed on long string " "variables (%s)."), - handle_get_filename (r->fh), v->name)); + fh_get_filename (r->fh), v->name)); /* Add it to the list of variables. */ var[i] = v; @@ -1155,7 +1155,7 @@ read_value_labels (struct sfm_reader *r, lose ((ME, _("%s: Variables associated with value label are not all of " "identical type. Variable %s has %s type, but variable " "%s has %s type."), - handle_get_filename (r->fh), + fh_get_filename (r->fh), var[0]->name, var[0]->type == ALPHA ? _("string") : _("numeric"), var[i]->name, var[i]->type == ALPHA ? _("string") : _("numeric"))); @@ -1195,11 +1195,11 @@ read_value_labels (struct sfm_reader *r, if (var[0]->type == NUMERIC) msg (MW, _("%s: File contains duplicate label for value %g for " "variable %s."), - handle_get_filename (r->fh), label->value.f, v->name); + fh_get_filename (r->fh), label->value.f, v->name); else msg (MW, _("%s: File contains duplicate label for value `%.*s' " "for variable %s."), - handle_get_filename (r->fh), v->width, label->value.s, v->name); + fh_get_filename (r->fh), v->width, label->value.s, v->name); } } @@ -1240,10 +1240,10 @@ buf_read (struct sfm_reader *r, void *buf, size_t byte_cnt, size_t min_alloc) { if (ferror (r->file)) msg (ME, _("%s: Reading system file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); else corrupt_msg (ME, _("%s: Unexpected end of file."), - handle_get_filename (r->fh)); + fh_get_filename (r->fh)); return NULL; } return buf; @@ -1258,7 +1258,7 @@ buf_unread(struct sfm_reader *r, size_t byte_cnt) if ( 0 != fseek(r->file, -byte_cnt, SEEK_CUR)) { msg (ME, _("%s: Seeking system file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); } } @@ -1274,13 +1274,13 @@ read_documents (struct sfm_reader *r, struct dictionary *dict) if (dict_get_documents (dict) != NULL) lose ((ME, _("%s: System file contains multiple " "type 6 (document) records."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); assertive_buf_read (r, &line_cnt, sizeof line_cnt, 0); if (line_cnt <= 0) lose ((ME, _("%s: Number of document lines (%ld) " "must be greater than 0."), - handle_get_filename (r->fh), (long) line_cnt)); + fh_get_filename (r->fh), (long) line_cnt)); documents = buf_read (r, NULL, 80 * line_cnt, line_cnt * 80 + 1); /* FIXME? Run through asciify. */ @@ -1311,7 +1311,7 @@ buffer_input (struct sfm_reader *r) if (ferror (r->file)) { msg (ME, _("%s: Error reading file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); return 0; } r->ptr = r->buf; @@ -1349,7 +1349,7 @@ read_compressed_data (struct sfm_reader *r, flt64 *buf) if (buf_beg != buf) lose ((ME, _("%s: Compressed data is corrupted. Data ends " "in partial case."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); goto error; case 253: /* Code 253 indicates that the value is stored explicitly @@ -1358,7 +1358,7 @@ read_compressed_data (struct sfm_reader *r, flt64 *buf) if (!buffer_input (r)) { lose ((ME, _("%s: Unexpected end of file."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); goto error; } memcpy (buf++, r->ptr++, sizeof *buf); @@ -1400,7 +1400,7 @@ read_compressed_data (struct sfm_reader *r, flt64 *buf) { if (buf_beg != buf) lose ((ME, _("%s: Unexpected end of file."), - handle_get_filename (r->fh))); + fh_get_filename (r->fh))); goto error; } memcpy (r->x, r->ptr++, sizeof *buf); @@ -1517,10 +1517,10 @@ fread_ok (struct sfm_reader *r, void *buffer, size_t byte_cnt) { if (ferror (r->file)) msg (ME, _("%s: Reading system file: %s."), - handle_get_filename (r->fh), strerror (errno)); + fh_get_filename (r->fh), strerror (errno)); else if (read_bytes != 0) msg (ME, _("%s: Partial record at end of system file."), - handle_get_filename (r->fh)); + fh_get_filename (r->fh)); return 0; } } diff --git a/src/sfm-write.c b/src/sfm-write.c index d06a65f5a2..3b74efe151 100644 --- a/src/sfm-write.c +++ b/src/sfm-write.c @@ -151,7 +151,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, mode = S_IRUSR | S_IRGRP | S_IROTH; if (opts.create_writeable) mode |= S_IWUSR | S_IWGRP | S_IWOTH; - fd = open (handle_get_filename (fh), O_WRONLY | O_CREAT | O_TRUNC, mode); + fd = open (fh_get_filename (fh), O_WRONLY | O_CREAT | O_TRUNC, mode); if (fd < 0) goto open_error; @@ -257,7 +257,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, open_error: msg (ME, _("Error opening \"%s\" for writing as a system file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); err_cond_fail (); goto error; } @@ -749,7 +749,7 @@ buf_write (struct sfm_writer *w, const void *buf, size_t nbytes) if (fwrite (buf, nbytes, 1, w->file) != 1) { msg (ME, _("%s: Writing system file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); return 0; } return 1; @@ -929,7 +929,7 @@ sfm_close_writer (struct sfm_writer *w) if (fclose (w->file) == EOF) msg (ME, _("%s: Closing system file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); } free (w->buf); diff --git a/src/sysfile-info.c b/src/sysfile-info.c index b5f559e518..a9f074ab3b 100644 --- a/src/sysfile-info.c +++ b/src/sysfile-info.c @@ -98,7 +98,7 @@ cmd_sysfile_info (void) t = tab_create (2, 9, 0); tab_vline (t, TAL_1 | TAL_SPACING, 1, 0, 8); tab_text (t, 0, 0, TAB_LEFT, _("File:")); - tab_text (t, 1, 0, TAB_LEFT, handle_get_filename (h)); + tab_text (t, 1, 0, TAB_LEFT, fh_get_filename (h)); tab_text (t, 0, 1, TAB_LEFT, _("Label:")); { const char *label = dict_get_label (d); -- 2.30.2