- format->type = translate_fmt (portable_format[0]);
- if (format->type == -1)
- 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));
+ struct fmt_spec format;
+ bool ok;
+
+ if (!fmt_from_io (portable_format[0], &format.type))
+ {
+ if (*report_error)
+ warning (r, _("%s: Bad format specifier byte (%d). Variable "
+ "will be assigned a default format."),
+ var_get_name (v), portable_format[0]);
+ goto assign_default;
+ }
+
+ format.w = portable_format[1];
+ format.d = portable_format[2];
+
+ msg_disable ();
+ ok = (fmt_check_output (&format)
+ && fmt_check_width_compat (&format, var_get_width (v)));
+ msg_enable ();
+
+ if (!ok)
+ {
+ if (*report_error)
+ {
+ char fmt_string[FMT_STRING_LEN_MAX + 1];
+ fmt_to_string (&format, fmt_string);
+ if (var_is_numeric (v))
+ warning (r, _("Numeric variable %s has invalid format "
+ "specifier %s."),
+ var_get_name (v), fmt_string);
+ else
+ warning (r, _("String variable %s with width %d has "
+ "invalid format specifier %s."),
+ var_get_name (v), var_get_width (v), fmt_string);
+ }
+ goto assign_default;
+ }
+
+ return format;
+
+assign_default:
+ *report_error = false;
+ return fmt_default_for_width (var_get_width (v));