cmd: Migrate IF/FOR instructions inside CMD_NODE.

Basically:
- IF and FOR command parsing in integrated into node_builder,
- CMD_NODE is no longer degenerated (and no longer use
  NULL CMD_COMMAND to mark end of block)
- lexer evolves to delegate a bunch of things to node_builder
  (esp. command nesting...)

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53190
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50132
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=44063
Signed-off-by: Eric Pouech <epouech@codeweavers.com>
This commit is contained in:
Eric Pouech 2024-04-30 15:25:27 +02:00 committed by Alexandre Julliard
parent be0d882e89
commit 6c39db0ca0
57 changed files with 837 additions and 752 deletions

View file

@ -15896,6 +15896,12 @@ msgstr "خطأ بنيوي\n"
msgid "End of line"
msgstr "نهاية الملف.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "نهاية الملف.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "حجم المؤشر"

View file

@ -14491,6 +14491,12 @@ msgstr "Error de la sintaxis\n"
msgid "End of line"
msgstr "Fin del ficheru.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Fin del ficheru.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Tamañu del cursor"

View file

@ -14584,6 +14584,11 @@ msgstr ""
msgid "End of line"
msgstr "Добави към от&метките..."
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "Добави към от&метките..."
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14693,6 +14693,12 @@ msgstr "Error de sintaxi\n"
msgid "End of line"
msgstr "S'ha acabat el fitxer.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "S'ha acabat el fitxer.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Mida de cursor"

View file

@ -15410,6 +15410,12 @@ msgstr "Chyba syntaxe\n"
msgid "End of line"
msgstr "Konec souboru.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Konec souboru.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Velikost kurzoru"

View file

@ -15805,6 +15805,12 @@ msgstr "Syntaks fejl\n"
msgid "End of line"
msgstr "Slutningen af filen.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Slutningen af filen.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Markør størrelse"

View file

@ -14675,6 +14675,12 @@ msgstr "Syntaxfehler\n"
msgid "End of line"
msgstr "Ende der Datei.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Ende der Datei.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Cursorgröße"

View file

@ -14340,6 +14340,11 @@ msgstr ""
msgid "End of line"
msgstr "Α&γαπημένα.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "Α&γαπημένα.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14583,6 +14583,10 @@ msgstr "Syntax error: unexpected %1\n"
msgid "End of line"
msgstr "End of line"
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr "End of file"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Cursor size"

View file

@ -14583,6 +14583,10 @@ msgstr "Syntax error: unexpected %1\n"
msgid "End of line"
msgstr "End of line"
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr "End of file"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Cursor size"

View file

@ -14950,6 +14950,12 @@ msgstr ""
msgid "End of line"
msgstr "&Ordinara zono"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "&Standard bar"
msgid "End of file"
msgstr "&Ordinara zono"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Kursor-grando"

View file

@ -15270,6 +15270,12 @@ msgstr "Error de sintaxis\n"
msgid "End of line"
msgstr "Fin del archivo.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Fin del archivo.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Tamaño del cursor"

View file

@ -14525,6 +14525,11 @@ msgstr ""
msgid "End of line"
msgstr "&حذف\tDel"
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "&حذف\tDel"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14567,6 +14567,12 @@ msgstr "Syntaksivirhe\n"
msgid "End of line"
msgstr "Tiedoston loppu.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Tiedoston loppu.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Kursorin koko"

View file

@ -15187,6 +15187,12 @@ msgstr "Erreur de syntaxe\n"
msgid "End of line"
msgstr "Fin de fichier atteinte.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Fin de fichier atteinte.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Taille du curseur"

View file

@ -15350,6 +15350,11 @@ msgstr "שגיאת תחביר"
msgid "End of line"
msgstr "&איגוד לקובץ..."
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "&איגוד לקובץ..."
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "גודל הסמן"

View file

@ -14079,6 +14079,10 @@ msgstr ""
msgid "End of line"
msgstr ""
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr ""
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -15362,6 +15362,12 @@ msgstr "Sintaksna greška\n"
msgid "End of line"
msgstr "Kraj datoteke.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Kraj datoteke.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Veličina pokazivača"

View file

@ -15796,6 +15796,12 @@ msgstr "Szintaktikai hiba\n"
msgid "End of line"
msgstr "Fájl vége.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Fájl vége.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Kurzor mérete"

View file

