[CMD] Fix the command echo-er/unparser.

- Use ConOutPuts() instead of ConOutPrintf() for displaying strings that
  are not printf formatted.

- When echo-ing/unparsing FOR command, any possible FOR variables
  present in the FOR parenthesized list (before the "do" part) should be
  substituted as well.
This commit is contained in:
Hermès Bélusca-Maïto 2020-06-06 20:48:59 +02:00
parent 6f87d45e1c
commit 47ea3f1faa
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -1169,11 +1169,11 @@ EchoCommand(PARSED_COMMAND *Cmd)
break; break;
case C_IF: case C_IF:
ConOutPrintf(_T("if")); ConOutPuts(_T("if"));
if (Cmd->If.Flags & IFFLAG_IGNORECASE) if (Cmd->If.Flags & IFFLAG_IGNORECASE)
ConOutPrintf(_T(" /I")); ConOutPuts(_T(" /I"));
if (Cmd->If.Flags & IFFLAG_NEGATE) if (Cmd->If.Flags & IFFLAG_NEGATE)
ConOutPrintf(_T(" not")); ConOutPuts(_T(" not"));
if (Cmd->If.LeftArg && SubstituteForVars(Cmd->If.LeftArg, Buf)) if (Cmd->If.LeftArg && SubstituteForVars(Cmd->If.LeftArg, Buf))
ConOutPrintf(_T(" %s"), Buf); ConOutPrintf(_T(" %s"), Buf);
ConOutPrintf(_T(" %s"), IfOperatorString[Cmd->If.Operator]); ConOutPrintf(_T(" %s"), IfOperatorString[Cmd->If.Operator]);
@ -1183,20 +1183,23 @@ EchoCommand(PARSED_COMMAND *Cmd)
EchoCommand(Sub); EchoCommand(Sub);
if (Sub->Next) if (Sub->Next)
{ {
ConOutPrintf(_T(" else ")); ConOutPuts(_T(" else "));
EchoCommand(Sub->Next); EchoCommand(Sub->Next);
} }
break; break;
case C_FOR: case C_FOR:
ConOutPrintf(_T("for")); ConOutPuts(_T("for"));
if (Cmd->For.Switches & FOR_DIRS) ConOutPrintf(_T(" /D")); if (Cmd->For.Switches & FOR_DIRS) ConOutPuts(_T(" /D"));
if (Cmd->For.Switches & FOR_F) ConOutPrintf(_T(" /F")); if (Cmd->For.Switches & FOR_F) ConOutPuts(_T(" /F"));
if (Cmd->For.Switches & FOR_LOOP) ConOutPrintf(_T(" /L")); if (Cmd->For.Switches & FOR_LOOP) ConOutPuts(_T(" /L"));
if (Cmd->For.Switches & FOR_RECURSIVE) ConOutPrintf(_T(" /R")); if (Cmd->For.Switches & FOR_RECURSIVE) ConOutPuts(_T(" /R"));
if (Cmd->For.Params) if (Cmd->For.Params)
ConOutPrintf(_T(" %s"), Cmd->For.Params); ConOutPrintf(_T(" %s"), Cmd->For.Params);
ConOutPrintf(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List); if (Cmd->For.List && SubstituteForVars(Cmd->For.List, Buf))
ConOutPrintf(_T(" %%%c in (%s) do "), Cmd->For.Variable, Buf);
else
ConOutPrintf(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List);
EchoCommand(Cmd->Subcommands); EchoCommand(Cmd->Subcommands);
break; break;
} }
@ -1316,7 +1319,10 @@ do { \
if (Cmd->For.Switches & FOR_RECURSIVE) STRING(_T(" /R")); if (Cmd->For.Switches & FOR_RECURSIVE) STRING(_T(" /R"));
if (Cmd->For.Params) if (Cmd->For.Params)
PRINTF(_T(" %s"), Cmd->For.Params); PRINTF(_T(" %s"), Cmd->For.Params);
PRINTF(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List); if (Cmd->For.List && SubstituteForVars(Cmd->For.List, Buf))
PRINTF(_T(" %%%c in (%s) do "), Cmd->For.Variable, Buf);
else
PRINTF(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List);
RECURSE(Cmd->Subcommands); RECURSE(Cmd->Subcommands);
break; break;
} }