static int
do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant)
{
- enum segmenter_mode syntax_mode;
- enum lex_error_mode error_mode;
- char *relative_name;
- char *filename;
- char *encoding;
- int status;
- bool cd;
-
/* Skip optional FILE=. */
if (lex_match_id (lexer, "FILE"))
lex_match (lexer, T_EQUALS);
if (!lex_force_string_or_id (lexer))
return CMD_FAILURE;
- relative_name = utf8_to_filename (lex_tokcstr (lexer));
- if (NULL == relative_name)
- return CMD_FAILURE;
-
- filename = include_path_search (relative_name);
+ char *relative_name = utf8_to_filename (lex_tokcstr (lexer));
+ char *filename = include_path_search (relative_name);
free (relative_name);
- if (! filename)
+ if (!filename)
{
msg (SE, _("Can't find `%s' in include file search path."),
lex_tokcstr (lexer));
}
lex_get (lexer);
- syntax_mode = SEG_MODE_INTERACTIVE;
- error_mode = LEX_ERROR_CONTINUE;
- cd = false;
- status = CMD_FAILURE;
- encoding = xstrdup (session_get_default_syntax_encoding (
- dataset_session (ds)));
+ enum segmenter_mode syntax_mode = SEG_MODE_INTERACTIVE;
+ enum lex_error_mode error_mode = LEX_ERROR_CONTINUE;
+ bool cd = false;
+ int status = CMD_FAILURE;
+ char *encoding = xstrdup (session_get_default_syntax_encoding (
+ dataset_session (ds)));
while (T_ENDCMD != lex_token (lexer))
{
if (lex_match_id (lexer, "ENCODING"))
{
lex_match (lexer, T_EQUALS);
if (lex_match_id (lexer, "YES"))
- {
- cd = true;
- }
+ cd = true;
else if (lex_match_id (lexer, "NO"))
- {
- cd = false;
- }
+ cd = false;
else
{
lex_error_expecting (lexer, "YES", "NO");
goto exit;
}
}
-
else
{
- lex_error (lexer, NULL);
+ if (variant == INSERT)
+ lex_error_expecting (lexer, "ENCODING", "SYNTAX", "CD", "ERROR");
+ else
+ lex_error_expecting (lexer, "ENCODING");
goto exit;
}
}
if (status == CMD_SUCCESS)
{
- struct lex_reader *reader;
-
- reader = lex_reader_for_file (filename, encoding,
- syntax_mode, error_mode);
+ struct lex_reader *reader = lex_reader_for_file (filename, encoding,
+ syntax_mode, error_mode);
if (reader != NULL)
{
lex_discard_rest_of_command (lexer);
if (cd)
{
char *directory = dir_name (filename);
- int ret = chdir (directory);
- if (0 != ret)
+ if (chdir (directory))
{
int err = errno;
msg (SE, _("Cannot change directory to %s: %s"), directory,
AT_CHECK([pspp -O format=csv insert.sps], [1], [ignore])
AT_CLEANUP
+
+AT_SETUP([INSERT syntax errors])
+AT_KEYWORDS([INCLUDE])
+: >inner.sps
+AT_DATA([insert.sps], [dnl
+INSERT **.
+INSERT 'nonexistent.sps'.
+INSERT 'inner.sps' ENCODING=**.
+INSERT 'inner.sps' SYNTAX=**.
+INSERT 'inner.sps' CD=**.
+INSERT 'inner.sps' ERROR=**.
+INSERT 'inner.sps' **.
+INCLUDE 'inner.sps' **.
+])
+AT_CHECK([pspp -O format=csv insert.sps], [1], [dnl
+"insert.sps:1.8-1.9: error: INSERT: Syntax error expecting string.
+ 1 | INSERT **.
+ | ^~"
+
+insert.sps:2: error: INSERT: Can't find `nonexistent.sps' in include file search path.
+
+"insert.sps:3.29-3.30: error: INSERT: Syntax error expecting string.
+ 3 | INSERT 'inner.sps' ENCODING=**.
+ | ^~"
+
+"insert.sps:4.27-4.28: error: INSERT: Syntax error expecting BATCH, INTERACTIVE, or AUTO.
+ 4 | INSERT 'inner.sps' SYNTAX=**.
+ | ^~"
+
+"insert.sps:5.23-5.24: error: INSERT: Syntax error expecting YES or NO.
+ 5 | INSERT 'inner.sps' CD=**.
+ | ^~"
+
+"insert.sps:6.26-6.27: error: INSERT: Syntax error expecting CONTINUE or STOP.
+ 6 | INSERT 'inner.sps' ERROR=**.
+ | ^~"
+
+"insert.sps:7.20-7.21: error: INSERT: Syntax error expecting ENCODING, SYNTAX, CD, or ERROR.
+ 7 | INSERT 'inner.sps' **.
+ | ^~"
+
+"insert.sps:8.21-8.22: error: INCLUDE: Syntax error expecting ENCODING.
+ 8 | INCLUDE 'inner.sps' **.
+ | ^~"
+])
+AT_CLEANUP