summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
12d6971)
- Clarify the code, no functional changes.
svn path=/trunk/; revision=57415
/* 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
{
struct _REDIRECTION *Next;
HANDLE OldHandle;
BYTE Number;
typedef struct _REDIRECTION
{
struct _REDIRECTION *Next;
HANDLE OldHandle;
BYTE Number;
TCHAR Filename[];
} REDIRECTION;
BOOL PerformRedirection(REDIRECTION *);
TCHAR Filename[];
} REDIRECTION;
BOOL PerformRedirection(REDIRECTION *);
{
TCHAR *Tok = CurrentToken;
BYTE Number;
{
TCHAR *Tok = CurrentToken;
BYTE Number;
REDIRECTION *Redir;
if (*Tok >= _T('0') && *Tok <= _T('9'))
REDIRECTION *Redir;
if (*Tok >= _T('0') && *Tok <= _T('9'))
- RedirType = REDIR_READ;
+ RedirMode = REDIR_READ;
if (*Tok == _T('<'))
goto fail;
}
else
{
if (*Tok == _T('<'))
goto fail;
}
else
{
- RedirType = REDIR_WRITE;
+ RedirMode = REDIR_WRITE;
- RedirType = REDIR_APPEND;
+ RedirMode = REDIR_APPEND;
Redir->Next = NULL;
Redir->OldHandle = INVALID_HANDLE_VALUE;
Redir->Number = Number;
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;
_tcscpy(Redir->Filename, Tok);
*List = Redir;
return TRUE;
{
if (SubstituteForVars(Redir->Filename, Buf))
ConOutPrintf(_T(" %c%s%s"), _T('0') + Redir->Number,
{
if (SubstituteForVars(Redir->Filename, Buf))
ConOutPrintf(_T(" %c%s%s"), _T('0') + Redir->Number,
- RedirString[Redir->Type], Buf);
+ RedirString[Redir->Mode], Buf);
{
if (!SubstituteForVars(Redir->Filename, Buf)) return NULL;
PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
{
if (!SubstituteForVars(Redir->Filename, Buf)) return NULL;
PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
- RedirString[Redir->Type], Buf)
+ RedirString[Redir->Mode], Buf)
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.
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.
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.
LPTSTR Filename;
HANDLE hNew;
UINT DupNumber;
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 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)
};
for (Redir = RedirList; Redir; Redir = Redir->Next)
else
{
hNew = CreateFile(Filename,
else
{
hNew = CreateFile(Filename,
- dwAccess[Redir->Type],
- dwShareMode[Redir->Type],
+ RedirParams[Redir->Mode].dwDesiredAccess,
+ RedirParams[Redir->Mode].dwShareMode,
- dwCreationDisposition[Redir->Type],
+ RedirParams[Redir->Mode].dwCreationDisposition,
0,
NULL);
}
if (hNew == INVALID_HANDLE_VALUE)
{
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:
Filename);
cmd_free(Filename);
redir_error:
- 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);
SetFilePointer(hNew, 0, NULL, FILE_END);
Redir->OldHandle = GetHandle(Redir->Number);
SetHandle(Redir->Number, hNew);