#include "gettext.h"
#define _(msgid) gettext (msgid)
-#include <libpspp/debug-print.h>
-
/* portable_to_local[PORTABLE] translates the given portable
character into the local character set. */
static const char portable_to_local[256] =
static void
error (struct pfm_reader *r, const char *msg,...)
- PRINTF_FORMAT (2, 3);
+ PRINTF_FORMAT (2, 3)
+ NO_RETURN;
/* Displays MSG as an error message and aborts reading the
portable file via longjmp(). */
static void
error (struct pfm_reader *r, const char *msg, ...)
{
- struct error e;
- const char *filename;
- char *title;
+ struct msg m;
+ struct string text;
va_list args;
- e.class = ME;
- e.where.filename = NULL;
- e.where.line_number = 0;
- 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));
-
+ ds_init_empty (&text);
+ ds_put_format (&text, _("portable file %s corrupt at offset %ld: "),
+ fh_get_file_name (r->fh), ftell (r->file));
va_start (args, msg);
- err_vmsg (&e, msg, args);
+ ds_put_vformat (&text, msg, args);
va_end (args);
+ m.category = MSG_GENERAL;
+ m.severity = MSG_ERROR;
+ m.where.file_name = NULL;
+ m.where.line_number = 0;
+ m.text = ds_cstr (&text);
+
+ msg_emit (&m);
+
r->ok = false;
longjmp (r->bail_out, 1);
if (setjmp (r->bail_out))
goto error;
r->fh = fh;
- r->file = pool_fopen (r->pool, fh_get_filename (r->fh), "rb");
+ r->file = pool_fopen (r->pool, fh_get_file_name (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."),
- fh_get_filename (r->fh), strerror (errno));
+ fh_get_file_name (r->fh), strerror (errno));
goto error;
}
for (i = 0; i < 8; i++)
if (!match (r, "SPSSPORT"[i]))
{
- msg (SE, _("%s: Not a portable file."), fh_get_filename (r->fh));
+ msg (SE, _("%s: Not a portable file."), fh_get_file_name (r->fh));
longjmp (r->bail_out, 1);
}
}
convert_format (struct pfm_reader *r, const int portable_format[3],
struct fmt_spec *format, struct variable *v)
{
- format->type = translate_fmt (portable_format[0]);
- if (format->type == -1)
+ bool ok;
+
+ if (!fmt_from_io (portable_format[0], &format->type))
error (r, _("%s: Bad format specifier byte (%d)."),
v->name, portable_format[0]);
format->w = portable_format[1];
format->d = portable_format[2];
- if (!check_output_specifier (format, false)
- || !check_specifier_width (format, v->width, false))
- error (r, _("%s variable %s has invalid format specifier %s."),
- v->type == NUMERIC ? _("Numeric") : _("String"),
- v->name, fmt_to_string (format));
+ msg_disable ();
+ ok = fmt_check_output (format) && fmt_check_width_compat (format, v->width);
+ msg_enable ();
+
+ if (!ok)
+ {
+ char fmt_string[FMT_STRING_LEN_MAX + 1];
+ error (r, _("%s variable %s has invalid format specifier %s."),
+ v->type == NUMERIC ? _("Numeric") : _("String"),
+ v->name, fmt_to_string (format, fmt_string));
+ }
}
static union value parse_value (struct pfm_reader *, struct variable *);