X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Finclude.c;h=f02291e5e72bed4f13b4465941e3f32ca07f6d6c;hb=cbf273bfb07d7db5353eb691b903a321b7e5bd59;hp=bcee162c6a04f56e44a01164d0c7af87662cba62;hpb=fe8dc2171009e90d2335f159d05f7e6660e24780;p=pspp diff --git a/src/language/utilities/include.c b/src/language/utilities/include.c index bcee162c6a..f02291e5e7 100644 --- a/src/language/utilities/include.c +++ b/src/language/utilities/include.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2007, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2007, 2010, 2011, 2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,7 +23,6 @@ #include #include "data/dataset.h" -#include "data/file-name.h" #include "data/session.h" #include "language/command.h" #include "language/lexer/include-path.h" @@ -47,30 +46,18 @@ enum variant static int do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant) { - enum lex_syntax_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); - /* File name can be identifier or string. */ - if (lex_token (lexer) != T_ID && !lex_is_string (lexer)) - { - lex_error (lexer, _("expecting file name")); - return CMD_FAILURE; - } + if (!lex_force_string_or_id (lexer)) + return CMD_FAILURE; - relative_name = utf8_to_filename (lex_tokcstr (lexer)); - 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)); @@ -78,13 +65,13 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant) } lex_get (lexer); - 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)) + 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")) { @@ -94,83 +81,83 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant) free (encoding); encoding = xstrdup (lex_tokcstr (lexer)); + lex_get (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; + if (lex_match_id (lexer, "INTERACTIVE")) + syntax_mode = SEG_MODE_INTERACTIVE; + else if (lex_match_id (lexer, "BATCH")) + syntax_mode = SEG_MODE_BATCH; + else if (lex_match_id (lexer, "AUTO")) + syntax_mode = SEG_MODE_AUTO; else { - lex_error (lexer, _("expecting %s, %s, or %s after %s"), - "BATCH", "INTERACTIVE", "AUTO", "SYNTAX"); + lex_error_expecting (lexer, "BATCH", "INTERACTIVE", "AUTO"); 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; - } + if (lex_match_id (lexer, "YES")) + cd = true; + else if (lex_match_id (lexer, "NO")) + cd = false; else { - lex_error (lexer, _("expecting %s or %s after %s"), - "YES", "NO", "CD"); + lex_error_expecting (lexer, "YES", "NO"); 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; - } + if (lex_match_id (lexer, "CONTINUE")) + error_mode = LEX_ERROR_CONTINUE; + else if (lex_match_id (lexer, "STOP")) + error_mode = LEX_ERROR_STOP; + else if (settings_get_testing_mode () + && lex_match_id (lexer, "IGNORE")) + error_mode = LEX_ERROR_IGNORE; else { - lex_error (lexer, _("expecting %s or %s after %s"), - "CONTINUE", "STOP", "ERROR"); + lex_error_expecting (lexer, "CONTINUE", "STOP"); 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; } } status = lex_end_of_command (lexer); - if ( status == CMD_SUCCESS) + 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); lex_include (lexer, reader); - if ( cd ) + if (cd) { char *directory = dir_name (filename); - chdir (directory); + if (chdir (directory)) + { + int err = errno; + msg (SE, _("Cannot change directory to %s: %s"), directory, + strerror (err)); + status = CMD_FAILURE; + } + free (directory); } }