From f911bb482d2c7ba2ad2fc57e734ee19bd245fcfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 22 May 2020 23:58:12 +0200 Subject: [PATCH] [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();