@ -15872,6 +15872,12 @@ msgstr "Errore di sintassi\n"
msgid "End of line"
msgstr "Fine del file.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Fine del file.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Dimensione del cursore"

View file

@ -14587,6 +14587,12 @@ msgstr "構文エラー\n"
msgid "End of line"
msgstr "ファイルの終端です。\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "ファイルの終端です。\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "カーソルの大きさ"

View file

@ -14190,6 +14190,12 @@ msgstr "სინტაქსური შეცდომა\n"
msgid "End of line"
msgstr "ფაილის დასასრული.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "ფაილის დასასრული.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "კურსორის ზომა"

View file

@ -14544,6 +14544,12 @@ msgstr "문법 오류\n"
msgid "End of line"
msgstr "파일 끝.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "파일 끝.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "커서 크기"

View file

@ -14589,6 +14589,12 @@ msgstr "Sintaksės klaida: netikėtas %1\n"
msgid "End of line"
msgstr "Eilutės pabaiga"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Failo pabaiga.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Žymeklio dydis"

View file

@ -14078,6 +14078,10 @@ msgstr ""
msgid "End of line"
msgstr ""
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr ""
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -15392,6 +15392,12 @@ msgstr "Syntaksfeil\n"
msgid "End of line"
msgstr "Enden av filen.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Enden av filen.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Pekerstørrelse"

View file

@ -14642,6 +14642,12 @@ msgstr "Formuleringsfout\n"
msgid "End of line"
msgstr "Einde van bestand.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Einde van bestand.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Cursorgrootte"

View file

@ -14064,6 +14064,10 @@ msgstr ""
msgid "End of line"
msgstr ""
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr ""
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14064,6 +14064,10 @@ msgstr ""
msgid "End of line"
msgstr ""
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr ""
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14627,6 +14627,12 @@ msgstr "Błąd składni\n"
msgid "End of line"
msgstr "Koniec pliku.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Koniec pliku.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Rozmiar kursora"

View file

@ -14793,6 +14793,12 @@ msgstr "Erro de sintaxe\n"
msgid "End of line"
msgstr "Fim do arquivo.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Fim do arquivo.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Cursor"

View file

@ -15567,6 +15567,12 @@ msgstr "Erro de sintaxe\n"
msgid "End of line"
msgstr "Fim de ficheiro.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Fim de ficheiro.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Tamanho do Cursor"

View file

@ -14152,6 +14152,10 @@ msgstr ""
msgid "End of line"
msgstr ""
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr ""
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -15641,6 +15641,12 @@ msgstr "Eroare de sintaxă\n"
msgid "End of line"
msgstr "Sfârșit de fișier.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Sfârșit de fișier.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Dimensiune cursor"

View file

@ -15024,6 +15024,12 @@ msgstr "Синтаксическая ошибка\n"
msgid "End of line"
msgstr "Достигнут конец файла.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Достигнут конец файла.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Размер курсора"

View file

@ -14689,6 +14689,12 @@ msgstr "වාග් රීති දෝෂයක්\n"
msgid "End of line"
msgstr "ගොනුවේ අවසානය.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "ගොනුවේ අවසානය.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "කර්සරය ප්රමාණය"

View file

@ -15106,6 +15106,12 @@ msgstr ""
msgid "End of line"
msgstr "Koniec súboru.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Koniec súboru.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -15826,6 +15826,12 @@ msgstr "Napaka skladnje\n"
msgid "End of line"
msgstr "Konec datoteke.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Konec datoteke.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Velikost kazalca"

View file

@ -15136,6 +15136,11 @@ msgstr "Грешка у синтакси"
msgid "End of line"
msgstr "&Додај у омиљене..."
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "&Додај у омиљене..."
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -15277,6 +15277,11 @@ msgstr "Greška u sintaksi"
msgid "End of line"
msgstr "&Dodaj u omiljene..."
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "&Dodaj u omiljene..."
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -15521,6 +15521,12 @@ msgstr "Syntaxfel\n"
msgid "End of line"
msgstr "Filslut.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Filslut.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Markörstorlek"

View file

@ -14054,6 +14054,12 @@ msgstr ""
msgid "End of line"
msgstr "கையொப்பமிடும் நேரம்"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "Signing Time"
msgid "End of file"
msgstr "கையொப்பமிடும் நேரம்"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14064,6 +14064,10 @@ msgstr ""
msgid "End of line"
msgstr ""
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr ""
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14616,6 +14616,11 @@ msgstr ""
msgid "End of line"
msgstr "ลบ\tDel"
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "ลบ\tDel"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14613,6 +14613,12 @@ msgstr "Sözdizimi hatası\n"
msgid "End of line"
msgstr "Dosya sonu.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Dosya sonu.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "İmleç boyutu"

