cmd: Fix if/else tab handling.
This commit is contained in:
parent
6d3fd3abcd
commit
eda33f22ff
|
@ -1250,7 +1250,7 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
|
||||||
if (isIF) processThese = conditionTRUE;
|
if (isIF) processThese = conditionTRUE;
|
||||||
|
|
||||||
while (*cmdList) {
|
while (*cmdList) {
|
||||||
const WCHAR ifElse[] = {'e','l','s','e',' ','\0'};
|
const WCHAR ifElse[] = {'e','l','s','e'};
|
||||||
|
|
||||||
/* execute all appropriate commands */
|
/* execute all appropriate commands */
|
||||||
curPosition = *cmdList;
|
curPosition = *cmdList;
|
||||||
|
@ -1280,16 +1280,17 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
|
||||||
|
|
||||||
/* End of the command - does 'ELSE ' follow as the next command? */
|
/* End of the command - does 'ELSE ' follow as the next command? */
|
||||||
} else {
|
} else {
|
||||||
if (isIF && CompareStringW(LOCALE_USER_DEFAULT,
|
if (isIF
|
||||||
NORM_IGNORECASE | SORT_STRINGSORT,
|
&& WCMD_keyword_ws_found(ifElse, sizeof(ifElse)/sizeof(ifElse[0]),
|
||||||
(*cmdList)->command, 5, ifElse, -1) == CSTR_EQUAL) {
|
(*cmdList)->command)) {
|
||||||
|
|
||||||
/* Swap between if and else processing */
|
/* Swap between if and else processing */
|
||||||
processThese = !processThese;
|
processThese = !processThese;
|
||||||
|
|
||||||
/* Process the ELSE part */
|
/* Process the ELSE part */
|
||||||
if (processThese) {
|
if (processThese) {
|
||||||
WCHAR *cmd = ((*cmdList)->command) + strlenW(ifElse);
|
const int keyw_len = sizeof(ifElse)/sizeof(ifElse[0]) + 1;
|
||||||
|
WCHAR *cmd = ((*cmdList)->command) + keyw_len;
|
||||||
|
|
||||||
/* Skip leading whitespace between condition and the command */
|
/* Skip leading whitespace between condition and the command */
|
||||||
while (*cmd && (*cmd==' ' || *cmd=='\t')) cmd++;
|
while (*cmd && (*cmd==' ' || *cmd=='\t')) cmd++;
|
||||||
|
|
|
@ -391,6 +391,13 @@ if /i foo==FOO echo if /i seems to work
|
||||||
if /i not foo==FOO echo if /i seems to be broken
|
if /i not foo==FOO echo if /i seems to be broken
|
||||||
if /I foo==FOO echo if /I seems to work
|
if /I foo==FOO echo if /I seems to work
|
||||||
if /I not foo==FOO echo if /I seems to be broken
|
if /I not foo==FOO echo if /I seems to be broken
|
||||||
|
if@tab@1==1 echo doom
|
||||||
|
if @tab@1==1 echo doom
|
||||||
|
if 1==1 (echo doom) else@tab@echo quake
|
||||||
|
if@tab@not @tab@1==@tab@0 @tab@echo lol
|
||||||
|
if 1==0@tab@(echo doom) else echo quake
|
||||||
|
if 1==0 (echo doom)@tab@else echo quake
|
||||||
|
if 1==0 (echo doom) else@tab@echo quake
|
||||||
|
|
||||||
echo -----------Testing for -----------
|
echo -----------Testing for -----------
|
||||||
echo ...plain FOR
|
echo ...plain FOR
|
||||||
|
|
|
@ -271,6 +271,13 @@ Testing case sensitivity with and without /i option
|
||||||
if seems to default to case sensitivity
|
if seems to default to case sensitivity
|
||||||
if /i seems to work
|
if /i seems to work
|
||||||
if /I seems to work
|
if /I seems to work
|
||||||
|
doom
|
||||||
|
doom
|
||||||
|
doom
|
||||||
|
lol
|
||||||
|
quake
|
||||||
|
quake
|
||||||
|
quake
|
||||||
-----------Testing for -----------
|
-----------Testing for -----------
|
||||||
...plain FOR
|
...plain FOR
|
||||||
A
|
A
|
||||||
|
|
|
@ -1755,8 +1755,8 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
|
||||||
static WCHAR *extraSpace = NULL; /* Deliberately never freed */
|
static WCHAR *extraSpace = NULL; /* Deliberately never freed */
|
||||||
const WCHAR remCmd[] = {'r','e','m'};
|
const WCHAR remCmd[] = {'r','e','m'};
|
||||||
const WCHAR forCmd[] = {'f','o','r'};
|
const WCHAR forCmd[] = {'f','o','r'};
|
||||||
const WCHAR ifCmd[] = {'i','f',' ','\0'};
|
const WCHAR ifCmd[] = {'i','f'};
|
||||||
const WCHAR ifElse[] = {'e','l','s','e',' ','\0'};
|
const WCHAR ifElse[] = {'e','l','s','e'};
|
||||||
BOOL inRem = FALSE;
|
BOOL inRem = FALSE;
|
||||||
BOOL inFor = FALSE;
|
BOOL inFor = FALSE;
|
||||||
BOOL inIn = FALSE;
|
BOOL inIn = FALSE;
|
||||||
|
@ -1847,24 +1847,23 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
|
||||||
} else if (WCMD_keyword_ws_found(forCmd, sizeof(forCmd)/sizeof(forCmd[0]), curPos)) {
|
} else if (WCMD_keyword_ws_found(forCmd, sizeof(forCmd)/sizeof(forCmd[0]), curPos)) {
|
||||||
inFor = TRUE;
|
inFor = TRUE;
|
||||||
|
|
||||||
/* If command starts with 'if' or 'else', handle ('s mid line. We should ensure this
|
/* If command starts with 'if ' or 'else ', handle ('s mid line. We should ensure this
|
||||||
is only true in the command portion of the IF statement, but this
|
is only true in the command portion of the IF statement, but this
|
||||||
should suffice for now
|
should suffice for now
|
||||||
FIXME: Silly syntax like "if 1(==1( (
|
FIXME: Silly syntax like "if 1(==1( (
|
||||||
echo they equal
|
echo they equal
|
||||||
)" will be parsed wrong */
|
)" will be parsed wrong */
|
||||||
} else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
|
} else if (WCMD_keyword_ws_found(ifCmd, sizeof(ifCmd)/sizeof(ifCmd[0]), curPos)) {
|
||||||
curPos, 3, ifCmd, -1) == CSTR_EQUAL) {
|
|
||||||
inIf = TRUE;
|
inIf = TRUE;
|
||||||
|
|
||||||
} else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
|
} else if (WCMD_keyword_ws_found(ifElse, sizeof(ifElse)/sizeof(ifElse[0]), curPos)) {
|
||||||
curPos, 5, ifElse, -1) == CSTR_EQUAL) {
|
const int keyw_len = sizeof(ifElse)/sizeof(ifElse[0]) + 1;
|
||||||
inElse = TRUE;
|
inElse = TRUE;
|
||||||
lastWasElse = TRUE;
|
lastWasElse = TRUE;
|
||||||
onlyWhiteSpace = TRUE;
|
onlyWhiteSpace = TRUE;
|
||||||
memcpy(&curCopyTo[*curLen], curPos, 5*sizeof(WCHAR));
|
memcpy(&curCopyTo[*curLen], curPos, keyw_len*sizeof(WCHAR));
|
||||||
(*curLen)+=5;
|
(*curLen)+=keyw_len;
|
||||||
curPos+=5;
|
curPos+=keyw_len;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* In a for loop, the DO command will follow a close bracket followed by
|
/* In a for loop, the DO command will follow a close bracket followed by
|
||||||
|
|
Loading…
Reference in New Issue