mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
[CMD]
- Clarify the code, no functional changes. svn path=/trunk/; revision=57415
This commit is contained in:
parent
12d697145f
commit
893015f03c
4 changed files with 33 additions and 29 deletions
|
@ -409,13 +409,18 @@ INT cmd_prompt (LPTSTR);
|
||||||
|
|
||||||
|
|
||||||
/* Prototypes for REDIR.C */
|
/* 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
|
typedef struct _REDIRECTION
|
||||||
{
|
{
|
||||||
struct _REDIRECTION *Next;
|
struct _REDIRECTION *Next;
|
||||||
HANDLE OldHandle;
|
HANDLE OldHandle;
|
||||||
BYTE Number;
|
BYTE Number;
|
||||||
BYTE Type;
|
REDIR_MODE Mode;
|
||||||
TCHAR Filename[];
|
TCHAR Filename[];
|
||||||
} REDIRECTION;
|
} REDIRECTION;
|
||||||
BOOL PerformRedirection(REDIRECTION *);
|
BOOL PerformRedirection(REDIRECTION *);
|
||||||
|
|
|
@ -214,7 +214,7 @@ static BOOL ParseRedirection(REDIRECTION **List)
|
||||||
{
|
{
|
||||||
TCHAR *Tok = CurrentToken;
|
TCHAR *Tok = CurrentToken;
|
||||||
BYTE Number;
|
BYTE Number;
|
||||||
BYTE RedirType;
|
REDIR_MODE RedirMode;
|
||||||
REDIRECTION *Redir;
|
REDIRECTION *Redir;
|
||||||
|
|
||||||
if (*Tok >= _T('0') && *Tok <= _T('9'))
|
if (*Tok >= _T('0') && *Tok <= _T('9'))
|
||||||
|
@ -224,16 +224,16 @@ static BOOL ParseRedirection(REDIRECTION **List)
|
||||||
|
|
||||||
if (*Tok++ == _T('<'))
|
if (*Tok++ == _T('<'))
|
||||||
{
|
{
|
||||||
RedirType = REDIR_READ;
|
RedirMode = REDIR_READ;
|
||||||
if (*Tok == _T('<'))
|
if (*Tok == _T('<'))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RedirType = REDIR_WRITE;
|
RedirMode = REDIR_WRITE;
|
||||||
if (*Tok == _T('>'))
|
if (*Tok == _T('>'))
|
||||||
{
|
{
|
||||||
RedirType = REDIR_APPEND;
|
RedirMode = REDIR_APPEND;
|
||||||
Tok++;
|
Tok++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ static BOOL ParseRedirection(REDIRECTION **List)
|
||||||
Redir->Next = NULL;
|
Redir->Next = NULL;
|
||||||
Redir->OldHandle = INVALID_HANDLE_VALUE;
|
Redir->OldHandle = INVALID_HANDLE_VALUE;
|
||||||
Redir->Number = Number;
|
Redir->Number = Number;
|
||||||
Redir->Type = RedirType;
|
Redir->Mode = RedirMode;
|
||||||
_tcscpy(Redir->Filename, Tok);
|
_tcscpy(Redir->Filename, Tok);
|
||||||
*List = Redir;
|
*List = Redir;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -815,7 +815,7 @@ EchoCommand(PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
if (SubstituteForVars(Redir->Filename, Buf))
|
if (SubstituteForVars(Redir->Filename, Buf))
|
||||||
ConOutPrintf(_T(" %c%s%s"), _T('0') + Redir->Number,
|
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;
|
if (!SubstituteForVars(Redir->Filename, Buf)) return NULL;
|
||||||
PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
|
PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
|
||||||
RedirString[Redir->Type], Buf)
|
RedirString[Redir->Mode], Buf)
|
||||||
}
|
}
|
||||||
return Out;
|
return Out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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().
|
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.
|
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.
|
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.
|
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.
|
personally i dont like this code and i tried to chnage it before but failed.
|
||||||
|
|
|
@ -57,23 +57,21 @@ PerformRedirection(REDIRECTION *RedirList)
|
||||||
LPTSTR Filename;
|
LPTSTR Filename;
|
||||||
HANDLE hNew;
|
HANDLE hNew;
|
||||||
UINT DupNumber;
|
UINT DupNumber;
|
||||||
|
|
||||||
static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
|
static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
|
||||||
|
|
||||||
/* Some parameters used for read, write, and append, respectively */
|
/* Some parameters used for read, write, and append, respectively */
|
||||||
static const DWORD dwAccess[] = {
|
static
|
||||||
GENERIC_READ,
|
struct REDIR_PARAMS
|
||||||
GENERIC_WRITE,
|
{
|
||||||
GENERIC_WRITE
|
DWORD dwDesiredAccess;
|
||||||
};
|
DWORD dwShareMode;
|
||||||
static const DWORD dwShareMode[] = {
|
DWORD dwCreationDisposition;
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
} RedirParams[] =
|
||||||
FILE_SHARE_READ,
|
{
|
||||||
FILE_SHARE_READ
|
{GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING}, // REDIR_READ
|
||||||
};
|
{GENERIC_WRITE, FILE_SHARE_READ , CREATE_ALWAYS}, // REDIR_WRITE
|
||||||
static const DWORD dwCreationDisposition[] = {
|
{GENERIC_WRITE, FILE_SHARE_READ , OPEN_ALWAYS } // REDIR_APPEND
|
||||||
OPEN_EXISTING,
|
|
||||||
CREATE_ALWAYS,
|
|
||||||
OPEN_ALWAYS
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (Redir = RedirList; Redir; Redir = Redir->Next)
|
for (Redir = RedirList; Redir; Redir = Redir->Next)
|
||||||
|
@ -101,17 +99,18 @@ PerformRedirection(REDIRECTION *RedirList)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hNew = CreateFile(Filename,
|
hNew = CreateFile(Filename,
|
||||||
dwAccess[Redir->Type],
|
RedirParams[Redir->Mode].dwDesiredAccess,
|
||||||
dwShareMode[Redir->Type],
|
RedirParams[Redir->Mode].dwShareMode,
|
||||||
&SecAttr,
|
&SecAttr,
|
||||||
dwCreationDisposition[Redir->Type],
|
RedirParams[Redir->Mode].dwCreationDisposition,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hNew == INVALID_HANDLE_VALUE)
|
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);
|
Filename);
|
||||||
cmd_free(Filename);
|
cmd_free(Filename);
|
||||||
redir_error:
|
redir_error:
|
||||||
|
@ -120,7 +119,7 @@ redir_error:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Redir->Type == REDIR_APPEND)
|
if (Redir->Mode == REDIR_APPEND)
|
||||||
SetFilePointer(hNew, 0, NULL, FILE_END);
|
SetFilePointer(hNew, 0, NULL, FILE_END);
|
||||||
Redir->OldHandle = GetHandle(Redir->Number);
|
Redir->OldHandle = GetHandle(Redir->Number);
|
||||||
SetHandle(Redir->Number, hNew);
|
SetHandle(Redir->Number, hNew);
|
||||||
|
|
Loading…
Reference in a new issue