+
+ syntax_mode = LEX_SYNTAX_INTERACTIVE;
+ error_mode = LEX_ERROR_CONTINUE;
+ cd = false;
+ status = CMD_FAILURE;
+ 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_force_string (lexer))
+ goto exit;
+
+ free (encoding);
+ encoding = xstrdup (lex_tokcstr (lexer));
+ }
+ else if (variant == INSERT && lex_match_id (lexer, "SYNTAX"))
+ {
+ lex_match (lexer, T_EQUALS);
+ if ( lex_match_id (lexer, "INTERACTIVE") )
+ syntax_mode = LEX_SYNTAX_INTERACTIVE;
+ else if ( lex_match_id (lexer, "BATCH"))
+ syntax_mode = LEX_SYNTAX_BATCH;
+ else if ( lex_match_id (lexer, "AUTO"))
+ syntax_mode = LEX_SYNTAX_AUTO;
+ else
+ {
+ lex_error_expecting (lexer, "BATCH", "INTERACTIVE", "AUTO",
+ NULL_SENTINEL);
+ goto exit;
+ }
+ }
+ else if (variant == INSERT && lex_match_id (lexer, "CD"))
+ {
+ lex_match (lexer, T_EQUALS);
+ if ( lex_match_id (lexer, "YES") )
+ {
+ cd = true;
+ }
+ else if ( lex_match_id (lexer, "NO"))
+ {
+ cd = false;
+ }
+ else
+ {
+ lex_error_expecting (lexer, "YES", "NO", NULL_SENTINEL);
+ goto exit;
+ }
+ }
+ else if (variant == INSERT && lex_match_id (lexer, "ERROR"))
+ {
+ lex_match (lexer, T_EQUALS);
+ if ( lex_match_id (lexer, "CONTINUE") )
+ {
+ error_mode = LEX_ERROR_CONTINUE;
+ }
+ else if ( lex_match_id (lexer, "STOP"))
+ {
+ error_mode = LEX_ERROR_STOP;
+ }
+ else
+ {
+ lex_error_expecting (lexer, "CONTINUE", "STOP", NULL_SENTINEL);
+ goto exit;
+ }
+ }
+
+ else
+ {
+ lex_error (lexer, NULL);
+ goto exit;
+ }
+ }
+ status = lex_end_of_command (lexer);
+
+ if ( status == CMD_SUCCESS)
+ {
+ struct lex_reader *reader;
+
+ reader = lex_reader_for_file (filename, encoding,
+ syntax_mode, error_mode);
+ if (reader != NULL)
+ {
+ lex_discard_rest_of_command (lexer);
+ lex_include (lexer, reader);
+
+ if ( cd )
+ {
+ char *directory = dir_name (filename);
+ chdir (directory);
+ free (directory);
+ }
+ }
+ }
+
+exit:
+ free (encoding);
+ free (filename);
+ return status;
+}
+
+int
+cmd_include (struct lexer *lexer, struct dataset *ds)
+{
+ return do_insert (lexer, ds, INCLUDE);