View file

@ -14886,6 +14886,12 @@ msgstr "Синтаксична помилка\n"
msgid "End of line"
msgstr "Кінець файлу.\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "Кінець файлу.\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "Розмір курсора"

View file

@ -14510,6 +14510,11 @@ msgstr ""
msgid "End of line"
msgstr "&Rafacer\tDel"
#: programs/cmd/cmd.rc:413
#, fuzzy
msgid "End of file"
msgstr "&Rafacer\tDel"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -13979,6 +13979,10 @@ msgstr ""
msgid "End of line"
msgstr ""
#: programs/cmd/cmd.rc:413
msgid "End of file"
msgstr ""
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr ""

View file

@ -14381,6 +14381,12 @@ msgstr "语法错误\n"
msgid "End of line"
msgstr "文件尾。\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "文件尾。\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "光标尺寸"

View file

@ -14447,6 +14447,12 @@ msgstr "語法錯誤\n"
msgid "End of line"
msgstr "檔案結尾。\n"
#: programs/cmd/cmd.rc:413
#, fuzzy
#| msgid "End of file.\n"
msgid "End of file"
msgstr "檔案結尾。\n"
#: programs/conhost/conhost.rc:54
msgid "Cursor size"
msgstr "游標大小"

View file

@ -92,7 +92,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, WCHAR *startLabel, HANDLE pgmHandl
/* Note: although this batch program itself may be called, we are not retrying
the command as a result of a call failing to find a program, hence the
retryCall parameter below is FALSE */
WCMD_process_commands(toExecute, FALSE, FALSE);
node_execute(toExecute);
node_dispose_tree(toExecute);
toExecute = NULL;
}

View file

