goto error;
struct spreadsheet *spreadsheet = NULL;
- if ( 0 == strncasecmp (tok, "GNM", 3))
+ if (0 == strncasecmp (tok, "GNM", 3))
spreadsheet = gnumeric_probe (filename, true);
- else if ( 0 == strncasecmp (tok, "ODS", 3))
+ else if (0 == strncasecmp (tok, "ODS", 3))
spreadsheet = ods_probe (filename, true);
if (spreadsheet == NULL)
spreadsheet_unref (spreadsheet);
}
else
- msg (SE, _("Unsupported TYPE %s."), tok);
-
+ lex_error_expecting (lexer, "TXT", "PSQL", "GNM", "ODS");
error:
destroy_spreadsheet_read_info (&opts);
lex_get (lexer);
- while (lex_match (lexer, T_SLASH) )
+ while (lex_match (lexer, T_SLASH))
{
- if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
+ if (lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
{
lex_match (lexer, T_EQUALS);
- if (lex_force_int (lexer))
+ if (lex_force_int_range (lexer, "ASSUMEDSTRWIDTH", 1, 32767))
{
psql.str_width = lex_integer (lexer);
lex_get (lexer);
}
}
- else if ( lex_match_id (lexer, "BSIZE"))
+ else if (lex_match_id (lexer, "BSIZE"))
{
lex_match (lexer, T_EQUALS);
- if (lex_force_int (lexer))
+ if (lex_force_int_range (lexer, "BSIZE", 1, INT_MAX))
{
psql.bsize = lex_integer (lexer);
lex_get (lexer);
}
}
- else if ( lex_match_id (lexer, "UNENCRYPTED"))
+ else if (lex_match_id (lexer, "UNENCRYPTED"))
{
psql.allow_clear = true;
}
else if (lex_match_id (lexer, "SQL"))
{
lex_match (lexer, T_EQUALS);
- if ( ! lex_force_string (lexer) )
+ if (! lex_force_string (lexer))
goto error;
ds_put_substring (&psql.sql, lex_tokss (lexer));
struct dictionary *dict = NULL;
struct casereader *reader = psql_open_reader (&psql, &dict);
- if ( reader )
+ if (reader)
{
dataset_set_dict (ds, dict);
dataset_set_source (ds, reader);
lex_get (lexer);
- while (lex_match (lexer, T_SLASH) )
+ while (lex_match (lexer, T_SLASH))
{
- if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
+ if (lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
{
lex_match (lexer, T_EQUALS);
- if (lex_force_int (lexer))
+ if (lex_force_int_range (lexer, "ASSUMEDSTRWIDTH", 1, 32767))
{
opts->asw = lex_integer (lexer);
lex_get (lexer);
lex_match (lexer, T_EQUALS);
if (lex_match_id (lexer, "NAME"))
{
- if ( ! lex_force_string (lexer) )
+ if (! lex_force_string (lexer))
goto error;
opts->sheet_name = ss_xstrdup (lex_tokss (lexer));
}
else if (lex_match_id (lexer, "INDEX"))
{
- if (!lex_force_int (lexer))
+ if (!lex_force_int_range (lexer, "INDEX", 1, INT_MAX))
goto error;
-
opts->sheet_index = lex_integer (lexer);
- if (opts->sheet_index <= 0)
- {
- msg (SE, _("The sheet index must be greater than or equal to 1"));
- goto error;
- }
lex_get (lexer);
}
else
{
- msg (SE, _("%s must be followed by either \"%s\" or \"%s\"."),
- "/SHEET", "NAME", "INDEX");
+ lex_error_expecting (lexer, "NAME", "INDEX");
goto error;
}
}
}
else if (lex_match_id (lexer, "RANGE"))
{
- if ( ! lex_force_string (lexer) )
+ if (! lex_force_string (lexer))
goto error;
opts->cell_range = ss_xstrdup (lex_tokss (lexer));
}
else
{
- msg (SE, _("%s must be followed by either \"%s\" or \"%s\"."),
- "/CELLRANGE", "FULL", "RANGE");
+ lex_error_expecting (lexer, "FULL", "RANGE");
goto error;
}
}
{
lex_match (lexer, T_EQUALS);
- if ( lex_match_id (lexer, "ON"))
+ if (lex_match_id (lexer, "ON"))
{
opts->read_names = true;
}
}
else
{
- msg (SE, _("%s must be followed by either \"%s\" or \"%s\"."),
- "/READNAMES", "ON", "OFF");
+ lex_error_expecting (lexer, "ON", "OFF");
goto error;
}
}
if (fh == NULL)
goto error;
- parser = data_parser_create (dict);
+ parser = data_parser_create ();
has_type = false;
data_parser_set_type (parser, DP_DELIMITED);
data_parser_set_span (parser, false);
DP_DELIMITED, &has_type);
else
{
- lex_error_expecting (lexer, "FIXED", "DELIMITED", NULL_SENTINEL);
+ lex_error_expecting (lexer, "FIXED", "DELIMITED");
goto error;
}
if (!ok)
else if (lex_match_id (lexer, "FIRSTCASE"))
{
lex_match (lexer, T_EQUALS);
- if (!lex_force_int (lexer))
+ if (!lex_force_int_range (lexer, "FIRSTCASE", 1, INT_MAX))
goto error;
- if (lex_integer (lexer) < 1)
- {
- msg (SE, _("Value of %s must be 1 or greater."), "FIRSTCASE");
- goto error;
- }
data_parser_set_skip (parser, lex_integer (lexer) - 1);
lex_get (lexer);
}
}
else
{
- lex_error_expecting (lexer, "LINE", "VARIABLES", NULL_SENTINEL);
+ lex_error_expecting (lexer, "LINE", "VARIABLES");
goto error;
}
}
if (!set_type (parser, "FIXCASE", DP_FIXED, &has_type))
goto error;
lex_match (lexer, T_EQUALS);
- if (!lex_force_int (lexer))
+ if (!lex_force_int_range (lexer, "FIXCASE", 1, INT_MAX))
goto error;
- if (lex_integer (lexer) < 1)
- {
- msg (SE, _("Value of %s must be 1 or greater."), "FIXCASE");
- goto error;
- }
data_parser_set_records (parser, lex_integer (lexer));
lex_get (lexer);
}
else if (lex_match_id (lexer, "IMPORTCASES"))
{
+ int start_ofs = lex_ofs (lexer) - 1;
lex_match (lexer, T_EQUALS);
if (lex_match (lexer, T_ALL))
{
goto error;
lex_get (lexer);
}
- msg (SW, _("Ignoring obsolete IMPORTCASES subcommand. (N OF CASES "
- "or SAMPLE may be used to substitute.)"));
+ lex_ofs_msg (lexer, SW, start_ofs, lex_ofs (lexer) - 1,
+ _("Ignoring obsolete IMPORTCASES subcommand. (N OF "
+ "CASES or SAMPLE may be used to substitute.)"));
}
else if (lex_match_id_n (lexer, "DELIMITERS", 4))
{
if (settings_get_syntax () == COMPATIBLE
&& ss_length (lex_tokss (lexer)) != 1)
{
- msg (SE, _("In compatible syntax mode, the QUALIFIER string "
- "must contain exactly one character."));
+ lex_error (lexer, _("In compatible syntax mode, the QUALIFIER "
+ "string must contain exactly one character."));
goto error;
}
break;
else
{
- lex_error_expecting (lexer, "VARIABLES", NULL_SENTINEL);
+ lex_error_expecting (lexer, "VARIABLES");
goto error;
}
}
while (type == DP_FIXED && lex_match (lexer, T_SLASH))
{
- if (!lex_force_int (lexer))
+ if (!lex_force_int_range (lexer, NULL, record,
+ data_parser_get_records (parser)))
goto error;
- if (lex_integer (lexer) < record)
- {
- msg (SE, _("The record number specified, %ld, is at or "
- "before the previous record, %d. Data "
- "fields must be listed in order of "
- "increasing record number."),
- lex_integer (lexer), record);
- goto error;
- }
- if (lex_integer (lexer) > data_parser_get_records (parser))
- {
- msg (SE, _("The record number specified, %ld, exceeds "
- "the number of records per case specified "
- "on FIXCASE, %d."),
- lex_integer (lexer), data_parser_get_records (parser));
- goto error;
- }
record = lex_integer (lexer);
lex_get (lexer);
}
- const char * tstr = lex_tokcstr (lexer);
- if (tstr == NULL)
- {
- lex_error (lexer, NULL);
- goto error;
- }
- name = xstrdup (tstr);
- if (!lex_force_id (lexer)
- || !dict_id_is_valid (dict, name, true))
- {
+ int name_ofs = lex_ofs (lexer);
+ if (!lex_force_id (lexer))
+ goto error;
+ name = xstrdup (lex_tokcstr (lexer));
+ char *error = dict_id_is_valid__ (dict, name);
+ if (error)
+ {
+ lex_error (lexer, "%s", error);
+ free (error);
goto error;
}
lex_get (lexer);
if (type == DP_DELIMITED)
{
- if (!parse_format_specifier (lexer, &input)
- || !fmt_check_input (&input))
+ if (!parse_format_specifier (lexer, &input))
+ goto error;
+ error = fmt_check_input__ (&input);
+ if (error)
{
+ lex_next_error (lexer, -1, -1, "%s", error);
+ free (error);
goto error;
}
- output = fmt_for_output_from_input (&input);
+ output = fmt_for_output_from_input (&input,
+ settings_get_fmt_settings ());
}
else
{
- char fmt_type_name[FMT_TYPE_LEN_MAX + 1];
- enum fmt_type fmt_type;
- int w, d;
-
+ int start_ofs = lex_ofs (lexer);
if (!parse_column_range (lexer, 0, &fc, &lc, NULL))
goto error;
/* Accept a format (e.g. F8.2) or just a type name (e.g. DOLLAR). */
+ char fmt_type_name[FMT_TYPE_LEN_MAX + 1];
+ uint16_t w;
+ uint8_t d;
if (!parse_abstract_format_specifier (lexer, fmt_type_name, &w, &d))
goto error;
+
+ enum fmt_type fmt_type;
if (!fmt_from_name (fmt_type_name, &fmt_type))
{
- msg (SE, _("Unknown format type `%s'."), fmt_type_name);
+ lex_next_error (lexer, -1, -1,
+ _("Unknown format type `%s'."), fmt_type_name);
goto error;
}
+ int end_ofs = lex_ofs (lexer) - 1;
+
/* Compose input format. */
- input.type = fmt_type;
- input.w = lc - fc + 1;
- input.d = 0;
- if (!fmt_check_input (&input))
- goto error;
+ input = (struct fmt_spec) { .type = fmt_type, .w = lc - fc + 1 };
+ error = fmt_check_input__ (&input);
+ if (error)
+ {
+ lex_next_error (lexer, start_ofs, end_ofs, "%s", error);
+ free (error);
+ goto error;
+ }
+
/* Compose output format. */
if (w != 0)
{
- output.type = fmt_type;
- output.w = w;
- output.d = d;
- if (!fmt_check_output (&output))
- goto error;
+ output = (struct fmt_spec) { .type = fmt_type, .w = w, .d = d };
+ error = fmt_check_output__ (&output);
+ if (error)
+ {
+ lex_next_error (lexer, start_ofs, end_ofs, "%s", error);
+ free (error);
+ goto error;
+ }
}
else
- output = fmt_for_output_from_input (&input);
+ output = fmt_for_output_from_input (&input,
+ settings_get_fmt_settings ());
}
v = dict_create_var (dict, name, fmt_var_width (&input));
if (v == NULL)
{
- msg (SE, _("%s is a duplicate variable name."), name);
+ lex_ofs_error (lexer, name_ofs, name_ofs,
+ _("%s is a duplicate variable name."), name);
goto error;
}
var_set_both_formats (v, &output);