handles.
+Wed Jan 11 19:28:39 2006 Ben Pfaff <blp@gnu.org>
+
+ 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 <jason@sakla.net>
* regression.q: (run_regression) Moved coefficient initialization
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.",
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."));
/* 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)
{
}
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)
{
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;
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;
{
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);
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))
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)
{
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;
{
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 ();
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++)
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;
{
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;
}
{
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);
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;
}
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. */
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;
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;
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;
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;
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)
{
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
{
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;
}
}
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
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;
/* 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;
/* 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;
}
-
#include <config.h>
/* 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
#include <stddef.h>
#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 */
/* (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;
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;
}
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;
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. */
/* 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
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;
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;
}
#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"
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));
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;
{
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;
}
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);
}
}
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;
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;
}
error:
msg (ME, _("%s: Writing portable file: %s."),
- handle_get_filename (w->fh), strerror (errno));
+ fh_get_filename (w->fh), strerror (errno));
return 0;
}
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);
if (prt.writer == NULL)
goto error;
- if (handle_get_mode (fh) == MODE_BINARY)
+ if (fh_get_mode (fh) == MODE_BINARY)
prt.options |= PRT_BINARY;
}
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);
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);
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);
/* 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;
{
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;
}
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];
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);
}
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))
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)
{
{
msg (MW, _("%s: Invalid subrecord length. "
"Record: 7; Subrecord: 11"),
- handle_get_filename (r->fh));
+ fh_get_filename (r->fh));
skip = 1;
}
{
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;
}
{
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;
}
{
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;
}
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;
}
default:
corrupt_msg(MW, _("%s: Unrecognized record type %d."),
- handle_get_filename (r->fh), rec_type);
+ fh_get_filename (r->fh), rec_type);
}
}
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)
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
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"))));
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")))));
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)
"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);
}
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);
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);
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. */
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;
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. */
{
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 == '@'
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);
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 )
{
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);
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]);
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;
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"),
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;
}
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
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);
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];
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;
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")));
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);
}
}
{
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;
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));
}
}
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. */
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;
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
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);
{
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);
{
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;
}
}
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;
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;
}
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;
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);
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);