mirror of
https://github.com/reactos/reactos.git
synced 2025-01-01 03:54:02 +00:00
[CMD]
Fix whitespace (part 2/x) (convert tabs into 4-space indent). svn path=/trunk/; revision=59378
This commit is contained in:
parent
b067add889
commit
9b6dc5bd15
21 changed files with 2581 additions and 2573 deletions
|
@ -1,38 +1,37 @@
|
|||
/*
|
||||
* BATCH.H - A structure to preserve the context of a batch file
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct tagBATCHCONTEXT
|
||||
{
|
||||
struct tagBATCHCONTEXT *prev;
|
||||
char *mem; /* batchfile content in memory */
|
||||
DWORD memsize; /* size of batchfile */
|
||||
DWORD mempos; /* current position to read from */
|
||||
BOOL memfree; /* true if it need to be freed when exitbatch is called */
|
||||
TCHAR BatchFilePath[MAX_PATH];
|
||||
LPTSTR params;
|
||||
LPTSTR raw_params; /* Holds the raw params given by the input */
|
||||
INT shiftlevel[10];
|
||||
BOOL bEcho; /* Preserve echo flag across batch calls */
|
||||
REDIRECTION *RedirList;
|
||||
PARSED_COMMAND *current;
|
||||
struct _SETLOCAL *setlocal;
|
||||
struct tagBATCHCONTEXT *prev;
|
||||
char *mem; /* batchfile content in memory */
|
||||
DWORD memsize; /* size of batchfile */
|
||||
DWORD mempos; /* current position to read from */
|
||||
BOOL memfree; /* true if it need to be freed when exitbatch is called */
|
||||
TCHAR BatchFilePath[MAX_PATH];
|
||||
LPTSTR params;
|
||||
LPTSTR raw_params; /* Holds the raw params given by the input */
|
||||
INT shiftlevel[10];
|
||||
BOOL bEcho; /* Preserve echo flag across batch calls */
|
||||
REDIRECTION *RedirList;
|
||||
PARSED_COMMAND *current;
|
||||
struct _SETLOCAL *setlocal;
|
||||
} BATCH_CONTEXT, *LPBATCH_CONTEXT;
|
||||
|
||||
typedef struct tagFORCONTEXT
|
||||
{
|
||||
struct tagFORCONTEXT *prev;
|
||||
TCHAR firstvar;
|
||||
UINT varcount;
|
||||
LPTSTR *values;
|
||||
struct tagFORCONTEXT *prev;
|
||||
TCHAR firstvar;
|
||||
UINT varcount;
|
||||
LPTSTR *values;
|
||||
} FOR_CONTEXT, *LPFOR_CONTEXT;
|
||||
|
||||
|
||||
/* The stack of current batch contexts.
|
||||
/*
|
||||
* The stack of current batch contexts.
|
||||
* NULL when no batch is active
|
||||
*/
|
||||
extern LPBATCH_CONTEXT bc;
|
||||
|
|
|
@ -129,12 +129,12 @@ BOOL ReadCommand (LPTSTR, INT);
|
|||
|
||||
typedef struct tagCOMMAND
|
||||
{
|
||||
LPTSTR name;
|
||||
INT flags;
|
||||
INT (*func)(LPTSTR);
|
||||
LPTSTR name;
|
||||
INT flags;
|
||||
INT (*func)(LPTSTR);
|
||||
} COMMAND, *LPCOMMAND;
|
||||
|
||||
extern COMMAND cmds[]; /* The internal command table */
|
||||
extern COMMAND cmds[]; /* The internal command table */
|
||||
|
||||
VOID PrintCommandList (VOID);
|
||||
VOID PrintCommandListDetail (VOID);
|
||||
|
@ -366,33 +366,33 @@ INT CommandMsgbox (LPTSTR);
|
|||
enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
|
||||
typedef struct _PARSED_COMMAND
|
||||
{
|
||||
struct _PARSED_COMMAND *Subcommands;
|
||||
struct _PARSED_COMMAND *Next;
|
||||
struct _REDIRECTION *Redirections;
|
||||
BYTE Type;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
TCHAR *Rest;
|
||||
TCHAR First[];
|
||||
} Command;
|
||||
struct
|
||||
{
|
||||
BYTE Flags;
|
||||
BYTE Operator;
|
||||
TCHAR *LeftArg;
|
||||
TCHAR *RightArg;
|
||||
} If;
|
||||
struct
|
||||
{
|
||||
BYTE Switches;
|
||||
TCHAR Variable;
|
||||
LPTSTR Params;
|
||||
LPTSTR List;
|
||||
struct tagFORCONTEXT *Context;
|
||||
} For;
|
||||
};
|
||||
struct _PARSED_COMMAND *Subcommands;
|
||||
struct _PARSED_COMMAND *Next;
|
||||
struct _REDIRECTION *Redirections;
|
||||
BYTE Type;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
TCHAR *Rest;
|
||||
TCHAR First[];
|
||||
} Command;
|
||||
struct
|
||||
{
|
||||
BYTE Flags;
|
||||
BYTE Operator;
|
||||
TCHAR *LeftArg;
|
||||
TCHAR *RightArg;
|
||||
} If;
|
||||
struct
|
||||
{
|
||||
BYTE Switches;
|
||||
TCHAR Variable;
|
||||
LPTSTR Params;
|
||||
LPTSTR List;
|
||||
struct tagFORCONTEXT *Context;
|
||||
} For;
|
||||
};
|
||||
} PARSED_COMMAND;
|
||||
PARSED_COMMAND *ParseCommand(LPTSTR Line);
|
||||
VOID EchoCommand(PARSED_COMMAND *Cmd);
|
||||
|
@ -412,17 +412,17 @@ INT cmd_prompt (LPTSTR);
|
|||
/* Prototypes for REDIR.C */
|
||||
typedef enum _REDIR_MODE
|
||||
{
|
||||
REDIR_READ = 0,
|
||||
REDIR_WRITE = 1,
|
||||
REDIR_APPEND = 2
|
||||
REDIR_READ = 0,
|
||||
REDIR_WRITE = 1,
|
||||
REDIR_APPEND = 2
|
||||
} REDIR_MODE;
|
||||
typedef struct _REDIRECTION
|
||||
{
|
||||
struct _REDIRECTION *Next;
|
||||
HANDLE OldHandle;
|
||||
BYTE Number;
|
||||
REDIR_MODE Mode;
|
||||
TCHAR Filename[];
|
||||
struct _REDIRECTION *Next;
|
||||
HANDLE OldHandle;
|
||||
BYTE Number;
|
||||
REDIR_MODE Mode;
|
||||
TCHAR Filename[];
|
||||
} REDIRECTION;
|
||||
BOOL PerformRedirection(REDIRECTION *);
|
||||
VOID UndoRedirection(REDIRECTION *, REDIRECTION *End);
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
* 24-Jan-1999 (Eric Kohl)
|
||||
* Fixed Win32 environment handling.
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
#include "precomp.h"
|
||||
|
||||
|
@ -53,133 +53,133 @@
|
|||
*/
|
||||
VOID PrintPrompt(VOID)
|
||||
{
|
||||
static TCHAR default_pr[] = _T("$P$G");
|
||||
TCHAR szPrompt[256];
|
||||
LPTSTR pr;
|
||||
static TCHAR default_pr[] = _T("$P$G");
|
||||
TCHAR szPrompt[256];
|
||||
LPTSTR pr;
|
||||
|
||||
if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
|
||||
pr = szPrompt;
|
||||
else
|
||||
pr = default_pr;
|
||||
if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
|
||||
pr = szPrompt;
|
||||
else
|
||||
pr = default_pr;
|
||||
|
||||
while (*pr)
|
||||
{
|
||||
if (*pr != _T('$'))
|
||||
{
|
||||
ConOutChar (*pr);
|
||||
}
|
||||
else
|
||||
{
|
||||
pr++;
|
||||
while (*pr)
|
||||
{
|
||||
if (*pr != _T('$'))
|
||||
{
|
||||
ConOutChar (*pr);
|
||||
}
|
||||
else
|
||||
{
|
||||
pr++;
|
||||
|
||||
switch (_totupper (*pr))
|
||||
{
|
||||
case _T('A'):
|
||||
ConOutChar (_T('&'));
|
||||
break;
|
||||
switch (_totupper (*pr))
|
||||
{
|
||||
case _T('A'):
|
||||
ConOutChar (_T('&'));
|
||||
break;
|
||||
|
||||
case _T('B'):
|
||||
ConOutChar (_T('|'));
|
||||
break;
|
||||
case _T('B'):
|
||||
ConOutChar (_T('|'));
|
||||
break;
|
||||
|
||||
case _T('C'):
|
||||
ConOutChar (_T('('));
|
||||
break;
|
||||
case _T('C'):
|
||||
ConOutChar (_T('('));
|
||||
break;
|
||||
|
||||
case _T('D'):
|
||||
ConOutPrintf(_T("%s"), GetDateString());
|
||||
break;
|
||||
case _T('D'):
|
||||
ConOutPrintf(_T("%s"), GetDateString());
|
||||
break;
|
||||
|
||||
case _T('E'):
|
||||
ConOutChar (_T('\x1B'));
|
||||
break;
|
||||
case _T('E'):
|
||||
ConOutChar (_T('\x1B'));
|
||||
break;
|
||||
|
||||
case _T('F'):
|
||||
ConOutChar (_T(')'));
|
||||
break;
|
||||
case _T('F'):
|
||||
ConOutChar (_T(')'));
|
||||
break;
|
||||
|
||||
case _T('G'):
|
||||
ConOutChar (_T('>'));
|
||||
break;
|
||||
case _T('G'):
|
||||
ConOutChar (_T('>'));
|
||||
break;
|
||||
|
||||
case _T('H'):
|
||||
ConOutChar (_T('\x08'));
|
||||
case _T('H'):
|
||||
ConOutChar (_T('\x08'));
|
||||
ConOutChar (_T(' '));
|
||||
ConOutChar (_T('\x08'));
|
||||
break;
|
||||
break;
|
||||
|
||||
case _T('L'):
|
||||
ConOutChar (_T('<'));
|
||||
break;
|
||||
case _T('L'):
|
||||
ConOutChar (_T('<'));
|
||||
break;
|
||||
|
||||
case _T('N'):
|
||||
{
|
||||
TCHAR szPath[MAX_PATH];
|
||||
GetCurrentDirectory (MAX_PATH, szPath);
|
||||
ConOutChar (szPath[0]);
|
||||
}
|
||||
break;
|
||||
case _T('N'):
|
||||
{
|
||||
TCHAR szPath[MAX_PATH];
|
||||
GetCurrentDirectory (MAX_PATH, szPath);
|
||||
ConOutChar (szPath[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
case _T('P'):
|
||||
{
|
||||
TCHAR szPath[MAX_PATH];
|
||||
GetCurrentDirectory (MAX_PATH, szPath);
|
||||
ConOutPrintf (_T("%s"), szPath);
|
||||
}
|
||||
break;
|
||||
case _T('P'):
|
||||
{
|
||||
TCHAR szPath[MAX_PATH];
|
||||
GetCurrentDirectory (MAX_PATH, szPath);
|
||||
ConOutPrintf (_T("%s"), szPath);
|
||||
}
|
||||
break;
|
||||
|
||||
case _T('Q'):
|
||||
ConOutChar (_T('='));
|
||||
break;
|
||||
case _T('Q'):
|
||||
ConOutChar (_T('='));
|
||||
break;
|
||||
|
||||
case _T('S'):
|
||||
ConOutChar (_T(' '));
|
||||
break;
|
||||
ConOutChar (_T(' '));
|
||||
break;
|
||||
|
||||
case _T('T'):
|
||||
ConOutPrintf(_T("%s"), GetTimeString());
|
||||
break;
|
||||
case _T('T'):
|
||||
ConOutPrintf(_T("%s"), GetTimeString());
|
||||
break;
|
||||
|
||||
case _T('V'):
|
||||
switch (osvi.dwPlatformId)
|
||||
{
|
||||
case VER_PLATFORM_WIN32_WINDOWS:
|
||||
if (osvi.dwMajorVersion == 4 &&
|
||||
osvi.dwMinorVersion == 1)
|
||||
ConOutPrintf (_T("Windows 98"));
|
||||
else
|
||||
ConOutPrintf (_T("Windows 95"));
|
||||
break;
|
||||
case _T('V'):
|
||||
switch (osvi.dwPlatformId)
|
||||
{
|
||||
case VER_PLATFORM_WIN32_WINDOWS:
|
||||
if (osvi.dwMajorVersion == 4 &&
|
||||
osvi.dwMinorVersion == 1)
|
||||
ConOutPrintf (_T("Windows 98"));
|
||||
else
|
||||
ConOutPrintf (_T("Windows 95"));
|
||||
break;
|
||||
|
||||
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
ConOutPrintf (_T("Windows NT Version %lu.%lu"),
|
||||
osvi.dwMajorVersion, osvi.dwMinorVersion);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
ConOutPrintf (_T("Windows NT Version %lu.%lu"),
|
||||
osvi.dwMajorVersion, osvi.dwMinorVersion);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case _T('_'):
|
||||
ConOutChar (_T('\n'));
|
||||
break;
|
||||
case _T('_'):
|
||||
ConOutChar (_T('\n'));
|
||||
break;
|
||||
|
||||
case '$':
|
||||
ConOutChar (_T('$'));
|
||||
break;
|
||||
case '$':
|
||||
ConOutChar (_T('$'));
|
||||
break;
|
||||
|
||||
#ifdef FEATURE_DIRECTORY_STACK
|
||||
case '+':
|
||||
{
|
||||
INT i;
|
||||
for (i = 0; i < GetDirectoryStackDepth (); i++)
|
||||
ConOutChar (_T('+'));
|
||||
}
|
||||
break;
|
||||
case '+':
|
||||
{
|
||||
INT i;
|
||||
for (i = 0; i < GetDirectoryStackDepth (); i++)
|
||||
ConOutChar (_T('+'));
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
pr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
pr++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -187,42 +187,42 @@ VOID PrintPrompt(VOID)
|
|||
|
||||
INT cmd_prompt (LPTSTR param)
|
||||
{
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_PROMPT_HELP1);
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_PROMPT_HELP1);
|
||||
|
||||
#ifdef FEATURE_DIRECTORY_STACK
|
||||
ConOutResPaging(FALSE,STRING_PROMPT_HELP2);
|
||||
ConOutResPaging(FALSE,STRING_PROMPT_HELP2);
|
||||
#endif
|
||||
ConOutResPaging(FALSE,STRING_PROMPT_HELP3);
|
||||
return 0;
|
||||
}
|
||||
ConOutResPaging(FALSE,STRING_PROMPT_HELP3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if it is null, then it needs to set to default,
|
||||
because that means the user entered "prompt" only.
|
||||
so even if param is null you _must_ still set prompt
|
||||
to the default. There seems to be some kinda difference
|
||||
between winxp and 2k in this matter and this way will
|
||||
cover both. Do not use fixed size of szParam for param the buffer are 8192bytes
|
||||
and will later change to dymatic buffer */
|
||||
/*
|
||||
* if it is null, then it needs to set to default,
|
||||
* because that means the user entered "prompt" only.
|
||||
* so even if param is null you _must_ still set prompt
|
||||
* to the default. There seems to be some kinda difference
|
||||
* between winxp and 2k in this matter and this way will
|
||||
* cover both. Do not use fixed size of szParam for param the buffer
|
||||
* are 8192 bytes and will later change to dymatic buffer.
|
||||
*/
|
||||
|
||||
/* set PROMPT environment variable */
|
||||
if (param[0] != _T('\0'))
|
||||
{
|
||||
if (!SetEnvironmentVariable (_T("PROMPT"), param))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR szParam[5];
|
||||
_tcscpy(szParam,_T("$P$G"));
|
||||
if (!SetEnvironmentVariable (_T("PROMPT"),szParam))
|
||||
return 1;
|
||||
}
|
||||
/* set PROMPT environment variable */
|
||||
if (param[0] != _T('\0'))
|
||||
{
|
||||
if (!SetEnvironmentVariable (_T("PROMPT"), param))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR szParam[5];
|
||||
_tcscpy(szParam,_T("$P$G"));
|
||||
if (!SetEnvironmentVariable (_T("PROMPT"),szParam))
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -36,121 +36,121 @@ static HANDLE ExtraHandles[10 - 3];
|
|||
|
||||
static HANDLE GetHandle(UINT Number)
|
||||
{
|
||||
if (Number < 3)
|
||||
return GetStdHandle(STD_INPUT_HANDLE - Number);
|
||||
else
|
||||
return ExtraHandles[Number - 3];
|
||||
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;
|
||||
if (Number < 3)
|
||||
SetStdHandle(STD_INPUT_HANDLE - Number, Handle);
|
||||
else
|
||||
ExtraHandles[Number - 3] = Handle;
|
||||
}
|
||||
|
||||
BOOL
|
||||
PerformRedirection(REDIRECTION *RedirList)
|
||||
{
|
||||
REDIRECTION *Redir;
|
||||
LPTSTR Filename;
|
||||
HANDLE hNew;
|
||||
UINT DupNumber;
|
||||
REDIRECTION *Redir;
|
||||
LPTSTR Filename;
|
||||
HANDLE hNew;
|
||||
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 */
|
||||
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
|
||||
};
|
||||
/* Some parameters used for read, write, and append, respectively */
|
||||
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)
|
||||
{
|
||||
Filename = DoDelayedExpansion(Redir->Filename);
|
||||
if (!Filename)
|
||||
goto redir_error;
|
||||
StripQuotes(Filename);
|
||||
for (Redir = RedirList; Redir; Redir = Redir->Next)
|
||||
{
|
||||
Filename = DoDelayedExpansion(Redir->Filename);
|
||||
if (!Filename)
|
||||
goto redir_error;
|
||||
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,
|
||||
RedirParams[Redir->Mode].dwDesiredAccess,
|
||||
RedirParams[Redir->Mode].dwShareMode,
|
||||
&SecAttr,
|
||||
RedirParams[Redir->Mode].dwCreationDisposition,
|
||||
0,
|
||||
NULL);
|
||||
}
|
||||
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,
|
||||
RedirParams[Redir->Mode].dwDesiredAccess,
|
||||
RedirParams[Redir->Mode].dwShareMode,
|
||||
&SecAttr,
|
||||
RedirParams[Redir->Mode].dwCreationDisposition,
|
||||
0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (hNew == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/* TODO: Print a more detailed message */
|
||||
ConErrResPrintf(Redir->Mode == REDIR_READ ? STRING_CMD_ERROR1 : STRING_CMD_ERROR3,
|
||||
Filename);
|
||||
cmd_free(Filename);
|
||||
if (hNew == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/* TODO: Print a more detailed message */
|
||||
ConErrResPrintf(Redir->Mode == REDIR_READ ? STRING_CMD_ERROR1 : STRING_CMD_ERROR3,
|
||||
Filename);
|
||||
cmd_free(Filename);
|
||||
redir_error:
|
||||
/* Undo all the redirections before this one */
|
||||
UndoRedirection(RedirList, Redir);
|
||||
return FALSE;
|
||||
}
|
||||
/* Undo all the redirections before this one */
|
||||
UndoRedirection(RedirList, Redir);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Redir->Mode == REDIR_APPEND)
|
||||
SetFilePointer(hNew, 0, NULL, FILE_END);
|
||||
Redir->OldHandle = GetHandle(Redir->Number);
|
||||
SetHandle(Redir->Number, hNew);
|
||||
if (Redir->Mode == 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));
|
||||
cmd_free(Filename);
|
||||
}
|
||||
return TRUE;
|
||||
TRACE("%d redirected to: %s\n", Redir->Number, debugstr_aw(Filename));
|
||||
cmd_free(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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
REDIRECTION *Next;
|
||||
for (; Redir; Redir = Next)
|
||||
{
|
||||
Next = Redir->Next;
|
||||
ASSERT(Redir->OldHandle == INVALID_HANDLE_VALUE);
|
||||
cmd_free(Redir);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FEATURE_REDIRECTION */
|
||||
|
|
|
@ -17,15 +17,16 @@
|
|||
* 17-Oct-2001 (Eric Kohl)
|
||||
* Implemented basic rename code.
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 25-Nov-2008 (Victor Martinez) <vicmarcal@hotmail.com> Patch dedicated to Myrjala because her comprenhension and love :D
|
||||
* Fixing following Bugs:
|
||||
* -Wrong behavior with wildcards when Source and Destiny are Paths(FIXED).
|
||||
* -Wrong general behavior (MSDN:"Rename cant move files between subdirectories")(FIXED)
|
||||
* -Wrong behavior when renaming without path in destiny:(i.e) "ren C:\text\as.txt list.txt" it moves as.txt and then rename it(FIXED)
|
||||
* (MSDN: If there is a Path in Source and no Path in Destiny, then Destiny Path is Source Path,because never Ren has to be used to move.)
|
||||
* -Implemented checkings if SourcePath and DestinyPath are differents.
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*
|
||||
* 25-Nov-2008 (Victor Martinez) <vicmarcal@hotmail.com> Patch dedicated to Myrjala because her comprenhension and love :D
|
||||
* Fixing following Bugs:
|
||||
* -Wrong behavior with wildcards when Source and Destiny are Paths(FIXED).
|
||||
* -Wrong general behavior (MSDN:"Rename cant move files between subdirectories")(FIXED)
|
||||
* -Wrong behavior when renaming without path in destiny:(i.e) "ren C:\text\as.txt list.txt" it moves as.txt and then rename it(FIXED)
|
||||
* (MSDN: If there is a Path in Source and no Path in Destiny, then Destiny Path is Source Path,because never Ren has to be used to move.)
|
||||
* -Implemented checkings if SourcePath and DestinyPath are differents.
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -35,19 +36,18 @@
|
|||
|
||||
enum
|
||||
{
|
||||
REN_ATTRIBUTES = 0x001, /* /A : not implemented */
|
||||
REN_ERROR = 0x002, /* /E */
|
||||
REN_NOTHING = 0x004, /* /N */
|
||||
REN_PROMPT = 0x008, /* /P : not implemented */
|
||||
REN_QUIET = 0x010, /* /Q */
|
||||
REN_SUBDIR = 0x020, /* /S */
|
||||
REN_TOTAL = 0x040, /* /T */
|
||||
REN_ATTRIBUTES = 0x001, /* /A : not implemented */
|
||||
REN_ERROR = 0x002, /* /E */
|
||||
REN_NOTHING = 0x004, /* /N */
|
||||
REN_PROMPT = 0x008, /* /P : not implemented */
|
||||
REN_QUIET = 0x010, /* /Q */
|
||||
REN_SUBDIR = 0x020, /* /S */
|
||||
REN_TOTAL = 0x040, /* /T */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* file rename internal command.
|
||||
*
|
||||
*/
|
||||
INT cmd_rename (LPTSTR param)
|
||||
{
|
||||
|
@ -59,13 +59,11 @@ INT cmd_rename (LPTSTR param)
|
|||
DWORD dwFiles = 0; /* number of renamedd files */
|
||||
INT i;
|
||||
|
||||
|
||||
LPTSTR srcPattern = NULL; /* Source Argument*/
|
||||
TCHAR srcPath[MAX_PATH]; /*Source Path Directories*/
|
||||
LPTSTR srcFILE = NULL; /*Contains the files name(s)*/
|
||||
TCHAR srcFinal[MAX_PATH];
|
||||
|
||||
|
||||
LPTSTR dstPattern = NULL; /*Destiny Argument*/
|
||||
TCHAR dstPath[MAX_PATH]; /*Source Path Directories*/
|
||||
LPTSTR dstFILE = NULL; /*Contains the files name(s)*/
|
||||
|
@ -76,11 +74,6 @@ INT cmd_rename (LPTSTR param)
|
|||
BOOL bDstWildcard = FALSE;
|
||||
BOOL bPath = FALSE;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LPTSTR p,q,r;
|
||||
|
||||
HANDLE hFile;
|
||||
|
@ -88,8 +81,6 @@ INT cmd_rename (LPTSTR param)
|
|||
/*If the PARAM=/? then show the help*/
|
||||
if (!_tcsncmp(param, _T("/?"), 2))
|
||||
{
|
||||
|
||||
|
||||
ConOutResPaging(TRUE,STRING_REN_HELP1);
|
||||
return 0;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,8 +6,8 @@
|
|||
* 30 Aug 1999
|
||||
* started - Paolo Pantaleo <paolopan@freemail.it>
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -18,86 +18,86 @@
|
|||
|
||||
INT CommandScreen (LPTSTR param)
|
||||
{
|
||||
SHORT x,y;
|
||||
BOOL bSkipText = FALSE;
|
||||
SHORT x,y;
|
||||
BOOL bSkipText = FALSE;
|
||||
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_SCREEN_HELP);
|
||||
return 0;
|
||||
}
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_SCREEN_HELP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
//get row
|
||||
while(_istspace(*param))
|
||||
param++;
|
||||
//get row
|
||||
while(_istspace(*param))
|
||||
param++;
|
||||
|
||||
if(!(*param))
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
if(!(*param))
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
y = _ttoi(param);
|
||||
if (y<0 || y>(maxy-1))
|
||||
{
|
||||
ConOutResPuts(STRING_SCREEN_ROW);
|
||||
y = _ttoi(param);
|
||||
if (y<0 || y>(maxy-1))
|
||||
{
|
||||
ConOutResPuts(STRING_SCREEN_ROW);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//get col
|
||||
if(!(param = _tcschr(param,_T(' '))))
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
//get col
|
||||
if(!(param = _tcschr(param,_T(' '))))
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(_istspace(*param))
|
||||
param++;
|
||||
while(_istspace(*param))
|
||||
param++;
|
||||
|
||||
if(!(*param))
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
if(!(*param))
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
x = _ttoi(param);
|
||||
if (x<0 || x>(maxx-1))
|
||||
{
|
||||
ConErrResPuts(STRING_SCREEN_COL);
|
||||
return 1;
|
||||
}
|
||||
x = _ttoi(param);
|
||||
if (x<0 || x>(maxx-1))
|
||||
{
|
||||
ConErrResPuts(STRING_SCREEN_COL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//get text
|
||||
if(!(param = _tcschr(param,_T(' '))))
|
||||
{
|
||||
bSkipText = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(_istspace(*param))
|
||||
param++;
|
||||
//get text
|
||||
if(!(param = _tcschr(param,_T(' '))))
|
||||
{
|
||||
bSkipText = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(_istspace(*param))
|
||||
param++;
|
||||
|
||||
if(!(*param))
|
||||
{
|
||||
bSkipText = TRUE;
|
||||
}
|
||||
}
|
||||
if(!(*param))
|
||||
{
|
||||
bSkipText = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
bIgnoreEcho = TRUE;
|
||||
bIgnoreEcho = TRUE;
|
||||
|
||||
if(bSkipText)
|
||||
x=0;
|
||||
if(bSkipText)
|
||||
x=0;
|
||||
|
||||
|
||||
SetCursorXY(x,y);
|
||||
SetCursorXY(x,y);
|
||||
|
||||
if(!(bSkipText))
|
||||
ConOutPuts(param);
|
||||
if(!(bSkipText))
|
||||
ConOutPuts(param);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_CMD_SCREEN */
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
* 25-Feb-1999 (Eric Kohl)
|
||||
* Fixed little bug.
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
@ -48,9 +48,9 @@ seta_eval ( LPCTSTR expr );
|
|||
static LPCTSTR
|
||||
skip_ws ( LPCTSTR p )
|
||||
{
|
||||
while (*p && *p <= _T(' '))
|
||||
p++;
|
||||
return p;
|
||||
while (*p && *p <= _T(' '))
|
||||
p++;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Used to check for and handle:
|
||||
|
@ -58,163 +58,163 @@ skip_ws ( LPCTSTR p )
|
|||
static LPTSTR
|
||||
GetQuotedString(TCHAR *p)
|
||||
{
|
||||
TCHAR *end;
|
||||
if (*p == _T('"'))
|
||||
{
|
||||
p = (LPTSTR)skip_ws(p + 1);
|
||||
/* If a matching quote is found, truncate the string */
|
||||
end = _tcsrchr(p, _T('"'));
|
||||
if (end)
|
||||
*end = _T('\0');
|
||||
}
|
||||
return p;
|
||||
TCHAR *end;
|
||||
if (*p == _T('"'))
|
||||
{
|
||||
p = (LPTSTR)skip_ws(p + 1);
|
||||
/* If a matching quote is found, truncate the string */
|
||||
end = _tcsrchr(p, _T('"'));
|
||||
if (end)
|
||||
*end = _T('\0');
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
INT cmd_set (LPTSTR param)
|
||||
{
|
||||
LPTSTR p;
|
||||
LPTSTR lpEnv;
|
||||
LPTSTR lpOutput;
|
||||
LPTSTR p;
|
||||
LPTSTR lpEnv;
|
||||
LPTSTR lpOutput;
|
||||
|
||||
if ( !_tcsncmp (param, _T("/?"), 2) )
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_SET_HELP);
|
||||
return 0;
|
||||
}
|
||||
if ( !_tcsncmp (param, _T("/?"), 2) )
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_SET_HELP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
param = (LPTSTR)skip_ws(param);
|
||||
param = (LPTSTR)skip_ws(param);
|
||||
|
||||
/* if no parameters, show the environment */
|
||||
if (param[0] == _T('\0'))
|
||||
{
|
||||
lpEnv = (LPTSTR)GetEnvironmentStrings ();
|
||||
if (lpEnv)
|
||||
{
|
||||
lpOutput = lpEnv;
|
||||
while (*lpOutput)
|
||||
{
|
||||
if (*lpOutput != _T('='))
|
||||
ConOutPuts(lpOutput);
|
||||
lpOutput += _tcslen(lpOutput) + 1;
|
||||
ConOutPuts(_T("\r\n"));
|
||||
}
|
||||
FreeEnvironmentStrings (lpEnv);
|
||||
}
|
||||
/* if no parameters, show the environment */
|
||||
if (param[0] == _T('\0'))
|
||||
{
|
||||
lpEnv = (LPTSTR)GetEnvironmentStrings ();
|
||||
if (lpEnv)
|
||||
{
|
||||
lpOutput = lpEnv;
|
||||
while (*lpOutput)
|
||||
{
|
||||
if (*lpOutput != _T('='))
|
||||
ConOutPuts(lpOutput);
|
||||
lpOutput += _tcslen(lpOutput) + 1;
|
||||
ConOutPuts(_T("\r\n"));
|
||||
}
|
||||
FreeEnvironmentStrings (lpEnv);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the /A does *NOT* have to be followed by a whitespace */
|
||||
if ( !_tcsnicmp (param, _T("/A"), 2) )
|
||||
{
|
||||
BOOL Success;
|
||||
StripQuotes(param);
|
||||
Success = seta_eval ( skip_ws(param+2) );
|
||||
if(!Success)
|
||||
{
|
||||
/*might seem random but this is what windows xp does */
|
||||
nErrorLevel = 9165;
|
||||
}
|
||||
return !Success;
|
||||
}
|
||||
/* the /A does *NOT* have to be followed by a whitespace */
|
||||
if ( !_tcsnicmp (param, _T("/A"), 2) )
|
||||
{
|
||||
BOOL Success;
|
||||
StripQuotes(param);
|
||||
Success = seta_eval ( skip_ws(param+2) );
|
||||
if(!Success)
|
||||
{
|
||||
/*might seem random but this is what windows xp does */
|
||||
nErrorLevel = 9165;
|
||||
}
|
||||
return !Success;
|
||||
}
|
||||
|
||||
if (!_tcsnicmp(param, _T("/P"), 2))
|
||||
{
|
||||
TCHAR value[1023];
|
||||
param = GetQuotedString((LPTSTR)skip_ws(param + 2));
|
||||
p = _tcschr(param, _T('='));
|
||||
if (!p)
|
||||
{
|
||||
ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
if (!_tcsnicmp(param, _T("/P"), 2))
|
||||
{
|
||||
TCHAR value[1023];
|
||||
param = GetQuotedString((LPTSTR)skip_ws(param + 2));
|
||||
p = _tcschr(param, _T('='));
|
||||
if (!p)
|
||||
{
|
||||
ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*p++ = _T('\0');
|
||||
ConOutPrintf(_T("%s"), GetQuotedString(p));
|
||||
ConInString(value, 1023);
|
||||
*p++ = _T('\0');
|
||||
ConOutPrintf(_T("%s"), GetQuotedString(p));
|
||||
ConInString(value, 1023);
|
||||
|
||||
if (!*value || !SetEnvironmentVariable(param, value))
|
||||
{
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (!*value || !SetEnvironmentVariable(param, value))
|
||||
{
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
param = GetQuotedString(param);
|
||||
param = GetQuotedString(param);
|
||||
|
||||
p = _tcschr (param, _T('='));
|
||||
if (p)
|
||||
{
|
||||
/* set or remove environment variable */
|
||||
if (p == param)
|
||||
{
|
||||
/* handle set =val case */
|
||||
ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
p = _tcschr (param, _T('='));
|
||||
if (p)
|
||||
{
|
||||
/* set or remove environment variable */
|
||||
if (p == param)
|
||||
{
|
||||
/* handle set =val case */
|
||||
ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*p++ = _T('\0');
|
||||
if (!SetEnvironmentVariable(param, *p ? p : NULL))
|
||||
{
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* display all environment variable with the given prefix */
|
||||
BOOL bFound = FALSE;
|
||||
*p++ = _T('\0');
|
||||
if (!SetEnvironmentVariable(param, *p ? p : NULL))
|
||||
{
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* display all environment variable with the given prefix */
|
||||
BOOL bFound = FALSE;
|
||||
|
||||
while (_istspace(*param) || *param == _T(',') || *param == _T(';'))
|
||||
param++;
|
||||
while (_istspace(*param) || *param == _T(',') || *param == _T(';'))
|
||||
param++;
|
||||
|
||||
p = _tcsrchr(param, _T(' '));
|
||||
if (!p)
|
||||
p = param + _tcslen(param);
|
||||
*p = _T('\0');
|
||||
p = _tcsrchr(param, _T(' '));
|
||||
if (!p)
|
||||
p = param + _tcslen(param);
|
||||
*p = _T('\0');
|
||||
|
||||
lpEnv = GetEnvironmentStrings();
|
||||
if (lpEnv)
|
||||
{
|
||||
lpOutput = lpEnv;
|
||||
while (*lpOutput)
|
||||
{
|
||||
if (!_tcsnicmp(lpOutput, param, p - param))
|
||||
{
|
||||
ConOutPuts(lpOutput);
|
||||
ConOutPuts(_T("\r\n"));
|
||||
bFound = TRUE;
|
||||
}
|
||||
lpOutput += _tcslen(lpOutput) + 1;
|
||||
}
|
||||
FreeEnvironmentStrings(lpEnv);
|
||||
}
|
||||
lpEnv = GetEnvironmentStrings();
|
||||
if (lpEnv)
|
||||
{
|
||||
lpOutput = lpEnv;
|
||||
while (*lpOutput)
|
||||
{
|
||||
if (!_tcsnicmp(lpOutput, param, p - param))
|
||||
{
|
||||
ConOutPuts(lpOutput);
|
||||
ConOutPuts(_T("\r\n"));
|
||||
bFound = TRUE;
|
||||
}
|
||||
lpOutput += _tcslen(lpOutput) + 1;
|
||||
}
|
||||
FreeEnvironmentStrings(lpEnv);
|
||||
}
|
||||
|
||||
if (!bFound)
|
||||
{
|
||||
ConErrResPrintf (STRING_PATH_ERROR, param);
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!bFound)
|
||||
{
|
||||
ConErrResPrintf (STRING_PATH_ERROR, param);
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static INT
|
||||
ident_len ( LPCTSTR p )
|
||||
ident_len(LPCTSTR p)
|
||||
{
|
||||
LPCTSTR p2 = p;
|
||||
if ( __iscsymf(*p) )
|
||||
{
|
||||
++p2;
|
||||
while ( __iscsym(*p2) )
|
||||
++p2;
|
||||
}
|
||||
return (INT)(p2-p);
|
||||
LPCTSTR p2 = p;
|
||||
if ( __iscsymf(*p) )
|
||||
{
|
||||
++p2;
|
||||
while ( __iscsym(*p2) )
|
||||
++p2;
|
||||
}
|
||||
return (INT)(p2-p);
|
||||
}
|
||||
|
||||
#define PARSE_IDENT(ident,identlen,p) \
|
||||
|
@ -225,318 +225,318 @@ ident_len ( LPCTSTR p )
|
|||
p += identlen;
|
||||
|
||||
static BOOL
|
||||
seta_identval ( LPCTSTR ident, INT* result )
|
||||
seta_identval(LPCTSTR ident, INT* result)
|
||||
{
|
||||
LPCTSTR identVal = GetEnvVarOrSpecial ( ident );
|
||||
if ( !identVal )
|
||||
{
|
||||
/* TODO FIXME - what to do upon failure? */
|
||||
*result = 0;
|
||||
return FALSE;
|
||||
}
|
||||
*result = _tcstol ( identVal, NULL, 0 );
|
||||
return TRUE;
|
||||
LPCTSTR identVal = GetEnvVarOrSpecial ( ident );
|
||||
if ( !identVal )
|
||||
{
|
||||
/* TODO FIXME - what to do upon failure? */
|
||||
*result = 0;
|
||||
return FALSE;
|
||||
}
|
||||
*result = _tcstol ( identVal, NULL, 0 );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
calc ( INT* lval, TCHAR op, INT rval )
|
||||
calc(INT* lval, TCHAR op, INT rval)
|
||||
{
|
||||
switch ( op )
|
||||
{
|
||||
case '*':
|
||||
*lval *= rval;
|
||||
break;
|
||||
case '/':
|
||||
*lval /= rval;
|
||||
break;
|
||||
case '%':
|
||||
*lval %= rval;
|
||||
break;
|
||||
case '+':
|
||||
*lval += rval;
|
||||
break;
|
||||
case '-':
|
||||
*lval -= rval;
|
||||
break;
|
||||
case '&':
|
||||
*lval &= rval;
|
||||
break;
|
||||
case '^':
|
||||
*lval ^= rval;
|
||||
break;
|
||||
case '|':
|
||||
*lval |= rval;
|
||||
break;
|
||||
default:
|
||||
ConErrResPuts ( STRING_INVALID_OPERAND );
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
switch ( op )
|
||||
{
|
||||
case '*':
|
||||
*lval *= rval;
|
||||
break;
|
||||
case '/':
|
||||
*lval /= rval;
|
||||
break;
|
||||
case '%':
|
||||
*lval %= rval;
|
||||
break;
|
||||
case '+':
|
||||
*lval += rval;
|
||||
break;
|
||||
case '-':
|
||||
*lval -= rval;
|
||||
break;
|
||||
case '&':
|
||||
*lval &= rval;
|
||||
break;
|
||||
case '^':
|
||||
*lval ^= rval;
|
||||
break;
|
||||
case '|':
|
||||
*lval |= rval;
|
||||
break;
|
||||
default:
|
||||
ConErrResPuts ( STRING_INVALID_OPERAND );
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_stmt ( LPCTSTR* p_, INT* result );
|
||||
seta_stmt (LPCTSTR* p_, INT* result);
|
||||
|
||||
static BOOL
|
||||
seta_unaryTerm ( LPCTSTR* p_, INT* result )
|
||||
seta_unaryTerm(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
LPCTSTR p = *p_;
|
||||
if ( *p == _T('(') )
|
||||
{
|
||||
INT rval;
|
||||
p = skip_ws ( p + 1 );
|
||||
if ( !seta_stmt ( &p, &rval ) )
|
||||
return FALSE;
|
||||
if ( *p++ != _T(')') )
|
||||
{
|
||||
ConErrResPuts ( STRING_EXPECTED_CLOSE_PAREN );
|
||||
return FALSE;
|
||||
}
|
||||
*result = rval;
|
||||
}
|
||||
else if ( isdigit(*p) )
|
||||
{
|
||||
*result = _tcstol ( p, (LPTSTR *)&p, 0 );
|
||||
}
|
||||
else if ( __iscsymf(*p) )
|
||||
{
|
||||
LPTSTR ident;
|
||||
INT identlen;
|
||||
PARSE_IDENT(ident,identlen,p);
|
||||
if ( !seta_identval ( ident, result ) )
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ConErrResPuts ( STRING_EXPECTED_NUMBER_OR_VARIABLE );
|
||||
return FALSE;
|
||||
}
|
||||
*p_ = skip_ws ( p );
|
||||
return TRUE;
|
||||
LPCTSTR p = *p_;
|
||||
if ( *p == _T('(') )
|
||||
{
|
||||
INT rval;
|
||||
p = skip_ws ( p + 1 );
|
||||
if ( !seta_stmt ( &p, &rval ) )
|
||||
return FALSE;
|
||||
if ( *p++ != _T(')') )
|
||||
{
|
||||
ConErrResPuts ( STRING_EXPECTED_CLOSE_PAREN );
|
||||
return FALSE;
|
||||
}
|
||||
*result = rval;
|
||||
}
|
||||
else if ( isdigit(*p) )
|
||||
{
|
||||
*result = _tcstol ( p, (LPTSTR *)&p, 0 );
|
||||
}
|
||||
else if ( __iscsymf(*p) )
|
||||
{
|
||||
LPTSTR ident;
|
||||
INT identlen;
|
||||
PARSE_IDENT(ident,identlen,p);
|
||||
if ( !seta_identval ( ident, result ) )
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ConErrResPuts ( STRING_EXPECTED_NUMBER_OR_VARIABLE );
|
||||
return FALSE;
|
||||
}
|
||||
*p_ = skip_ws ( p );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_mulTerm ( LPCTSTR* p_, INT* result )
|
||||
seta_mulTerm(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
LPCTSTR p = *p_;
|
||||
TCHAR op = 0;
|
||||
INT rval;
|
||||
if ( _tcschr(_T("!~-"),*p) )
|
||||
{
|
||||
op = *p;
|
||||
p = skip_ws ( p + 1 );
|
||||
}
|
||||
if ( !seta_unaryTerm ( &p, &rval ) )
|
||||
return FALSE;
|
||||
switch ( op )
|
||||
{
|
||||
case '!':
|
||||
rval = !rval;
|
||||
break;
|
||||
case '~':
|
||||
rval = ~rval;
|
||||
break;
|
||||
case '-':
|
||||
rval = -rval;
|
||||
break;
|
||||
}
|
||||
LPCTSTR p = *p_;
|
||||
TCHAR op = 0;
|
||||
INT rval;
|
||||
if ( _tcschr(_T("!~-"),*p) )
|
||||
{
|
||||
op = *p;
|
||||
p = skip_ws ( p + 1 );
|
||||
}
|
||||
if ( !seta_unaryTerm ( &p, &rval ) )
|
||||
return FALSE;
|
||||
switch ( op )
|
||||
{
|
||||
case '!':
|
||||
rval = !rval;
|
||||
break;
|
||||
case '~':
|
||||
rval = ~rval;
|
||||
break;
|
||||
case '-':
|
||||
rval = -rval;
|
||||
break;
|
||||
}
|
||||
|
||||
*result = rval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
*result = rval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_ltorTerm ( LPCTSTR* p_, INT* result, LPCTSTR ops, BOOL (*subTerm)(LPCTSTR*,INT*) )
|
||||
seta_ltorTerm(LPCTSTR* p_, INT* result, LPCTSTR ops, BOOL (*subTerm)(LPCTSTR*,INT*))
|
||||
{
|
||||
LPCTSTR p = *p_;
|
||||
INT lval;
|
||||
if ( !subTerm ( &p, &lval ) )
|
||||
return FALSE;
|
||||
while ( *p && _tcschr(ops,*p) )
|
||||
{
|
||||
INT rval;
|
||||
TCHAR op = *p;
|
||||
LPCTSTR p = *p_;
|
||||
INT lval;
|
||||
if ( !subTerm ( &p, &lval ) )
|
||||
return FALSE;
|
||||
while ( *p && _tcschr(ops,*p) )
|
||||
{
|
||||
INT rval;
|
||||
TCHAR op = *p;
|
||||
|
||||
p = skip_ws ( p+1 );
|
||||
p = skip_ws ( p+1 );
|
||||
|
||||
if ( !subTerm ( &p, &rval ) )
|
||||
return FALSE;
|
||||
if ( !subTerm ( &p, &rval ) )
|
||||
return FALSE;
|
||||
|
||||
if ( !calc ( &lval, op, rval ) )
|
||||
return FALSE;
|
||||
}
|
||||
if ( !calc ( &lval, op, rval ) )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*result = lval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
*result = lval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_addTerm ( LPCTSTR* p_, INT* result )
|
||||
seta_addTerm(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
return seta_ltorTerm ( p_, result, _T("*/%"), seta_mulTerm );
|
||||
return seta_ltorTerm ( p_, result, _T("*/%"), seta_mulTerm );
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_logShiftTerm ( LPCTSTR* p_, INT* result )
|
||||
seta_logShiftTerm(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
return seta_ltorTerm ( p_, result, _T("+-"), seta_addTerm );
|
||||
return seta_ltorTerm ( p_, result, _T("+-"), seta_addTerm );
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_bitAndTerm ( LPCTSTR* p_, INT* result )
|
||||
seta_bitAndTerm(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
LPCTSTR p = *p_;
|
||||
INT lval;
|
||||
if ( !seta_logShiftTerm ( &p, &lval ) )
|
||||
return FALSE;
|
||||
while ( *p && _tcschr(_T("<>"),*p) && p[0] == p[1] )
|
||||
{
|
||||
INT rval;
|
||||
TCHAR op = *p;
|
||||
LPCTSTR p = *p_;
|
||||
INT lval;
|
||||
if ( !seta_logShiftTerm ( &p, &lval ) )
|
||||
return FALSE;
|
||||
while ( *p && _tcschr(_T("<>"),*p) && p[0] == p[1] )
|
||||
{
|
||||
INT rval;
|
||||
TCHAR op = *p;
|
||||
|
||||
p = skip_ws ( p+2 );
|
||||
p = skip_ws ( p+2 );
|
||||
|
||||
if ( !seta_logShiftTerm ( &p, &rval ) )
|
||||
return FALSE;
|
||||
if ( !seta_logShiftTerm ( &p, &rval ) )
|
||||
return FALSE;
|
||||
|
||||
switch ( op )
|
||||
{
|
||||
case '<':
|
||||
lval <<= rval;
|
||||
break;
|
||||
case '>':
|
||||
lval >>= rval;
|
||||
break;
|
||||
default:
|
||||
ConErrResPuts ( STRING_INVALID_OPERAND );
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
switch ( op )
|
||||
{
|
||||
case '<':
|
||||
lval <<= rval;
|
||||
break;
|
||||
case '>':
|
||||
lval >>= rval;
|
||||
break;
|
||||
default:
|
||||
ConErrResPuts ( STRING_INVALID_OPERAND );
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
*result = lval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
*result = lval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_bitExclOrTerm ( LPCTSTR* p_, INT* result )
|
||||
seta_bitExclOrTerm(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
return seta_ltorTerm ( p_, result, _T("&"), seta_bitAndTerm );
|
||||
return seta_ltorTerm ( p_, result, _T("&"), seta_bitAndTerm );
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_bitOrTerm ( LPCTSTR* p_, INT* result )
|
||||
seta_bitOrTerm(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
return seta_ltorTerm ( p_, result, _T("^"), seta_bitExclOrTerm );
|
||||
return seta_ltorTerm ( p_, result, _T("^"), seta_bitExclOrTerm );
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_expr ( LPCTSTR* p_, INT* result )
|
||||
seta_expr(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
return seta_ltorTerm ( p_, result, _T("|"), seta_bitOrTerm );
|
||||
return seta_ltorTerm ( p_, result, _T("|"), seta_bitOrTerm );
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_assignment ( LPCTSTR* p_, INT* result )
|
||||
seta_assignment(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
LPCTSTR p = *p_;
|
||||
LPTSTR ident;
|
||||
TCHAR op = 0;
|
||||
INT identlen, exprval;
|
||||
LPCTSTR p = *p_;
|
||||
LPTSTR ident;
|
||||
TCHAR op = 0;
|
||||
INT identlen, exprval;
|
||||
|
||||
PARSE_IDENT(ident,identlen,p);
|
||||
if ( identlen )
|
||||
{
|
||||
p = skip_ws(p);
|
||||
if ( *p == _T('=') )
|
||||
op = *p, p = skip_ws(p+1);
|
||||
else if ( _tcschr ( _T("*/%+-&^|"), *p ) && p[1] == _T('=') )
|
||||
op = *p, p = skip_ws(p+2);
|
||||
else if ( _tcschr ( _T("<>"), *p ) && *p == p[1] && p[2] == _T('=') )
|
||||
op = *p, p = skip_ws(p+3);
|
||||
}
|
||||
PARSE_IDENT(ident,identlen,p);
|
||||
if ( identlen )
|
||||
{
|
||||
p = skip_ws(p);
|
||||
if ( *p == _T('=') )
|
||||
op = *p, p = skip_ws(p+1);
|
||||
else if ( _tcschr ( _T("*/%+-&^|"), *p ) && p[1] == _T('=') )
|
||||
op = *p, p = skip_ws(p+2);
|
||||
else if ( _tcschr ( _T("<>"), *p ) && *p == p[1] && p[2] == _T('=') )
|
||||
op = *p, p = skip_ws(p+3);
|
||||
}
|
||||
|
||||
/* allow to chain multiple assignments, such as: a=b=1 */
|
||||
if ( ident && op )
|
||||
{
|
||||
INT identval;
|
||||
LPTSTR buf;
|
||||
/* allow to chain multiple assignments, such as: a=b=1 */
|
||||
if ( ident && op )
|
||||
{
|
||||
INT identval;
|
||||
LPTSTR buf;
|
||||
|
||||
if ( !seta_assignment ( &p, &exprval ) )
|
||||
return FALSE;
|
||||
if ( !seta_assignment ( &p, &exprval ) )
|
||||
return FALSE;
|
||||
|
||||
if ( !seta_identval ( ident, &identval ) )
|
||||
identval = 0;
|
||||
switch ( op )
|
||||
{
|
||||
case '=':
|
||||
identval = exprval;
|
||||
break;
|
||||
case '<':
|
||||
identval <<= exprval;
|
||||
break;
|
||||
case '>':
|
||||
identval >>= exprval;
|
||||
break;
|
||||
default:
|
||||
if ( !calc ( &identval, op, exprval ) )
|
||||
return FALSE;
|
||||
}
|
||||
buf = (LPTSTR)alloca ( 32 * sizeof(TCHAR) );
|
||||
_sntprintf ( buf, 32, _T("%i"), identval );
|
||||
SetEnvironmentVariable ( ident, buf ); // TODO FIXME - check return value
|
||||
exprval = identval;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* restore p in case we found an ident but not an op */
|
||||
p = *p_;
|
||||
if ( !seta_expr ( &p, &exprval ) )
|
||||
return FALSE;
|
||||
}
|
||||
if ( !seta_identval ( ident, &identval ) )
|
||||
identval = 0;
|
||||
switch ( op )
|
||||
{
|
||||
case '=':
|
||||
identval = exprval;
|
||||
break;
|
||||
case '<':
|
||||
identval <<= exprval;
|
||||
break;
|
||||
case '>':
|
||||
identval >>= exprval;
|
||||
break;
|
||||
default:
|
||||
if ( !calc ( &identval, op, exprval ) )
|
||||
return FALSE;
|
||||
}
|
||||
buf = (LPTSTR)alloca ( 32 * sizeof(TCHAR) );
|
||||
_sntprintf ( buf, 32, _T("%i"), identval );
|
||||
SetEnvironmentVariable ( ident, buf ); // TODO FIXME - check return value
|
||||
exprval = identval;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* restore p in case we found an ident but not an op */
|
||||
p = *p_;
|
||||
if ( !seta_expr ( &p, &exprval ) )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*result = exprval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
*result = exprval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_stmt ( LPCTSTR* p_, INT* result )
|
||||
seta_stmt(LPCTSTR* p_, INT* result)
|
||||
{
|
||||
LPCTSTR p = *p_;
|
||||
INT rval;
|
||||
LPCTSTR p = *p_;
|
||||
INT rval;
|
||||
|
||||
if ( !seta_assignment ( &p, &rval ) )
|
||||
return FALSE;
|
||||
while ( *p == _T(',') )
|
||||
{
|
||||
p = skip_ws ( p+1 );
|
||||
if ( !seta_assignment ( &p, &rval ) )
|
||||
return FALSE;
|
||||
while ( *p == _T(',') )
|
||||
{
|
||||
p = skip_ws ( p+1 );
|
||||
|
||||
if ( !seta_assignment ( &p, &rval ) )
|
||||
return FALSE;
|
||||
}
|
||||
if ( !seta_assignment ( &p, &rval ) )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*result = rval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
*result = rval;
|
||||
*p_ = p;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
seta_eval ( LPCTSTR p )
|
||||
seta_eval(LPCTSTR p)
|
||||
{
|
||||
INT rval;
|
||||
if ( !*p )
|
||||
{
|
||||
ConErrResPuts ( STRING_SYNTAX_COMMAND_INCORRECT );
|
||||
return FALSE;
|
||||
}
|
||||
if ( !seta_stmt ( &p, &rval ) )
|
||||
return FALSE;
|
||||
if ( !bc )
|
||||
ConOutPrintf ( _T("%i"), rval );
|
||||
return TRUE;
|
||||
INT rval;
|
||||
if ( !*p )
|
||||
{
|
||||
ConErrResPuts ( STRING_SYNTAX_COMMAND_INCORRECT );
|
||||
return FALSE;
|
||||
}
|
||||
if ( !seta_stmt ( &p, &rval ) )
|
||||
return FALSE;
|
||||
if ( !bc )
|
||||
ConOutPrintf ( _T("%i"), rval );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,121 +9,124 @@
|
|||
|
||||
#include "precomp.h"
|
||||
|
||||
typedef struct _SETLOCAL {
|
||||
struct _SETLOCAL *Prev;
|
||||
BOOL DelayedExpansion;
|
||||
LPTSTR Environment;
|
||||
typedef struct _SETLOCAL
|
||||
{
|
||||
struct _SETLOCAL *Prev;
|
||||
BOOL DelayedExpansion;
|
||||
LPTSTR Environment;
|
||||
} SETLOCAL;
|
||||
|
||||
/* Create a copy of the current environment */
|
||||
LPTSTR
|
||||
DuplicateEnvironment(VOID)
|
||||
{
|
||||
LPTSTR Environ = GetEnvironmentStrings();
|
||||
LPTSTR End, EnvironCopy;
|
||||
if (!Environ)
|
||||
return NULL;
|
||||
for (End = Environ; *End; End += _tcslen(End) + 1)
|
||||
;
|
||||
EnvironCopy = cmd_alloc((End + 1 - Environ) * sizeof(TCHAR));
|
||||
if (EnvironCopy)
|
||||
memcpy(EnvironCopy, Environ, (End + 1 - Environ) * sizeof(TCHAR));
|
||||
FreeEnvironmentStrings(Environ);
|
||||
return EnvironCopy;
|
||||
LPTSTR Environ = GetEnvironmentStrings();
|
||||
LPTSTR End, EnvironCopy;
|
||||
|
||||
if (!Environ) return NULL;
|
||||
|
||||
for (End = Environ; *End; End += _tcslen(End) + 1) ;
|
||||
EnvironCopy = cmd_alloc((End + 1 - Environ) * sizeof(TCHAR));
|
||||
|
||||
if (EnvironCopy)
|
||||
memcpy(EnvironCopy, Environ, (End + 1 - Environ) * sizeof(TCHAR));
|
||||
|
||||
FreeEnvironmentStrings(Environ);
|
||||
return EnvironCopy;
|
||||
}
|
||||
|
||||
INT cmd_setlocal(LPTSTR param)
|
||||
{
|
||||
SETLOCAL *Saved;
|
||||
LPTSTR *arg;
|
||||
INT argc, i;
|
||||
SETLOCAL *Saved;
|
||||
LPTSTR *arg;
|
||||
INT argc, i;
|
||||
|
||||
/* SETLOCAL only works inside a batch file */
|
||||
if (!bc)
|
||||
return 0;
|
||||
/* SETLOCAL only works inside a batch file */
|
||||
if (!bc)
|
||||
return 0;
|
||||
|
||||
Saved = cmd_alloc(sizeof(SETLOCAL));
|
||||
if (!Saved)
|
||||
{
|
||||
error_out_of_memory();
|
||||
return 1;
|
||||
}
|
||||
Saved->Prev = bc->setlocal;
|
||||
Saved->DelayedExpansion = bDelayedExpansion;
|
||||
Saved->Environment = DuplicateEnvironment();
|
||||
if (!Saved->Environment)
|
||||
{
|
||||
error_out_of_memory();
|
||||
cmd_free(Saved);
|
||||
return 1;
|
||||
}
|
||||
bc->setlocal = Saved;
|
||||
Saved = cmd_alloc(sizeof(SETLOCAL));
|
||||
if (!Saved)
|
||||
{
|
||||
error_out_of_memory();
|
||||
return 1;
|
||||
}
|
||||
Saved->Prev = bc->setlocal;
|
||||
Saved->DelayedExpansion = bDelayedExpansion;
|
||||
Saved->Environment = DuplicateEnvironment();
|
||||
if (!Saved->Environment)
|
||||
{
|
||||
error_out_of_memory();
|
||||
cmd_free(Saved);
|
||||
return 1;
|
||||
}
|
||||
bc->setlocal = Saved;
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
arg = splitspace(param, &argc);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (!_tcsicmp(arg[i], _T("enableextensions")))
|
||||
/* not implemented, ignore */;
|
||||
else if (!_tcsicmp(arg[i], _T("disableextensions")))
|
||||
/* not implemented, ignore */;
|
||||
else if (!_tcsicmp(arg[i], _T("enabledelayedexpansion")))
|
||||
bDelayedExpansion = TRUE;
|
||||
else if (!_tcsicmp(arg[i], _T("disabledelayedexpansion")))
|
||||
bDelayedExpansion = FALSE;
|
||||
else
|
||||
{
|
||||
error_invalid_parameter_format(arg[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
freep(arg);
|
||||
arg = splitspace(param, &argc);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (!_tcsicmp(arg[i], _T("enableextensions")))
|
||||
/* not implemented, ignore */;
|
||||
else if (!_tcsicmp(arg[i], _T("disableextensions")))
|
||||
/* not implemented, ignore */;
|
||||
else if (!_tcsicmp(arg[i], _T("enabledelayedexpansion")))
|
||||
bDelayedExpansion = TRUE;
|
||||
else if (!_tcsicmp(arg[i], _T("disabledelayedexpansion")))
|
||||
bDelayedExpansion = FALSE;
|
||||
else
|
||||
{
|
||||
error_invalid_parameter_format(arg[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
freep(arg);
|
||||
|
||||
return nErrorLevel;
|
||||
return nErrorLevel;
|
||||
}
|
||||
|
||||
/* endlocal doesn't take any params */
|
||||
INT cmd_endlocal(LPTSTR param)
|
||||
{
|
||||
LPTSTR Environ, Name, Value;
|
||||
SETLOCAL *Saved;
|
||||
LPTSTR Environ, Name, Value;
|
||||
SETLOCAL *Saved;
|
||||
|
||||
/* Pop a SETLOCAL struct off of this batch file's stack */
|
||||
if (!bc || !(Saved = bc->setlocal))
|
||||
return 0;
|
||||
bc->setlocal = Saved->Prev;
|
||||
/* Pop a SETLOCAL struct off of this batch file's stack */
|
||||
if (!bc || !(Saved = bc->setlocal))
|
||||
return 0;
|
||||
bc->setlocal = Saved->Prev;
|
||||
|
||||
bDelayedExpansion = Saved->DelayedExpansion;
|
||||
bDelayedExpansion = Saved->DelayedExpansion;
|
||||
|
||||
/* First, clear out the environment. Since making any changes to the
|
||||
* environment invalidates pointers obtained from GetEnvironmentStrings(),
|
||||
* we must make a copy of it and get the variable names from that */
|
||||
Environ = DuplicateEnvironment();
|
||||
if (Environ)
|
||||
{
|
||||
for (Name = Environ; *Name; Name += _tcslen(Name) + 1)
|
||||
{
|
||||
if (!(Value = _tcschr(Name + 1, _T('='))))
|
||||
continue;
|
||||
*Value++ = _T('\0');
|
||||
SetEnvironmentVariable(Name, NULL);
|
||||
Name = Value;
|
||||
}
|
||||
cmd_free(Environ);
|
||||
}
|
||||
/* First, clear out the environment. Since making any changes to the
|
||||
* environment invalidates pointers obtained from GetEnvironmentStrings(),
|
||||
* we must make a copy of it and get the variable names from that */
|
||||
Environ = DuplicateEnvironment();
|
||||
if (Environ)
|
||||
{
|
||||
for (Name = Environ; *Name; Name += _tcslen(Name) + 1)
|
||||
{
|
||||
if (!(Value = _tcschr(Name + 1, _T('='))))
|
||||
continue;
|
||||
*Value++ = _T('\0');
|
||||
SetEnvironmentVariable(Name, NULL);
|
||||
Name = Value;
|
||||
}
|
||||
cmd_free(Environ);
|
||||
}
|
||||
|
||||
/* Now, restore variables from the copy saved by cmd_setlocal */
|
||||
for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1)
|
||||
{
|
||||
if (!(Value = _tcschr(Name + 1, _T('='))))
|
||||
continue;
|
||||
*Value++ = _T('\0');
|
||||
SetEnvironmentVariable(Name, Value);
|
||||
Name = Value;
|
||||
}
|
||||
/* Now, restore variables from the copy saved by cmd_setlocal */
|
||||
for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1)
|
||||
{
|
||||
if (!(Value = _tcschr(Name + 1, _T('='))))
|
||||
continue;
|
||||
*Value++ = _T('\0');
|
||||
SetEnvironmentVariable(Name, Value);
|
||||
Name = Value;
|
||||
}
|
||||
|
||||
cmd_free(Saved->Environment);
|
||||
cmd_free(Saved);
|
||||
return 0;
|
||||
cmd_free(Saved->Environment);
|
||||
cmd_free(Saved);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
* 20-Jan-1999 (Eric Kohl)
|
||||
* Unicode and redirection safe!
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
@ -37,48 +37,48 @@
|
|||
|
||||
INT cmd_shift (LPTSTR param)
|
||||
{
|
||||
INT i = 0;
|
||||
TRACE ("cmd_shift: (\'%s\')\n", debugstr_aw(param));
|
||||
INT i = 0;
|
||||
TRACE ("cmd_shift: (\'%s\')\n", debugstr_aw(param));
|
||||
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_SHIFT_HELP);
|
||||
return 0;
|
||||
}
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_SHIFT_HELP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
if (bc == NULL)
|
||||
{
|
||||
/* not in batch - error!! */
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
if (bc == NULL)
|
||||
{
|
||||
/* not in batch - error!! */
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!_tcsicmp (param, _T("down")))
|
||||
{
|
||||
if (bc->shiftlevel[0])
|
||||
for (; i <= 9; i++)
|
||||
bc->shiftlevel[i]--;
|
||||
}
|
||||
else /* shift up */
|
||||
{
|
||||
if (*param == _T('/'))
|
||||
{
|
||||
if (param[1] < '0' || param[1] > '9')
|
||||
{
|
||||
error_invalid_switch(param[1]);
|
||||
return 1;
|
||||
}
|
||||
i = param[1] - '0';
|
||||
}
|
||||
if (!_tcsicmp (param, _T("down")))
|
||||
{
|
||||
if (bc->shiftlevel[0])
|
||||
for (; i <= 9; i++)
|
||||
bc->shiftlevel[i]--;
|
||||
}
|
||||
else /* shift up */
|
||||
{
|
||||
if (*param == _T('/'))
|
||||
{
|
||||
if (param[1] < '0' || param[1] > '9')
|
||||
{
|
||||
error_invalid_switch(param[1]);
|
||||
return 1;
|
||||
}
|
||||
i = param[1] - '0';
|
||||
}
|
||||
|
||||
for (; i < 9; i++)
|
||||
bc->shiftlevel[i] = bc->shiftlevel[i + 1];
|
||||
bc->shiftlevel[i]++;
|
||||
}
|
||||
for (; i < 9; i++)
|
||||
bc->shiftlevel[i] = bc->shiftlevel[i + 1];
|
||||
bc->shiftlevel[i]++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
* 24-Jul-1999 (Eric Kohl)
|
||||
* Started.
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
@ -19,303 +19,302 @@
|
|||
* in place. (It's moved back one character, to make room for the nul) */
|
||||
static TCHAR *GetParameter(TCHAR **pPointer)
|
||||
{
|
||||
BOOL bInQuote = FALSE;
|
||||
TCHAR *start = *pPointer;
|
||||
TCHAR *p;
|
||||
for (p = start; *p; p++)
|
||||
{
|
||||
if (!bInQuote && (*p == _T('/') || _istspace(*p)))
|
||||
break;
|
||||
bInQuote ^= (*p == _T('"'));
|
||||
p[-1] = *p;
|
||||
}
|
||||
p[-1] = _T('\0');
|
||||
*pPointer = p;
|
||||
return start - 1;
|
||||
BOOL bInQuote = FALSE;
|
||||
TCHAR *start = *pPointer;
|
||||
TCHAR *p;
|
||||
for (p = start; *p; p++)
|
||||
{
|
||||
if (!bInQuote && (*p == _T('/') || _istspace(*p)))
|
||||
break;
|
||||
bInQuote ^= (*p == _T('"'));
|
||||
p[-1] = *p;
|
||||
}
|
||||
p[-1] = _T('\0');
|
||||
*pPointer = p;
|
||||
return start - 1;
|
||||
}
|
||||
|
||||
INT cmd_start (LPTSTR Rest)
|
||||
{
|
||||
TCHAR szFullName[CMDLINE_LENGTH];
|
||||
TCHAR szUnquotedName[CMDLINE_LENGTH];
|
||||
TCHAR *param = NULL;
|
||||
TCHAR *dot;
|
||||
INT size;
|
||||
LPTSTR comspec;
|
||||
BOOL bWait = FALSE;
|
||||
BOOL bBat = FALSE;
|
||||
BOOL bCreate = FALSE;
|
||||
TCHAR szFullCmdLine [CMDLINE_LENGTH];
|
||||
PROCESS_INFORMATION prci;
|
||||
STARTUPINFO stui;
|
||||
TCHAR szFullName[CMDLINE_LENGTH];
|
||||
TCHAR szUnquotedName[CMDLINE_LENGTH];
|
||||
TCHAR *param = NULL;
|
||||
TCHAR *dot;
|
||||
INT size;
|
||||
LPTSTR comspec;
|
||||
BOOL bWait = FALSE;
|
||||
BOOL bBat = FALSE;
|
||||
BOOL bCreate = FALSE;
|
||||
TCHAR szFullCmdLine [CMDLINE_LENGTH];
|
||||
PROCESS_INFORMATION prci;
|
||||
STARTUPINFO stui;
|
||||
#ifdef UNICODE
|
||||
DWORD dwCreationFlags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT;
|
||||
DWORD dwCreationFlags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT;
|
||||
#else
|
||||
DWORD dwCreationFlags = CREATE_NEW_CONSOLE;
|
||||
DWORD dwCreationFlags = CREATE_NEW_CONSOLE;
|
||||
#endif
|
||||
DWORD dwAffinityMask = 0;
|
||||
LPTSTR lpTitle = NULL;
|
||||
LPTSTR lpDirectory = NULL;
|
||||
LPTSTR lpEnvironment = NULL;
|
||||
WORD wShowWindow = SW_SHOWNORMAL;
|
||||
DWORD dwAffinityMask = 0;
|
||||
LPTSTR lpTitle = NULL;
|
||||
LPTSTR lpDirectory = NULL;
|
||||
LPTSTR lpEnvironment = NULL;
|
||||
WORD wShowWindow = SW_SHOWNORMAL;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (_istspace(*Rest))
|
||||
{
|
||||
Rest++;
|
||||
}
|
||||
else if (*Rest == _T('"') && !lpTitle)
|
||||
{
|
||||
lpTitle = GetParameter(&Rest);
|
||||
StripQuotes(lpTitle);
|
||||
}
|
||||
else if (*Rest == L'/')
|
||||
{
|
||||
LPTSTR option;
|
||||
Rest++;
|
||||
option = GetParameter(&Rest);
|
||||
if (*option == _T('?'))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_START_HELP1);
|
||||
return 0;
|
||||
}
|
||||
else if (_totupper(*option) == _T('D'))
|
||||
{
|
||||
lpDirectory = option + 1;
|
||||
if (!*lpDirectory)
|
||||
{
|
||||
while (_istspace(*Rest))
|
||||
Rest++;
|
||||
lpDirectory = GetParameter(&Rest);
|
||||
}
|
||||
StripQuotes(lpDirectory);
|
||||
}
|
||||
else if (_totupper(*option) == _T('I'))
|
||||
{
|
||||
/* rest of the option is apparently ignored */
|
||||
lpEnvironment = lpOriginalEnvironment;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("MIN")))
|
||||
{
|
||||
wShowWindow = SW_MINIMIZE;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("MAX")))
|
||||
{
|
||||
wShowWindow = SW_MAXIMIZE;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("AFFINITY")))
|
||||
{
|
||||
TCHAR *end;
|
||||
while (_istspace(*Rest))
|
||||
Rest++;
|
||||
option = GetParameter(&Rest);
|
||||
/* Affinity mask is given in hexadecimal */
|
||||
dwAffinityMask = _tcstoul(option, &end, 16);
|
||||
if (*end != _T('\0') || dwAffinityMask == 0 ||
|
||||
dwAffinityMask == (DWORD)-1)
|
||||
{
|
||||
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, option);
|
||||
return 1;
|
||||
}
|
||||
dwCreationFlags |= CREATE_SUSPENDED;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("B")))
|
||||
{
|
||||
dwCreationFlags &= ~CREATE_NEW_CONSOLE;
|
||||
dwCreationFlags |= CREATE_NEW_PROCESS_GROUP;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("LOW")))
|
||||
{
|
||||
dwCreationFlags |= IDLE_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("NORMAL")))
|
||||
{
|
||||
dwCreationFlags |= NORMAL_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("HIGH")))
|
||||
{
|
||||
dwCreationFlags |= HIGH_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("REALTIME")))
|
||||
{
|
||||
dwCreationFlags |= REALTIME_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("ABOVENORMAL")))
|
||||
{
|
||||
dwCreationFlags |= ABOVE_NORMAL_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("BELOWNORMAL")))
|
||||
{
|
||||
dwCreationFlags |= BELOW_NORMAL_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("SEPARATE")))
|
||||
{
|
||||
dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("SHARED")))
|
||||
{
|
||||
dwCreationFlags |= CREATE_SHARED_WOW_VDM;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("W")) ||
|
||||
!_tcsicmp(option, _T("WAIT")))
|
||||
{
|
||||
bWait = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ConErrResPrintf(STRING_TYPE_ERROR1, option);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* It's not an option - must be the beginning of
|
||||
* the actual command. Leave the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
if (_istspace(*Rest))
|
||||
{
|
||||
Rest++;
|
||||
}
|
||||
else if (*Rest == _T('"') && !lpTitle)
|
||||
{
|
||||
lpTitle = GetParameter(&Rest);
|
||||
StripQuotes(lpTitle);
|
||||
}
|
||||
else if (*Rest == L'/')
|
||||
{
|
||||
LPTSTR option;
|
||||
Rest++;
|
||||
option = GetParameter(&Rest);
|
||||
if (*option == _T('?'))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_START_HELP1);
|
||||
return 0;
|
||||
}
|
||||
else if (_totupper(*option) == _T('D'))
|
||||
{
|
||||
lpDirectory = option + 1;
|
||||
if (!*lpDirectory)
|
||||
{
|
||||
while (_istspace(*Rest))
|
||||
Rest++;
|
||||
lpDirectory = GetParameter(&Rest);
|
||||
}
|
||||
StripQuotes(lpDirectory);
|
||||
}
|
||||
else if (_totupper(*option) == _T('I'))
|
||||
{
|
||||
/* rest of the option is apparently ignored */
|
||||
lpEnvironment = lpOriginalEnvironment;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("MIN")))
|
||||
{
|
||||
wShowWindow = SW_MINIMIZE;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("MAX")))
|
||||
{
|
||||
wShowWindow = SW_MAXIMIZE;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("AFFINITY")))
|
||||
{
|
||||
TCHAR *end;
|
||||
while (_istspace(*Rest))
|
||||
Rest++;
|
||||
option = GetParameter(&Rest);
|
||||
/* Affinity mask is given in hexadecimal */
|
||||
dwAffinityMask = _tcstoul(option, &end, 16);
|
||||
if (*end != _T('\0') || dwAffinityMask == 0 ||
|
||||
dwAffinityMask == (DWORD)-1)
|
||||
{
|
||||
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, option);
|
||||
return 1;
|
||||
}
|
||||
dwCreationFlags |= CREATE_SUSPENDED;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("B")))
|
||||
{
|
||||
dwCreationFlags &= ~CREATE_NEW_CONSOLE;
|
||||
dwCreationFlags |= CREATE_NEW_PROCESS_GROUP;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("LOW")))
|
||||
{
|
||||
dwCreationFlags |= IDLE_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("NORMAL")))
|
||||
{
|
||||
dwCreationFlags |= NORMAL_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("HIGH")))
|
||||
{
|
||||
dwCreationFlags |= HIGH_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("REALTIME")))
|
||||
{
|
||||
dwCreationFlags |= REALTIME_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("ABOVENORMAL")))
|
||||
{
|
||||
dwCreationFlags |= ABOVE_NORMAL_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("BELOWNORMAL")))
|
||||
{
|
||||
dwCreationFlags |= BELOW_NORMAL_PRIORITY_CLASS;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("SEPARATE")))
|
||||
{
|
||||
dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("SHARED")))
|
||||
{
|
||||
dwCreationFlags |= CREATE_SHARED_WOW_VDM;
|
||||
}
|
||||
else if (!_tcsicmp(option, _T("W")) ||
|
||||
!_tcsicmp(option, _T("WAIT")))
|
||||
{
|
||||
bWait = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ConErrResPrintf(STRING_TYPE_ERROR1, option);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* It's not an option - must be the beginning of
|
||||
* the actual command. Leave the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get comspec */
|
||||
comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
|
||||
if (comspec == NULL)
|
||||
{
|
||||
error_out_of_memory();
|
||||
return 1;
|
||||
}
|
||||
SetLastError(0);
|
||||
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, MAX_PATH);
|
||||
if(GetLastError() == ERROR_ENVVAR_NOT_FOUND)
|
||||
{
|
||||
_tcscpy(comspec, _T("cmd"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size > MAX_PATH)
|
||||
{
|
||||
LPTSTR Oldcomspec = comspec;
|
||||
comspec = cmd_realloc(comspec,size * sizeof(TCHAR) );
|
||||
if (comspec==NULL)
|
||||
{
|
||||
cmd_free(Oldcomspec);
|
||||
return 1;
|
||||
}
|
||||
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, size);
|
||||
}
|
||||
}
|
||||
/* get comspec */
|
||||
comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
|
||||
if (comspec == NULL)
|
||||
{
|
||||
error_out_of_memory();
|
||||
return 1;
|
||||
}
|
||||
SetLastError(0);
|
||||
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, MAX_PATH);
|
||||
if(GetLastError() == ERROR_ENVVAR_NOT_FOUND)
|
||||
{
|
||||
_tcscpy(comspec, _T("cmd"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size > MAX_PATH)
|
||||
{
|
||||
LPTSTR Oldcomspec = comspec;
|
||||
comspec = cmd_realloc(comspec,size * sizeof(TCHAR) );
|
||||
if (comspec==NULL)
|
||||
{
|
||||
cmd_free(Oldcomspec);
|
||||
return 1;
|
||||
}
|
||||
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, size);
|
||||
}
|
||||
}
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
if (!*Rest)
|
||||
{
|
||||
Rest = _T("cmd.exe");
|
||||
}
|
||||
else
|
||||
/* Parsing the command that gets called by start, and it's parameters */
|
||||
{
|
||||
BOOL bInside = FALSE;
|
||||
INT i;
|
||||
/* find the end of the command and put the arguments in param */
|
||||
for (i = 0; Rest[i]; i++)
|
||||
{
|
||||
if (Rest[i] == _T('\"'))
|
||||
bInside = !bInside;
|
||||
if (_istspace(Rest[i]) && !bInside)
|
||||
{
|
||||
param = &Rest[i+1];
|
||||
Rest[i] = _T('\0');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!*Rest)
|
||||
{
|
||||
Rest = _T("cmd.exe");
|
||||
}
|
||||
else
|
||||
/* Parsing the command that gets called by start, and it's parameters */
|
||||
{
|
||||
BOOL bInside = FALSE;
|
||||
INT i;
|
||||
/* find the end of the command and put the arguments in param */
|
||||
for (i = 0; Rest[i]; i++)
|
||||
{
|
||||
if (Rest[i] == _T('\"'))
|
||||
bInside = !bInside;
|
||||
if (_istspace(Rest[i]) && !bInside)
|
||||
{
|
||||
param = &Rest[i+1];
|
||||
Rest[i] = _T('\0');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_tcscpy(szUnquotedName, Rest);
|
||||
StripQuotes(szUnquotedName);
|
||||
_tcscpy(szUnquotedName, Rest);
|
||||
StripQuotes(szUnquotedName);
|
||||
|
||||
/* get the PATH environment variable and parse it */
|
||||
/* search the PATH environment variable for the binary */
|
||||
if (SearchForExecutable(szUnquotedName, szFullName))
|
||||
{
|
||||
/* check if this is a .BAT or .CMD file */
|
||||
dot = _tcsrchr(szFullName, _T('.'));
|
||||
if (dot && (!_tcsicmp(dot, _T(".bat")) || !_tcsicmp(dot, _T(".cmd"))))
|
||||
{
|
||||
bBat = TRUE;
|
||||
_stprintf(szFullCmdLine, _T("\"%s\" /K %s"), comspec, Rest);
|
||||
TRACE ("[BATCH: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE ("[EXEC: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
|
||||
_tcscpy(szFullCmdLine, szFullName);
|
||||
}
|
||||
/* get the PATH environment variable and parse it */
|
||||
/* search the PATH environment variable for the binary */
|
||||
if (SearchForExecutable(szUnquotedName, szFullName))
|
||||
{
|
||||
/* check if this is a .BAT or .CMD file */
|
||||
dot = _tcsrchr(szFullName, _T('.'));
|
||||
if (dot && (!_tcsicmp(dot, _T(".bat")) || !_tcsicmp(dot, _T(".cmd"))))
|
||||
{
|
||||
bBat = TRUE;
|
||||
_stprintf(szFullCmdLine, _T("\"%s\" /K %s"), comspec, Rest);
|
||||
TRACE ("[BATCH: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE ("[EXEC: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
|
||||
_tcscpy(szFullCmdLine, szFullName);
|
||||
}
|
||||
|
||||
/* build command line for CreateProcess() */
|
||||
if (param != NULL)
|
||||
{
|
||||
_tcsncat(szFullCmdLine, _T(" "), CMDLINE_LENGTH - _tcslen(szFullCmdLine));
|
||||
_tcsncat(szFullCmdLine, param, CMDLINE_LENGTH - _tcslen(szFullCmdLine));
|
||||
}
|
||||
/* build command line for CreateProcess() */
|
||||
if (param != NULL)
|
||||
{
|
||||
_tcsncat(szFullCmdLine, _T(" "), CMDLINE_LENGTH - _tcslen(szFullCmdLine));
|
||||
_tcsncat(szFullCmdLine, param, CMDLINE_LENGTH - _tcslen(szFullCmdLine));
|
||||
}
|
||||
|
||||
/* fill startup info */
|
||||
memset (&stui, 0, sizeof (STARTUPINFO));
|
||||
stui.cb = sizeof (STARTUPINFO);
|
||||
stui.dwFlags = STARTF_USESHOWWINDOW;
|
||||
stui.lpTitle = lpTitle;
|
||||
stui.wShowWindow = wShowWindow;
|
||||
/* fill startup info */
|
||||
memset (&stui, 0, sizeof (STARTUPINFO));
|
||||
stui.cb = sizeof (STARTUPINFO);
|
||||
stui.dwFlags = STARTF_USESHOWWINDOW;
|
||||
stui.lpTitle = lpTitle;
|
||||
stui.wShowWindow = wShowWindow;
|
||||
|
||||
bCreate = CreateProcess(bBat ? comspec : szFullName,
|
||||
szFullCmdLine, NULL, NULL, TRUE, dwCreationFlags,
|
||||
lpEnvironment, lpDirectory, &stui, &prci);
|
||||
if (bCreate)
|
||||
{
|
||||
if (dwAffinityMask)
|
||||
{
|
||||
SetProcessAffinityMask(prci.hProcess, dwAffinityMask);
|
||||
ResumeThread(prci.hThread);
|
||||
}
|
||||
CloseHandle(prci.hThread);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The file name did not seem to be valid, but maybe it's actually a
|
||||
* directory or URL, so we still want to pass it to ShellExecute. */
|
||||
_tcscpy(szFullName, szUnquotedName);
|
||||
}
|
||||
bCreate = CreateProcess(bBat ? comspec : szFullName,
|
||||
szFullCmdLine, NULL, NULL, TRUE, dwCreationFlags,
|
||||
lpEnvironment, lpDirectory, &stui, &prci);
|
||||
if (bCreate)
|
||||
{
|
||||
if (dwAffinityMask)
|
||||
{
|
||||
SetProcessAffinityMask(prci.hProcess, dwAffinityMask);
|
||||
ResumeThread(prci.hThread);
|
||||
}
|
||||
CloseHandle(prci.hThread);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The file name did not seem to be valid, but maybe it's actually a
|
||||
* directory or URL, so we still want to pass it to ShellExecute. */
|
||||
_tcscpy(szFullName, szUnquotedName);
|
||||
}
|
||||
|
||||
if (!bCreate)
|
||||
{
|
||||
/* CreateProcess didn't work; try ShellExecute */
|
||||
DWORD flags = SEE_MASK_NOCLOSEPROCESS;
|
||||
if (!(dwCreationFlags & CREATE_NEW_CONSOLE))
|
||||
flags |= SEE_MASK_NO_CONSOLE;
|
||||
prci.hProcess = RunFile(flags, szFullName, param, lpDirectory, wShowWindow);
|
||||
}
|
||||
if (!bCreate)
|
||||
{
|
||||
/* CreateProcess didn't work; try ShellExecute */
|
||||
DWORD flags = SEE_MASK_NOCLOSEPROCESS;
|
||||
if (!(dwCreationFlags & CREATE_NEW_CONSOLE))
|
||||
flags |= SEE_MASK_NO_CONSOLE;
|
||||
prci.hProcess = RunFile(flags, szFullName, param, lpDirectory, wShowWindow);
|
||||
}
|
||||
|
||||
if (prci.hProcess != NULL)
|
||||
{
|
||||
if (bWait)
|
||||
{
|
||||
DWORD dwExitCode;
|
||||
WaitForSingleObject (prci.hProcess, INFINITE);
|
||||
GetExitCodeProcess (prci.hProcess, &dwExitCode);
|
||||
nErrorLevel = (INT)dwExitCode;
|
||||
}
|
||||
CloseHandle (prci.hProcess);
|
||||
/* Get New code page if it has change */
|
||||
InputCodePage= GetConsoleCP();
|
||||
if (prci.hProcess != NULL)
|
||||
{
|
||||
if (bWait)
|
||||
{
|
||||
DWORD dwExitCode;
|
||||
WaitForSingleObject (prci.hProcess, INFINITE);
|
||||
GetExitCodeProcess (prci.hProcess, &dwExitCode);
|
||||
nErrorLevel = (INT)dwExitCode;
|
||||
}
|
||||
CloseHandle (prci.hProcess);
|
||||
/* Get New code page if it has change */
|
||||
InputCodePage= GetConsoleCP();
|
||||
OutputCodePage = GetConsoleOutputCP();
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage(GetLastError (),
|
||||
_T("Error executing CreateProcess()!!\n"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage(GetLastError (),
|
||||
_T("Error executing CreateProcess()!!\n"));
|
||||
}
|
||||
|
||||
|
||||
cmd_free(comspec);
|
||||
return 0;
|
||||
cmd_free(comspec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
* 07-Oct-1999 (Paolo Pantaleo)
|
||||
* Started.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -37,52 +36,52 @@
|
|||
|
||||
typedef struct _CLRTABLE
|
||||
{
|
||||
LPTSTR name;
|
||||
WORD val;
|
||||
LPTSTR name;
|
||||
WORD val;
|
||||
} CLRTABLE;
|
||||
|
||||
|
||||
CLRTABLE clrtable[] =
|
||||
{
|
||||
{_T("bla"), 0 },
|
||||
{_T("blu"), _B },
|
||||
{_T("gre"), _G },
|
||||
{_T("cya"), _B|_G },
|
||||
{_T("red"), _R },
|
||||
{_T("mag"), _B|_R },
|
||||
{_T("yel"), _R|_G },
|
||||
{_T("whi"), _R|_G|_B },
|
||||
{_T("gra"), _I },
|
||||
{_T("bla"), 0 },
|
||||
{_T("blu"), _B },
|
||||
{_T("gre"), _G },
|
||||
{_T("cya"), _B|_G },
|
||||
{_T("red"), _R },
|
||||
{_T("mag"), _B|_R },
|
||||
{_T("yel"), _R|_G },
|
||||
{_T("whi"), _R|_G|_B },
|
||||
{_T("gra"), _I },
|
||||
|
||||
{_T("0") , 0 },
|
||||
{_T("2") , _G },
|
||||
{_T("3") , _B|_G },
|
||||
{_T("4") , _R },
|
||||
{_T("5") , _B|_R },
|
||||
{_T("6") , _R|_G },
|
||||
{_T("7") , _R|_G|_B },
|
||||
{_T("0") , 0 },
|
||||
{_T("2") , _G },
|
||||
{_T("3") , _B|_G },
|
||||
{_T("4") , _R },
|
||||
{_T("5") , _B|_R },
|
||||
{_T("6") , _R|_G },
|
||||
{_T("7") , _R|_G|_B },
|
||||
|
||||
{_T("8") , _I },
|
||||
{_T("9") , _I|_B },
|
||||
{_T("10") , _I|_G },
|
||||
{_T("11") , _I|_B|_G },
|
||||
{_T("12") , _I|_R },
|
||||
{_T("13") , _I|_B|_R },
|
||||
{_T("14") , _I|_R|_G },
|
||||
{_T("15") , _I|_R|_G|_B },
|
||||
{_T("8") , _I },
|
||||
{_T("9") , _I|_B },
|
||||
{_T("10") , _I|_G },
|
||||
{_T("11") , _I|_B|_G },
|
||||
{_T("12") , _I|_R },
|
||||
{_T("13") , _I|_B|_R },
|
||||
{_T("14") , _I|_R|_G },
|
||||
{_T("15") , _I|_R|_G|_B },
|
||||
|
||||
/*
|
||||
/*
|
||||
* Note that 1 is at the end of list
|
||||
* to avoid to confuse it with 10-15
|
||||
* to avoid to confuse it with 10-15
|
||||
*/
|
||||
{_T("1") , _B },
|
||||
{_T("1") , _B },
|
||||
|
||||
/* Cyan synonym */
|
||||
{_T("aqu"), _B|_G },
|
||||
/* Magenta synonym */
|
||||
{_T("pur"), _B|_R },
|
||||
/* Cyan synonym */
|
||||
{_T("aqu"), _B|_G },
|
||||
/* Magenta synonym */
|
||||
{_T("pur"), _B|_R },
|
||||
|
||||
{_T("") ,0},
|
||||
{_T("") ,0},
|
||||
};
|
||||
|
||||
|
||||
|
@ -93,28 +92,28 @@ CLRTABLE clrtable[] =
|
|||
static
|
||||
INT chop_blank(LPTSTR *arg_str)
|
||||
{
|
||||
LPTSTR str;
|
||||
str = _tcschr(*arg_str,_T(' '));
|
||||
if(!str)
|
||||
{
|
||||
str = _tcschr (*arg_str, _T('\0'));
|
||||
if(str != NULL)
|
||||
*arg_str=str;
|
||||
return CP_BLANK_NOT_FOUND;
|
||||
}
|
||||
LPTSTR str;
|
||||
str = _tcschr(*arg_str,_T(' '));
|
||||
if(!str)
|
||||
{
|
||||
str = _tcschr (*arg_str, _T('\0'));
|
||||
if(str != NULL)
|
||||
*arg_str=str;
|
||||
return CP_BLANK_NOT_FOUND;
|
||||
}
|
||||
|
||||
while(_istspace(*str))
|
||||
str++;
|
||||
while(_istspace(*str))
|
||||
str++;
|
||||
|
||||
if (*str == _T('\0'))
|
||||
{
|
||||
*arg_str=str;
|
||||
return CP_END_OF_STRING;
|
||||
}
|
||||
if (*str == _T('\0'))
|
||||
{
|
||||
*arg_str=str;
|
||||
return CP_END_OF_STRING;
|
||||
}
|
||||
|
||||
*arg_str = str;
|
||||
*arg_str = str;
|
||||
|
||||
return CP_OK;
|
||||
return CP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,38 +124,38 @@ INT chop_blank(LPTSTR *arg_str)
|
|||
static
|
||||
WORD hex_clr(LPTSTR str)
|
||||
{
|
||||
WORD ret= (WORD)-1;
|
||||
TCHAR ch;
|
||||
WORD ret= (WORD)-1;
|
||||
TCHAR ch;
|
||||
|
||||
ch = str[1];
|
||||
ch = str[1];
|
||||
|
||||
if(_istdigit(ch))
|
||||
ret = ch-_T('0');
|
||||
else
|
||||
{
|
||||
ch=_totupper(ch);
|
||||
if(_istdigit(ch))
|
||||
ret = ch-_T('0');
|
||||
else
|
||||
{
|
||||
ch=_totupper(ch);
|
||||
|
||||
if( ch >= _T('A') && ch <= _T('F') )
|
||||
ret = ch-_T('A')+10;
|
||||
else
|
||||
return (WORD)-1;
|
||||
}
|
||||
if( ch >= _T('A') && ch <= _T('F') )
|
||||
ret = ch-_T('A')+10;
|
||||
else
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
ch = str[0];
|
||||
ch = str[0];
|
||||
|
||||
if(_istdigit(ch))
|
||||
ret |= (ch-_T('0')) << 4;
|
||||
else
|
||||
{
|
||||
ch=_totupper(ch);
|
||||
if(_istdigit(ch))
|
||||
ret |= (ch-_T('0')) << 4;
|
||||
else
|
||||
{
|
||||
ch=_totupper(ch);
|
||||
|
||||
if( ch >= _T('A') && ch <= _T('F') )
|
||||
ret |= (ch-_T('A')+10) <<4;
|
||||
else
|
||||
return (WORD)-1;
|
||||
}
|
||||
if( ch >= _T('A') && ch <= _T('F') )
|
||||
ret |= (ch-_T('A')+10) <<4;
|
||||
else
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,13 +166,13 @@ WORD hex_clr(LPTSTR str)
|
|||
static
|
||||
WORD txt_clr(LPTSTR str)
|
||||
{
|
||||
INT i;
|
||||
INT i;
|
||||
|
||||
for(i = 0; *(clrtable[i].name); i++)
|
||||
if (_tcsnicmp(str, clrtable[i].name, _tcslen(clrtable[i].name)) == 0)
|
||||
return clrtable[i].val;
|
||||
for(i = 0; *(clrtable[i].name); i++)
|
||||
if (_tcsnicmp(str, clrtable[i].name, _tcslen(clrtable[i].name)) == 0)
|
||||
return clrtable[i].val;
|
||||
|
||||
return (WORD)-1;
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,58 +180,58 @@ WORD txt_clr(LPTSTR str)
|
|||
static
|
||||
WORD str_to_color(LPTSTR* arg_str)
|
||||
{
|
||||
LPTSTR str;
|
||||
BOOL bBri;
|
||||
LPTSTR str;
|
||||
BOOL bBri;
|
||||
|
||||
WORD tmp_clr,ret_clr;
|
||||
WORD tmp_clr,ret_clr;
|
||||
|
||||
str = *arg_str;
|
||||
str = *arg_str;
|
||||
|
||||
if (!(*str))
|
||||
return (WORD)-1;
|
||||
if (!(*str))
|
||||
return (WORD)-1;
|
||||
|
||||
/* foreground */
|
||||
bBri = FALSE;
|
||||
/* foreground */
|
||||
bBri = FALSE;
|
||||
|
||||
if (_tcsnicmp(str,_T("bri"),3) == 0)
|
||||
{
|
||||
bBri = TRUE;
|
||||
if (_tcsnicmp(str,_T("bri"),3) == 0)
|
||||
{
|
||||
bBri = TRUE;
|
||||
|
||||
if (chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
}
|
||||
if (chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
if ((tmp_clr = txt_clr(str)) == (WORD)-1)
|
||||
{
|
||||
return (WORD)-1;
|
||||
}
|
||||
if ((tmp_clr = txt_clr(str)) == (WORD)-1)
|
||||
{
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
/* skip spaces and "on" keyword */
|
||||
if (chop_blank(&str) || chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
/* skip spaces and "on" keyword */
|
||||
if (chop_blank(&str) || chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
|
||||
ret_clr = tmp_clr | (bBri << 3);
|
||||
ret_clr = tmp_clr | (bBri << 3);
|
||||
|
||||
/* background */
|
||||
bBri = FALSE;
|
||||
/* background */
|
||||
bBri = FALSE;
|
||||
|
||||
if(_tcsnicmp(str,_T("bri"),3) == 0 )
|
||||
{
|
||||
bBri = TRUE;
|
||||
if(_tcsnicmp(str,_T("bri"),3) == 0 )
|
||||
{
|
||||
bBri = TRUE;
|
||||
|
||||
if(chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
}
|
||||
if(chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
if( (tmp_clr = txt_clr(str)) == (WORD)-1 )
|
||||
return (WORD)-1;
|
||||
if( (tmp_clr = txt_clr(str)) == (WORD)-1 )
|
||||
return (WORD)-1;
|
||||
|
||||
chop_blank(&str);
|
||||
chop_blank(&str);
|
||||
|
||||
*arg_str = str;
|
||||
*arg_str = str;
|
||||
|
||||
/* NOTE: See the note on SC_HEX in the StringToColor()'s description */
|
||||
return /* SC_HEX | */ ret_clr | tmp_clr << 4 | bBri << 7;
|
||||
/* NOTE: See the note on SC_HEX in the StringToColor()'s description */
|
||||
return /* SC_HEX | */ ret_clr | tmp_clr << 4 | bBri << 7;
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,20 +254,20 @@ WORD str_to_color(LPTSTR* arg_str)
|
|||
*/
|
||||
BOOL StringToColor(LPWORD lpColor, LPTSTR*str)
|
||||
{
|
||||
WORD wRet;
|
||||
WORD wRet;
|
||||
|
||||
wRet = str_to_color (str);
|
||||
if (wRet == (WORD)-1)
|
||||
{
|
||||
wRet=hex_clr (*str);
|
||||
chop_blank (str);
|
||||
if (wRet == (WORD)-1)
|
||||
return FALSE;
|
||||
}
|
||||
wRet = str_to_color (str);
|
||||
if (wRet == (WORD)-1)
|
||||
{
|
||||
wRet=hex_clr (*str);
|
||||
chop_blank (str);
|
||||
if (wRet == (WORD)-1)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*lpColor = wRet;
|
||||
*lpColor = wRet;
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
* 04-Feb-1999 (Eric Kohl)
|
||||
* Fixed time input bug.
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc.
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc.
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
@ -31,187 +31,187 @@
|
|||
|
||||
static BOOL ParseTime (LPTSTR s)
|
||||
{
|
||||
SYSTEMTIME t;
|
||||
LPTSTR p = s;
|
||||
SYSTEMTIME t;
|
||||
LPTSTR p = s;
|
||||
|
||||
if (!*s)
|
||||
return TRUE;
|
||||
if (!*s)
|
||||
return TRUE;
|
||||
|
||||
GetLocalTime (&t);
|
||||
t.wHour = 0;
|
||||
t.wMinute = 0;
|
||||
t.wSecond = 0;
|
||||
t.wMilliseconds = 0;
|
||||
GetLocalTime (&t);
|
||||
t.wHour = 0;
|
||||
t.wMinute = 0;
|
||||
t.wSecond = 0;
|
||||
t.wMilliseconds = 0;
|
||||
|
||||
// first get hour
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
t.wHour = t.wHour * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
// first get hour
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
t.wHour = t.wHour * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
// get time separator
|
||||
if (*p != cTimeSeparator)
|
||||
return FALSE;
|
||||
p++;
|
||||
// get time separator
|
||||
if (*p != cTimeSeparator)
|
||||
return FALSE;
|
||||
p++;
|
||||
|
||||
// now get minutes
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
t.wMinute = t.wMinute * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
// now get minutes
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
t.wMinute = t.wMinute * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
// get time separator
|
||||
if (*p != cTimeSeparator)
|
||||
return FALSE;
|
||||
p++;
|
||||
// get time separator
|
||||
if (*p != cTimeSeparator)
|
||||
return FALSE;
|
||||
p++;
|
||||
|
||||
// now get seconds
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
t.wSecond = t.wSecond * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
// now get seconds
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
t.wSecond = t.wSecond * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
// get decimal separator
|
||||
if (*p == cDecimalSeparator)
|
||||
{
|
||||
p++;
|
||||
// get decimal separator
|
||||
if (*p == cDecimalSeparator)
|
||||
{
|
||||
p++;
|
||||
|
||||
// now get hundreths
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
// t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
// t.wMilliseconds *= 10;
|
||||
}
|
||||
}
|
||||
// now get hundreths
|
||||
if (_istdigit(*p))
|
||||
{
|
||||
while (_istdigit(*p))
|
||||
{
|
||||
// t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
|
||||
p++;
|
||||
}
|
||||
// t.wMilliseconds *= 10;
|
||||
}
|
||||
}
|
||||
|
||||
/* special case: 12 hour format */
|
||||
if (nTimeFormat == 0)
|
||||
{
|
||||
if (_totupper(*s) == _T('P'))
|
||||
{
|
||||
t.wHour += 12;
|
||||
}
|
||||
/* special case: 12 hour format */
|
||||
if (nTimeFormat == 0)
|
||||
{
|
||||
if (_totupper(*s) == _T('P'))
|
||||
{
|
||||
t.wHour += 12;
|
||||
}
|
||||
|
||||
if ((_totupper(*s) == _T('A')) && (t.wHour == 12))
|
||||
{
|
||||
t.wHour = 0;
|
||||
}
|
||||
}
|
||||
if ((_totupper(*s) == _T('A')) && (t.wHour == 12))
|
||||
{
|
||||
t.wHour = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.wHour > 23 || t.wMinute > 60 || t.wSecond > 60 || t.wMilliseconds > 999)
|
||||
return FALSE;
|
||||
if (t.wHour > 23 || t.wMinute > 60 || t.wSecond > 60 || t.wMilliseconds > 999)
|
||||
return FALSE;
|
||||
|
||||
SetLocalTime (&t);
|
||||
SetLocalTime (&t);
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
INT cmd_time (LPTSTR param)
|
||||
{
|
||||
LPTSTR *arg;
|
||||
INT argc;
|
||||
INT i;
|
||||
INT nTimeString = -1;
|
||||
LPTSTR *arg;
|
||||
INT argc;
|
||||
INT i;
|
||||
INT nTimeString = -1;
|
||||
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_TIME_HELP1);
|
||||
return 0;
|
||||
}
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_TIME_HELP1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
/* build parameter array */
|
||||
arg = split (param, &argc, FALSE, FALSE);
|
||||
/* build parameter array */
|
||||
arg = split (param, &argc, FALSE, FALSE);
|
||||
|
||||
/* check for options */
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (_tcsicmp (arg[i], _T("/t")) == 0)
|
||||
{
|
||||
/* Display current time in short format */
|
||||
SYSTEMTIME st;
|
||||
TCHAR szTime[20];
|
||||
GetLocalTime(&st);
|
||||
FormatTime(szTime, &st);
|
||||
ConOutPuts(szTime);
|
||||
freep(arg);
|
||||
return 0;
|
||||
}
|
||||
/* check for options */
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (_tcsicmp (arg[i], _T("/t")) == 0)
|
||||
{
|
||||
/* Display current time in short format */
|
||||
SYSTEMTIME st;
|
||||
TCHAR szTime[20];
|
||||
GetLocalTime(&st);
|
||||
FormatTime(szTime, &st);
|
||||
ConOutPuts(szTime);
|
||||
freep(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((*arg[i] != _T('/')) && (nTimeString == -1))
|
||||
nTimeString = i;
|
||||
}
|
||||
if ((*arg[i] != _T('/')) && (nTimeString == -1))
|
||||
nTimeString = i;
|
||||
}
|
||||
|
||||
if (nTimeString == -1)
|
||||
{
|
||||
ConOutResPrintf(STRING_LOCALE_HELP1);
|
||||
ConOutPrintf(_T(": %s\n"), GetTimeString());
|
||||
}
|
||||
if (nTimeString == -1)
|
||||
{
|
||||
ConOutResPrintf(STRING_LOCALE_HELP1);
|
||||
ConOutPrintf(_T(": %s\n"), GetTimeString());
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (nTimeString == -1)
|
||||
{
|
||||
TCHAR s[40];
|
||||
while (1)
|
||||
{
|
||||
if (nTimeString == -1)
|
||||
{
|
||||
TCHAR s[40];
|
||||
|
||||
ConOutResPuts(STRING_TIME_HELP2);
|
||||
ConOutResPuts(STRING_TIME_HELP2);
|
||||
|
||||
ConInString (s, 40);
|
||||
ConInString (s, 40);
|
||||
|
||||
TRACE ("\'%s\'\n", debugstr_aw(s));
|
||||
TRACE ("\'%s\'\n", debugstr_aw(s));
|
||||
|
||||
while (*s && s[_tcslen (s) - 1] < _T(' '))
|
||||
s[_tcslen(s) - 1] = _T('\0');
|
||||
while (*s && s[_tcslen (s) - 1] < _T(' '))
|
||||
s[_tcslen(s) - 1] = _T('\0');
|
||||
|
||||
if (ParseTime (s))
|
||||
{
|
||||
freep (arg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ParseTime (arg[nTimeString]))
|
||||
{
|
||||
freep (arg);
|
||||
return 0;
|
||||
}
|
||||
if (ParseTime (s))
|
||||
{
|
||||
freep (arg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ParseTime (arg[nTimeString]))
|
||||
{
|
||||
freep (arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* force input the next time around. */
|
||||
nTimeString = -1;
|
||||
}
|
||||
/* force input the next time around. */
|
||||
nTimeString = -1;
|
||||
}
|
||||
|
||||
ConErrResPuts(STRING_TIME_ERROR1);
|
||||
ConErrResPuts(STRING_TIME_ERROR1);
|
||||
nErrorLevel = 1;
|
||||
}
|
||||
}
|
||||
|
||||
freep (arg);
|
||||
freep (arg);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,189 +30,189 @@
|
|||
static VOID
|
||||
PrintElapsedTime (DWORD time,INT format)
|
||||
{
|
||||
DWORD h,m,s,ms;
|
||||
DWORD h,m,s,ms;
|
||||
|
||||
TRACE ("PrintElapsedTime(%d,%d)",time,format);
|
||||
TRACE ("PrintElapsedTime(%d,%d)",time,format);
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case 0:
|
||||
ConOutResPrintf(STRING_TIMER_HELP1, time);
|
||||
break;
|
||||
switch (format)
|
||||
{
|
||||
case 0:
|
||||
ConOutResPrintf(STRING_TIMER_HELP1, time);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
ms = time % 1000;
|
||||
time /= 1000;
|
||||
s = time % 60;
|
||||
time /=60;
|
||||
m = time % 60;
|
||||
h = time / 60;
|
||||
ConOutResPrintf(STRING_TIMER_HELP2,
|
||||
h, cTimeSeparator,
|
||||
m, cTimeSeparator,
|
||||
s, cDecimalSeparator, ms/10);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
ms = time % 1000;
|
||||
time /= 1000;
|
||||
s = time % 60;
|
||||
time /=60;
|
||||
m = time % 60;
|
||||
h = time / 60;
|
||||
ConOutResPrintf(STRING_TIMER_HELP2,
|
||||
h, cTimeSeparator,
|
||||
m, cTimeSeparator,
|
||||
s, cDecimalSeparator, ms/10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
INT CommandTimer (LPTSTR param)
|
||||
{
|
||||
// all timers are kept
|
||||
static DWORD clksT[10];
|
||||
// all timers are kept
|
||||
static DWORD clksT[10];
|
||||
|
||||
// timers status
|
||||
// set all the clocks off by default
|
||||
static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
|
||||
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE};
|
||||
// timers status
|
||||
// set all the clocks off by default
|
||||
static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
|
||||
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE};
|
||||
|
||||
// TRUE if /S in command line
|
||||
BOOL bS = FALSE;
|
||||
// TRUE if /S in command line
|
||||
BOOL bS = FALSE;
|
||||
|
||||
// avoid to set clk_n more than once
|
||||
BOOL bCanNSet = TRUE;
|
||||
// avoid to set clk_n more than once
|
||||
BOOL bCanNSet = TRUE;
|
||||
|
||||
INT NewClkStatus = NCS_NOT_SPECIFIED;
|
||||
INT NewClkStatus = NCS_NOT_SPECIFIED;
|
||||
|
||||
// the clock number specified on the command line
|
||||
// 1 by default
|
||||
INT clk_n=1;
|
||||
// the clock number specified on the command line
|
||||
// 1 by default
|
||||
INT clk_n=1;
|
||||
|
||||
// output format
|
||||
INT iFormat=1;
|
||||
// output format
|
||||
INT iFormat=1;
|
||||
|
||||
|
||||
// command line parsing variables
|
||||
INT argc;
|
||||
LPTSTR *p;
|
||||
// command line parsing variables
|
||||
INT argc;
|
||||
LPTSTR *p;
|
||||
|
||||
INT i;
|
||||
INT i;
|
||||
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator);
|
||||
return 0;
|
||||
}
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
p = split (param, &argc, FALSE, FALSE);
|
||||
p = split (param, &argc, FALSE, FALSE);
|
||||
|
||||
//read options
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
//set timer on
|
||||
if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED)
|
||||
{
|
||||
NewClkStatus = NCS_ON;
|
||||
continue;
|
||||
}
|
||||
//read options
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
//set timer on
|
||||
if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED)
|
||||
{
|
||||
NewClkStatus = NCS_ON;
|
||||
continue;
|
||||
}
|
||||
|
||||
//set timer off
|
||||
if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED)
|
||||
{
|
||||
NewClkStatus = NCS_OFF;
|
||||
continue;
|
||||
}
|
||||
//set timer off
|
||||
if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED)
|
||||
{
|
||||
NewClkStatus = NCS_OFF;
|
||||
continue;
|
||||
}
|
||||
|
||||
// other options
|
||||
if (p[i][0] == _T('/'))
|
||||
{
|
||||
// set timer number
|
||||
if (_istdigit(p[i][1]) && bCanNSet)
|
||||
{
|
||||
clk_n = p[i][1] - _T('0');
|
||||
bCanNSet = FALSE;
|
||||
continue;
|
||||
}
|
||||
// other options
|
||||
if (p[i][0] == _T('/'))
|
||||
{
|
||||
// set timer number
|
||||
if (_istdigit(p[i][1]) && bCanNSet)
|
||||
{
|
||||
clk_n = p[i][1] - _T('0');
|
||||
bCanNSet = FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
// set s(plit) option
|
||||
if (_totupper(p[i][1]) == _T('S'))
|
||||
{
|
||||
bS = TRUE;
|
||||
continue;
|
||||
}
|
||||
// set s(plit) option
|
||||
if (_totupper(p[i][1]) == _T('S'))
|
||||
{
|
||||
bS = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
// specify format
|
||||
if (_totupper(p[i][1]) == _T('F'))
|
||||
{
|
||||
iFormat = p[i][2] - _T('0');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// specify format
|
||||
if (_totupper(p[i][1]) == _T('F'))
|
||||
{
|
||||
iFormat = p[i][2] - _T('0');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// do stuff (start/stop/read timer)
|
||||
if(NewClkStatus == NCS_ON)
|
||||
{
|
||||
cT=GetTickCount();
|
||||
cS=TRUE;
|
||||
// do stuff (start/stop/read timer)
|
||||
if(NewClkStatus == NCS_ON)
|
||||
{
|
||||
cT=GetTickCount();
|
||||
cS=TRUE;
|
||||
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(bS)
|
||||
{
|
||||
if(cS)
|
||||
{
|
||||
if(bS)
|
||||
{
|
||||
if(cS)
|
||||
{
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPrintf(_T("%s\n"), GetTimeString());
|
||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
ConOutPrintf(_T("%s\n"), GetTimeString());
|
||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cT=GetTickCount();
|
||||
cS=TRUE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
cT=GetTickCount();
|
||||
cS=TRUE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NewClkStatus == NCS_NOT_SPECIFIED)
|
||||
{
|
||||
if (cS)
|
||||
{
|
||||
cS=FALSE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPrintf(_T("%s\n"), GetTimeString());
|
||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
if (NewClkStatus == NCS_NOT_SPECIFIED)
|
||||
{
|
||||
if (cS)
|
||||
{
|
||||
cS=FALSE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPrintf(_T("%s\n"), GetTimeString());
|
||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cT=GetTickCount();
|
||||
cS=TRUE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
cT=GetTickCount();
|
||||
cS=TRUE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (NewClkStatus == NCS_OFF)
|
||||
{
|
||||
if (cS)
|
||||
{
|
||||
cS=FALSE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPrintf(_T("%s\n"), GetTimeString());
|
||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
if (NewClkStatus == NCS_OFF)
|
||||
{
|
||||
if (cS)
|
||||
{
|
||||
cS=FALSE;
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPrintf(_T("%s\n"), GetTimeString());
|
||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||
ConOutPuts(GetTimeString());
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
freep(p);
|
||||
return 0;
|
||||
freep(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_CMD_TIMER */
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
*
|
||||
*
|
||||
* History:
|
||||
* 1999-02-11 Emanuele Aliberti
|
||||
* 1999-02-11 Emanuele Aliberti
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
@ -16,19 +16,18 @@
|
|||
|
||||
INT cmd_title (LPTSTR param)
|
||||
{
|
||||
/* Do nothing if no args */
|
||||
if (*param == _T('\0'))
|
||||
return 0;
|
||||
|
||||
/* Do nothing if no args */
|
||||
if (*param == _T('\0'))
|
||||
return 0;
|
||||
/* Asking help? */
|
||||
if (!_tcsncmp(param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_TITLE_HELP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Asking help? */
|
||||
if (!_tcsncmp(param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_TITLE_HELP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return SetConsoleTitle (param);
|
||||
return SetConsoleTitle (param);
|
||||
}
|
||||
|
||||
#endif /* def INCLUDE_CMD_TITLE */
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
* 19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
|
||||
* Added multiple file support (copied from y.c)
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
@ -33,108 +33,108 @@
|
|||
|
||||
INT cmd_type (LPTSTR param)
|
||||
{
|
||||
TCHAR buff[256];
|
||||
HANDLE hFile, hConsoleOut;
|
||||
DWORD dwRet;
|
||||
INT argc,i;
|
||||
LPTSTR *argv;
|
||||
LPTSTR errmsg;
|
||||
BOOL bPaging = FALSE;
|
||||
BOOL bFirstTime = TRUE;
|
||||
TCHAR buff[256];
|
||||
HANDLE hFile, hConsoleOut;
|
||||
DWORD dwRet;
|
||||
INT argc,i;
|
||||
LPTSTR *argv;
|
||||
LPTSTR errmsg;
|
||||
BOOL bPaging = FALSE;
|
||||
BOOL bFirstTime = TRUE;
|
||||
|
||||
hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_TYPE_HELP1);
|
||||
return 0;
|
||||
}
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_TYPE_HELP1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!*param)
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
if (!*param)
|
||||
{
|
||||
error_req_param_missing ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
argv = split (param, &argc, TRUE, FALSE);
|
||||
argv = split (param, &argc, TRUE, FALSE);
|
||||
|
||||
for(i = 0; i < argc; i++)
|
||||
{
|
||||
if(*argv[i] == _T('/') && _tcslen(argv[i]) >= 2 && _totupper(argv[i][1]) == _T('P'))
|
||||
{
|
||||
bPaging = TRUE;
|
||||
}
|
||||
}
|
||||
for(i = 0; i < argc; i++)
|
||||
{
|
||||
if(*argv[i] == _T('/') && _tcslen(argv[i]) >= 2 && _totupper(argv[i][1]) == _T('P'))
|
||||
{
|
||||
bPaging = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (_T('/') == argv[i][0] && _totupper(argv[i][1]) != _T('P'))
|
||||
{
|
||||
ConErrResPrintf(STRING_TYPE_ERROR1, argv[i] + 1);
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (_T('/') == argv[i][0] && _totupper(argv[i][1]) != _T('P'))
|
||||
{
|
||||
ConErrResPrintf(STRING_TYPE_ERROR1, argv[i] + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
hFile = CreateFile(argv[i],
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
hFile = CreateFile(argv[i],
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &errmsg,
|
||||
0,
|
||||
NULL);
|
||||
ConErrPrintf (_T("%s - %s"), argv[i], errmsg);
|
||||
LocalFree (errmsg);
|
||||
nErrorLevel = 1;
|
||||
continue;
|
||||
}
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &errmsg,
|
||||
0,
|
||||
NULL);
|
||||
ConErrPrintf (_T("%s - %s"), argv[i], errmsg);
|
||||
LocalFree (errmsg);
|
||||
nErrorLevel = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bPaging)
|
||||
{
|
||||
while (FileGetString (hFile, buff, sizeof(buff) / sizeof(TCHAR)))
|
||||
{
|
||||
if (ConOutPrintfPaging(bFirstTime, _T("%s"), buff) == 1)
|
||||
{
|
||||
bCtrlBreak = FALSE;
|
||||
CloseHandle(hFile);
|
||||
freep(argv);
|
||||
return 0;
|
||||
}
|
||||
bFirstTime = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (ReadFile(hFile, buff, sizeof(buff), &dwRet, NULL) && dwRet > 0)
|
||||
{
|
||||
WriteFile(hConsoleOut, buff, dwRet, &dwRet, NULL);
|
||||
if (bCtrlBreak)
|
||||
{
|
||||
bCtrlBreak = FALSE;
|
||||
CloseHandle(hFile);
|
||||
freep(argv);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bPaging)
|
||||
{
|
||||
while (FileGetString (hFile, buff, sizeof(buff) / sizeof(TCHAR)))
|
||||
{
|
||||
if (ConOutPrintfPaging(bFirstTime, _T("%s"), buff) == 1)
|
||||
{
|
||||
bCtrlBreak = FALSE;
|
||||
CloseHandle(hFile);
|
||||
freep(argv);
|
||||
return 0;
|
||||
}
|
||||
bFirstTime = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (ReadFile(hFile, buff, sizeof(buff), &dwRet, NULL) && dwRet > 0)
|
||||
{
|
||||
WriteFile(hConsoleOut, buff, dwRet, &dwRet, NULL);
|
||||
if (bCtrlBreak)
|
||||
{
|
||||
bCtrlBreak = FALSE;
|
||||
CloseHandle(hFile);
|
||||
freep(argv);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConOutPuts(_T("\n"));
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
ConOutPuts(_T("\n"));
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
freep (argv);
|
||||
freep (argv);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,101 +27,98 @@
|
|||
|
||||
VOID ShortVersion (VOID)
|
||||
{
|
||||
OSVERSIONINFO VersionInfo;
|
||||
OSVERSIONINFO VersionInfo;
|
||||
|
||||
ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_RELEASE_STR), _T(KERNEL_VERSION_BUILD_STR));
|
||||
VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_RELEASE_STR), _T(KERNEL_VERSION_BUILD_STR));
|
||||
VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
|
||||
memset(VersionInfo.szCSDVersion, 0, sizeof(VersionInfo.szCSDVersion));
|
||||
if (GetVersionEx(&VersionInfo))
|
||||
{
|
||||
LPTSTR RosVersion;
|
||||
SIZE_T RosVersionLen;
|
||||
memset(VersionInfo.szCSDVersion, 0, sizeof(VersionInfo.szCSDVersion));
|
||||
if (GetVersionEx(&VersionInfo))
|
||||
{
|
||||
LPTSTR RosVersion;
|
||||
SIZE_T RosVersionLen;
|
||||
|
||||
RosVersion = VersionInfo.szCSDVersion + _tcslen(VersionInfo.szCSDVersion) + 1;
|
||||
RosVersionLen = sizeof(VersionInfo.szCSDVersion) / sizeof(VersionInfo.szCSDVersion[0]) -
|
||||
(RosVersion - VersionInfo.szCSDVersion);
|
||||
if (7 <= RosVersionLen && 0 == _tcsnicmp(RosVersion, _T("ReactOS"), 7))
|
||||
{
|
||||
ConOutResPrintf(STRING_VERSION_RUNVER, RosVersion);
|
||||
}
|
||||
}
|
||||
ConOutPuts (_T("\n"));
|
||||
RosVersion = VersionInfo.szCSDVersion + _tcslen(VersionInfo.szCSDVersion) + 1;
|
||||
RosVersionLen = sizeof(VersionInfo.szCSDVersion) / sizeof(VersionInfo.szCSDVersion[0]) -
|
||||
(RosVersion - VersionInfo.szCSDVersion);
|
||||
if (7 <= RosVersionLen && 0 == _tcsnicmp(RosVersion, _T("ReactOS"), 7))
|
||||
{
|
||||
ConOutResPrintf(STRING_VERSION_RUNVER, RosVersion);
|
||||
}
|
||||
}
|
||||
ConOutPuts (_T("\n"));
|
||||
}
|
||||
|
||||
|
||||
#ifdef INCLUDE_CMD_VER
|
||||
|
||||
/*
|
||||
* display shell version info internal command.
|
||||
*
|
||||
*
|
||||
* display shell version info internal command.
|
||||
*/
|
||||
INT cmd_ver (LPTSTR param)
|
||||
{
|
||||
INT i;
|
||||
INT i;
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
if (_tcsstr (param, _T("/?")) != NULL)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_VERSION_HELP1);
|
||||
return 0;
|
||||
}
|
||||
if (_tcsstr (param, _T("/?")) != NULL)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_VERSION_HELP1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShortVersion();
|
||||
ShortVersion();
|
||||
|
||||
/* Basic copyright notice */
|
||||
if (param[0] != _T('\0'))
|
||||
{
|
||||
/* Basic copyright notice */
|
||||
if (param[0] != _T('\0'))
|
||||
{
|
||||
ConOutPuts (_T("Copyright (C) 1994-1998 Tim Norman and others."));
|
||||
ConOutPuts (_T("Copyright (C) 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team"));
|
||||
|
||||
ConOutPuts (_T("Copyright (C) 1994-1998 Tim Norman and others."));
|
||||
ConOutPuts (_T("Copyright (C) 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team"));
|
||||
for (i = 0; param[i]; i++)
|
||||
{
|
||||
/* skip spaces */
|
||||
if (param[i] == _T(' '))
|
||||
continue;
|
||||
|
||||
for (i = 0; param[i]; i++)
|
||||
{
|
||||
/* skip spaces */
|
||||
if (param[i] == _T(' '))
|
||||
continue;
|
||||
if (param[i] == _T('/'))
|
||||
{
|
||||
/* is this a lone '/' ? */
|
||||
if (param[i + 1] == 0)
|
||||
{
|
||||
error_invalid_switch (_T(' '));
|
||||
return 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param[i] == _T('/'))
|
||||
{
|
||||
/* is this a lone '/' ? */
|
||||
if (param[i + 1] == 0)
|
||||
{
|
||||
error_invalid_switch (_T(' '));
|
||||
return 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_totupper (param[i]) == _T('W'))
|
||||
{
|
||||
/* Warranty notice */
|
||||
ConOutResPuts(STRING_VERSION_HELP3);
|
||||
}
|
||||
else if (_totupper (param[i]) == _T('R'))
|
||||
{
|
||||
/* Redistribution notice */
|
||||
ConOutResPuts(STRING_VERSION_HELP4);
|
||||
}
|
||||
else if (_totupper (param[i]) == _T('C'))
|
||||
{
|
||||
/* Developer listing */
|
||||
ConOutResPuts(STRING_VERSION_HELP6);
|
||||
ConOutResPuts(STRING_FREEDOS_DEV);
|
||||
ConOutResPuts(STRING_VERSION_HELP7);
|
||||
if (_totupper (param[i]) == _T('W'))
|
||||
{
|
||||
/* Warranty notice */
|
||||
ConOutResPuts(STRING_VERSION_HELP3);
|
||||
}
|
||||
else if (_totupper (param[i]) == _T('R'))
|
||||
{
|
||||
/* Redistribution notice */
|
||||
ConOutResPuts(STRING_VERSION_HELP4);
|
||||
}
|
||||
else if (_totupper (param[i]) == _T('C'))
|
||||
{
|
||||
/* Developer listing */
|
||||
ConOutResPuts(STRING_VERSION_HELP6);
|
||||
ConOutResPuts(STRING_FREEDOS_DEV);
|
||||
ConOutResPuts(STRING_VERSION_HELP7);
|
||||
ConOutResPuts(STRING_REACTOS_DEV);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_invalid_switch ((TCHAR)_totupper (param[i]));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ConOutResPuts(STRING_VERSION_HELP5);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_invalid_switch ((TCHAR)_totupper (param[i]));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ConOutResPuts(STRING_VERSION_HELP5);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* 20-Jan-1999 (Eric Kohl)
|
||||
* Unicode and redirection ready!
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
@ -29,19 +29,19 @@ static BOOL bVerify = FALSE;
|
|||
|
||||
INT cmd_verify (LPTSTR param)
|
||||
{
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_VERIFY_HELP1);
|
||||
return 0;
|
||||
}
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_VERIFY_HELP1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!OnOffCommand(param, &bVerify, STRING_VERIFY_HELP2))
|
||||
{
|
||||
ConErrResPuts(STRING_VERIFY_HELP3);
|
||||
return nErrorLevel = 1;
|
||||
}
|
||||
if (!OnOffCommand(param, &bVerify, STRING_VERIFY_HELP2))
|
||||
{
|
||||
ConErrResPuts(STRING_VERIFY_HELP3);
|
||||
return nErrorLevel = 1;
|
||||
}
|
||||
|
||||
return nErrorLevel = 0;
|
||||
return nErrorLevel = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,85 +28,87 @@
|
|||
static INT
|
||||
PrintVolumeHeader (LPTSTR pszRootPath)
|
||||
{
|
||||
TCHAR szVolName[80];
|
||||
DWORD dwSerialNr;
|
||||
TCHAR szVolName[80];
|
||||
DWORD dwSerialNr;
|
||||
|
||||
/* get the volume information of the drive */
|
||||
if(!GetVolumeInformation (pszRootPath,
|
||||
szVolName,
|
||||
80,
|
||||
&dwSerialNr,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0))
|
||||
{
|
||||
ErrorMessage (GetLastError (), _T(""));
|
||||
return 1;
|
||||
}
|
||||
/* get the volume information of the drive */
|
||||
if(!GetVolumeInformation(pszRootPath,
|
||||
szVolName,
|
||||
80,
|
||||
&dwSerialNr,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0))
|
||||
{
|
||||
ErrorMessage(GetLastError (), _T(""));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* print drive info */
|
||||
if (szVolName[0] != '\0')
|
||||
{
|
||||
ConOutResPrintf(STRING_VOL_HELP1, pszRootPath[0],szVolName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConOutResPrintf(STRING_VOL_HELP2, pszRootPath[0]);
|
||||
}
|
||||
/* print drive info */
|
||||
if (szVolName[0] != '\0')
|
||||
{
|
||||
ConOutResPrintf(STRING_VOL_HELP1, pszRootPath[0],szVolName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConOutResPrintf(STRING_VOL_HELP2, pszRootPath[0]);
|
||||
}
|
||||
|
||||
/* print the volume serial number */
|
||||
ConOutResPrintf(STRING_VOL_HELP3, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
|
||||
return 0;
|
||||
/* print the volume serial number */
|
||||
ConOutResPrintf(STRING_VOL_HELP3, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
INT cmd_vol (LPTSTR param)
|
||||
{
|
||||
TCHAR szRootPath[] = _T("A:\\");
|
||||
TCHAR szPath[MAX_PATH];
|
||||
TCHAR szRootPath[] = _T("A:\\");
|
||||
TCHAR szPath[MAX_PATH];
|
||||
|
||||
if (!_tcsncmp (param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_VOL_HELP4);
|
||||
return 0;
|
||||
}
|
||||
if (!_tcsncmp(param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_VOL_HELP4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nErrorLevel = 0;
|
||||
nErrorLevel = 0;
|
||||
|
||||
if (param[0] == _T('\0'))
|
||||
{
|
||||
GetCurrentDirectory (MAX_PATH, szPath);
|
||||
szRootPath[0] = szPath[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
_tcsupr (param);
|
||||
if (param[1] == _T(':'))
|
||||
szRootPath[0] = param[0];
|
||||
else
|
||||
{
|
||||
error_invalid_drive ();
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (param[0] == _T('\0'))
|
||||
{
|
||||
GetCurrentDirectory(MAX_PATH, szPath);
|
||||
szRootPath[0] = szPath[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
_tcsupr (param);
|
||||
if (param[1] == _T(':'))
|
||||
{
|
||||
szRootPath[0] = param[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
error_invalid_drive ();
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsValidPathName (szRootPath))
|
||||
{
|
||||
error_invalid_drive ();
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
if (!IsValidPathName (szRootPath))
|
||||
{
|
||||
error_invalid_drive ();
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* print the header */
|
||||
if (!PrintVolumeHeader (szRootPath))
|
||||
{
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
/* print the header */
|
||||
if (!PrintVolumeHeader (szRootPath))
|
||||
{
|
||||
nErrorLevel = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
* Some minor changes and improvements.
|
||||
*
|
||||
* 10-Jul-2004 (Jens Collin <jens.collin@lakhei.com>)
|
||||
* Fixed searxhing for files with specific extensions in PATHEXT order..
|
||||
* Fixed searching for files with specific extensions in PATHEXT order.
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -85,127 +85,127 @@
|
|||
BOOL
|
||||
SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pPathExt, LPTSTR pDirectory)
|
||||
{
|
||||
TCHAR szPathBuffer[CMDLINE_LENGTH], *pszPathEnd;
|
||||
LPTSTR s,f;
|
||||
/* initialize full name buffer */
|
||||
*pFullName = _T('\0');
|
||||
TCHAR szPathBuffer[CMDLINE_LENGTH], *pszPathEnd;
|
||||
LPTSTR s,f;
|
||||
/* initialize full name buffer */
|
||||
*pFullName = _T('\0');
|
||||
|
||||
TRACE ("SearchForExecutableSingle: \'%s\' in dir: \'%s\'\n",
|
||||
debugstr_aw(pFileName), debugstr_aw(pDirectory));
|
||||
TRACE ("SearchForExecutableSingle: \'%s\' in dir: \'%s\'\n",
|
||||
debugstr_aw(pFileName), debugstr_aw(pDirectory));
|
||||
|
||||
pszPathEnd = szPathBuffer;
|
||||
if (pDirectory != NULL)
|
||||
{
|
||||
_tcscpy(szPathBuffer, pDirectory);
|
||||
pszPathEnd += _tcslen(pszPathEnd);
|
||||
*pszPathEnd++ = _T('\\');
|
||||
}
|
||||
_tcscpy(pszPathEnd, pFileName);
|
||||
pszPathEnd += _tcslen(pszPathEnd);
|
||||
pszPathEnd = szPathBuffer;
|
||||
if (pDirectory != NULL)
|
||||
{
|
||||
_tcscpy(szPathBuffer, pDirectory);
|
||||
pszPathEnd += _tcslen(pszPathEnd);
|
||||
*pszPathEnd++ = _T('\\');
|
||||
}
|
||||
_tcscpy(pszPathEnd, pFileName);
|
||||
pszPathEnd += _tcslen(pszPathEnd);
|
||||
|
||||
if (IsExistingFile (szPathBuffer))
|
||||
{
|
||||
TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer));
|
||||
_tcscpy (pFullName, szPathBuffer);
|
||||
return TRUE;
|
||||
}
|
||||
if (IsExistingFile (szPathBuffer))
|
||||
{
|
||||
TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer));
|
||||
_tcscpy (pFullName, szPathBuffer);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
s = pPathExt;
|
||||
while (s && *s)
|
||||
{
|
||||
f = _tcschr (s, _T(';'));
|
||||
s = pPathExt;
|
||||
while (s && *s)
|
||||
{
|
||||
f = _tcschr (s, _T(';'));
|
||||
|
||||
if (f)
|
||||
{
|
||||
_tcsncpy (pszPathEnd, s, (size_t)(f-s));
|
||||
pszPathEnd[f-s] = _T('\0');
|
||||
s = f + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tcscpy (pszPathEnd, s);
|
||||
s = NULL;
|
||||
}
|
||||
if (f)
|
||||
{
|
||||
_tcsncpy (pszPathEnd, s, (size_t)(f-s));
|
||||
pszPathEnd[f-s] = _T('\0');
|
||||
s = f + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tcscpy (pszPathEnd, s);
|
||||
s = NULL;
|
||||
}
|
||||
|
||||
if (IsExistingFile (szPathBuffer))
|
||||
{
|
||||
TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer));
|
||||
_tcscpy (pFullName, szPathBuffer);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
if (IsExistingFile (szPathBuffer))
|
||||
{
|
||||
TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer));
|
||||
_tcscpy (pFullName, szPathBuffer);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
BOOL
|
||||
SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
|
||||
{
|
||||
static TCHAR pszDefaultPathExt[] = _T(".com;.exe;.bat;.cmd");
|
||||
LPTSTR pszPathExt, pszPath;
|
||||
LPTSTR pCh;
|
||||
DWORD dwBuffer;
|
||||
TRACE ("SearchForExecutable: \'%s\'\n", debugstr_aw(pFileName));
|
||||
static TCHAR pszDefaultPathExt[] = _T(".com;.exe;.bat;.cmd");
|
||||
LPTSTR pszPathExt, pszPath;
|
||||
LPTSTR pCh;
|
||||
DWORD dwBuffer;
|
||||
TRACE ("SearchForExecutable: \'%s\'\n", debugstr_aw(pFileName));
|
||||
|
||||
/* load environment varable PATHEXT */
|
||||
pszPathExt = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||
dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE);
|
||||
if (dwBuffer > ENV_BUFFER_SIZE)
|
||||
{
|
||||
pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR));
|
||||
GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, dwBuffer);
|
||||
_tcslwr(pszPathExt);
|
||||
}
|
||||
else if (0 == dwBuffer)
|
||||
{
|
||||
_tcscpy(pszPathExt, pszDefaultPathExt);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tcslwr(pszPathExt);
|
||||
}
|
||||
/* load environment varable PATHEXT */
|
||||
pszPathExt = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||
dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE);
|
||||
if (dwBuffer > ENV_BUFFER_SIZE)
|
||||
{
|
||||
pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR));
|
||||
GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, dwBuffer);
|
||||
_tcslwr(pszPathExt);
|
||||
}
|
||||
else if (0 == dwBuffer)
|
||||
{
|
||||
_tcscpy(pszPathExt, pszDefaultPathExt);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tcslwr(pszPathExt);
|
||||
}
|
||||
|
||||
/* Check if valid directly on specified path */
|
||||
if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, NULL))
|
||||
{
|
||||
cmd_free(pszPathExt);
|
||||
return TRUE;
|
||||
}
|
||||
/* Check if valid directly on specified path */
|
||||
if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, NULL))
|
||||
{
|
||||
cmd_free(pszPathExt);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* If an explicit directory was given, stop here - no need to search PATH. */
|
||||
if (pFileName[1] == _T(':') || _tcschr(pFileName, _T('\\')))
|
||||
{
|
||||
cmd_free(pszPathExt);
|
||||
return FALSE;
|
||||
}
|
||||
/* If an explicit directory was given, stop here - no need to search PATH. */
|
||||
if (pFileName[1] == _T(':') || _tcschr(pFileName, _T('\\')))
|
||||
{
|
||||
cmd_free(pszPathExt);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* load environment varable PATH into buffer */
|
||||
pszPath = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE);
|
||||
if (dwBuffer > ENV_BUFFER_SIZE)
|
||||
{
|
||||
pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR));
|
||||
GetEnvironmentVariable (_T("PATH"), pszPath, dwBuffer);
|
||||
}
|
||||
/* load environment varable PATH into buffer */
|
||||
pszPath = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE);
|
||||
if (dwBuffer > ENV_BUFFER_SIZE)
|
||||
{
|
||||
pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR));
|
||||
GetEnvironmentVariable (_T("PATH"), pszPath, dwBuffer);
|
||||
}
|
||||
|
||||
TRACE ("SearchForExecutable(): Loaded PATH: %s\n", debugstr_aw(pszPath));
|
||||
TRACE ("SearchForExecutable(): Loaded PATH: %s\n", debugstr_aw(pszPath));
|
||||
|
||||
/* search in PATH */
|
||||
pCh = _tcstok(pszPath, _T(";"));
|
||||
while (pCh)
|
||||
{
|
||||
if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, pCh))
|
||||
{
|
||||
cmd_free(pszPath);
|
||||
cmd_free(pszPathExt);
|
||||
return TRUE;
|
||||
}
|
||||
pCh = _tcstok(NULL, _T(";"));
|
||||
}
|
||||
/* search in PATH */
|
||||
pCh = _tcstok(pszPath, _T(";"));
|
||||
while (pCh)
|
||||
{
|
||||
if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, pCh))
|
||||
{
|
||||
cmd_free(pszPath);
|
||||
cmd_free(pszPathExt);
|
||||
return TRUE;
|
||||
}
|
||||
pCh = _tcstok(NULL, _T(";"));
|
||||
}
|
||||
|
||||
cmd_free(pszPath);
|
||||
cmd_free(pszPathExt);
|
||||
return FALSE;
|
||||
cmd_free(pszPath);
|
||||
cmd_free(pszPathExt);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -3,170 +3,168 @@
|
|||
*
|
||||
* clone from 4nt activate command
|
||||
*
|
||||
* 10 Sep 1999 (Paolo Pantaleo)
|
||||
* 10 Sep 1999 (Paolo Pantaleo)
|
||||
* started (window command in WINDOW.c)
|
||||
*
|
||||
* 29 Sep 1999 (Paolo Pantaleo)
|
||||
* 29 Sep 1999 (Paolo Pantaleo)
|
||||
* activate and window in a single file using mainly the same code
|
||||
* (nice size optimization :)
|
||||
*
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
||||
* Remove all hardcode string to En.rc
|
||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||
* Remove all hardcoded strings in En.rc
|
||||
*/
|
||||
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
#if ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) )
|
||||
#if defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE)
|
||||
|
||||
|
||||
#define A_MIN 0x01
|
||||
#define A_MAX 0x02
|
||||
#define A_RESTORE 0x04
|
||||
#define A_POS 0x08
|
||||
#define A_SIZE 0x10
|
||||
#define A_CLOSE 0x20
|
||||
#define A_MIN 0x01
|
||||
#define A_MAX 0x02
|
||||
#define A_RESTORE 0x04
|
||||
#define A_POS 0x08
|
||||
#define A_SIZE 0x10
|
||||
#define A_CLOSE 0x20
|
||||
|
||||
|
||||
/*service funciton to perform actions on windows
|
||||
|
||||
param is a string to parse for options/actions
|
||||
hWnd is the handle of window on wich perform actions
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* service function to perform actions on windows
|
||||
*
|
||||
* param is a string to parse for options/actions
|
||||
* hWnd is the handle of window on which to perform actions
|
||||
*/
|
||||
static INT ServiceActivate (LPTSTR param, HWND hWnd)
|
||||
{
|
||||
LPTSTR *p = 0, p_tmp;
|
||||
INT argc = 0, i;
|
||||
INT iAction = 0;
|
||||
LPTSTR title = 0;
|
||||
WINDOWPLACEMENT wp;
|
||||
RECT pos;
|
||||
LPTSTR tmp;
|
||||
LPTSTR *p = 0, p_tmp;
|
||||
INT argc = 0, i;
|
||||
INT iAction = 0;
|
||||
LPTSTR title = 0;
|
||||
WINDOWPLACEMENT wp;
|
||||
RECT pos;
|
||||
LPTSTR tmp;
|
||||
|
||||
if (*param)
|
||||
p = split(param, &argc, FALSE);
|
||||
|
||||
if (*param)
|
||||
p = split(param, &argc, FALSE);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
p_tmp = p[i];
|
||||
if (*p_tmp == _T('/'))
|
||||
p_tmp++;
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
p_tmp = p[i];
|
||||
if (*p_tmp == _T('/'))
|
||||
p_tmp++;
|
||||
if (_tcsicmp(p_tmp, _T("min")) == 0)
|
||||
{
|
||||
iAction |= A_MIN;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_tcsicmp(p_tmp, _T("min")) == 0)
|
||||
{
|
||||
iAction |= A_MIN;
|
||||
continue;
|
||||
}
|
||||
if (_tcsicmp(p_tmp, _T("max")) == 0)
|
||||
{
|
||||
iAction |= A_MAX;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_tcsicmp(p_tmp, _T("max")) == 0)
|
||||
{
|
||||
iAction |= A_MAX;
|
||||
continue;
|
||||
}
|
||||
if (_tcsicmp(p_tmp, _T("restore")) == 0)
|
||||
{
|
||||
iAction |= A_RESTORE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_tcsicmp(p_tmp, _T("restore")) == 0)
|
||||
{
|
||||
iAction |= A_RESTORE;
|
||||
continue;
|
||||
}
|
||||
if (_tcsicmp(p_tmp, _T("close")) == 0)
|
||||
{
|
||||
iAction |= A_CLOSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_tcsicmp(p_tmp, _T("close")) == 0)
|
||||
{
|
||||
iAction |= A_CLOSE;
|
||||
continue;
|
||||
}
|
||||
if (_tcsnicmp(p_tmp, _T("pos"), 3) == 0)
|
||||
{
|
||||
iAction |= A_POS;
|
||||
tmp = p_tmp+3;
|
||||
if (*tmp == _T('='))
|
||||
tmp++;
|
||||
|
||||
if (_tcsnicmp(p_tmp, _T("pos"), 3) == 0)
|
||||
{
|
||||
iAction |= A_POS;
|
||||
tmp = p_tmp+3;
|
||||
if (*tmp == _T('='))
|
||||
tmp++;
|
||||
pos.left= _ttoi(tmp);
|
||||
if(!(tmp=_tcschr(tmp, _T(','))))
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pos.left= _ttoi(tmp);
|
||||
if(!(tmp=_tcschr(tmp, _T(','))))
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
pos.top = _ttoi (++tmp);
|
||||
if(!(tmp=_tcschr(tmp, _T(','))))
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pos.top = _ttoi (++tmp);
|
||||
if(!(tmp=_tcschr(tmp, _T(','))))
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
pos.right = _ttoi(++tmp) + pos.left;
|
||||
if (!(tmp = _tcschr(tmp, _T(','))))
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
pos.bottom = _ttoi(++tmp) + pos.top;
|
||||
continue;
|
||||
}
|
||||
|
||||
pos.right = _ttoi(++tmp) + pos.left;
|
||||
if (!(tmp = _tcschr(tmp, _T(','))))
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
pos.bottom = _ttoi(++tmp) + pos.top;
|
||||
continue;
|
||||
}
|
||||
if (_tcsnicmp(p_tmp, _T("size"), 4)==0)
|
||||
{
|
||||
iAction |=A_SIZE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_tcsnicmp(p_tmp, _T("size"), 4)==0)
|
||||
{
|
||||
iAction |=A_SIZE;
|
||||
continue;
|
||||
}
|
||||
/* none of them=window title */
|
||||
if (title)
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* none of them=window title */
|
||||
if (title)
|
||||
{
|
||||
error_invalid_parameter_format(p[i]);
|
||||
freep(p);
|
||||
return 1;
|
||||
}
|
||||
if (p_tmp[0] == _T('"'))
|
||||
{
|
||||
title = (p_tmp + 1);
|
||||
*_tcschr(p_tmp + 1, _T('"')) = 0;
|
||||
continue;
|
||||
}
|
||||
title = p_tmp;
|
||||
}
|
||||
|
||||
if (p_tmp[0] == _T('"'))
|
||||
{
|
||||
title = (p_tmp + 1);
|
||||
*_tcschr(p_tmp + 1, _T('"')) = 0;
|
||||
continue;
|
||||
}
|
||||
title = p_tmp;
|
||||
}
|
||||
if (title)
|
||||
SetWindowText(hWnd, title);
|
||||
|
||||
if (title)
|
||||
SetWindowText(hWnd, title);
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
GetWindowPlacement(hWnd, &wp);
|
||||
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
GetWindowPlacement(hWnd, &wp);
|
||||
if (iAction & A_POS)
|
||||
wp.rcNormalPosition = pos;
|
||||
|
||||
if (iAction & A_POS)
|
||||
wp.rcNormalPosition = pos;
|
||||
if (iAction & A_MIN)
|
||||
wp.showCmd = SW_MINIMIZE;
|
||||
|
||||
if (iAction & A_MIN)
|
||||
wp.showCmd = SW_MINIMIZE;
|
||||
if (iAction & A_MAX)
|
||||
wp.showCmd = SW_SHOWMAXIMIZED;
|
||||
|
||||
if (iAction & A_MAX)
|
||||
wp.showCmd = SW_SHOWMAXIMIZED;
|
||||
/* if no actions are specified default is SW_RESTORE */
|
||||
if ((iAction & A_RESTORE) || (!iAction))
|
||||
wp.showCmd = SW_RESTORE;
|
||||
|
||||
/*if no actions are specified default is SW_RESTORE*/
|
||||
if ((iAction & A_RESTORE) || (!iAction))
|
||||
wp.showCmd = SW_RESTORE;
|
||||
if (iAction & A_CLOSE)
|
||||
{
|
||||
FIXME("!!!FIXME: CLOSE Not implemented!!!\n");
|
||||
}
|
||||
|
||||
if (iAction & A_CLOSE)
|
||||
{
|
||||
FIXME("!!!FIXME: CLOSE Not implemented!!!\n");
|
||||
}
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
SetWindowPlacement(hWnd, &wp);
|
||||
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
SetWindowPlacement(hWnd, &wp);
|
||||
if (p)
|
||||
freep(p);
|
||||
|
||||
if (p)
|
||||
freep(p);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -174,54 +172,54 @@ static INT ServiceActivate (LPTSTR param, HWND hWnd)
|
|||
|
||||
INT CommandWindow (LPTSTR param)
|
||||
{
|
||||
HWND hwnd;
|
||||
HWND hwnd;
|
||||
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_WINDOW_HELP1);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
hwnd = GetConsoleWindow();
|
||||
Sleep(0);
|
||||
return ServiceActivate(param, hwnd);
|
||||
hwnd = GetConsoleWindow();
|
||||
Sleep(0);
|
||||
return ServiceActivate(param, hwnd);
|
||||
}
|
||||
|
||||
|
||||
INT CommandActivate (LPTSTR param)
|
||||
{
|
||||
HWND hwnd;
|
||||
LPTSTR *arg;
|
||||
INT argc;
|
||||
HWND hwnd;
|
||||
LPTSTR *arg;
|
||||
INT argc;
|
||||
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_WINDOW_HELP2);
|
||||
return 0;
|
||||
}
|
||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_WINDOW_HELP2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!(*param))
|
||||
return 1;
|
||||
if(!(*param))
|
||||
return 1;
|
||||
|
||||
/*Split the user input into array*/
|
||||
arg = split (param, &argc, FALSE);
|
||||
if(argc < 2)
|
||||
{
|
||||
if(arg != NULL)
|
||||
freep(arg);
|
||||
}
|
||||
hwnd = FindWindow(NULL, arg[0]);
|
||||
if (hwnd == NULL)
|
||||
{
|
||||
if(arg != NULL)
|
||||
freep(arg);
|
||||
ConErrResPuts(STRING_WINDOW_ERROR1);
|
||||
return 1;
|
||||
}
|
||||
if(arg != NULL)
|
||||
freep(arg);
|
||||
/* Split the user input into array */
|
||||
arg = split (param, &argc, FALSE);
|
||||
if(argc < 2)
|
||||
{
|
||||
if(arg != NULL)
|
||||
freep(arg);
|
||||
}
|
||||
hwnd = FindWindow(NULL, arg[0]);
|
||||
if (hwnd == NULL)
|
||||
{
|
||||
if(arg != NULL)
|
||||
freep(arg);
|
||||
ConErrResPuts(STRING_WINDOW_ERROR1);
|
||||
return 1;
|
||||
}
|
||||
if(arg != NULL)
|
||||
freep(arg);
|
||||
|
||||
return ServiceActivate(param, hwnd);
|
||||
return ServiceActivate(param, hwnd);
|
||||
}
|
||||
|
||||
#endif /* ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) ) */
|
||||
#endif /* defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) */
|
||||
|
|
Loading…
Reference in a new issue