Merge branch 'master' into jgrpp

This commit is contained in:
Jonathan G Rennison
2021-04-05 17:50:39 +01:00
164 changed files with 3493 additions and 2443 deletions

View File

@@ -57,7 +57,7 @@
#include "safeguards.h"
/* scriptfile handling */
static bool _script_running; ///< Script is running (used to abort execution when #ConReturn is encountered).
static uint _script_current_depth; ///< Depth of scripts running (used to abort execution when #ConReturn is encountered).
/** File list storage for the console, for caching the last 'ls' command. */
class ConsoleFileList : public FileList {
@@ -1035,10 +1035,16 @@ DEF_CONSOLE_CMD(ConExec)
return true;
}
_script_running = true;
if (_script_current_depth == 11) {
IConsoleError("Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
return true;
}
_script_current_depth++;
uint script_depth = _script_current_depth;
char cmdline[ICON_CMDLN_SIZE];
while (_script_running && fgets(cmdline, sizeof(cmdline), script_file) != nullptr) {
while (fgets(cmdline, sizeof(cmdline), script_file) != nullptr) {
/* Remove newline characters from the executing script */
for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
if (*cmdptr == '\n' || *cmdptr == '\r') {
@@ -1047,13 +1053,18 @@ DEF_CONSOLE_CMD(ConExec)
}
}
IConsoleCmdExec(cmdline);
/* Ensure that we are still on the same depth or that we returned via 'return'. */
assert(_script_current_depth == script_depth || _script_current_depth == script_depth - 1);
/* The 'return' command was executed. */
if (_script_current_depth == script_depth - 1) break;
}
if (ferror(script_file)) {
IConsoleError("Encountered error while trying to read from script file");
}
_script_running = false;
if (_script_current_depth == script_depth) _script_current_depth--;
FioFCloseFile(script_file);
return true;
}
@@ -1065,7 +1076,7 @@ DEF_CONSOLE_CMD(ConReturn)
return true;
}
_script_running = false;
_script_current_depth--;
return true;
}
@@ -1409,7 +1420,7 @@ DEF_CONSOLE_CMD(ConRescanNewGRF)
return true;
}
ScanNewGRFFiles(nullptr);
RequestNewGRFScan();
return true;
}