Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkcgen <kcgen@users.noreply.github.com>2022-07-25 18:41:07 +0300
committerkcgen <kcgen@users.noreply.github.com>2022-07-25 19:36:28 +0300
commit91ef5aaf3abfeb56a8bc9cff09d1534c7ec4b162 (patch)
tree9ad5e1276450dba4bf35c2d3ff5bb96046a30185
parent63d4b92f4911f46738f2291c9cce5bf3816311ba (diff)
Stop CHOICE from waiting for input when EOF is reachedkc/choice-break-1
Flagged by SanekGamer007 in https://github.com/joncampbell123/dosbox-x/issues/3613 and documented and fixed by Jookia in https://github.com/joncampbell123/dosbox-x/pull/3648, as follows: Running 'REM | CHOICE' or 'CHOICE < NUL' will freeze CHOICE as it doesn't check for the end of file (EOF) condition. FreeDOS and MS-DOS documentation specify the following behaviour: - 0 is returned on abort (in this case Ctrl-C or break is pressed) - 255 is returned on error (in this case no more input) --- This commit was adapted from the EOF check authored by Jookia in https://github.com/joncampbell123/dosbox-x/pull/3648. This commit also improves the reporting for the EOF and abort conditions. Thanks, SanekGamer007 and Jookia! Reported-by: SanekGamer007 <SanekGamer007@users.noreply.github.com> Co-Authored-by: Jookia <contact@jookia.org>
-rw-r--r--src/shell/shell.cpp3
-rw-r--r--src/shell/shell_cmds.cpp16
2 files changed, 14 insertions, 5 deletions
diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp
index d5d3042fd..c6ee9eb20 100644
--- a/src/shell/shell.cpp
+++ b/src/shell/shell.cpp
@@ -1408,7 +1408,8 @@ void SHELL_Init() {
"Examples:\n"
" [color=green]choice[reset] /t:[color=white]y[reset],[color=magenta]2[reset] [color=cyan]Continue?[reset]\n"
" [color=green]choice[reset] /c:[color=white]abc[reset] /s [color=cyan]Type the letter a, b, or c[reset]\n");
- MSG_Add("SHELL_CMD_CHOICE_ABORTED", "\nChoice aborted.\n");
+ MSG_Add("SHELL_CMD_CHOICE_EOF", "\n[color=red]Choice failed[reset]: the input stream ended without a valid choice.\n");
+ MSG_Add("SHELL_CMD_CHOICE_ABORTED", "\n[color=yellow]Choice aborted.[reset]\n");
MSG_Add("SHELL_CMD_PATH_HELP",
"Displays or sets a search path for executable files.\n");
MSG_Add("SHELL_CMD_PATH_HELP_LONG",
diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp
index 03b6b7277..f369b23c5 100644
--- a/src/shell/shell_cmds.cpp
+++ b/src/shell/shell_cmds.cpp
@@ -2067,9 +2067,16 @@ void DOS_Shell::CMD_CHOICE(char * args){
// Begin waiting for input, but maybe break on some conditions
constexpr char ctrl_c = 3;
char choice = '\0';
+ uint16_t bytes_read = 1;
while (!contains(choices, choice)) {
- uint16_t n = 1;
- DOS_ReadFile(STDIN, reinterpret_cast<uint8_t *>(&choice), &n);
+ DOS_ReadFile(STDIN, reinterpret_cast<uint8_t *>(&choice), &bytes_read);
+ if (!bytes_read) {
+ WriteOut_NoParsing(MSG_Get("SHELL_CMD_CHOICE_EOF"));
+ dos.return_code = 255;
+ LOG_ERR("CHOICE: Failed, returing errorlevel %u",
+ dos.return_code);
+ return;
+ }
if (always_capitalize)
choice = static_cast<char>(toupper(choice));
if (using_auto_type)
@@ -2091,8 +2098,9 @@ void DOS_Shell::CMD_CHOICE(char * args){
} else {
WriteOut_NoParsing(MSG_Get("SHELL_CMD_CHOICE_ABORTED"));
dos.return_code = 0;
- LOG_MSG("CHOICE: Aborted, returning %u (from %d choices)",
- dos.return_code, num_choices);
+ LOG_WARNING("CHOICE: Aborted, returning errorlevel %u (from %d choices)",
+ dos.return_code,
+ num_choices);
}
}