[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.

This commit is contained in:
Hermès Bélusca-Maïto 2020-05-22 23:58:12 +02:00
parent 8ed9a46dc2
commit f911bb482d
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -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();