Author: hbelusca
Date: Fri Sep 28 19:36:49 2012
New Revision: 57415
URL:
http://svn.reactos.org/svn/reactos?rev=57415&view=rev
Log:
[CMD]
- Clarify the code, no functional changes.
Modified:
trunk/reactos/base/shell/cmd/cmd.h
trunk/reactos/base/shell/cmd/parser.c
trunk/reactos/base/shell/cmd/readme2.txt
trunk/reactos/base/shell/cmd/redir.c
Modified: trunk/reactos/base/shell/cmd/cmd.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=5…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Fri Sep 28 19:36:49 2012
@@ -409,13 +409,18 @@
/* Prototypes for REDIR.C */
-enum { REDIR_READ, REDIR_WRITE, REDIR_APPEND };
+typedef enum _REDIR_MODE
+{
+ REDIR_READ = 0,
+ REDIR_WRITE = 1,
+ REDIR_APPEND = 2
+} REDIR_MODE;
typedef struct _REDIRECTION
{
struct _REDIRECTION *Next;
HANDLE OldHandle;
BYTE Number;
- BYTE Type;
+ REDIR_MODE Mode;
TCHAR Filename[];
} REDIRECTION;
BOOL PerformRedirection(REDIRECTION *);
Modified: 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 [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/parser.c [iso-8859-1] Fri Sep 28 19:36:49 2012
@@ -214,7 +214,7 @@
{
TCHAR *Tok = CurrentToken;
BYTE Number;
- BYTE RedirType;
+ REDIR_MODE RedirMode;
REDIRECTION *Redir;
if (*Tok >= _T('0') && *Tok <= _T('9'))
@@ -224,16 +224,16 @@
if (*Tok++ == _T('<'))
{
- RedirType = REDIR_READ;
+ RedirMode = REDIR_READ;
if (*Tok == _T('<'))
goto fail;
}
else
{
- RedirType = REDIR_WRITE;
+ RedirMode = REDIR_WRITE;
if (*Tok == _T('>'))
{
- RedirType = REDIR_APPEND;
+ RedirMode = REDIR_APPEND;
Tok++;
}
}
@@ -262,7 +262,7 @@
Redir->Next = NULL;
Redir->OldHandle = INVALID_HANDLE_VALUE;
Redir->Number = Number;
- Redir->Type = RedirType;
+ Redir->Mode = RedirMode;
_tcscpy(Redir->Filename, Tok);
*List = Redir;
return TRUE;
@@ -815,7 +815,7 @@
{
if (SubstituteForVars(Redir->Filename, Buf))
ConOutPrintf(_T(" %c%s%s"), _T('0') + Redir->Number,
- RedirString[Redir->Type], Buf);
+ RedirString[Redir->Mode], Buf);
}
}
@@ -916,7 +916,7 @@
{
if (!SubstituteForVars(Redir->Filename, Buf)) return NULL;
PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
- RedirString[Redir->Type], Buf)
+ RedirString[Redir->Mode], Buf)
}
return Out;
}
Modified: trunk/reactos/base/shell/cmd/readme2.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/readme2.txt…
==============================================================================
--- trunk/reactos/base/shell/cmd/readme2.txt [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/readme2.txt [iso-8859-1] Fri Sep 28 19:36:49 2012
@@ -15,7 +15,7 @@
Once there is input taken in from the command line it is sent into ParseCommandLine().
In here we fist check for aliases and convert if need be.
-THen we look for redirections using GetRedirection() which will remove any redirection
symbols.
+Then we look for redirections using GetRedirection() which will remove any redirection
symbols.
and pass back info about where to redirect.
from this info it will do some switching around with the handles for where things go and
send them as need be.
personally i dont like this code and i tried to chnage it before but failed.
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] Fri Sep 28 19:36:49 2012
@@ -57,23 +57,21 @@
LPTSTR Filename;
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
+ static
+ struct REDIR_PARAMS
+ {
+ DWORD dwDesiredAccess;
+ DWORD dwShareMode;
+ DWORD dwCreationDisposition;
+ } RedirParams[] =
+ {
+ {GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING}, // REDIR_READ
+ {GENERIC_WRITE, FILE_SHARE_READ , CREATE_ALWAYS}, // REDIR_WRITE
+ {GENERIC_WRITE, FILE_SHARE_READ , OPEN_ALWAYS } // REDIR_APPEND
};
for (Redir = RedirList; Redir; Redir = Redir->Next)
@@ -101,17 +99,18 @@
else
{
hNew = CreateFile(Filename,
- dwAccess[Redir->Type],
- dwShareMode[Redir->Type],
+ RedirParams[Redir->Mode].dwDesiredAccess,
+ RedirParams[Redir->Mode].dwShareMode,
&SecAttr,
- dwCreationDisposition[Redir->Type],
+ RedirParams[Redir->Mode].dwCreationDisposition,
0,
NULL);
}
if (hNew == INVALID_HANDLE_VALUE)
{
- ConErrResPrintf(Redir->Type == REDIR_READ ? STRING_CMD_ERROR1 : STRING_CMD_ERROR3,
+ /* TODO: Print a more detailed message */
+ ConErrResPrintf(Redir->Mode == REDIR_READ ? STRING_CMD_ERROR1 : STRING_CMD_ERROR3,
Filename);
cmd_free(Filename);
redir_error:
@@ -120,7 +119,7 @@
return FALSE;
}
- if (Redir->Type == REDIR_APPEND)
+ if (Redir->Mode == REDIR_APPEND)
SetFilePointer(hNew, 0, NULL, FILE_END);
Redir->OldHandle = GetHandle(Redir->Number);
SetHandle(Redir->Number, hNew);