[CMD]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 28 Sep 2012 19:36:49 +0000 (19:36 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 28 Sep 2012 19:36:49 +0000 (19:36 +0000)
- Clarify the code, no functional changes.

svn path=/trunk/; revision=57415

reactos/base/shell/cmd/cmd.h
reactos/base/shell/cmd/parser.c
reactos/base/shell/cmd/readme2.txt
reactos/base/shell/cmd/redir.c

index 25df588..c99f024 100644 (file)
@@ -409,13 +409,18 @@ INT  cmd_prompt (LPTSTR);
 
 
 /* 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 *);
index eea9662..f188185 100644 (file)
@@ -214,7 +214,7 @@ static BOOL ParseRedirection(REDIRECTION **List)
 {
        TCHAR *Tok = CurrentToken;
        BYTE Number;
-       BYTE RedirType;
+       REDIR_MODE RedirMode;
        REDIRECTION *Redir;
 
        if (*Tok >= _T('0') && *Tok <= _T('9'))
@@ -224,16 +224,16 @@ static BOOL ParseRedirection(REDIRECTION **List)
 
        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 @@ static BOOL ParseRedirection(REDIRECTION **List)
        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 @@ EchoCommand(PARSED_COMMAND *Cmd)
        {
                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 @@ Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd)
        {
                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;
 }
index 4cd6f98..3e43851 100644 (file)
@@ -15,7 +15,7 @@ Currently there is some stuff for set /a in there, which might stay there or see
 
 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.  
index 923638f..d342ffb 100644 (file)
@@ -57,23 +57,21 @@ PerformRedirection(REDIRECTION *RedirList)
        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 @@ PerformRedirection(REDIRECTION *RedirList)
                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 @@ redir_error:
                        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);