@ -1539,140 +1539,6 @@ void WCMD_echo (const WCHAR *args)
free(trimmed);
}
/*****************************************************************************
* WCMD_part_execute
*
* Execute a command, and any && or bracketed follow on to the command. The
* first command to be executed may not be at the front of the
* commands->thiscommand string (eg. it may point after a DO or ELSE)
*/
void WCMD_part_execute(CMD_NODE **cmdList, const WCHAR *firstcmd,
BOOL isIF, BOOL executecmds)
{
CMD_NODE *curPosition = *cmdList;
int myDepth = CMD_node_get_depth(*cmdList);
CMD_OPERATOR prev_op = CMD_CONCAT;
WINE_TRACE("cmdList(%p), firstCmd(%s), doIt(%d), isIF(%d)\n", cmdList,
wine_dbgstr_w(firstcmd), executecmds, isIF);
/* Skip leading whitespace between condition and the command */
while (firstcmd && *firstcmd && (*firstcmd==' ' || *firstcmd=='\t')) firstcmd++;
/* Process the first command, if there is one */
if (executecmds && firstcmd && *firstcmd) {
WCHAR *command = xstrdupW(firstcmd);
WCMD_execute (firstcmd, CMD_node_get_single_node(*cmdList)->redirects, cmdList, FALSE);
free(command);
}
/* If it didn't move the position, step to next command */
if (curPosition == *cmdList) *cmdList = CMD_node_next(*cmdList);
/* Process any other parts of the command */
if (*cmdList) {
BOOL processThese = executecmds;
while (*cmdList) {
/* execute all appropriate commands */
curPosition = *cmdList;
WINE_TRACE("Processing cmdList(%p) - operator(%d) bd(%d / %d) processThese(%d)\n",
*cmdList,
prev_op,
CMD_node_get_depth(*cmdList),
myDepth,
processThese);
/* Execute any statements appended to the line */
/* FIXME: Only if previous call worked for && or failed for || */
if (prev_op == CMD_ONFAILURE ||
prev_op == CMD_ONSUCCESS) {
if (processThese && CMD_node_get_command(*cmdList)->command) {
WCMD_execute (CMD_node_get_command(*cmdList)->command, CMD_node_get_single_node(*cmdList)->redirects,
cmdList, FALSE);
}
if (curPosition == *cmdList)
{
prev_op = (*cmdList)->op;
*cmdList = CMD_node_next(*cmdList);
}
/* Execute any appended to the statement with (...) */
} else if (CMD_node_get_depth(*cmdList) > myDepth) {
if (processThese) {
/* FIXME this is wrong, we don't recompute prev_op */
*cmdList = WCMD_process_commands(*cmdList, TRUE, FALSE);
} else {
WINE_TRACE("Skipping command %p due to stack depth\n", *cmdList);
}
if (curPosition == *cmdList)
{
prev_op = (*cmdList)->op;
*cmdList = CMD_node_next(*cmdList);
}
/* End of the command - does 'ELSE ' follow as the next command? */
} else {
if (isIF && WCMD_keyword_ws_found(L"else", CMD_node_get_command(*cmdList)->command)) {
/* Swap between if and else processing */
processThese = !executecmds;
/* Process the ELSE part */
if (processThese) {
const int keyw_len = lstrlenW(L"else") + 1;
WCHAR *cmd = (CMD_node_get_command(*cmdList)->command) + keyw_len;
/* Skip leading whitespace between condition and the command */
while (*cmd && (*cmd==' ' || *cmd=='\t')) cmd++;
if (*cmd) {
WCMD_execute (cmd, CMD_node_get_single_node(*cmdList)->redirects, cmdList, FALSE);
}
} else {
/* Loop skipping all commands until we get back to the current
depth, including skipping commands and their subsequent
pipes (eg cmd | prog) */
do {
prev_op = (*cmdList)->op;
*cmdList = CMD_node_next(*cmdList);
} while (*cmdList &&
(CMD_node_get_depth(*cmdList) > myDepth ||
(prev_op != CMD_SINGLE && prev_op != CMD_CONCAT)));
/* After the else is complete, we need to now process subsequent commands */
processThese = TRUE;
}
if (curPosition == *cmdList)
{
prev_op = (*cmdList)->op;
*cmdList = CMD_node_next(*cmdList);
}
/* If we were in an IF statement and we didn't find an else and yet we get back to
the same bracket depth as the IF, then the IF statement is over. This is required
to handle nested ifs properly */
} else if (isIF && CMD_node_get_depth(*cmdList) == myDepth) {
if (WCMD_keyword_ws_found(L"do", CMD_node_get_command(*cmdList)->command)) {
WINE_TRACE("Still inside FOR-loop, not an end of IF statement\n");
prev_op = (*cmdList)->op;
*cmdList = CMD_node_next(*cmdList);
} else {
WINE_TRACE("Found end of this nested IF statement, ending this if\n");
break;
}
} else if (!processThese) {
if (curPosition == *cmdList) *cmdList = CMD_node_next(*cmdList);
WINE_TRACE("Skipping this command, as in not process mode (next = %p)\n", *cmdList);
} else {
WINE_TRACE("Found end of this IF statement (next = %p)\n", *cmdList);
break;
}
}
}
}
}
/*****************************************************************************
* WCMD_add_dirstowalk
*
@ -1849,43 +1715,6 @@ int WCMD_for_nexttoken(int lasttoken, const WCHAR *tokenstr,
return nexttoken;
}
/**************************************************************************
* WCMD_for
*
* Batch file loop processing.
*
* On entry: cmdList contains the syntax up to the set
* next cmdList and all in that bracket contain the set data
* next cmdlist contains the DO cmd
* following that is either brackets or && entries (as per if)
*
*/
void WCMD_for(WCHAR *p, CMD_NODE **cmdList)
{
CMD_FOR_CONTROL *for_ctrl;
for_ctrl = for_control_parse(p);
if (!for_ctrl)
{
*cmdList = NULL;
return;
}
for (*cmdList = CMD_node_next(*cmdList); /* swallow options */
*cmdList && CMD_node_get_command(*cmdList)->command != NULL;
*cmdList = CMD_node_next(*cmdList))
{
for_control_append_set(for_ctrl, CMD_node_get_command(*cmdList)->command);
}
/* step over terminating NULL CMD_NODE of set */
*cmdList = CMD_node_next(*cmdList);
for_control_execute(for_ctrl, cmdList);
for_control_dispose(for_ctrl);
}
/**************************************************************************
* WCMD_give_help
*
@ -2088,46 +1917,6 @@ void WCMD_popd (void) {
LocalFree (temp);
}
/****************************************************************************
* WCMD_if
*
* Batch file conditional.
*
* On entry, cmdlist will point to command containing the IF, and optionally
* the first command to execute (if brackets not found)
* If &&'s were found, this may be followed by a record flagged as isAmpersand
* If ('s were found, execute all within that bracket
* Command may optionally be followed by an ELSE - need to skip instructions
* in the else using the same logic
*
* FIXME: Much more syntax checking needed!
*/
void WCMD_if (WCHAR *p, CMD_NODE **cmdList)
{
CMD_IF_CONDITION if_cond;
WCHAR *command;
int test;
if (if_condition_create(p, &command, &if_cond))
{
TRACE("%s\n", debugstr_if_condition(&if_cond));
if (if_condition_evaluate(&if_cond, &test))
{
WINE_TRACE("p: %s, quals: %s, param1: %s, param2: %s, command: %s\n",
wine_dbgstr_w(p), wine_dbgstr_w(quals), wine_dbgstr_w(param1),
wine_dbgstr_w(param2), wine_dbgstr_w(command));
/* Process rest of IF statement which is on the same line
Note: This may process all or some of the cmdList (eg a GOTO) */
WCMD_part_execute(cmdList, command, TRUE, test);
}
if_condition_dispose(&if_cond);
return;
}
WCMD_output_stderr(WCMD_LoadMessage(WCMD_SYNTAXERR));
}
/****************************************************************************
* WCMD_move
*

View file

@ -409,4 +409,5 @@ Enter HELP <command> for further information on any of the above commands.\n"
WCMD_FILENAMETOOLONG, "File name is too long.\n"
WCMD_BADTOKEN, "Syntax error: unexpected %1\n"
WCMD_ENDOFLINE, "End of line"
WCMD_ENDOFFILE, "End of file"
}

View file

@ -1458,7 +1458,6 @@ for %%a in ("f"
"g"
"h"
) do if #==# (echo %%a)
echo ---
mkdir foobar & cd foobar
mkdir foo

View file

@ -371,8 +371,8 @@ r1
r2
r3
--- chain pipe
@todo_wine@a@space@
@todo_wine@a@space@
a@space@
a@space@
---
b2
c1
@ -399,9 +399,9 @@ f4:[f3:[f2:[f1,f2],f3],f4]@or_broken@f4:[f3:[f2:,f3],f4]@or_broken@f4:[f3:,f4]
a1
b2
@todo_wine@---
@todo_wine@c3
c3
@todo_wine@---
@todo_wine@d3
d3
@todo_wine@---
@todo_wine@---
@todo_wine@---
@ -634,7 +634,7 @@ gotitright
@todo_wine@0@or_broken@1
foo
!WINE_FOO!
@todo_wine@not empty
not empty
--- using /V cmd flag
foo
foo@or_broken@!WINE_FOO!
@ -1031,10 +1031,9 @@ b 1 3
3-A1
3-B2
--- nesting if/for
@todo_wine@"f"
@todo_wine@"g"
@todo_wine@"h"
@todo_wine@---
"f"
"g"
"h"
--- basic wildcards
bazbaz
--- wildcards in subdirs

View file

@ -56,6 +56,8 @@ typedef enum _CMD_OPERATOR
CMD_ONFAILURE, /* || */
CMD_ONSUCCESS, /* && */
CMD_PIPE, /* Single | */
CMD_IF, /* IF command */
CMD_FOR, /* FOR command */
} CMD_OPERATOR;
/* Data structure to hold commands to be processed */
@ -109,14 +111,12 @@ typedef struct _CMD_FOR_CONTROL
typedef struct _CMD_COMMAND
{
WCHAR *command; /* Command string to execute */
int bracketDepth;/* How deep bracketing have we got to */
WCHAR pipeFile[MAX_PATH]; /* Where to get input from for pipes */
} CMD_COMMAND;
typedef struct _CMD_NODE
{
CMD_OPERATOR op; /* operator */
CMD_REDIRECTION *redirects; /* Redirects in place */
CMD_REDIRECTION *redirects; /* Redirections */
union
{
CMD_COMMAND *command; /* CMD_SINGLE */
@ -125,51 +125,23 @@ typedef struct _CMD_NODE
struct _CMD_NODE *left;
struct _CMD_NODE *right;
};
struct /* CMD_IF */
{
CMD_IF_CONDITION condition;
struct _CMD_NODE *then_block;
struct _CMD_NODE *else_block;
};
struct /* CMD_FOR */
{
CMD_FOR_CONTROL for_ctrl;
struct _CMD_NODE *do_block;
};
};
} CMD_NODE;
/* temporary helpers to fake a list into a tree */
/* Note: for binary op, left should be a CMD_SINGLE node */
static inline const CMD_NODE *CMD_node_get_single_node(const CMD_NODE *node)
{
/* assert(node->left && node->left->op == CMD_SINGLE); */
return (node->op == CMD_SINGLE) ? node : node->left;
}
static inline CMD_COMMAND *CMD_node_get_command(const CMD_NODE *node)
{
return CMD_node_get_single_node(node)->command;
}
static inline CMD_NODE *CMD_node_next(const CMD_NODE *node)
{
return (node->op == CMD_SINGLE) ? NULL : node->right;
}
static inline int CMD_node_get_depth(const CMD_NODE *node)
{
CMD_COMMAND *cmd = CMD_node_get_command(node);
return cmd->bracketDepth;
}
/* end temporary */
/* temporary helpers for parsing transition */
BOOL if_condition_create(WCHAR *start, WCHAR **end, CMD_IF_CONDITION *cond);
void if_condition_dispose(CMD_IF_CONDITION *);
BOOL if_condition_evaluate(CMD_IF_CONDITION *cond, int *test);
const char *debugstr_if_condition(const CMD_IF_CONDITION *cond);
void for_control_create(enum for_control_operator for_op, unsigned flags, const WCHAR *options, int var_idx, CMD_FOR_CONTROL *for_ctrl);
void for_control_create_fileset(unsigned flags, int var_idx, WCHAR eol, int num_lines_to_skip, BOOL use_backq,
const WCHAR *delims, const WCHAR *tokens,
CMD_FOR_CONTROL *for_ctrl);
CMD_FOR_CONTROL *for_control_parse(WCHAR *opts_var);
void for_control_append_set(CMD_FOR_CONTROL *for_ctrl, const WCHAR *string);
void for_control_dump(const CMD_FOR_CONTROL *for_ctrl);
void for_control_dispose(CMD_FOR_CONTROL *for_ctrl);
void for_control_execute(CMD_FOR_CONTROL *for_ctrl, CMD_NODE **cmdList);
int WCMD_for_nexttoken(int lasttoken, const WCHAR *tokenstr,
int *totalfound, BOOL *doall,
BOOL *duplicates);
void WCMD_part_execute(CMD_NODE **cmdList, const WCHAR *firstcmd,
BOOL isIF, BOOL executecmds);
struct _DIRECTORY_STACK;
void WCMD_add_dirstowalk(struct _DIRECTORY_STACK *dirsToWalk);
struct _DIRECTORY_STACK *WCMD_dir_stack_create(const WCHAR *dir, const WCHAR *file);
@ -200,11 +172,9 @@ void WCMD_echo (const WCHAR *);
void WCMD_endlocal (void);
void WCMD_enter_paged_mode(const WCHAR *);
RETURN_CODE WCMD_exit(void);
void WCMD_for (WCHAR *, CMD_NODE **cmdList);
BOOL WCMD_get_fullpath(const WCHAR *, SIZE_T, WCHAR *, WCHAR **);
void WCMD_give_help (const WCHAR *args);
RETURN_CODE WCMD_goto(void);
void WCMD_if (WCHAR *, CMD_NODE **cmdList);
void WCMD_leave_paged_mode(void);
void WCMD_more (WCHAR *);
void WCMD_move (void);
@ -250,10 +220,8 @@ WCHAR *WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int
BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWORD charsRead);
WCHAR *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_NODE **output, HANDLE readFrom);
CMD_NODE *WCMD_process_commands(CMD_NODE *thisCmd, BOOL oneBracket, BOOL retrycall);
void node_dispose_tree(CMD_NODE *cmds);
void WCMD_execute(const WCHAR *orig_command, CMD_REDIRECTION *redirects,
CMD_NODE **cmdList, BOOL retrycall);
RETURN_CODE node_execute(CMD_NODE *node);
void *xrealloc(void *, size_t) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(free);
@ -483,3 +451,4 @@ extern WCHAR version_string[];
#define WCMD_FILENAMETOOLONG 1046
#define WCMD_BADTOKEN 1047
#define WCMD_ENDOFLINE 1048
#define WCMD_ENDOFFILE 1049

File diff suppressed because it is too large Load diff