12#define MSCMD_ECHO_COMMAND_COMPAT
15#define MSCMD_PARSER_BUGS
21#define MSCMD_REDIR_PARSE_BUGS
38#define C_OP_LOWEST C_MULTI
39#define C_OP_HIGHEST C_PIPE
55#define IF_MAX_UNARY IF_DEFINED
69#define IF_MAX_COMPARISON IF_GEQ
101#ifndef MSCMD_PARSER_BUGS
103static PTCHAR LastCurTokPos;
168#ifndef MSCMD_PARSER_BUGS
169 bReparseToken =
TRUE;
179#ifndef MSCMD_PARSER_BUGS
180 bReparseToken =
FALSE;
181 LastCurTokPos =
NULL;
204 while (Char ==
_T(
'\r'));
253#ifndef MSCMD_PARSER_BUGS
256 bReparseToken =
FALSE;
262 CurrentTokStart = LastCurTokPos;
263 Out = CurrentTokStart;
276 bInQuote ^= (Char ==
_T(
'"'));
279 if (Separators !=
NULL)
284 if (
Out == CurrentTokStart)
291 if ((
Out == CurrentTokStart) && (Char == PrefixOperator))
313 if (Char == ExtraEnd)
324 if (Char ==
_T(
'\n'))
326#ifndef MSCMD_PARSER_BUGS
333 if (
Out == CurrentTokStart)
355 if (
Out != CurrentTokStart)
362 else if (Char ==
_T(
'@'))
368 else if (Char ==
_T(
'('))
374 else if (Char ==
_T(
')'))
380 else if (Char ==
_T(
'&') || Char ==
_T(
'|'))
393 (Char ==
_T(
'<') || Char ==
_T(
'>')) )
475 Command.First[CmdHeadLen + CmdTailLen]));
484 Cmd->Command.Rest =
Cmd->Command.First + CmdHeadLen;
520 ERR(
"Unknown command type 0x%x\n",
Type);
530 if (
Cmd->Subcommands)
559 if ( !(*Tok ==
_T(
'<') || *Tok ==
_T(
'>')) &&
561 (Tok[1] ==
_T(
'<') || Tok[1] ==
_T(
'>')) ) )
574 if (*Tok++ ==
_T(
'<'))
598#ifndef MSCMD_REDIR_PARSE_BUGS
611 while ((Redir = *
List))
625 WARN(
"Cannot allocate memory for Redir!\n");
631 Redir->
Mode = RedirMode;
657 WARN(
"Cannot allocate memory for Cmd!\n");
663 NextPtr = &
Cmd->Subcommands;
701 NextPtr = &Sub->
Next;
727#ifndef MSCMD_REDIR_PARSE_BUGS
787 WARN(
"Cannot allocate memory for Cmd!\n");
858 if (
Cmd->Subcommands->Next ==
NULL)
886 WARN(
"Cannot allocate memory for Cmd!\n");
904 if (!
Cmd->For.Params)
919 if (!
Cmd->For.Params)
938 if ((
Cmd->For.Switches & (
Cmd->For.Switches - 1)) != 0
1039 ParsedLine + TailOffset);
1042 WARN(
"Cannot allocate memory for Cmd!\n");
1130#ifndef MSCMD_REDIR_PARSE_BUGS
1198 ParsedLine + TailOffset);
1201 WARN(
"Cannot allocate memory for Cmd!\n");
1220 WARN(
"Cannot allocate memory for Cmd!\n");
1231#ifndef MSCMD_REDIR_PARSE_BUGS
1283 Cmd->Redirections = RedirList;
1308#ifdef MSCMD_PARENS_PARSE_BUGS
1321#ifdef MSCMD_PARENS_PARSE_BUGS
1382#ifdef MSCMD_PARENS_PARSE_BUGS
1422#ifndef MSCMD_MULTI_EMPTY_RHS
1430 WARN(
"Cannot allocate memory for Cmd!\n");
1436 Cmd->Subcommands = Left;
1438#ifdef MSCMD_MULTI_EMPTY_RHS
1520#ifndef MSCMD_ECHO_COMMAND_COMPAT
1525 for (Redir = Redirections; Redir; Redir = Redir->
Next)
1542#define DUMP(Command, Pad) \
1564#ifndef MSCMD_ECHO_COMMAND_COMPAT
1566 Cmd->Command.First,
Cmd->Type);
1569 Cmd->Command.First,
Cmd->Type);
1572 if (
Cmd->Command.Rest && *(
Cmd->Command.Rest))
1573#ifndef MSCMD_ECHO_COMMAND_COMPAT
1587#ifndef MSCMD_ECHO_COMMAND_COMPAT
1595 DUMP(
Cmd->Subcommands, SpacePad + 2);
1601#ifndef MSCMD_ECHO_COMMAND_COMPAT
1611 for (Sub =
Cmd->Subcommands; Sub; Sub = Sub->
Next)
1613#if defined(MSCMD_ECHO_COMMAND_COMPAT) && defined(MSCMD_PARSER_BUGS)
1661#ifndef MSCMD_ECHO_COMMAND_COMPAT
1680#ifndef MSCMD_ECHO_COMMAND_COMPAT
1689 Sub =
Cmd->Subcommands;
1704 if (
Cmd->For.Params)
1707 DUMP(
Cmd->Subcommands, SpacePad + 2);
1757#ifndef MSCMD_ECHO_COMMAND_COMPAT
1771#ifndef MSCMD_ECHO_COMMAND_COMPAT
1784 Sub =
Cmd->Subcommands;
1827#ifdef MSCMD_ECHO_COMMAND_COMPAT
1844 Sub =
Cmd->Subcommands;
1846 bIsFirstCmdCRLF = (Sub && Sub->
Next);
1848#if defined(MSCMD_ECHO_COMMAND_COMPAT) && defined(MSCMD_PARSER_BUGS)
1853 bIsFirstCmdCRLF = bIsFirstCmdCRLF && (Sub->
Type !=
C_MULTI);
1860 if (bIsFirstCmdCRLF)
1863 for (; Sub; Sub = Sub->
Next)
1867#ifdef MSCMD_ECHO_COMMAND_COMPAT
1874 if (bIsFirstCmdCRLF)
1877#ifdef MSCMD_ECHO_COMMAND_COMPAT
1891 Sub =
Cmd->Subcommands;
1905 if (
Cmd->For.Params)
1927 Sub =
Cmd->Subcommands;
1942 for (Redir =
Cmd->Redirections; Redir; Redir = Redir->
Next)
1946#ifdef MSCMD_ECHO_COMMAND_COMPAT
1977 if (Out == OutEnd) return NULL; \
1980#define STRING(String) \
1982 if (Out + _tcslen(String) > OutEnd) return NULL; \
1983 Out = _stpcpy(Out, String); \
1985#define PRINTF(Format, ...) \
1987 UINT Len = _sntprintf(Out, OutEnd - Out, Format, __VA_ARGS__); \
1988 if (Len > (UINT)(OutEnd - Out)) return NULL; \
1991#define RECURSE(Subcommand) \
1993 Out = UnparseCommand(Subcommand, Out, OutEnd); \
1994 if (!Out) return NULL; \
2028 for (Sub =
Cmd->Subcommands; Sub; Sub = Sub->
Next)
2043 Sub =
Cmd->Subcommands;
2057 if (
Cmd->For.Params)
2062 PRINTF(
_T(
" %%%c in (%s) do "),
Cmd->For.Variable,
Cmd->For.List);
2079 Sub =
Cmd->Subcommands;
2094 for (Redir =
Cmd->Redirections; Redir; Redir = Redir->
Next)
void restart(int argc, const char *argv[])
BOOL SubstituteVars(IN PCTSTR Src, OUT PTSTR Dest, IN TCHAR Delim)
BOOL ReadLine(TCHAR *commandline, BOOL bMore)
BOOL SubstituteForVars(IN PCTSTR Src, OUT PTSTR Dest)
#define IFFLAG_IGNORECASE
enum _COMMAND_TYPE COMMAND_TYPE
LPTSTR _stpcpy(LPTSTR, LPCTSTR)
enum _REDIR_MODE REDIR_MODE
VOID FreeRedirection(REDIRECTION *)
VOID error_syntax(PCTSTR s)
#define ConOutPrintf(szStr,...)
#define ConOutPuts(szStr)
static PARSED_COMMAND * ParseIf(VOID)
#define DUMP(Command, Pad)
PARSED_COMMAND * ParseCommand(IN PCTSTR Line)
BOOL bHandleContinuations
static __inline PARSED_COMMAND * ParseCommandOp(IN COMMAND_TYPE OpType)
static TOK_TYPE CurrentTokenType
PTCHAR UnparseCommand(IN PARSED_COMMAND *Cmd, OUT PTCHAR Out, IN PTCHAR OutEnd)
static PARSED_COMMAND * ParseRem(VOID)
VOID ParseErrorEx(IN PCTSTR s)
static const TCHAR *const IfOperatorString[]
static __inline BOOL IsSeparator(TCHAR Char)
static __inline VOID ParseError(VOID)
static PARSED_COMMAND * ParsePrimary(VOID)
#define PRINTF(Format,...)
static VOID DumpRedir(IN REDIRECTION *Redirections)
VOID EchoCommand(IN PARSED_COMMAND *Cmd)
static __inline INT ParseToken(IN TCHAR ExtraEnd OPTIONAL, IN PCTSTR Separators OPTIONAL)
static TOK_TYPE ParseTokenEx(IN TCHAR PrefixOperator OPTIONAL, IN TCHAR ExtraEnd OPTIONAL, IN PCTSTR Separators OPTIONAL, IN BOOL bHandleContinuations)
static PARSED_COMMAND * ParseBlock(IN OUT REDIRECTION **RedirList)
VOID DumpCommand(IN PARSED_COMMAND *Cmd, IN ULONG SpacePad)
static TCHAR TempBuf[CMDLINE_LENGTH]
static BOOL ParseRedirection(IN OUT REDIRECTION **List)
static TCHAR CurrentToken[CMDLINE_LENGTH]
static VOID InitParser(VOID)
static const TCHAR OpString[][3]
static VOID UnParseToken(VOID)
static BOOL bLineContinuations
static const TCHAR RedirString[][3]
static PARSED_COMMAND * ParseCommandPart(IN OUT REDIRECTION **RedirList)
BOOL bIgnoreParserComments
static TCHAR ParseChar(VOID)
#define RECURSE(Subcommand)
static PTCHAR OldParsePos
TCHAR ParseLine[CMDLINE_LENGTH]
static PARSED_COMMAND * AllocCommand(IN COMMAND_TYPE Type, IN PCTSTR CmdHead OPTIONAL, IN PCTSTR CmdTail OPTIONAL)
#define IF_MAX_COMPARISON
static PARSED_COMMAND * ParseFor(VOID)
VOID FreeCommand(IN OUT PARSED_COMMAND *Cmd)
static PARSED_COMMAND * ParseCommandBinaryOp(IN COMMAND_TYPE OpType)
static VOID ResetParser(IN PTCHAR Pos)
static VOID StripQuotes(LPSTR in)
#define INVALID_HANDLE_VALUE
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
#define memcpy(s1, s2, n)
static void dump(const void *ptr, unsigned len)
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
PULONG MinorVersion OPTIONAL
struct _PARSED_COMMAND * Next
struct _REDIRECTION * Next
#define FIELD_OFFSET(t, f)
_Must_inspect_result_ _In_ WDFCMRESLIST List