https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f911bb482d2c7ba2ad2fc5...
commit f911bb482d2c7ba2ad2fc57e734ee19bd245fcfb Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Fri May 22 23:58:12 2020 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Wed Aug 19 20:36:00 2020 +0200
[CMD] GOTO: The command should search labels from its position down to the end, then loop back to the beginning of the batch and down to the original position. --- base/shell/cmd/goto.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/base/shell/cmd/goto.c b/base/shell/cmd/goto.c index 10eeb28b12e..585a9708072 100644 --- a/base/shell/cmd/goto.c +++ b/base/shell/cmd/goto.c @@ -36,6 +36,8 @@ INT cmd_goto(LPTSTR param) { LPTSTR tmp, tmp2; + DWORD dwCurrPos; + BOOL bRetry;
TRACE("cmd_goto('%s')\n", debugstr_aw(param));
@@ -74,14 +76,23 @@ INT cmd_goto(LPTSTR param) return 0; }
- /* jump to begin of the file */ - bc->mempos=0; + /* + * Search the next label starting our position, until the end of the file. + * If none has been found, restart at the beginning of the file, and continue + * until reaching back our old current position. + */ + bRetry = FALSE; + dwCurrPos = bc->mempos;
+retry: while (BatchGetString(textline, ARRAYSIZE(textline))) { INT pos; INT_PTR size;
+ if (bRetry && (bc->mempos >= dwCurrPos)) + break; + /* Strip out any trailing spaces or control chars */ tmp = textline + _tcslen(textline) - 1; while (tmp > textline && (_istcntrl(*tmp) || _istspace(*tmp) || (*tmp == _T(':')))) @@ -112,6 +123,12 @@ INT cmd_goto(LPTSTR param) return 0; } } + if (!bRetry && (bc->mempos >= bc->memsize)) + { + bRetry = TRUE; + bc->mempos = 0; + goto retry; + }
ConErrResPrintf(STRING_GOTO_ERROR2, param); ExitBatch();