ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
August 2008
----- 2024 -----
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
27 participants
853 discussions
Start a n
N
ew thread
[jmorlan] 35514: - Begin writing a real parser for cmd. &, &&, ||, and () are implemented. The parenthesized blocks aren't too useful yet as the parser can't read additional lines; doing this will require some restructuring in cmd.c. - Remove ^-removing hacks in echo and set.
by jmorlan@svn.reactos.org
Author: jmorlan Date: Thu Aug 21 15:18:35 2008 New Revision: 35514 URL:
http://svn.reactos.org/svn/reactos?rev=35514&view=rev
Log: - Begin writing a real parser for cmd. &, &&, ||, and () are implemented. The parenthesized blocks aren't too useful yet as the parser can't read additional lines; doing this will require some restructuring in cmd.c. - Remove ^-removing hacks in echo and set. Added: trunk/reactos/base/shell/cmd/parser.c (with props) Modified: trunk/reactos/base/shell/cmd/cmd.c trunk/reactos/base/shell/cmd/cmd.h trunk/reactos/base/shell/cmd/cmd.rbuild trunk/reactos/base/shell/cmd/echo.c trunk/reactos/base/shell/cmd/redir.c trunk/reactos/base/shell/cmd/set.c Modified: trunk/reactos/base/shell/cmd/cmd.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=3…
============================================================================== --- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Thu Aug 21 15:18:35 2008 @@ -323,7 +323,7 @@ * Rest - rest of command line */ -static VOID +static BOOL Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest) { TCHAR *szFullName=NULL; @@ -345,7 +345,7 @@ { error_out_of_memory(); nErrorLevel = 1; - return ; + return FALSE; } rest = cmd_alloc ( (_tcslen(Rest) + 512) * sizeof(TCHAR)); @@ -354,7 +354,7 @@ cmd_free (first); error_out_of_memory(); nErrorLevel = 1; - return ; + return FALSE; } full = cmd_alloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); @@ -364,7 +364,7 @@ cmd_free (rest); error_out_of_memory(); nErrorLevel = 1; - return ; + return FALSE; } szFullName = cmd_alloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); @@ -375,7 +375,7 @@ cmd_free (full); error_out_of_memory(); nErrorLevel = 1; - return ; + return FALSE; } @@ -446,7 +446,7 @@ cmd_free (full); cmd_free (szFullName); nErrorLevel = 1; - return; + return working; } /* get the PATH environment variable and parse it */ @@ -459,7 +459,7 @@ cmd_free (full); cmd_free (szFullName); nErrorLevel = 1; - return; + return FALSE; } @@ -554,6 +554,7 @@ cmd_free(rest); cmd_free(full); cmd_free (szFullName); + return nErrorLevel == 0; } @@ -566,7 +567,7 @@ * */ -VOID +BOOL DoCommand (LPTSTR line) { TCHAR *com = NULL; /* the first word in the command */ @@ -575,6 +576,7 @@ LPTSTR rest; /* pointer to the rest of the command line */ INT cl; LPCOMMAND cmdptr; + BOOL ret = TRUE; TRACE ("DoCommand: (\'%s\')\n", debugstr_aw(line)); @@ -582,7 +584,7 @@ if (com == NULL) { error_out_of_memory(); - return; + return FALSE; } cp = com; @@ -640,7 +642,7 @@ /* If end of table execute ext cmd */ if (cmdptr->name == NULL) { - Execute (line, com, rest); + ret = Execute (line, com, rest); break; } @@ -677,6 +679,7 @@ } } cmd_free(com); + return ret; } @@ -687,25 +690,28 @@ VOID ParseCommandLine (LPTSTR cmd) { - TCHAR cmdline[CMDLINE_LENGTH]; - LPTSTR s; + PARSED_COMMAND *Cmd = ParseCommand(cmd); + if (Cmd) + { + ExecuteCommand(Cmd); + FreeCommand(Cmd); + } +} + +static VOID +ExecutePipeline(PARSED_COMMAND *Cmd) +{ #ifdef FEATURE_REDIRECTION - REDIRECTION *RedirList = NULL; TCHAR szTempPath[MAX_PATH] = _T(".\\"); TCHAR szFileName[2][MAX_PATH] = {_T(""), _T("")}; HANDLE hFile[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE}; - INT num = 0; INT Length; UINT Attributes; - BOOL bNewBatch = TRUE; HANDLE hOldConIn; HANDLE hOldConOut; #endif /* FEATURE_REDIRECTION */ - _tcscpy (cmdline, cmd); - s = &cmdline[0]; - - TRACE ("ParseCommandLine: (\'%s\')\n", debugstr_aw(s)); + //TRACE ("ParseCommandLine: (\'%s\')\n", debugstr_aw(s)); #ifdef FEATURE_REDIRECTION /* find the temp path to store temporary files */ @@ -726,15 +732,6 @@ if (szTempPath[_tcslen (szTempPath) - 1] != _T('\\')) _tcscat (szTempPath, _T("\\")); - /* get the redirections from the command line */ - num = GetRedirection (s, &RedirList); - - if (!PerformRedirection(RedirList)) - { - FreeRedirection(RedirList); - return; - } - /* Set up the initial conditions ... */ /* preserve STDIN and STDOUT handles */ hOldConIn = GetStdHandle (STD_INPUT_HANDLE); @@ -744,7 +741,7 @@ *szFileName[0] = _T('\0'); hFile[0] = INVALID_HANDLE_VALUE; - while (num-- > 1) + while (Cmd->Type == C_PIPE) { SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; @@ -766,7 +763,7 @@ SetStdHandle (STD_OUTPUT_HANDLE, hFile[1]); - DoCommand (s); + ExecuteCommand(Cmd->Subcommands); /* close stdout file */ SetStdHandle (STD_OUTPUT_HANDLE, hOldConOut); @@ -799,22 +796,18 @@ OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL); SetStdHandle (STD_INPUT_HANDLE, hFile[0]); - s = s + _tcslen (s) + 1; + Cmd = Cmd->Subcommands->Next; } /* Now set up the end conditions... */ SetStdHandle(STD_OUTPUT_HANDLE, hOldConOut); - if(bc) - bNewBatch = FALSE; #endif /* process final command */ - DoCommand (s); + ExecuteCommand(Cmd); #ifdef FEATURE_REDIRECTION - if(bNewBatch && bc) - AddBatchRedirection(&RedirList); /* close old stdin file */ #if 0 /* buggy implementation */ SetStdHandle (STD_INPUT_HANDLE, hOldConIn); @@ -870,10 +863,53 @@ } } } - - UndoRedirection(RedirList, NULL); - FreeRedirection(RedirList); #endif /* FEATURE_REDIRECTION */ +} + +BOOL +ExecuteCommand(PARSED_COMMAND *Cmd) +{ + BOOL bNewBatch = TRUE; + PARSED_COMMAND *Sub; + BOOL Success = TRUE; + + if (!PerformRedirection(Cmd->Redirections)) + return FALSE; + + switch (Cmd->Type) + { + case C_COMMAND: + if(bc) + bNewBatch = FALSE; + + Success = DoCommand(Cmd->CommandLine); + + if(bNewBatch && bc) + AddBatchRedirection(&Cmd->Redirections); + break; + case C_QUIET: + case C_BLOCK: + case C_MULTI: + for (Sub = Cmd->Subcommands; Sub; Sub = Sub->Next) + Success = ExecuteCommand(Sub); + break; + case C_IFFAILURE: + case C_IFSUCCESS: + Sub = Cmd->Subcommands; + Success = ExecuteCommand(Sub); + if (Success == (Cmd->Type - C_IFFAILURE)) + { + Sub = Sub->Next; + Success = ExecuteCommand(Sub); + } + break; + case C_PIPE: + ExecutePipeline(Cmd); + break; + } + + UndoRedirection(Cmd->Redirections, NULL); + return Success; } BOOL Modified: trunk/reactos/base/shell/cmd/cmd.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=3…
============================================================================== --- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Thu Aug 21 15:18:35 2008 @@ -97,10 +97,12 @@ /* Prototypes for CMD.C */ INT ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len, BOOL bPutSeperator); VOID ParseCommandLine (LPTSTR); +struct _PARSED_COMMAND; +BOOL ExecuteCommand(struct _PARSED_COMMAND *Cmd); LPCTSTR GetEnvVarOrSpecial ( LPCTSTR varName ); VOID AddBreakHandler (VOID); VOID RemoveBreakHandler (VOID); -VOID DoCommand (LPTSTR line); +BOOL DoCommand (LPTSTR line); int cmd_main (int argc, const TCHAR *argv[]); extern HANDLE CMD_ModuleHandle; @@ -326,6 +328,21 @@ INT CommandMsgbox (LPTSTR, LPTSTR); +/* Prototypes from PARSER.C */ +enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE }; +typedef struct _PARSED_COMMAND +{ + struct _PARSED_COMMAND *Subcommands; + struct _PARSED_COMMAND *Next; + struct _REDIRECTION *Redirections; + TCHAR *Tail; + BYTE Type; + TCHAR CommandLine[]; +} PARSED_COMMAND; +PARSED_COMMAND *ParseCommand(LPTSTR Line); +VOID FreeCommand(PARSED_COMMAND *Cmd); + + /* Prototypes from PATH.C */ INT cmd_path (LPTSTR, LPTSTR); Modified: trunk/reactos/base/shell/cmd/cmd.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.rbuild?…
============================================================================== --- trunk/reactos/base/shell/cmd/cmd.rbuild [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.rbuild [iso-8859-1] Thu Aug 21 15:18:35 2008 @@ -44,6 +44,7 @@ <file>misc.c</file> <file>move.c</file> <file>msgbox.c</file> + <file>parser.c</file> <file>path.c</file> <file>pause.c</file> <file>prompt.c</file> Modified: trunk/reactos/base/shell/cmd/echo.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/echo.c?rev=…
============================================================================== --- trunk/reactos/base/shell/cmd/echo.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/echo.c [iso-8859-1] Thu Aug 21 15:18:35 2008 @@ -83,16 +83,6 @@ } if (*p1 != _T('\0')) { - p1 = param; - while (NULL != (p1 = _tcschr(p1, _T('^')))) - { - memmove(p1, p1 + 1, (_tcslen(p1 + 1) + 1) * sizeof(TCHAR)); - if (*p1) - { - //skip past the char being escaped - p1++; - } - } ConOutPuts (param); } else Added: trunk/reactos/base/shell/cmd/parser.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/parser.c?re…
============================================================================== --- trunk/reactos/base/shell/cmd/parser.c (added) +++ trunk/reactos/base/shell/cmd/parser.c [iso-8859-1] Thu Aug 21 15:18:35 2008 @@ -1,0 +1,456 @@ +#include <precomp.h> + +#define C_OP_LOWEST C_MULTI +#define C_OP_HIGHEST C_PIPE +static const TCHAR OpString[][3] = { _T("&"), _T("||"), _T("&&"), _T("|") }; + +static const TCHAR RedirString[][3] = { _T("<"), _T(">"), _T(">>") }; + +static BOOL IsSeparator(TCHAR Char) +{ + /* These three characters act like spaces to the parser */ + return _istspace(Char) || (Char && _tcschr(_T(",;="), Char)); +} + +enum { TOK_END, TOK_NORMAL, TOK_OPERATOR, TOK_REDIRECTION, + TOK_BEGIN_BLOCK, TOK_END_BLOCK }; + +static BOOL bParseError; +static BOOL bLineContinuations; +static TCHAR ParseLine[CMDLINE_LENGTH]; +static TCHAR *ParsePos; +static TCHAR CurChar; + +static TCHAR CurrentToken[CMDLINE_LENGTH]; +static int CurrentTokenType; +static int InsideBlock; + +static TCHAR ParseChar() +{ + TCHAR Char; + +//restart: + /* Although CRs can be injected into a line via an environment + * variable substitution, the parser ignores them - they won't + * even separate tokens. */ + do + Char = *ParsePos++; + while (Char == _T('\r')); + + if (!Char) + { + /*if (bLineContinuations) + if (ReadLine(ParseLine, TRUE) && *(ParsePos = ParseLine)) + goto restart;*/ + } + return CurChar = Char; +} + +static void ParseError() +{ + if (CurrentTokenType == TOK_END) + ConOutResPuts(STRING_SYNTAX_COMMAND_INCORRECT); + else + ConOutPrintf(_T("%s was unexpected at this time.\n"), CurrentToken); + bParseError = TRUE; +} + +/* Yes, cmd has a Lexical Analyzer. Whenever the parser gives an "xxx was + * unexpected at this time." message, it shows what the last token read was */ +static int ParseToken(TCHAR ExtraEnd, BOOL PreserveSpace) +{ + TCHAR *Out = CurrentToken; + TCHAR Char = CurChar; + int Type; + BOOL bInQuote = FALSE; + + if (!PreserveSpace) + { + while (Char != _T('\n') && IsSeparator(Char)) + Char = ParseChar(); + } + + while (Char && Char != _T('\n')) + { + bInQuote ^= (Char == _T('"')); + if (!bInQuote) + { + /* Check for all the myriad ways in which this token + * may be brought to an untimely end. */ + if ((Char >= _T('0') && Char <= _T('9') && + (ParsePos == &ParseLine[1] || IsSeparator(ParsePos[-2])) + && (*ParsePos == _T('<') || *ParsePos == _T('>'))) + || _tcschr(_T(")&|<>") + (InsideBlock ? 0 : 1), Char) + || (!PreserveSpace && IsSeparator(Char)) + || (Char == ExtraEnd)) + { + break; + } + + if (Char == _T('^')) + { + Char = ParseChar(); + /* Eat up a \n, allowing line continuation */ + if (Char == _T('\n')) + Char = ParseChar(); + /* Next character is a forced literal */ + } + } + /* FIXME: potential buffer overflow here */ + *Out++ = Char; + Char = ParseChar(); + } + + /* Check if we got at least one character before reaching a special one. + * If so, return them and leave the special for the next call. */ + if (Out != CurrentToken) + { + Type = TOK_NORMAL; + } + else if (Char == _T('(')) + { + Type = TOK_BEGIN_BLOCK; + *Out++ = Char; + ParseChar(); + } + else if (Char == _T(')')) + { + Type = TOK_END_BLOCK; + *Out++ = Char; + ParseChar(); + } + else if (Char == _T('&') || Char == _T('|')) + { + Type = TOK_OPERATOR; + *Out++ = Char; + Char = ParseChar(); + /* check for && or || */ + if (Char == Out[-1]) + { + *Out++ = Char; + ParseChar(); + } + } + else if ((Char >= _T('0') && Char <= _T('9')) + || (Char == _T('<') || Char == _T('>'))) + { + Type = TOK_REDIRECTION; + if (Char >= _T('0') && Char <= _T('9')) + { + *Out++ = Char; + Char = ParseChar(); + } + *Out++ = Char; + Char = ParseChar(); + if (Char == Out[-1]) + { + /* Strangely, the tokenizer allows << as well as >>... (it + * will cause an error when trying to parse it though) */ + *Out++ = Char; + Char = ParseChar(); + } + if (Char == _T('&')) + { + *Out++ = Char; + while (IsSeparator(Char = ParseChar())) + ; + if (Char >= _T('0') && Char <= _T('9')) + { + *Out++ = Char; + ParseChar(); + } + } + } + else + { + Type = TOK_END; + } + *Out = _T('\0'); + return CurrentTokenType = Type; +} + +static BOOL ParseRedirection(REDIRECTION **List) +{ + TCHAR *Tok = CurrentToken; + BYTE Number; + BYTE RedirType; + REDIRECTION *Redir; + + if (*Tok >= _T('0') && *Tok <= _T('9')) + Number = *Tok++ - _T('0'); + else + Number = *Tok == _T('<') ? 0 : 1; + + if (*Tok++ == _T('<')) + { + RedirType = REDIR_READ; + if (*Tok == _T('<')) + goto fail; + } + else + { + RedirType = REDIR_WRITE; + if (*Tok == _T('>')) + { + RedirType = REDIR_APPEND; + Tok++; + } + } + + if (!*Tok) + { + /* The file name was not part of this token, so it'll be the next one */ + if (ParseToken(0, FALSE) != TOK_NORMAL) + goto fail; + Tok = CurrentToken; + } + + /* If a redirection for this handle number already exists, delete it */ + while ((Redir = *List)) + { + if (Redir->Number == Number) + { + *List = Redir->Next; + cmd_free(Redir); + continue; + } + List = &Redir->Next; + } + + Redir = cmd_alloc(FIELD_OFFSET(REDIRECTION, Filename[_tcslen(Tok) + 1])); + Redir->Next = NULL; + Redir->OldHandle = INVALID_HANDLE_VALUE; + Redir->Number = Number; + Redir->Type = RedirType; + _tcscpy(Redir->Filename, Tok); + *List = Redir; + return TRUE; +fail: + ParseError(); + FreeRedirection(*List); + *List = NULL; + return FALSE; +} + +static PARSED_COMMAND *ParseCommandOp(int OpType); + +/* Parse a parenthesized block */ +static PARSED_COMMAND *ParseBlock(REDIRECTION *RedirList) +{ + PARSED_COMMAND *Cmd, *Sub, **NextPtr; + Cmd = cmd_alloc(sizeof(PARSED_COMMAND)); + Cmd->Type = C_BLOCK; + Cmd->Next = NULL; + Cmd->Subcommands = NULL; + Cmd->Redirections = RedirList; + + /* Read the block contents */ + NextPtr = &Cmd->Subcommands; + InsideBlock++; + do + { + Sub = ParseCommandOp(C_OP_LOWEST); + if (Sub) + { + *NextPtr = Sub; + NextPtr = &Sub->Next; + } + else if (bParseError) + { + InsideBlock--; + FreeCommand(Cmd); + return NULL; + } + } while (CurrentTokenType != TOK_END_BLOCK); + InsideBlock--; + + /* Process any trailing redirections */ + while (ParseToken(0, FALSE) == TOK_REDIRECTION) + { + if (!ParseRedirection(&Cmd->Redirections)) + { + FreeCommand(Cmd); + return NULL; + } + } + return Cmd; +} + +static PARSED_COMMAND *ParseCommandPart(void) +{ + TCHAR ParsedLine[CMDLINE_LENGTH]; + TCHAR *Pos; + DWORD TailOffset; + PARSED_COMMAND *Cmd; + REDIRECTION *RedirList = NULL; + int Type; + + while (IsSeparator(CurChar)) + { + if (CurChar == _T('\n')) + return NULL; + ParseChar(); + } + + if (!CurChar) + return NULL; + + if (CurChar == _T(':')) + { + /* "Ignore" the rest of the line. + * (Line continuations will still be parsed, though.) */ + while (ParseToken(0, TRUE) != TOK_END) + ; + return NULL; + } + + if (CurChar == _T('@')) + { + ParseChar(); + Cmd = cmd_alloc(sizeof(PARSED_COMMAND)); + Cmd->Type = C_QUIET; + Cmd->Next = NULL; + /* @ acts like a unary operator with low precedence, + * so call the top-level parser */ + Cmd->Subcommands = ParseCommandOp(C_OP_LOWEST); + Cmd->Redirections = NULL; + return Cmd; + } + + /* Get the head of the command */ + while (1) + { + Type = ParseToken(_T('('), FALSE); + if (Type == TOK_NORMAL) + { + Pos = _stpcpy(ParsedLine, CurrentToken); + break; + } + else if (Type == TOK_REDIRECTION) + { + if (!ParseRedirection(&RedirList)) + return NULL; + } + else if (Type == TOK_BEGIN_BLOCK) + { + return ParseBlock(RedirList); + } + else + { + ParseError(); + FreeRedirection(RedirList); + return NULL; + } + } + TailOffset = Pos - ParsedLine; + + /* FIXME: FOR, IF, and REM need special processing by the parser. */ + + /* Now get the tail */ + while (1) + { + Type = ParseToken(0, TRUE); + if (Type == TOK_NORMAL) + { + /* FIXME: potential buffer overflow here */ + Pos = _stpcpy(Pos, CurrentToken); + } + else if (Type == TOK_REDIRECTION) + { + if (!ParseRedirection(&RedirList)) + return NULL; + } + else + { + break; + } + } + + Cmd = cmd_alloc(FIELD_OFFSET(PARSED_COMMAND, CommandLine[Pos + 1 - ParsedLine])); + Cmd->Type = C_COMMAND; + Cmd->Next = NULL; + Cmd->Subcommands = NULL; + Cmd->Redirections = RedirList; + _tcscpy(Cmd->CommandLine, ParsedLine); + Cmd->Tail = Cmd->CommandLine + TailOffset; + return Cmd; +} + +static PARSED_COMMAND *ParseCommandOp(int OpType) +{ + PARSED_COMMAND *Cmd, *Left, *Right; + + if (OpType == C_OP_HIGHEST) + Cmd = ParseCommandPart(); + else + Cmd = ParseCommandOp(OpType + 1); + + if (Cmd && !_tcscmp(CurrentToken, OpString[OpType - C_OP_LOWEST])) + { + Left = Cmd; + Right = ParseCommandOp(OpType); + if (!Right) + { + if (!bParseError) + { + /* & is allowed to have an empty RHS */ + if (OpType == C_MULTI) + return Left; + ParseError(); + } + FreeCommand(Left); + return NULL; + } + + Cmd = cmd_alloc(sizeof(PARSED_COMMAND)); + Cmd->Type = OpType; + Cmd->Next = NULL; + Cmd->Redirections = NULL; + Cmd->Subcommands = Left; + Left->Next = Right; + Right->Next = NULL; + } + + return Cmd; +} + +PARSED_COMMAND * +ParseCommand(LPTSTR Line) +{ + PARSED_COMMAND *Cmd; + + if (Line) + { + _tcscpy(ParseLine, Line); + bLineContinuations = FALSE; + } + else + { + /*if (!ReadLine(ParseLine, FALSE))*/ + return NULL; + bLineContinuations = TRUE; + } + bParseError = FALSE; + ParsePos = ParseLine; + CurChar = _T(' '); + + Cmd = ParseCommandOp(C_OP_LOWEST); + if (Cmd && CurrentTokenType != TOK_END) + { + ParseError(); + FreeCommand(Cmd); + Cmd = NULL; + } + return Cmd; +} + +VOID +FreeCommand(PARSED_COMMAND *Cmd) +{ + if (Cmd->Subcommands) + FreeCommand(Cmd->Subcommands); + if (Cmd->Next) + FreeCommand(Cmd->Next); + FreeRedirection(Cmd->Redirections); + cmd_free(Cmd); +} Propchange: trunk/reactos/base/shell/cmd/parser.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/reactos/base/shell/cmd/redir.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/redir.c?rev…
============================================================================== --- trunk/reactos/base/shell/cmd/redir.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/redir.c [iso-8859-1] Thu Aug 21 15:18:35 2008 @@ -29,175 +29,6 @@ #ifdef FEATURE_REDIRECTION - -static BOOL -IsRedirection (TCHAR c) -{ - return (c == _T('<')) || (c == _T('>')) || (c == _T('|')); -} - - -/* - * Gets the redirection info from the command line and copies the - * file names into ifn, ofn and efn removing them from the command - * line. - * - * Converts remaining command line into a series of null terminated - * strings defined by the pipe char '|'. Each string corresponds - * to a single executable command. A double null terminates the - * command strings. - * - * Return number of command strings found. - * - */ - -INT GetRedirection (LPTSTR s, REDIRECTION **RedirList) -{ - INT num = 1; - LPTSTR dp = s; - LPTSTR sp = s; - TCHAR Filename[MAX_PATH]; - -#ifdef INCLUDE_CMD_REM - - TCHAR * line = s; - - - while (_istspace (*line)) - line++; - - /*first thing first. check to see if this is "rem" and hope out*/ - if(!_tcsncmp (line, _T("rem "), 4)) - { - return 1; - } -#endif - /* find and remove all the redirections first */ - while (*sp) - { - if (*sp == _T('^')) - { - *dp++ = *sp++; - *dp++ = *sp++; - continue; - } - if ((*sp == _T('"')) || (*sp == _T('\''))) - { - /* No redirects inside quotes */ - TCHAR qc = *sp; - - do - *dp++ = *sp++; - while (*sp && *sp != qc); - - *dp++ = *sp++; - continue; - } - - int NumberGiven = (*sp >= _T('0') && *sp <= _T('9')) ? 1 : 0; - if (sp[NumberGiven] == _T('<') || sp[NumberGiven] == _T('>')) - { - BYTE HandleNumber; - BYTE Type; - BOOL bInQuote = FALSE; - TCHAR *fn = Filename; - REDIRECTION *Redir, **ListPtr; - - if (NumberGiven) - HandleNumber = *sp++ - _T('0'); - else - HandleNumber = *sp == _T('<') ? 0 : 1; - - if (*sp == _T('<')) - { - /* input redirection */ - Type = REDIR_READ; - sp++; - } - else - { - /* output redirection */ - Type = REDIR_WRITE; - sp++; - - /* append request ? */ - if (*sp == _T('>')) - { - Type = REDIR_APPEND; - sp++; - } - } - - while (_istspace(*sp)) - sp++; - - /* copy file name */ - while (*sp && (bInQuote || (!IsRedirection (*sp) && !_istspace (*sp)))) - { - bInQuote ^= (*sp == _T('"')); - *fn++ = *sp++; - } - *fn++ = _T('\0'); - - /* Delete any existing redirection for the same handle number */ - ListPtr = RedirList; - while ((Redir = *ListPtr)) - { - if (Redir->Number == HandleNumber) - { - *ListPtr = Redir->Next; - cmd_free(Redir); - continue; - } - ListPtr = &Redir->Next; - } - - Redir = cmd_alloc(FIELD_OFFSET(REDIRECTION, Filename[fn - Filename])); - Redir->Next = NULL; - Redir->OldHandle = INVALID_HANDLE_VALUE; - Redir->Number = HandleNumber; - Redir->Type = Type; - _tcscpy(Redir->Filename, Filename); - *ListPtr = Redir; - } - else - *dp++ = *sp++; - } - - *dp++ = _T('\0'); - *dp = _T('\0'); - - /* now go for the pipes */ - sp = s; - while (*sp) - { - if (*sp == _T('^')) - { - sp++; - sp++; - continue; - } - else if ((*sp == _T('"')) || (*sp == _T('\''))) - { - TCHAR qc = *sp; - - do - sp++; - while (*sp && *sp != qc); - - sp++; - } - else if (*sp == _T('|')) - { - *sp++ = _T('\0'); - num++; - } - else - sp++; - } - - return num; -} /* cmd allows redirection of handles numbered 3-9 even though these don't * correspond to any STD_ constant. */ Modified: trunk/reactos/base/shell/cmd/set.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/set.c?rev=3…
============================================================================== --- trunk/reactos/base/shell/cmd/set.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/set.c [iso-8859-1] Thu Aug 21 15:18:35 2008 @@ -53,22 +53,12 @@ INT cmd_set (LPTSTR cmd, LPTSTR param) { - INT i; LPTSTR p; if ( !_tcsncmp (param, _T("/?"), 2) ) { ConOutResPaging(TRUE,STRING_SET_HELP); return 0; - } - - /* remove escapes */ - if ( param[0] ) for ( i = 0; param[i+1]; i++ ) - { - if ( param[i] == _T('^') ) - { - memmove ( ¶m[i], ¶m[i+1], _tcslen(¶m[i]) * sizeof(TCHAR) ); - } } /* if no parameters, show the environment */
16 years, 2 months
1
0
0
0
[tkreuzer] 35513: Add KeSetCurrentIrql
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Thu Aug 21 13:15:23 2008 New Revision: 35513 URL:
http://svn.reactos.org/svn/reactos?rev=35513&view=rev
Log: Add KeSetCurrentIrql Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/intrin_i.h Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/intrin_i.h URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/intrin_i.h [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/intrin_i.h [iso-8859-1] Thu Aug 21 13:15:23 2008 @@ -6,6 +6,8 @@ #else #define LOCK "" #endif + +#define KeSetCurrentIrql(x) __writecr8(x) #if defined(__GNUC__)
16 years, 2 months
1
0
0
0
[tkreuzer] 35512: Implement KxGetCurrentIrql, KxLowerIrql, KxRaiseIrql and KxRaiseIrqlToDpcLevel and use them for the Ke/Kf exports.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Thu Aug 21 13:13:42 2008 New Revision: 35512 URL:
http://svn.reactos.org/svn/reactos?rev=35512&view=rev
Log: Implement KxGetCurrentIrql, KxLowerIrql, KxRaiseIrql and KxRaiseIrqlToDpcLevel and use them for the Ke/Kf exports. Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c [iso-8859-1] Thu Aug 21 13:13:42 2008 @@ -1,7 +1,7 @@ /* * PROJECT: ReactOS Kernel * LICENSE: GPL - See COPYING in the top level directory - * PURPOSE: Routines for IRQL-level support + * PURPOSE: Routines for IRQL support * PROGRAMMERS: Timo Kreuzer */ @@ -11,60 +11,35 @@ #define NDEBUG #include <debug.h> -#undef UNIMPLEMENTED - -#define UNIMPLEMENTED \ - FrLdrDbgPrint("Sorry, %s is unimplemented!\n", __FUNCTION__) - /* FUNCTIONS ****************************************************************/ -#undef KeGetCurrentIrql NTKERNELAPI KIRQL -KeGetCurrentIrql(VOID) +KxGetCurrentIrql(VOID) { - UNIMPLEMENTED; - return 0; + return KeGetCurrentIrql(); } - NTKERNELAPI VOID -KfLowerIrql(IN KIRQL NewIrql) +KxLowerIrql(IN KIRQL NewIrql) { - UNIMPLEMENTED; + KeLowerIrql(NewIrql); } NTKERNELAPI KIRQL -KfRaiseIrql(IN KIRQL NewIrql) +KxRaiseIrql(IN KIRQL NewIrql) { - UNIMPLEMENTED; - return 0; + return KfRaiseIrql(NewIrql); } NTKERNELAPI KIRQL -KeRaiseIrqlToDpcLevel(VOID) +KxRaiseIrqlToDpcLevel(VOID) { - UNIMPLEMENTED; - return 0; + return KeRaiseIrqlToDpcLevel(); } -NTKERNELAPI -KIRQL -KeRaiseIrqlToSynchLevel(VOID) -{ - UNIMPLEMENTED; - return 0; -} - -NTKERNELAPI -VOID -KeLowerIrql(IN KIRQL NewIrql) -{ - UNIMPLEMENTED; - return 0; -} /* EOF */ Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def [iso-8859-1] Thu Aug 21 13:13:42 2008 @@ -565,7 +565,7 @@ KeFlushEntireTb KeFlushQueuedDpcs KeGenericCallDpc -KeGetCurrentIrql +KeGetCurrentIrql=KxGetCurrentIrql KeGetCurrentThread KeGetRecommendedSharedDataAlignment KeInitializeApc @@ -596,7 +596,7 @@ KeLeaveCriticalRegion KeLeaveGuardedRegion KeLoaderBlock -KeLowerIrql +KeLowerIrql=KxLowerIrql KeNumberProcessors KeProfileInterruptWithSource KePulseEvent @@ -606,7 +606,7 @@ KeQueryPriorityThread KeQueryRuntimeThread KeQueryTimeIncrement -KeRaiseIrqlToDpcLevel +KeRaiseIrqlToDpcLevel=KxRaiseIrqlToDpcLevel KeRaiseUserException KeReadStateEvent KeReadStateMutant @@ -676,7 +676,7 @@ KeWaitForMultipleObjects KeWaitForMutexObject KeWaitForSingleObject -KfRaiseIrql +KfRaiseIrql=KxRaiseIrql KiBugCheckData KiCheckForKernelApcDelivery KiCpuId
16 years, 2 months
1
0
0
0
[tkreuzer] 35511: fix build ;-)
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Thu Aug 21 13:10:08 2008 New Revision: 35511 URL:
http://svn.reactos.org/svn/reactos?rev=35511&view=rev
Log: fix build ;-) Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/boot.S Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/boot.S URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/boot.S [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/boot.S [iso-8859-1] Thu Aug 21 13:10:08 2008 @@ -76,7 +76,7 @@ /* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */ sti mov rcx, DISPATCH_LEVEL - call _KfLowerIrql + mov cr8, rcx /* Set the right wait IRQL */ mov byte ptr [rbx+KTHREAD_WAIT_IRQL], DISPATCH_LEVEL;
16 years, 2 months
1
0
0
0
[tkreuzer] 35510: Make KeGetCurrentIrql, KeLowerIrql, KfRaiseIrql, KeRaiseIrql, KeRaiseIrqlToDpcLevel and KeRaiseIrqlToSynchLevel intrinsics as in the WDK 2008.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Thu Aug 21 13:07:45 2008 New Revision: 35510 URL:
http://svn.reactos.org/svn/reactos?rev=35510&view=rev
Log: Make KeGetCurrentIrql, KeLowerIrql, KfRaiseIrql, KeRaiseIrql, KeRaiseIrqlToDpcLevel and KeRaiseIrqlToSynchLevel intrinsics as in the WDK 2008. Modified: branches/ros-amd64-bringup/reactos/include/ddk/winddk.h Modified: branches/ros-amd64-bringup/reactos/include/ddk/winddk.h URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/inclu…
============================================================================== --- branches/ros-amd64-bringup/reactos/include/ddk/winddk.h [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/include/ddk/winddk.h [iso-8859-1] Thu Aug 21 13:07:45 2008 @@ -9962,47 +9962,47 @@ #elif defined(_M_AMD64) -/* -NTKERNELAPI -KIRQL -KeGetCurrentIrql( - VOID); -*/ FORCEINLINE KIRQL -_KeGetCurrentIrql(VOID) +KeGetCurrentIrql(VOID) { return (KIRQL)__readcr8(); } -#define KeGetCurrentIrql _KeGetCurrentIrql - -NTKERNELAPI -VOID -KfLowerIrql( - IN KIRQL NewIrql); - -NTKERNELAPI + +FORCEINLINE +VOID +KeLowerIrql(IN KIRQL NewIrql) +{ + ASSERT(KeGetCurrentIrql() >= NewIrql); + __writecr8(NewIrql); +} + +FORCEINLINE KIRQL -KfRaiseIrql( - IN KIRQL NewIrql); - -NTKERNELAPI +KfRaiseIrql(IN KIRQL NewIrql) +{ + KIRQL OldIrql; + + OldIrql = __readcr8(); + ASSERT(OldIrql <= NewIrql); + __writecr8(NewIrql); + return OldIrql; +} +#define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a) + +FORCEINLINE KIRQL -KeRaiseIrqlToDpcLevel( - VOID); - -NTKERNELAPI +KeRaiseIrqlToDpcLevel(VOID) +{ + return KfRaiseIrql(DISPATCH_LEVEL); +} + +FORCEINLINE KIRQL -KeRaiseIrqlToSynchLevel( - VOID); - -NTKERNELAPI -VOID -KeLowerIrql( - IN KIRQL NewIrql); - -#define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a) - +KeRaiseIrqlToSynchLevel(VOID) +{ + return KfRaiseIrql(12); // SYNCH_LEVEL = IPI_LEVEL - 2 +} #elif defined(__PowerPC__)
16 years, 2 months
1
0
0
0
[tkreuzer] 35509: On SMP builds SYNCH_LEVEL is (IPI_LEVEL - 2) or 12
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Thu Aug 21 13:04:23 2008 New Revision: 35509 URL:
http://svn.reactos.org/svn/reactos?rev=35509&view=rev
Log: On SMP builds SYNCH_LEVEL is (IPI_LEVEL - 2) or 12 Modified: branches/ros-amd64-bringup/reactos/include/ndk/amd64/ketypes.h Modified: branches/ros-amd64-bringup/reactos/include/ndk/amd64/ketypes.h URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/inclu…
============================================================================== --- branches/ros-amd64-bringup/reactos/include/ndk/amd64/ketypes.h [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/include/ndk/amd64/ketypes.h [iso-8859-1] Thu Aug 21 13:04:23 2008 @@ -139,7 +139,7 @@ #ifndef CONFIG_SMP #define SYNCH_LEVEL DISPATCH_LEVEL #else -#define SYNCH_LEVEL (IPI_LEVEL - 1) +#define SYNCH_LEVEL (IPI_LEVEL - 2) #endif //
16 years, 2 months
1
0
0
0
[jmorlan] 35508: - Implement X>&Y redirections. Hold redirections in a linked list structure, because order matters (>x 2>&1 is not the same as 2>&1 >x). Allow redirection of any handle number from 0 to 9. - Allow quotes around the redirection file name. - Batch: Fix buffer overflow bug (incorrect size for bc->BatchFilePath)
by jmorlan@svn.reactos.org
Author: jmorlan Date: Thu Aug 21 10:33:59 2008 New Revision: 35508 URL:
http://svn.reactos.org/svn/reactos?rev=35508&view=rev
Log: - Implement X>&Y redirections. Hold redirections in a linked list structure, because order matters (>x 2>&1 is not the same as 2>&1 >x). Allow redirection of any handle number from 0 to 9. - Allow quotes around the redirection file name. - Batch: Fix buffer overflow bug (incorrect size for bc->BatchFilePath) Modified: trunk/reactos/base/shell/cmd/batch.c trunk/reactos/base/shell/cmd/batch.h trunk/reactos/base/shell/cmd/call.c trunk/reactos/base/shell/cmd/cmd.c trunk/reactos/base/shell/cmd/cmd.h trunk/reactos/base/shell/cmd/for.c trunk/reactos/base/shell/cmd/misc.c trunk/reactos/base/shell/cmd/redir.c trunk/reactos/base/shell/cmd/start.c Modified: trunk/reactos/base/shell/cmd/batch.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/batch.c?rev…
============================================================================== --- trunk/reactos/base/shell/cmd/batch.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/batch.c [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -193,6 +193,9 @@ if (bc->ffind) cmd_free(bc->ffind); + + UndoRedirection(bc->RedirList, NULL); + FreeRedirection(bc->RedirList); /* Preserve echo state across batch calls */ bEcho = bc->bEcho; @@ -248,9 +251,7 @@ n->prev = bc; bc = n; - bc->In[0] = _T('\0'); - bc->Out[0] = _T('\0'); - bc->Err[0] = _T('\0'); + bc->RedirList = NULL; } else if (bc->hBatchFile != INVALID_HANDLE_VALUE) { @@ -263,7 +264,7 @@ cmd_free (bc->raw_params); } - GetFullPathName(fullname, sizeof(bc->BatchFilePath), bc->BatchFilePath, &tmp); + GetFullPathName(fullname, sizeof(bc->BatchFilePath) / sizeof(TCHAR), bc->BatchFilePath, &tmp); *tmp = '\0'; bc->hBatchFile = hFile; @@ -300,17 +301,23 @@ return TRUE; } -VOID AddBatchRedirection(TCHAR * ifn, TCHAR * ofn, TCHAR * efn) +VOID AddBatchRedirection(REDIRECTION **RedirList) { + REDIRECTION **ListEnd; + if(!bc) return; - if(_tcslen(ifn)) - _tcscpy(bc->In,ifn); - if(_tcslen(ofn)) - _tcscpy(bc->Out,ofn); - if(_tcslen(efn)) - _tcscpy(bc->Err,efn); - + + /* Prepend the list to the batch context's list */ + ListEnd = RedirList; + while (*ListEnd) + ListEnd = &(*ListEnd)->Next; + *ListEnd = bc->RedirList; + bc->RedirList = *RedirList; + + /* Null out the pointer so that the list will not be cleared prematurely. + * These redirections should persist until the batch file exits. */ + *RedirList = NULL; } /* Modified: trunk/reactos/base/shell/cmd/batch.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/batch.h?rev…
============================================================================== --- trunk/reactos/base/shell/cmd/batch.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/batch.h [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -19,9 +19,7 @@ INT shiftlevel; BOOL bEcho; /* Preserve echo flag across batch calls */ HANDLE hFind; /* Preserve find handle when doing a for */ - TCHAR In[MAX_PATH]; - TCHAR Out[MAX_PATH]; - TCHAR Err[MAX_PATH]; + REDIRECTION *RedirList; TCHAR forvar; INT bCmdBlock; BOOL bExecuteBlock[MAX_PATH]; @@ -47,6 +45,6 @@ VOID ExitBatch (LPTSTR); BOOL Batch (LPTSTR, LPTSTR, LPTSTR); LPTSTR ReadBatchLine (LPBOOL); -VOID AddBatchRedirection(TCHAR *, TCHAR *, TCHAR *); +VOID AddBatchRedirection(REDIRECTION **); #endif /* _BATCH_H_INCLUDED_ */ Modified: trunk/reactos/base/shell/cmd/call.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/call.c?rev=…
============================================================================== --- trunk/reactos/base/shell/cmd/call.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/call.c [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -76,19 +76,8 @@ bc->shiftlevel = 0; bc->forvar = 0; /* HBP004 */ bc->forproto = NULL; /* HBP004 */ + bc->RedirList = NULL; ParseCommandLine (param); - if (bc->prev) - { - _tcscpy(bc->In, bc->prev->In); - _tcscpy(bc->Out, bc->prev->Out); - _tcscpy(bc->Err, bc->prev->Err); - } - else - { - bc->In[0] = _T('\0'); - bc->Out[0] = _T('\0'); - bc->Err[0] = _T('\0'); - } /* Wasn't a batch file so remove conext */ Modified: trunk/reactos/base/shell/cmd/cmd.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=3…
============================================================================== --- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -690,21 +690,16 @@ TCHAR cmdline[CMDLINE_LENGTH]; LPTSTR s; #ifdef FEATURE_REDIRECTION - TCHAR in[CMDLINE_LENGTH] = _T(""); - TCHAR out[CMDLINE_LENGTH] = _T(""); - TCHAR err[CMDLINE_LENGTH] = _T(""); + REDIRECTION *RedirList = NULL; TCHAR szTempPath[MAX_PATH] = _T(".\\"); TCHAR szFileName[2][MAX_PATH] = {_T(""), _T("")}; HANDLE hFile[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE}; - LPTSTR t = NULL; INT num = 0; - INT nRedirFlags = 0; INT Length; UINT Attributes; BOOL bNewBatch = TRUE; HANDLE hOldConIn; HANDLE hOldConOut; - HANDLE hOldConErr; #endif /* FEATURE_REDIRECTION */ _tcscpy (cmdline, cmd); @@ -732,65 +727,18 @@ _tcscat (szTempPath, _T("\\")); /* get the redirections from the command line */ - num = GetRedirection (s, in, out, err, &nRedirFlags); - - /* more efficient, but do we really need to do this? */ - for (t = in; _istspace (*t); t++) - ; - _tcscpy (in, t); - - for (t = out; _istspace (*t); t++) - ; - _tcscpy (out, t); - - for (t = err; _istspace (*t); t++) - ; - _tcscpy (err, t); - - if(bc && !_tcslen (in) && _tcslen (bc->In)) - _tcscpy(in, bc->In); - if(bc && !out[0] && _tcslen(bc->Out)) - { - nRedirFlags |= OUTPUT_APPEND; - _tcscpy(out, bc->Out); - } - if(bc && !_tcslen (err) && _tcslen (bc->Err)) - { - nRedirFlags |= ERROR_APPEND; - _tcscpy(err, bc->Err); + num = GetRedirection (s, &RedirList); + + if (!PerformRedirection(RedirList)) + { + FreeRedirection(RedirList); + return; } /* Set up the initial conditions ... */ - /* preserve STDIN, STDOUT and STDERR handles */ + /* preserve STDIN and STDOUT handles */ hOldConIn = GetStdHandle (STD_INPUT_HANDLE); hOldConOut = GetStdHandle (STD_OUTPUT_HANDLE); - hOldConErr = GetStdHandle (STD_ERROR_HANDLE); - - /* redirect STDIN */ - if (in[0]) - { - HANDLE hFile; - SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; - - /* we need make sure the LastError msg is zero before calling CreateFile */ - SetLastError(0); - - /* Set up pipe for the standard input handler */ - hFile = CreateFile (in, GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - ConErrResPrintf(STRING_CMD_ERROR1, in); - return; - } - - if (!SetStdHandle (STD_INPUT_HANDLE, hFile)) - { - ConErrResPrintf(STRING_CMD_ERROR1, in); - return; - } - TRACE ("Input redirected from: %s\n", debugstr_aw(in)); - } /* Now do all but the last pipe command */ *szFileName[0] = _T('\0'); @@ -855,123 +803,7 @@ } /* Now set up the end conditions... */ - /* redirect STDOUT */ - if (out[0]) - { - /* Final output to here */ - HANDLE hFile; - SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; - - /* we need make sure the LastError msg is zero before calling CreateFile */ - SetLastError(0); - - hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, &sa, - (nRedirFlags & OUTPUT_APPEND) ? OPEN_ALWAYS : CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - INT size = _tcslen(out)-1; - - if (out[size] != _T(':')) - { - ConErrResPrintf(STRING_CMD_ERROR3, out); - return; - } - - out[size]=_T('\0'); - hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, &sa, - (nRedirFlags & OUTPUT_APPEND) ? OPEN_ALWAYS : CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - ConErrResPrintf(STRING_CMD_ERROR3, out); - return; - } - - } - - if (!SetStdHandle (STD_OUTPUT_HANDLE, hFile)) - { - ConErrResPrintf(STRING_CMD_ERROR3, out); - return; - } - - if (nRedirFlags & OUTPUT_APPEND) - { - LONG lHighPos = 0; - - if (GetFileType (hFile) == FILE_TYPE_DISK) - SetFilePointer (hFile, 0, &lHighPos, FILE_END); - } - TRACE ("Output redirected to: %s\n", debugstr_aw(out)); - } - else if (hOldConOut != INVALID_HANDLE_VALUE) - { - /* Restore original stdout */ - HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); - SetStdHandle (STD_OUTPUT_HANDLE, hOldConOut); - if (hOldConOut != hOut) - CloseHandle (hOut); - hOldConOut = INVALID_HANDLE_VALUE; - } - - /* redirect STDERR */ - if (err[0]) - { - /* Final output to here */ - HANDLE hFile; - SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; - - if (!_tcscmp (err, out)) - { - TRACE ("Stdout and stderr will use the same file!!\n"); - DuplicateHandle (GetCurrentProcess (), - GetStdHandle (STD_OUTPUT_HANDLE), - GetCurrentProcess (), - &hFile, 0, TRUE, DUPLICATE_SAME_ACCESS); - } - else - { - hFile = CreateFile (err, - GENERIC_WRITE, - FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, - &sa, - (nRedirFlags & ERROR_APPEND) ? OPEN_ALWAYS : CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - ConErrResPrintf(STRING_CMD_ERROR3, err); - return; - } - } - - if (!SetStdHandle (STD_ERROR_HANDLE, hFile)) - { - ConErrResPrintf(STRING_CMD_ERROR3, err); - return; - } - - if (nRedirFlags & ERROR_APPEND) - { - LONG lHighPos = 0; - - if (GetFileType (hFile) == FILE_TYPE_DISK) - SetFilePointer (hFile, 0, &lHighPos, FILE_END); - } - TRACE ("Error redirected to: %s\n", debugstr_aw(err)); - } - else if (hOldConErr != INVALID_HANDLE_VALUE) - { - /* Restore original stderr */ - HANDLE hErr = GetStdHandle (STD_ERROR_HANDLE); - SetStdHandle (STD_ERROR_HANDLE, hOldConErr); - if (hOldConErr != hErr) - CloseHandle (hErr); - hOldConErr = INVALID_HANDLE_VALUE; - } + SetStdHandle(STD_OUTPUT_HANDLE, hOldConOut); if(bc) bNewBatch = FALSE; @@ -982,7 +814,7 @@ #ifdef FEATURE_REDIRECTION if(bNewBatch && bc) - AddBatchRedirection(in, out, err); + AddBatchRedirection(&RedirList); /* close old stdin file */ #if 0 /* buggy implementation */ SetStdHandle (STD_INPUT_HANDLE, hOldConIn); @@ -1039,26 +871,8 @@ } } - - /* Restore original STDOUT */ - if (hOldConOut != INVALID_HANDLE_VALUE) - { - HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); - SetStdHandle (STD_OUTPUT_HANDLE, hOldConOut); - if (hOldConOut != hOut) - CloseHandle (hOut); - hOldConOut = INVALID_HANDLE_VALUE; - } - - /* Restore original STDERR */ - if (hOldConErr != INVALID_HANDLE_VALUE) - { - HANDLE hErr = GetStdHandle (STD_ERROR_HANDLE); - SetStdHandle (STD_ERROR_HANDLE, hOldConErr); - if (hOldConErr != hErr) - CloseHandle (hErr); - hOldConErr = INVALID_HANDLE_VALUE; - } + UndoRedirection(RedirList, NULL); + FreeRedirection(RedirList); #endif /* FEATURE_REDIRECTION */ } Modified: trunk/reactos/base/shell/cmd/cmd.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=3…
============================================================================== --- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -301,6 +301,7 @@ LPTSTR *split (LPTSTR, LPINT, BOOL); VOID freep (LPTSTR *); LPTSTR _stpcpy (LPTSTR, LPCTSTR); +VOID StripQuotes(LPTSTR); BOOL IsValidPathName (LPCTSTR); BOOL IsExistingFile (LPCTSTR); BOOL IsExistingDirectory (LPCTSTR); @@ -335,12 +336,19 @@ /* Prototypes for REDIR.C */ -#define INPUT_REDIRECTION 1 -#define OUTPUT_REDIRECTION 2 -#define OUTPUT_APPEND 4 -#define ERROR_REDIRECTION 8 -#define ERROR_APPEND 16 -INT GetRedirection (LPTSTR, LPTSTR, LPTSTR, LPTSTR, LPINT); +enum { REDIR_READ, REDIR_WRITE, REDIR_APPEND }; +typedef struct _REDIRECTION +{ + struct _REDIRECTION *Next; + HANDLE OldHandle; + BYTE Number; + BYTE Type; + TCHAR Filename[]; +} REDIRECTION; +BOOL PerformRedirection(REDIRECTION *); +VOID UndoRedirection(REDIRECTION *, REDIRECTION *End); +INT GetRedirection(LPTSTR, REDIRECTION **); +VOID FreeRedirection(REDIRECTION *); /* Prototypes for REN.C */ Modified: trunk/reactos/base/shell/cmd/for.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/for.c?rev=3…
============================================================================== --- trunk/reactos/base/shell/cmd/for.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/for.c [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -138,9 +138,7 @@ bc->bEcho = bc->prev->bEcho; else bc->bEcho = bEcho; - bc->In[0] = _T('\0'); - bc->Out[0] = _T('\0'); - bc->Err[0] = _T('\0'); + bc->RedirList = NULL; return 0; Modified: trunk/reactos/base/shell/cmd/misc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/misc.c?rev=…
============================================================================== --- trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -411,6 +411,18 @@ return (dest + _tcslen (src)); } +VOID +StripQuotes(TCHAR *in) +{ + TCHAR *out = in; + for (; *in; in++) + { + if (*in != _T('"')) + *out++ = *in; + } + *out = _T('\0'); +} + /* Modified: trunk/reactos/base/shell/cmd/redir.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/redir.c?rev…
============================================================================== --- trunk/reactos/base/shell/cmd/redir.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/redir.c [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -51,11 +51,12 @@ * */ -INT GetRedirection (LPTSTR s, LPTSTR ifn, LPTSTR ofn, LPTSTR efn, LPINT lpnFlags) +INT GetRedirection (LPTSTR s, REDIRECTION **RedirList) { INT num = 1; LPTSTR dp = s; LPTSTR sp = s; + TCHAR Filename[MAX_PATH]; #ifdef INCLUDE_CMD_REM @@ -68,10 +69,6 @@ /*first thing first. check to see if this is "rem" and hope out*/ if(!_tcsncmp (line, _T("rem "), 4)) { - lpnFlags = 0; - *ifn=('\0'); - *ofn=('\0'); - *efn=_T('\0'); return 1; } #endif @@ -94,148 +91,74 @@ while (*sp && *sp != qc); *dp++ = *sp++; - } - else if ((*sp == _T('<')) || (*sp == _T('>')) || - (*sp == _T('1')) || (*sp == _T('2')) || (*sp == _T('&'))) - { - /* MS-DOS ignores multiple redirection symbols and uses the last */ - /* redirection, so we'll emulate that and not check */ + continue; + } + + int NumberGiven = (*sp >= _T('0') && *sp <= _T('9')) ? 1 : 0; + if (sp[NumberGiven] == _T('<') || sp[NumberGiven] == _T('>')) + { + BYTE HandleNumber; + BYTE Type; + BOOL bInQuote = FALSE; + TCHAR *fn = Filename; + REDIRECTION *Redir, **ListPtr; + + if (NumberGiven) + HandleNumber = *sp++ - _T('0'); + else + HandleNumber = *sp == _T('<') ? 0 : 1; if (*sp == _T('<')) { /* input redirection */ - *lpnFlags |= INPUT_REDIRECTION; - do sp++; - while( _istspace (*sp) ); - - /* copy file name */ - while (*sp && !IsRedirection (*sp) && !_istspace (*sp)) - *ifn++ = *sp++; - *ifn = _T('\0'); - } - else if (*sp == _T('>')) + Type = REDIR_READ; + sp++; + } + else { /* output redirection */ - *lpnFlags |= OUTPUT_REDIRECTION; + Type = REDIR_WRITE; sp++; /* append request ? */ if (*sp == _T('>')) { - *lpnFlags |= OUTPUT_APPEND; + Type = REDIR_APPEND; sp++; } - - while (_istspace (*sp)) - sp++; - - /* copy file name */ - while (*sp && !IsRedirection (*sp) && !_istspace (*sp)) - *ofn++ = *sp++; - *ofn = _T('\0'); - } - - else if (*sp == _T('1')) - { - /* output redirection */ + } + + while (_istspace(*sp)) sp++; - if (*sp == _T('>')) + /* copy file name */ + while (*sp && (bInQuote || (!IsRedirection (*sp) && !_istspace (*sp)))) + { + bInQuote ^= (*sp == _T('"')); + *fn++ = *sp++; + } + *fn++ = _T('\0'); + + /* Delete any existing redirection for the same handle number */ + ListPtr = RedirList; + while ((Redir = *ListPtr)) + { + if (Redir->Number == HandleNumber) { - /* output redirection */ - *lpnFlags |= OUTPUT_REDIRECTION; - sp++; - - /* append request ? */ - if (*sp == _T('>')) - { - *lpnFlags |= OUTPUT_APPEND; - sp++; - } - } - else - { - /* no redirection!! copy the '1' character! */ - sp--; - *dp++ = *sp++; + *ListPtr = Redir->Next; + cmd_free(Redir); continue; } - - while (_istspace (*sp)) - sp++; - - /* copy file name */ - while (*sp && !IsRedirection (*sp) && !_istspace (*sp)) - *ofn++ = *sp++; - *ofn = _T('\0'); - } - - else if (*sp == _T('2')) - { - /* error redirection */ - sp++; - - if (*sp == _T('>')) - { - *lpnFlags |= ERROR_REDIRECTION; - sp++; - - /* append request ? */ - if (*sp == _T('>')) - { - *lpnFlags |= ERROR_APPEND; - sp++; - } - } - else - { - /* no redirection!! copy the '2' character! */ - sp--; - *dp++ = *sp++; - continue; - } - - while (_istspace (*sp)) - sp++; - - /* copy file name */ - while (*sp && !IsRedirection (*sp) && !_istspace (*sp)) - *efn++ = *sp++; - *efn = _T('\0'); - } - else if (*sp == _T('&')) - { - /* output AND error redirection */ - sp++; - - if (*sp == _T('>')) - { - *lpnFlags |= (ERROR_REDIRECTION | OUTPUT_REDIRECTION); - sp++; - - /* append request ? */ - if (*sp == _T('>')) - { - *lpnFlags |= (ERROR_APPEND | OUTPUT_APPEND); - sp++; - } - } - else - { - /* no redirection!! copy the '&' character! */ - sp--; - *dp++ = *sp++; - continue; - } - - while (_istspace (*sp)) - sp++; - - /* copy file name */ - while (*sp && !IsRedirection (*sp) && !_istspace (*sp)) - *ofn++ = *efn++ = *sp++; - *ofn = *efn = _T('\0'); - } + ListPtr = &Redir->Next; + } + + Redir = cmd_alloc(FIELD_OFFSET(REDIRECTION, Filename[fn - Filename])); + Redir->Next = NULL; + Redir->OldHandle = INVALID_HANDLE_VALUE; + Redir->Number = HandleNumber; + Redir->Type = Type; + _tcscpy(Redir->Filename, Filename); + *ListPtr = Redir; } else *dp++ = *sp++; @@ -276,4 +199,124 @@ return num; } +/* cmd allows redirection of handles numbered 3-9 even though these don't + * correspond to any STD_ constant. */ +static HANDLE ExtraHandles[10 - 3]; + +static HANDLE GetHandle(UINT Number) +{ + if (Number < 3) + return GetStdHandle(STD_INPUT_HANDLE - Number); + else + return ExtraHandles[Number - 3]; +} + +static VOID SetHandle(UINT Number, HANDLE Handle) +{ + if (Number < 3) + SetStdHandle(STD_INPUT_HANDLE - Number, Handle); + else + ExtraHandles[Number - 3] = Handle; +} + +BOOL +PerformRedirection(REDIRECTION *RedirList) +{ + REDIRECTION *Redir; + TCHAR Filename[MAX_PATH]; + HANDLE hNew; + UINT DupNumber; + static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; + + /* Some parameters used for read, write, and append, respectively */ + static const DWORD dwAccess[] = { + GENERIC_READ, + GENERIC_WRITE, + GENERIC_WRITE + }; + static const DWORD dwShareMode[] = { + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_SHARE_READ, + FILE_SHARE_READ + }; + static const DWORD dwCreationDisposition[] = { + OPEN_EXISTING, + CREATE_ALWAYS, + OPEN_ALWAYS + }; + + for (Redir = RedirList; Redir; Redir = Redir->Next) + { + *Filename = _T('\0'); + _tcsncat(Filename, Redir->Filename, MAX_PATH - 1); + StripQuotes(Filename); + + if (*Filename == _T('&')) + { + DupNumber = Filename[1] - _T('0'); + if (DupNumber >= 10 || + !DuplicateHandle(GetCurrentProcess(), + GetHandle(DupNumber), + GetCurrentProcess(), + &hNew, + 0, + TRUE, + DUPLICATE_SAME_ACCESS)) + { + hNew = INVALID_HANDLE_VALUE; + } + } + else + { + hNew = CreateFile(Filename, + dwAccess[Redir->Type], + dwShareMode[Redir->Type], + &SecAttr, + dwCreationDisposition[Redir->Type], + 0, + NULL); + } + + if (hNew == INVALID_HANDLE_VALUE) + { + ConErrResPrintf(Redir->Type == REDIR_READ ? STRING_CMD_ERROR1 : STRING_CMD_ERROR3, + Filename); + /* Undo all the redirections before this one */ + UndoRedirection(RedirList, Redir); + return FALSE; + } + + if (Redir->Type == REDIR_APPEND) + SetFilePointer(hNew, 0, NULL, FILE_END); + Redir->OldHandle = GetHandle(Redir->Number); + SetHandle(Redir->Number, hNew); + + TRACE("%d redirected to: %s\n", Redir->Number, debugstr_aw(Filename)); + } + return TRUE; +} + +VOID +UndoRedirection(REDIRECTION *Redir, REDIRECTION *End) +{ + for (; Redir != End; Redir = Redir->Next) + { + CloseHandle(GetHandle(Redir->Number)); + SetHandle(Redir->Number, Redir->OldHandle); + Redir->OldHandle = INVALID_HANDLE_VALUE; + } +} + +VOID +FreeRedirection(REDIRECTION *Redir) +{ + REDIRECTION *Next; + for (; Redir; Redir = Next) + { + Next = Redir->Next; + ASSERT(Redir->OldHandle == INVALID_HANDLE_VALUE); + cmd_free(Redir); + } +} + #endif /* FEATURE_REDIRECTION */ Modified: trunk/reactos/base/shell/cmd/start.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/start.c?rev…
============================================================================== --- trunk/reactos/base/shell/cmd/start.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/start.c [iso-8859-1] Thu Aug 21 10:33:59 2008 @@ -32,17 +32,6 @@ p[-1] = _T('\0'); *pPointer = p; return start - 1; -} - -static void StripQuotes(TCHAR *in) -{ - TCHAR *out = in; - for (; *in; in++) - { - if (*in != _T('"')) - *out++ = *in; - } - *out = _T('\0'); } INT cmd_start (LPTSTR First, LPTSTR Rest)
16 years, 2 months
1
0
0
0
[cgutman] 35507: - Replace MmMapLockedPages with MmGetSystemAddressForMdlSafe - Add a check to UnlockRequest - Enclose MmProbeAndLockPages in SEH - Fixes bug 3672
by cgutman@svn.reactos.org
Author: cgutman Date: Thu Aug 21 09:46:03 2008 New Revision: 35507 URL:
http://svn.reactos.org/svn/reactos?rev=35507&view=rev
Log: - Replace MmMapLockedPages with MmGetSystemAddressForMdlSafe - Add a check to UnlockRequest - Enclose MmProbeAndLockPages in SEH - Fixes bug 3672 Modified: branches/aicom-network-fixes/drivers/network/afd/afd/lock.c Modified: branches/aicom-network-fixes/drivers/network/afd/afd/lock.c URL:
http://svn.reactos.org/svn/reactos/branches/aicom-network-fixes/drivers/net…
============================================================================== --- branches/aicom-network-fixes/drivers/network/afd/afd/lock.c [iso-8859-1] (original) +++ branches/aicom-network-fixes/drivers/network/afd/afd/lock.c [iso-8859-1] Thu Aug 21 09:46:03 2008 @@ -37,7 +37,7 @@ } IrpSp->Parameters.DeviceIoControl.Type3InputBuffer = - MmMapLockedPages( Irp->MdlAddress, KernelMode ); + MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority ); if( !IrpSp->Parameters.DeviceIoControl.Type3InputBuffer ) { IoFreeMdl( Irp->MdlAddress ); @@ -50,12 +50,13 @@ } VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) { - if( !IrpSp->Parameters.DeviceIoControl.Type3InputBuffer || !Irp->MdlAddress ) return; - - MmUnmapLockedPages( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer, - Irp->MdlAddress ); - MmUnlockPages( Irp->MdlAddress ); - IoFreeMdl( Irp->MdlAddress ); + PVOID Buffer = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority ); + if( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer == Buffer || Buffer == NULL ) { + MmUnmapLockedPages( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer, Irp->MdlAddress ); + MmUnlockPages( Irp->MdlAddress ); + IoFreeMdl( Irp->MdlAddress ); + } + Irp->MdlAddress = NULL; } @@ -72,6 +73,7 @@ UINT Size = sizeof(AFD_WSABUF) * (Count + Lock); PAFD_WSABUF NewBuf = ExAllocatePool( PagedPool, Size * 2 ); PMDL NewMdl; + BOOLEAN LockFailed = FALSE; AFD_DbgPrint(MID_TRACE,("Called(%08x)\n", NewBuf)); @@ -117,9 +119,19 @@ if( MapBuf[i].Mdl ) { AFD_DbgPrint(MID_TRACE,("Probe and lock pages\n")); - MmProbeAndLockPages( MapBuf[i].Mdl, KernelMode, - Write ? IoModifyAccess : IoReadAccess ); + _SEH_TRY { + MmProbeAndLockPages( MapBuf[i].Mdl, KernelMode, + Write ? IoModifyAccess : IoReadAccess ); + } _SEH_HANDLE { + LockFailed = TRUE; + } _SEH_END; AFD_DbgPrint(MID_TRACE,("MmProbeAndLock finished\n")); + + if( LockFailed ) { + IoFreeMdl( MapBuf[i].Mdl ); + MapBuf[i].Mdl = NULL; + LockFailed = FALSE; + } } } }
16 years, 2 months
1
0
0
0
[tkreuzer] 35506: Implement KeGetCurrentIrql as intrinsic.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Thu Aug 21 08:33:57 2008 New Revision: 35506 URL:
http://svn.reactos.org/svn/reactos?rev=35506&view=rev
Log: Implement KeGetCurrentIrql as intrinsic. Modified: branches/ros-amd64-bringup/reactos/include/ddk/winddk.h Modified: branches/ros-amd64-bringup/reactos/include/ddk/winddk.h URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/inclu…
============================================================================== --- branches/ros-amd64-bringup/reactos/include/ddk/winddk.h [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/include/ddk/winddk.h [iso-8859-1] Thu Aug 21 08:33:57 2008 @@ -9962,10 +9962,19 @@ #elif defined(_M_AMD64) +/* NTKERNELAPI KIRQL KeGetCurrentIrql( VOID); +*/ +FORCEINLINE +KIRQL +_KeGetCurrentIrql(VOID) +{ + return (KIRQL)__readcr8(); +} +#define KeGetCurrentIrql _KeGetCurrentIrql NTKERNELAPI VOID
16 years, 2 months
1
0
0
0
[tkreuzer] 35505: Remove private __lidt definition.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Thu Aug 21 08:30:39 2008 New Revision: 35505 URL:
http://svn.reactos.org/svn/reactos?rev=35505&view=rev
Log: Remove private __lidt definition. Modified: branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h Modified: branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/boot/…
============================================================================== --- branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h [iso-8859-1] Thu Aug 21 08:30:39 2008 @@ -58,13 +58,6 @@ asm volatile ("lgdt %0\n" : : "m"(*(short*)gdt)); } -VOID -FORCEINLINE -__lidt(void *idt) -{ - asm volatile ("lidt %0\n" : : "m"(*(short*)idt)); -} - PKGDTENTRY64 FORCEINLINE KiGetGdtEntry(PVOID pGdt, USHORT Index)
16 years, 2 months
1
0
0
0
← Newer
1
...
31
32
33
34
35
36
37
...
86
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Results per page:
10
25
50
100
200