Fix whitespace (part 2/x) (convert tabs into 4-space indent).

svn path=/trunk/; revision=59378
This commit is contained in:
Hermès Bélusca-Maïto 2013-06-29 23:50:13 +00:00
parent b067add889
commit 9b6dc5bd15
21 changed files with 2581 additions and 2573 deletions

View file

@ -1,38 +1,37 @@
/* /*
* BATCH.H - A structure to preserve the context of a batch file * BATCH.H - A structure to preserve the context of a batch file
*
*
*/ */
#pragma once #pragma once
typedef struct tagBATCHCONTEXT typedef struct tagBATCHCONTEXT
{ {
struct tagBATCHCONTEXT *prev; struct tagBATCHCONTEXT *prev;
char *mem; /* batchfile content in memory */ char *mem; /* batchfile content in memory */
DWORD memsize; /* size of batchfile */ DWORD memsize; /* size of batchfile */
DWORD mempos; /* current position to read from */ DWORD mempos; /* current position to read from */
BOOL memfree; /* true if it need to be freed when exitbatch is called */ BOOL memfree; /* true if it need to be freed when exitbatch is called */
TCHAR BatchFilePath[MAX_PATH]; TCHAR BatchFilePath[MAX_PATH];
LPTSTR params; LPTSTR params;
LPTSTR raw_params; /* Holds the raw params given by the input */ LPTSTR raw_params; /* Holds the raw params given by the input */
INT shiftlevel[10]; INT shiftlevel[10];
BOOL bEcho; /* Preserve echo flag across batch calls */ BOOL bEcho; /* Preserve echo flag across batch calls */
REDIRECTION *RedirList; REDIRECTION *RedirList;
PARSED_COMMAND *current; PARSED_COMMAND *current;
struct _SETLOCAL *setlocal; struct _SETLOCAL *setlocal;
} BATCH_CONTEXT, *LPBATCH_CONTEXT; } BATCH_CONTEXT, *LPBATCH_CONTEXT;
typedef struct tagFORCONTEXT typedef struct tagFORCONTEXT
{ {
struct tagFORCONTEXT *prev; struct tagFORCONTEXT *prev;
TCHAR firstvar; TCHAR firstvar;
UINT varcount; UINT varcount;
LPTSTR *values; LPTSTR *values;
} FOR_CONTEXT, *LPFOR_CONTEXT; } FOR_CONTEXT, *LPFOR_CONTEXT;
/* The stack of current batch contexts. /*
* The stack of current batch contexts.
* NULL when no batch is active * NULL when no batch is active
*/ */
extern LPBATCH_CONTEXT bc; extern LPBATCH_CONTEXT bc;

View file

@ -129,12 +129,12 @@ BOOL ReadCommand (LPTSTR, INT);
typedef struct tagCOMMAND typedef struct tagCOMMAND
{ {
LPTSTR name; LPTSTR name;
INT flags; INT flags;
INT (*func)(LPTSTR); INT (*func)(LPTSTR);
} COMMAND, *LPCOMMAND; } COMMAND, *LPCOMMAND;
extern COMMAND cmds[]; /* The internal command table */ extern COMMAND cmds[]; /* The internal command table */
VOID PrintCommandList (VOID); VOID PrintCommandList (VOID);
VOID PrintCommandListDetail (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 }; enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
typedef struct _PARSED_COMMAND typedef struct _PARSED_COMMAND
{ {
struct _PARSED_COMMAND *Subcommands; struct _PARSED_COMMAND *Subcommands;
struct _PARSED_COMMAND *Next; struct _PARSED_COMMAND *Next;
struct _REDIRECTION *Redirections; struct _REDIRECTION *Redirections;
BYTE Type; BYTE Type;
union union
{ {
struct struct
{ {
TCHAR *Rest; TCHAR *Rest;
TCHAR First[]; TCHAR First[];
} Command; } Command;
struct struct
{ {
BYTE Flags; BYTE Flags;
BYTE Operator; BYTE Operator;
TCHAR *LeftArg; TCHAR *LeftArg;
TCHAR *RightArg; TCHAR *RightArg;
} If; } If;
struct struct
{ {
BYTE Switches; BYTE Switches;
TCHAR Variable; TCHAR Variable;
LPTSTR Params; LPTSTR Params;
LPTSTR List; LPTSTR List;
struct tagFORCONTEXT *Context; struct tagFORCONTEXT *Context;
} For; } For;
}; };
} PARSED_COMMAND; } PARSED_COMMAND;
PARSED_COMMAND *ParseCommand(LPTSTR Line); PARSED_COMMAND *ParseCommand(LPTSTR Line);
VOID EchoCommand(PARSED_COMMAND *Cmd); VOID EchoCommand(PARSED_COMMAND *Cmd);
@ -412,17 +412,17 @@ INT cmd_prompt (LPTSTR);
/* Prototypes for REDIR.C */ /* Prototypes for REDIR.C */
typedef enum _REDIR_MODE typedef enum _REDIR_MODE
{ {
REDIR_READ = 0, REDIR_READ = 0,
REDIR_WRITE = 1, REDIR_WRITE = 1,
REDIR_APPEND = 2 REDIR_APPEND = 2
} REDIR_MODE; } REDIR_MODE;
typedef struct _REDIRECTION typedef struct _REDIRECTION
{ {
struct _REDIRECTION *Next; struct _REDIRECTION *Next;
HANDLE OldHandle; HANDLE OldHandle;
BYTE Number; BYTE Number;
REDIR_MODE Mode; REDIR_MODE Mode;
TCHAR Filename[]; TCHAR Filename[];
} REDIRECTION; } REDIRECTION;
BOOL PerformRedirection(REDIRECTION *); BOOL PerformRedirection(REDIRECTION *);
VOID UndoRedirection(REDIRECTION *, REDIRECTION *End); VOID UndoRedirection(REDIRECTION *, REDIRECTION *End);

View file

@ -43,8 +43,8 @@
* 24-Jan-1999 (Eric Kohl) * 24-Jan-1999 (Eric Kohl)
* Fixed Win32 environment handling. * Fixed Win32 environment handling.
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #include "precomp.h"
@ -53,133 +53,133 @@
*/ */
VOID PrintPrompt(VOID) VOID PrintPrompt(VOID)
{ {
static TCHAR default_pr[] = _T("$P$G"); static TCHAR default_pr[] = _T("$P$G");
TCHAR szPrompt[256]; TCHAR szPrompt[256];
LPTSTR pr; LPTSTR pr;
if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256)) if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
pr = szPrompt; pr = szPrompt;
else else
pr = default_pr; pr = default_pr;
while (*pr) while (*pr)
{ {
if (*pr != _T('$')) if (*pr != _T('$'))
{ {
ConOutChar (*pr); ConOutChar (*pr);
} }
else else
{ {
pr++; pr++;
switch (_totupper (*pr)) switch (_totupper (*pr))
{ {
case _T('A'): case _T('A'):
ConOutChar (_T('&')); ConOutChar (_T('&'));
break; break;
case _T('B'): case _T('B'):
ConOutChar (_T('|')); ConOutChar (_T('|'));
break; break;
case _T('C'): case _T('C'):
ConOutChar (_T('(')); ConOutChar (_T('('));
break; break;
case _T('D'): case _T('D'):
ConOutPrintf(_T("%s"), GetDateString()); ConOutPrintf(_T("%s"), GetDateString());
break; break;
case _T('E'): case _T('E'):
ConOutChar (_T('\x1B')); ConOutChar (_T('\x1B'));
break; break;
case _T('F'): case _T('F'):
ConOutChar (_T(')')); ConOutChar (_T(')'));
break; break;
case _T('G'): case _T('G'):
ConOutChar (_T('>')); ConOutChar (_T('>'));
break; break;
case _T('H'): case _T('H'):
ConOutChar (_T('\x08')); ConOutChar (_T('\x08'));
ConOutChar (_T(' ')); ConOutChar (_T(' '));
ConOutChar (_T('\x08')); ConOutChar (_T('\x08'));
break; break;
case _T('L'): case _T('L'):
ConOutChar (_T('<')); ConOutChar (_T('<'));
break; break;
case _T('N'): case _T('N'):
{ {
TCHAR szPath[MAX_PATH]; TCHAR szPath[MAX_PATH];
GetCurrentDirectory (MAX_PATH, szPath); GetCurrentDirectory (MAX_PATH, szPath);
ConOutChar (szPath[0]); ConOutChar (szPath[0]);
} }
break; break;
case _T('P'): case _T('P'):
{ {
TCHAR szPath[MAX_PATH]; TCHAR szPath[MAX_PATH];
GetCurrentDirectory (MAX_PATH, szPath); GetCurrentDirectory (MAX_PATH, szPath);
ConOutPrintf (_T("%s"), szPath); ConOutPrintf (_T("%s"), szPath);
} }
break; break;
case _T('Q'): case _T('Q'):
ConOutChar (_T('=')); ConOutChar (_T('='));
break; break;
case _T('S'): case _T('S'):
ConOutChar (_T(' ')); ConOutChar (_T(' '));
break; break;
case _T('T'): case _T('T'):
ConOutPrintf(_T("%s"), GetTimeString()); ConOutPrintf(_T("%s"), GetTimeString());
break; break;
case _T('V'): case _T('V'):
switch (osvi.dwPlatformId) switch (osvi.dwPlatformId)
{ {
case VER_PLATFORM_WIN32_WINDOWS: case VER_PLATFORM_WIN32_WINDOWS:
if (osvi.dwMajorVersion == 4 && if (osvi.dwMajorVersion == 4 &&
osvi.dwMinorVersion == 1) osvi.dwMinorVersion == 1)
ConOutPrintf (_T("Windows 98")); ConOutPrintf (_T("Windows 98"));
else else
ConOutPrintf (_T("Windows 95")); ConOutPrintf (_T("Windows 95"));
break; break;
case VER_PLATFORM_WIN32_NT: case VER_PLATFORM_WIN32_NT:
ConOutPrintf (_T("Windows NT Version %lu.%lu"), ConOutPrintf (_T("Windows NT Version %lu.%lu"),
osvi.dwMajorVersion, osvi.dwMinorVersion); osvi.dwMajorVersion, osvi.dwMinorVersion);
break; break;
} }
break; break;
case _T('_'): case _T('_'):
ConOutChar (_T('\n')); ConOutChar (_T('\n'));
break; break;
case '$': case '$':
ConOutChar (_T('$')); ConOutChar (_T('$'));
break; break;
#ifdef FEATURE_DIRECTORY_STACK #ifdef FEATURE_DIRECTORY_STACK
case '+': case '+':
{ {
INT i; INT i;
for (i = 0; i < GetDirectoryStackDepth (); i++) for (i = 0; i < GetDirectoryStackDepth (); i++)
ConOutChar (_T('+')); ConOutChar (_T('+'));
} }
break; break;
#endif #endif
} }
} }
pr++; pr++;
} }
} }
@ -187,42 +187,42 @@ VOID PrintPrompt(VOID)
INT cmd_prompt (LPTSTR param) INT cmd_prompt (LPTSTR param)
{ {
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
ConOutResPaging(TRUE,STRING_PROMPT_HELP1); ConOutResPaging(TRUE,STRING_PROMPT_HELP1);
#ifdef FEATURE_DIRECTORY_STACK #ifdef FEATURE_DIRECTORY_STACK
ConOutResPaging(FALSE,STRING_PROMPT_HELP2); ConOutResPaging(FALSE,STRING_PROMPT_HELP2);
#endif #endif
ConOutResPaging(FALSE,STRING_PROMPT_HELP3); ConOutResPaging(FALSE,STRING_PROMPT_HELP3);
return 0; return 0;
} }
/* if it is null, then it needs to set to default, /*
because that means the user entered "prompt" only. * if it is null, then it needs to set to default,
so even if param is null you _must_ still set prompt * because that means the user entered "prompt" only.
to the default. There seems to be some kinda difference * so even if param is null you _must_ still set prompt
between winxp and 2k in this matter and this way will * to the default. There seems to be some kinda difference
cover both. Do not use fixed size of szParam for param the buffer are 8192bytes * between winxp and 2k in this matter and this way will
and will later change to dymatic buffer */ * 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 */ /* set PROMPT environment variable */
if (param[0] != _T('\0')) if (param[0] != _T('\0'))
{ {
if (!SetEnvironmentVariable (_T("PROMPT"), param)) if (!SetEnvironmentVariable (_T("PROMPT"), param))
return 1; return 1;
} }
else else
{ {
TCHAR szParam[5]; TCHAR szParam[5];
_tcscpy(szParam,_T("$P$G")); _tcscpy(szParam,_T("$P$G"));
if (!SetEnvironmentVariable (_T("PROMPT"),szParam)) if (!SetEnvironmentVariable (_T("PROMPT"),szParam))
return 1; return 1;
} }
return 0;
return 0;
} }
#endif #endif

View file

@ -36,121 +36,121 @@ static HANDLE ExtraHandles[10 - 3];
static HANDLE GetHandle(UINT Number) static HANDLE GetHandle(UINT Number)
{ {
if (Number < 3) if (Number < 3)
return GetStdHandle(STD_INPUT_HANDLE - Number); return GetStdHandle(STD_INPUT_HANDLE - Number);
else else
return ExtraHandles[Number - 3]; return ExtraHandles[Number - 3];
} }
static VOID SetHandle(UINT Number, HANDLE Handle) static VOID SetHandle(UINT Number, HANDLE Handle)
{ {
if (Number < 3) if (Number < 3)
SetStdHandle(STD_INPUT_HANDLE - Number, Handle); SetStdHandle(STD_INPUT_HANDLE - Number, Handle);
else else
ExtraHandles[Number - 3] = Handle; ExtraHandles[Number - 3] = Handle;
} }
BOOL BOOL
PerformRedirection(REDIRECTION *RedirList) PerformRedirection(REDIRECTION *RedirList)
{ {
REDIRECTION *Redir; REDIRECTION *Redir;
LPTSTR Filename; LPTSTR Filename;
HANDLE hNew; HANDLE hNew;
UINT DupNumber; UINT DupNumber;
static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
/* Some parameters used for read, write, and append, respectively */ /* Some parameters used for read, write, and append, respectively */
static static
struct REDIR_PARAMS struct REDIR_PARAMS
{ {
DWORD dwDesiredAccess; DWORD dwDesiredAccess;
DWORD dwShareMode; DWORD dwShareMode;
DWORD dwCreationDisposition; DWORD dwCreationDisposition;
} RedirParams[] = } RedirParams[] =
{ {
{GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING}, // REDIR_READ {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 , CREATE_ALWAYS}, // REDIR_WRITE
{GENERIC_WRITE, FILE_SHARE_READ , OPEN_ALWAYS } // REDIR_APPEND {GENERIC_WRITE, FILE_SHARE_READ , OPEN_ALWAYS } // REDIR_APPEND
}; };
for (Redir = RedirList; Redir; Redir = Redir->Next) for (Redir = RedirList; Redir; Redir = Redir->Next)
{ {
Filename = DoDelayedExpansion(Redir->Filename); Filename = DoDelayedExpansion(Redir->Filename);
if (!Filename) if (!Filename)
goto redir_error; goto redir_error;
StripQuotes(Filename); StripQuotes(Filename);
if (*Filename == _T('&')) if (*Filename == _T('&'))
{ {
DupNumber = Filename[1] - _T('0'); DupNumber = Filename[1] - _T('0');
if (DupNumber >= 10 || if (DupNumber >= 10 ||
!DuplicateHandle(GetCurrentProcess(), !DuplicateHandle(GetCurrentProcess(),
GetHandle(DupNumber), GetHandle(DupNumber),
GetCurrentProcess(), GetCurrentProcess(),
&hNew, &hNew,
0, 0,
TRUE, TRUE,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
hNew = INVALID_HANDLE_VALUE; hNew = INVALID_HANDLE_VALUE;
} }
} }
else else
{ {
hNew = CreateFile(Filename, hNew = CreateFile(Filename,
RedirParams[Redir->Mode].dwDesiredAccess, RedirParams[Redir->Mode].dwDesiredAccess,
RedirParams[Redir->Mode].dwShareMode, RedirParams[Redir->Mode].dwShareMode,
&SecAttr, &SecAttr,
RedirParams[Redir->Mode].dwCreationDisposition, RedirParams[Redir->Mode].dwCreationDisposition,
0, 0,
NULL); NULL);
} }
if (hNew == INVALID_HANDLE_VALUE) if (hNew == INVALID_HANDLE_VALUE)
{ {
/* TODO: Print a more detailed message */ /* TODO: Print a more detailed message */
ConErrResPrintf(Redir->Mode == REDIR_READ ? STRING_CMD_ERROR1 : STRING_CMD_ERROR3, ConErrResPrintf(Redir->Mode == REDIR_READ ? STRING_CMD_ERROR1 : STRING_CMD_ERROR3,
Filename); Filename);
cmd_free(Filename); cmd_free(Filename);
redir_error: redir_error:
/* Undo all the redirections before this one */ /* Undo all the redirections before this one */
UndoRedirection(RedirList, Redir); UndoRedirection(RedirList, Redir);
return FALSE; return FALSE;
} }
if (Redir->Mode == REDIR_APPEND) if (Redir->Mode == REDIR_APPEND)
SetFilePointer(hNew, 0, NULL, FILE_END); SetFilePointer(hNew, 0, NULL, FILE_END);
Redir->OldHandle = GetHandle(Redir->Number); Redir->OldHandle = GetHandle(Redir->Number);
SetHandle(Redir->Number, hNew); SetHandle(Redir->Number, hNew);
TRACE("%d redirected to: %s\n", Redir->Number, debugstr_aw(Filename)); TRACE("%d redirected to: %s\n", Redir->Number, debugstr_aw(Filename));
cmd_free(Filename); cmd_free(Filename);
} }
return TRUE; return TRUE;
} }
VOID VOID
UndoRedirection(REDIRECTION *Redir, REDIRECTION *End) UndoRedirection(REDIRECTION *Redir, REDIRECTION *End)
{ {
for (; Redir != End; Redir = Redir->Next) for (; Redir != End; Redir = Redir->Next)
{ {
CloseHandle(GetHandle(Redir->Number)); CloseHandle(GetHandle(Redir->Number));
SetHandle(Redir->Number, Redir->OldHandle); SetHandle(Redir->Number, Redir->OldHandle);
Redir->OldHandle = INVALID_HANDLE_VALUE; Redir->OldHandle = INVALID_HANDLE_VALUE;
} }
} }
VOID VOID
FreeRedirection(REDIRECTION *Redir) FreeRedirection(REDIRECTION *Redir)
{ {
REDIRECTION *Next; REDIRECTION *Next;
for (; Redir; Redir = Next) for (; Redir; Redir = Next)
{ {
Next = Redir->Next; Next = Redir->Next;
ASSERT(Redir->OldHandle == INVALID_HANDLE_VALUE); ASSERT(Redir->OldHandle == INVALID_HANDLE_VALUE);
cmd_free(Redir); cmd_free(Redir);
} }
} }
#endif /* FEATURE_REDIRECTION */ #endif /* FEATURE_REDIRECTION */

View file

@ -17,15 +17,16 @@
* 17-Oct-2001 (Eric Kohl) * 17-Oct-2001 (Eric Kohl)
* Implemented basic rename code. * Implemented basic rename code.
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * 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: * 25-Nov-2008 (Victor Martinez) <vicmarcal@hotmail.com> Patch dedicated to Myrjala because her comprenhension and love :D
* -Wrong behavior with wildcards when Source and Destiny are Paths(FIXED). * Fixing following Bugs:
* -Wrong general behavior (MSDN:"Rename cant move files between subdirectories")(FIXED) * -Wrong behavior with wildcards when Source and Destiny are Paths(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) * -Wrong general behavior (MSDN:"Rename cant move files between subdirectories")(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.) * -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)
* -Implemented checkings if SourcePath and DestinyPath are differents. * (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 enum
{ {
REN_ATTRIBUTES = 0x001, /* /A : not implemented */ REN_ATTRIBUTES = 0x001, /* /A : not implemented */
REN_ERROR = 0x002, /* /E */ REN_ERROR = 0x002, /* /E */
REN_NOTHING = 0x004, /* /N */ REN_NOTHING = 0x004, /* /N */
REN_PROMPT = 0x008, /* /P : not implemented */ REN_PROMPT = 0x008, /* /P : not implemented */
REN_QUIET = 0x010, /* /Q */ REN_QUIET = 0x010, /* /Q */
REN_SUBDIR = 0x020, /* /S */ REN_SUBDIR = 0x020, /* /S */
REN_TOTAL = 0x040, /* /T */ REN_TOTAL = 0x040, /* /T */
}; };
/* /*
* file rename internal command. * file rename internal command.
*
*/ */
INT cmd_rename (LPTSTR param) INT cmd_rename (LPTSTR param)
{ {
@ -59,13 +59,11 @@ INT cmd_rename (LPTSTR param)
DWORD dwFiles = 0; /* number of renamedd files */ DWORD dwFiles = 0; /* number of renamedd files */
INT i; INT i;
LPTSTR srcPattern = NULL; /* Source Argument*/ LPTSTR srcPattern = NULL; /* Source Argument*/
TCHAR srcPath[MAX_PATH]; /*Source Path Directories*/ TCHAR srcPath[MAX_PATH]; /*Source Path Directories*/
LPTSTR srcFILE = NULL; /*Contains the files name(s)*/ LPTSTR srcFILE = NULL; /*Contains the files name(s)*/
TCHAR srcFinal[MAX_PATH]; TCHAR srcFinal[MAX_PATH];
LPTSTR dstPattern = NULL; /*Destiny Argument*/ LPTSTR dstPattern = NULL; /*Destiny Argument*/
TCHAR dstPath[MAX_PATH]; /*Source Path Directories*/ TCHAR dstPath[MAX_PATH]; /*Source Path Directories*/
LPTSTR dstFILE = NULL; /*Contains the files name(s)*/ LPTSTR dstFILE = NULL; /*Contains the files name(s)*/
@ -76,11 +74,6 @@ INT cmd_rename (LPTSTR param)
BOOL bDstWildcard = FALSE; BOOL bDstWildcard = FALSE;
BOOL bPath = FALSE; BOOL bPath = FALSE;
LPTSTR p,q,r; LPTSTR p,q,r;
HANDLE hFile; HANDLE hFile;
@ -88,8 +81,6 @@ INT cmd_rename (LPTSTR param)
/*If the PARAM=/? then show the help*/ /*If the PARAM=/? then show the help*/
if (!_tcsncmp(param, _T("/?"), 2)) if (!_tcsncmp(param, _T("/?"), 2))
{ {
ConOutResPaging(TRUE,STRING_REN_HELP1); ConOutResPaging(TRUE,STRING_REN_HELP1);
return 0; return 0;
} }

File diff suppressed because it is too large Load diff

View file

@ -6,8 +6,8 @@
* 30 Aug 1999 * 30 Aug 1999
* started - Paolo Pantaleo <paolopan@freemail.it> * started - Paolo Pantaleo <paolopan@freemail.it>
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
* *
*/ */
@ -18,86 +18,86 @@
INT CommandScreen (LPTSTR param) INT CommandScreen (LPTSTR param)
{ {
SHORT x,y; SHORT x,y;
BOOL bSkipText = FALSE; BOOL bSkipText = FALSE;
if (_tcsncmp (param, _T("/?"), 2) == 0) if (_tcsncmp (param, _T("/?"), 2) == 0)
{ {
ConOutResPaging(TRUE,STRING_SCREEN_HELP); ConOutResPaging(TRUE,STRING_SCREEN_HELP);
return 0; return 0;
} }
nErrorLevel = 0; nErrorLevel = 0;
//get row //get row
while(_istspace(*param)) while(_istspace(*param))
param++; param++;
if(!(*param)) if(!(*param))
{ {
error_req_param_missing (); error_req_param_missing ();
return 1; return 1;
} }
y = _ttoi(param); y = _ttoi(param);
if (y<0 || y>(maxy-1)) if (y<0 || y>(maxy-1))
{ {
ConOutResPuts(STRING_SCREEN_ROW); ConOutResPuts(STRING_SCREEN_ROW);
return 1; return 1;
} }
//get col //get col
if(!(param = _tcschr(param,_T(' ')))) if(!(param = _tcschr(param,_T(' '))))
{ {
error_req_param_missing (); error_req_param_missing ();
return 1; return 1;
} }
while(_istspace(*param)) while(_istspace(*param))
param++; param++;
if(!(*param)) if(!(*param))
{ {
error_req_param_missing (); error_req_param_missing ();
return 1; return 1;
} }
x = _ttoi(param); x = _ttoi(param);
if (x<0 || x>(maxx-1)) if (x<0 || x>(maxx-1))
{ {
ConErrResPuts(STRING_SCREEN_COL); ConErrResPuts(STRING_SCREEN_COL);
return 1; return 1;
} }
//get text //get text
if(!(param = _tcschr(param,_T(' ')))) if(!(param = _tcschr(param,_T(' '))))
{ {
bSkipText = TRUE; bSkipText = TRUE;
} }
else else
{ {
while(_istspace(*param)) while(_istspace(*param))
param++; param++;
if(!(*param)) if(!(*param))
{ {
bSkipText = TRUE; bSkipText = TRUE;
} }
} }
bIgnoreEcho = TRUE; bIgnoreEcho = TRUE;
if(bSkipText) if(bSkipText)
x=0; x=0;
SetCursorXY(x,y); SetCursorXY(x,y);
if(!(bSkipText)) if(!(bSkipText))
ConOutPuts(param); ConOutPuts(param);
return 0; return 0;
} }
#endif /* INCLUDE_CMD_SCREEN */ #endif /* INCLUDE_CMD_SCREEN */

View file

@ -30,8 +30,8 @@
* 25-Feb-1999 (Eric Kohl) * 25-Feb-1999 (Eric Kohl)
* Fixed little bug. * Fixed little bug.
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #include "precomp.h"
@ -48,9 +48,9 @@ seta_eval ( LPCTSTR expr );
static LPCTSTR static LPCTSTR
skip_ws ( LPCTSTR p ) skip_ws ( LPCTSTR p )
{ {
while (*p && *p <= _T(' ')) while (*p && *p <= _T(' '))
p++; p++;
return p; return p;
} }
/* Used to check for and handle: /* Used to check for and handle:
@ -58,163 +58,163 @@ skip_ws ( LPCTSTR p )
static LPTSTR static LPTSTR
GetQuotedString(TCHAR *p) GetQuotedString(TCHAR *p)
{ {
TCHAR *end; TCHAR *end;
if (*p == _T('"')) if (*p == _T('"'))
{ {
p = (LPTSTR)skip_ws(p + 1); p = (LPTSTR)skip_ws(p + 1);
/* If a matching quote is found, truncate the string */ /* If a matching quote is found, truncate the string */
end = _tcsrchr(p, _T('"')); end = _tcsrchr(p, _T('"'));
if (end) if (end)
*end = _T('\0'); *end = _T('\0');
} }
return p; return p;
} }
INT cmd_set (LPTSTR param) INT cmd_set (LPTSTR param)
{ {
LPTSTR p; LPTSTR p;
LPTSTR lpEnv; LPTSTR lpEnv;
LPTSTR lpOutput; LPTSTR lpOutput;
if ( !_tcsncmp (param, _T("/?"), 2) ) if ( !_tcsncmp (param, _T("/?"), 2) )
{ {
ConOutResPaging(TRUE,STRING_SET_HELP); ConOutResPaging(TRUE,STRING_SET_HELP);
return 0; return 0;
} }
param = (LPTSTR)skip_ws(param); param = (LPTSTR)skip_ws(param);
/* if no parameters, show the environment */ /* if no parameters, show the environment */
if (param[0] == _T('\0')) if (param[0] == _T('\0'))
{ {
lpEnv = (LPTSTR)GetEnvironmentStrings (); lpEnv = (LPTSTR)GetEnvironmentStrings ();
if (lpEnv) if (lpEnv)
{ {
lpOutput = lpEnv; lpOutput = lpEnv;
while (*lpOutput) while (*lpOutput)
{ {
if (*lpOutput != _T('=')) if (*lpOutput != _T('='))
ConOutPuts(lpOutput); ConOutPuts(lpOutput);
lpOutput += _tcslen(lpOutput) + 1; lpOutput += _tcslen(lpOutput) + 1;
ConOutPuts(_T("\r\n")); ConOutPuts(_T("\r\n"));
} }
FreeEnvironmentStrings (lpEnv); FreeEnvironmentStrings (lpEnv);
} }
return 0; return 0;
} }
/* the /A does *NOT* have to be followed by a whitespace */ /* the /A does *NOT* have to be followed by a whitespace */
if ( !_tcsnicmp (param, _T("/A"), 2) ) if ( !_tcsnicmp (param, _T("/A"), 2) )
{ {
BOOL Success; BOOL Success;
StripQuotes(param); StripQuotes(param);
Success = seta_eval ( skip_ws(param+2) ); Success = seta_eval ( skip_ws(param+2) );
if(!Success) if(!Success)
{ {
/*might seem random but this is what windows xp does */ /*might seem random but this is what windows xp does */
nErrorLevel = 9165; nErrorLevel = 9165;
} }
return !Success; return !Success;
} }
if (!_tcsnicmp(param, _T("/P"), 2)) if (!_tcsnicmp(param, _T("/P"), 2))
{ {
TCHAR value[1023]; TCHAR value[1023];
param = GetQuotedString((LPTSTR)skip_ws(param + 2)); param = GetQuotedString((LPTSTR)skip_ws(param + 2));
p = _tcschr(param, _T('=')); p = _tcschr(param, _T('='));
if (!p) if (!p)
{ {
ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT); ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
*p++ = _T('\0'); *p++ = _T('\0');
ConOutPrintf(_T("%s"), GetQuotedString(p)); ConOutPrintf(_T("%s"), GetQuotedString(p));
ConInString(value, 1023); ConInString(value, 1023);
if (!*value || !SetEnvironmentVariable(param, value)) if (!*value || !SetEnvironmentVariable(param, value))
{ {
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
return 0; return 0;
} }
param = GetQuotedString(param); param = GetQuotedString(param);
p = _tcschr (param, _T('=')); p = _tcschr (param, _T('='));
if (p) if (p)
{ {
/* set or remove environment variable */ /* set or remove environment variable */
if (p == param) if (p == param)
{ {
/* handle set =val case */ /* handle set =val case */
ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT); ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
*p++ = _T('\0'); *p++ = _T('\0');
if (!SetEnvironmentVariable(param, *p ? p : NULL)) if (!SetEnvironmentVariable(param, *p ? p : NULL))
{ {
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
} }
else else
{ {
/* display all environment variable with the given prefix */ /* display all environment variable with the given prefix */
BOOL bFound = FALSE; BOOL bFound = FALSE;
while (_istspace(*param) || *param == _T(',') || *param == _T(';')) while (_istspace(*param) || *param == _T(',') || *param == _T(';'))
param++; param++;
p = _tcsrchr(param, _T(' ')); p = _tcsrchr(param, _T(' '));
if (!p) if (!p)
p = param + _tcslen(param); p = param + _tcslen(param);
*p = _T('\0'); *p = _T('\0');
lpEnv = GetEnvironmentStrings(); lpEnv = GetEnvironmentStrings();
if (lpEnv) if (lpEnv)
{ {
lpOutput = lpEnv; lpOutput = lpEnv;
while (*lpOutput) while (*lpOutput)
{ {
if (!_tcsnicmp(lpOutput, param, p - param)) if (!_tcsnicmp(lpOutput, param, p - param))
{ {
ConOutPuts(lpOutput); ConOutPuts(lpOutput);
ConOutPuts(_T("\r\n")); ConOutPuts(_T("\r\n"));
bFound = TRUE; bFound = TRUE;
} }
lpOutput += _tcslen(lpOutput) + 1; lpOutput += _tcslen(lpOutput) + 1;
} }
FreeEnvironmentStrings(lpEnv); FreeEnvironmentStrings(lpEnv);
} }
if (!bFound) if (!bFound)
{ {
ConErrResPrintf (STRING_PATH_ERROR, param); ConErrResPrintf (STRING_PATH_ERROR, param);
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
} }
return 0; return 0;
} }
static INT static INT
ident_len ( LPCTSTR p ) ident_len(LPCTSTR p)
{ {
LPCTSTR p2 = p; LPCTSTR p2 = p;
if ( __iscsymf(*p) ) if ( __iscsymf(*p) )
{ {
++p2; ++p2;
while ( __iscsym(*p2) ) while ( __iscsym(*p2) )
++p2; ++p2;
} }
return (INT)(p2-p); return (INT)(p2-p);
} }
#define PARSE_IDENT(ident,identlen,p) \ #define PARSE_IDENT(ident,identlen,p) \
@ -225,318 +225,318 @@ ident_len ( LPCTSTR p )
p += identlen; p += identlen;
static BOOL static BOOL
seta_identval ( LPCTSTR ident, INT* result ) seta_identval(LPCTSTR ident, INT* result)
{ {
LPCTSTR identVal = GetEnvVarOrSpecial ( ident ); LPCTSTR identVal = GetEnvVarOrSpecial ( ident );
if ( !identVal ) if ( !identVal )
{ {
/* TODO FIXME - what to do upon failure? */ /* TODO FIXME - what to do upon failure? */
*result = 0; *result = 0;
return FALSE; return FALSE;
} }
*result = _tcstol ( identVal, NULL, 0 ); *result = _tcstol ( identVal, NULL, 0 );
return TRUE; return TRUE;
} }
static BOOL static BOOL
calc ( INT* lval, TCHAR op, INT rval ) calc(INT* lval, TCHAR op, INT rval)
{ {
switch ( op ) switch ( op )
{ {
case '*': case '*':
*lval *= rval; *lval *= rval;
break; break;
case '/': case '/':
*lval /= rval; *lval /= rval;
break; break;
case '%': case '%':
*lval %= rval; *lval %= rval;
break; break;
case '+': case '+':
*lval += rval; *lval += rval;
break; break;
case '-': case '-':
*lval -= rval; *lval -= rval;
break; break;
case '&': case '&':
*lval &= rval; *lval &= rval;
break; break;
case '^': case '^':
*lval ^= rval; *lval ^= rval;
break; break;
case '|': case '|':
*lval |= rval; *lval |= rval;
break; break;
default: default:
ConErrResPuts ( STRING_INVALID_OPERAND ); ConErrResPuts ( STRING_INVALID_OPERAND );
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
static BOOL static BOOL
seta_stmt ( LPCTSTR* p_, INT* result ); seta_stmt (LPCTSTR* p_, INT* result);
static BOOL static BOOL
seta_unaryTerm ( LPCTSTR* p_, INT* result ) seta_unaryTerm(LPCTSTR* p_, INT* result)
{ {
LPCTSTR p = *p_; LPCTSTR p = *p_;
if ( *p == _T('(') ) if ( *p == _T('(') )
{ {
INT rval; INT rval;
p = skip_ws ( p + 1 ); p = skip_ws ( p + 1 );
if ( !seta_stmt ( &p, &rval ) ) if ( !seta_stmt ( &p, &rval ) )
return FALSE; return FALSE;
if ( *p++ != _T(')') ) if ( *p++ != _T(')') )
{ {
ConErrResPuts ( STRING_EXPECTED_CLOSE_PAREN ); ConErrResPuts ( STRING_EXPECTED_CLOSE_PAREN );
return FALSE; return FALSE;
} }
*result = rval; *result = rval;
} }
else if ( isdigit(*p) ) else if ( isdigit(*p) )
{ {
*result = _tcstol ( p, (LPTSTR *)&p, 0 ); *result = _tcstol ( p, (LPTSTR *)&p, 0 );
} }
else if ( __iscsymf(*p) ) else if ( __iscsymf(*p) )
{ {
LPTSTR ident; LPTSTR ident;
INT identlen; INT identlen;
PARSE_IDENT(ident,identlen,p); PARSE_IDENT(ident,identlen,p);
if ( !seta_identval ( ident, result ) ) if ( !seta_identval ( ident, result ) )
return FALSE; return FALSE;
} }
else else
{ {
ConErrResPuts ( STRING_EXPECTED_NUMBER_OR_VARIABLE ); ConErrResPuts ( STRING_EXPECTED_NUMBER_OR_VARIABLE );
return FALSE; return FALSE;
} }
*p_ = skip_ws ( p ); *p_ = skip_ws ( p );
return TRUE; return TRUE;
} }
static BOOL static BOOL
seta_mulTerm ( LPCTSTR* p_, INT* result ) seta_mulTerm(LPCTSTR* p_, INT* result)
{ {
LPCTSTR p = *p_; LPCTSTR p = *p_;
TCHAR op = 0; TCHAR op = 0;
INT rval; INT rval;
if ( _tcschr(_T("!~-"),*p) ) if ( _tcschr(_T("!~-"),*p) )
{ {
op = *p; op = *p;
p = skip_ws ( p + 1 ); p = skip_ws ( p + 1 );
} }
if ( !seta_unaryTerm ( &p, &rval ) ) if ( !seta_unaryTerm ( &p, &rval ) )
return FALSE; return FALSE;
switch ( op ) switch ( op )
{ {
case '!': case '!':
rval = !rval; rval = !rval;
break; break;
case '~': case '~':
rval = ~rval; rval = ~rval;
break; break;
case '-': case '-':
rval = -rval; rval = -rval;
break; break;
} }
*result = rval; *result = rval;
*p_ = p; *p_ = p;
return TRUE; return TRUE;
} }
static BOOL 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_; LPCTSTR p = *p_;
INT lval; INT lval;
if ( !subTerm ( &p, &lval ) ) if ( !subTerm ( &p, &lval ) )
return FALSE; return FALSE;
while ( *p && _tcschr(ops,*p) ) while ( *p && _tcschr(ops,*p) )
{ {
INT rval; INT rval;
TCHAR op = *p; TCHAR op = *p;
p = skip_ws ( p+1 ); p = skip_ws ( p+1 );
if ( !subTerm ( &p, &rval ) ) if ( !subTerm ( &p, &rval ) )
return FALSE; return FALSE;
if ( !calc ( &lval, op, rval ) ) if ( !calc ( &lval, op, rval ) )
return FALSE; return FALSE;
} }
*result = lval; *result = lval;
*p_ = p; *p_ = p;
return TRUE; return TRUE;
} }
static BOOL 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 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 static BOOL
seta_bitAndTerm ( LPCTSTR* p_, INT* result ) seta_bitAndTerm(LPCTSTR* p_, INT* result)
{ {
LPCTSTR p = *p_; LPCTSTR p = *p_;
INT lval; INT lval;
if ( !seta_logShiftTerm ( &p, &lval ) ) if ( !seta_logShiftTerm ( &p, &lval ) )
return FALSE; return FALSE;
while ( *p && _tcschr(_T("<>"),*p) && p[0] == p[1] ) while ( *p && _tcschr(_T("<>"),*p) && p[0] == p[1] )
{ {
INT rval; INT rval;
TCHAR op = *p; TCHAR op = *p;
p = skip_ws ( p+2 ); p = skip_ws ( p+2 );
if ( !seta_logShiftTerm ( &p, &rval ) ) if ( !seta_logShiftTerm ( &p, &rval ) )
return FALSE; return FALSE;
switch ( op ) switch ( op )
{ {
case '<': case '<':
lval <<= rval; lval <<= rval;
break; break;
case '>': case '>':
lval >>= rval; lval >>= rval;
break; break;
default: default:
ConErrResPuts ( STRING_INVALID_OPERAND ); ConErrResPuts ( STRING_INVALID_OPERAND );
return FALSE; return FALSE;
} }
} }
*result = lval; *result = lval;
*p_ = p; *p_ = p;
return TRUE; return TRUE;
} }
static BOOL 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 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 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 static BOOL
seta_assignment ( LPCTSTR* p_, INT* result ) seta_assignment(LPCTSTR* p_, INT* result)
{ {
LPCTSTR p = *p_; LPCTSTR p = *p_;
LPTSTR ident; LPTSTR ident;
TCHAR op = 0; TCHAR op = 0;
INT identlen, exprval; INT identlen, exprval;
PARSE_IDENT(ident,identlen,p); PARSE_IDENT(ident,identlen,p);
if ( identlen ) if ( identlen )
{ {
p = skip_ws(p); p = skip_ws(p);
if ( *p == _T('=') ) if ( *p == _T('=') )
op = *p, p = skip_ws(p+1); op = *p, p = skip_ws(p+1);
else if ( _tcschr ( _T("*/%+-&^|"), *p ) && p[1] == _T('=') ) else if ( _tcschr ( _T("*/%+-&^|"), *p ) && p[1] == _T('=') )
op = *p, p = skip_ws(p+2); op = *p, p = skip_ws(p+2);
else if ( _tcschr ( _T("<>"), *p ) && *p == p[1] && p[2] == _T('=') ) else if ( _tcschr ( _T("<>"), *p ) && *p == p[1] && p[2] == _T('=') )
op = *p, p = skip_ws(p+3); op = *p, p = skip_ws(p+3);
} }
/* allow to chain multiple assignments, such as: a=b=1 */ /* allow to chain multiple assignments, such as: a=b=1 */
if ( ident && op ) if ( ident && op )
{ {
INT identval; INT identval;
LPTSTR buf; LPTSTR buf;
if ( !seta_assignment ( &p, &exprval ) ) if ( !seta_assignment ( &p, &exprval ) )
return FALSE; return FALSE;
if ( !seta_identval ( ident, &identval ) ) if ( !seta_identval ( ident, &identval ) )
identval = 0; identval = 0;
switch ( op ) switch ( op )
{ {
case '=': case '=':
identval = exprval; identval = exprval;
break; break;
case '<': case '<':
identval <<= exprval; identval <<= exprval;
break; break;
case '>': case '>':
identval >>= exprval; identval >>= exprval;
break; break;
default: default:
if ( !calc ( &identval, op, exprval ) ) if ( !calc ( &identval, op, exprval ) )
return FALSE; return FALSE;
} }
buf = (LPTSTR)alloca ( 32 * sizeof(TCHAR) ); buf = (LPTSTR)alloca ( 32 * sizeof(TCHAR) );
_sntprintf ( buf, 32, _T("%i"), identval ); _sntprintf ( buf, 32, _T("%i"), identval );
SetEnvironmentVariable ( ident, buf ); // TODO FIXME - check return value SetEnvironmentVariable ( ident, buf ); // TODO FIXME - check return value
exprval = identval; exprval = identval;
} }
else else
{ {
/* restore p in case we found an ident but not an op */ /* restore p in case we found an ident but not an op */
p = *p_; p = *p_;
if ( !seta_expr ( &p, &exprval ) ) if ( !seta_expr ( &p, &exprval ) )
return FALSE; return FALSE;
} }
*result = exprval; *result = exprval;
*p_ = p; *p_ = p;
return TRUE; return TRUE;
} }
static BOOL static BOOL
seta_stmt ( LPCTSTR* p_, INT* result ) seta_stmt(LPCTSTR* p_, INT* result)
{ {
LPCTSTR p = *p_; LPCTSTR p = *p_;
INT rval; INT rval;
if ( !seta_assignment ( &p, &rval ) ) if ( !seta_assignment ( &p, &rval ) )
return FALSE; return FALSE;
while ( *p == _T(',') ) while ( *p == _T(',') )
{ {
p = skip_ws ( p+1 ); p = skip_ws ( p+1 );
if ( !seta_assignment ( &p, &rval ) ) if ( !seta_assignment ( &p, &rval ) )
return FALSE; return FALSE;
} }
*result = rval; *result = rval;
*p_ = p; *p_ = p;
return TRUE; return TRUE;
} }
static BOOL static BOOL
seta_eval ( LPCTSTR p ) seta_eval(LPCTSTR p)
{ {
INT rval; INT rval;
if ( !*p ) if ( !*p )
{ {
ConErrResPuts ( STRING_SYNTAX_COMMAND_INCORRECT ); ConErrResPuts ( STRING_SYNTAX_COMMAND_INCORRECT );
return FALSE; return FALSE;
} }
if ( !seta_stmt ( &p, &rval ) ) if ( !seta_stmt ( &p, &rval ) )
return FALSE; return FALSE;
if ( !bc ) if ( !bc )
ConOutPrintf ( _T("%i"), rval ); ConOutPrintf ( _T("%i"), rval );
return TRUE; return TRUE;
} }
#endif #endif

View file

@ -9,121 +9,124 @@
#include "precomp.h" #include "precomp.h"
typedef struct _SETLOCAL { typedef struct _SETLOCAL
struct _SETLOCAL *Prev; {
BOOL DelayedExpansion; struct _SETLOCAL *Prev;
LPTSTR Environment; BOOL DelayedExpansion;
LPTSTR Environment;
} SETLOCAL; } SETLOCAL;
/* Create a copy of the current environment */ /* Create a copy of the current environment */
LPTSTR LPTSTR
DuplicateEnvironment(VOID) DuplicateEnvironment(VOID)
{ {
LPTSTR Environ = GetEnvironmentStrings(); LPTSTR Environ = GetEnvironmentStrings();
LPTSTR End, EnvironCopy; LPTSTR End, EnvironCopy;
if (!Environ)
return NULL; if (!Environ) return NULL;
for (End = Environ; *End; End += _tcslen(End) + 1)
; for (End = Environ; *End; End += _tcslen(End) + 1) ;
EnvironCopy = cmd_alloc((End + 1 - Environ) * sizeof(TCHAR)); EnvironCopy = cmd_alloc((End + 1 - Environ) * sizeof(TCHAR));
if (EnvironCopy)
memcpy(EnvironCopy, Environ, (End + 1 - Environ) * sizeof(TCHAR)); if (EnvironCopy)
FreeEnvironmentStrings(Environ); memcpy(EnvironCopy, Environ, (End + 1 - Environ) * sizeof(TCHAR));
return EnvironCopy;
FreeEnvironmentStrings(Environ);
return EnvironCopy;
} }
INT cmd_setlocal(LPTSTR param) INT cmd_setlocal(LPTSTR param)
{ {
SETLOCAL *Saved; SETLOCAL *Saved;
LPTSTR *arg; LPTSTR *arg;
INT argc, i; INT argc, i;
/* SETLOCAL only works inside a batch file */ /* SETLOCAL only works inside a batch file */
if (!bc) if (!bc)
return 0; return 0;
Saved = cmd_alloc(sizeof(SETLOCAL)); Saved = cmd_alloc(sizeof(SETLOCAL));
if (!Saved) if (!Saved)
{ {
error_out_of_memory(); error_out_of_memory();
return 1; return 1;
} }
Saved->Prev = bc->setlocal; Saved->Prev = bc->setlocal;
Saved->DelayedExpansion = bDelayedExpansion; Saved->DelayedExpansion = bDelayedExpansion;
Saved->Environment = DuplicateEnvironment(); Saved->Environment = DuplicateEnvironment();
if (!Saved->Environment) if (!Saved->Environment)
{ {
error_out_of_memory(); error_out_of_memory();
cmd_free(Saved); cmd_free(Saved);
return 1; return 1;
} }
bc->setlocal = Saved; bc->setlocal = Saved;
nErrorLevel = 0; nErrorLevel = 0;
arg = splitspace(param, &argc); arg = splitspace(param, &argc);
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
if (!_tcsicmp(arg[i], _T("enableextensions"))) if (!_tcsicmp(arg[i], _T("enableextensions")))
/* not implemented, ignore */; /* not implemented, ignore */;
else if (!_tcsicmp(arg[i], _T("disableextensions"))) else if (!_tcsicmp(arg[i], _T("disableextensions")))
/* not implemented, ignore */; /* not implemented, ignore */;
else if (!_tcsicmp(arg[i], _T("enabledelayedexpansion"))) else if (!_tcsicmp(arg[i], _T("enabledelayedexpansion")))
bDelayedExpansion = TRUE; bDelayedExpansion = TRUE;
else if (!_tcsicmp(arg[i], _T("disabledelayedexpansion"))) else if (!_tcsicmp(arg[i], _T("disabledelayedexpansion")))
bDelayedExpansion = FALSE; bDelayedExpansion = FALSE;
else else
{ {
error_invalid_parameter_format(arg[i]); error_invalid_parameter_format(arg[i]);
break; break;
} }
} }
freep(arg); freep(arg);
return nErrorLevel; return nErrorLevel;
} }
/* endlocal doesn't take any params */ /* endlocal doesn't take any params */
INT cmd_endlocal(LPTSTR param) INT cmd_endlocal(LPTSTR param)
{ {
LPTSTR Environ, Name, Value; LPTSTR Environ, Name, Value;
SETLOCAL *Saved; SETLOCAL *Saved;
/* Pop a SETLOCAL struct off of this batch file's stack */ /* Pop a SETLOCAL struct off of this batch file's stack */
if (!bc || !(Saved = bc->setlocal)) if (!bc || !(Saved = bc->setlocal))
return 0; return 0;
bc->setlocal = Saved->Prev; bc->setlocal = Saved->Prev;
bDelayedExpansion = Saved->DelayedExpansion; bDelayedExpansion = Saved->DelayedExpansion;
/* First, clear out the environment. Since making any changes to the /* First, clear out the environment. Since making any changes to the
* environment invalidates pointers obtained from GetEnvironmentStrings(), * environment invalidates pointers obtained from GetEnvironmentStrings(),
* we must make a copy of it and get the variable names from that */ * we must make a copy of it and get the variable names from that */
Environ = DuplicateEnvironment(); Environ = DuplicateEnvironment();
if (Environ) if (Environ)
{ {
for (Name = Environ; *Name; Name += _tcslen(Name) + 1) for (Name = Environ; *Name; Name += _tcslen(Name) + 1)
{ {
if (!(Value = _tcschr(Name + 1, _T('=')))) if (!(Value = _tcschr(Name + 1, _T('='))))
continue; continue;
*Value++ = _T('\0'); *Value++ = _T('\0');
SetEnvironmentVariable(Name, NULL); SetEnvironmentVariable(Name, NULL);
Name = Value; Name = Value;
} }
cmd_free(Environ); cmd_free(Environ);
} }
/* Now, restore variables from the copy saved by cmd_setlocal */ /* Now, restore variables from the copy saved by cmd_setlocal */
for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1) for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1)
{ {
if (!(Value = _tcschr(Name + 1, _T('=')))) if (!(Value = _tcschr(Name + 1, _T('='))))
continue; continue;
*Value++ = _T('\0'); *Value++ = _T('\0');
SetEnvironmentVariable(Name, Value); SetEnvironmentVariable(Name, Value);
Name = Value; Name = Value;
} }
cmd_free(Saved->Environment); cmd_free(Saved->Environment);
cmd_free(Saved); cmd_free(Saved);
return 0; return 0;
} }

View file

@ -19,8 +19,8 @@
* 20-Jan-1999 (Eric Kohl) * 20-Jan-1999 (Eric Kohl)
* Unicode and redirection safe! * Unicode and redirection safe!
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #include "precomp.h"
@ -37,48 +37,48 @@
INT cmd_shift (LPTSTR param) INT cmd_shift (LPTSTR param)
{ {
INT i = 0; INT i = 0;
TRACE ("cmd_shift: (\'%s\')\n", debugstr_aw(param)); TRACE ("cmd_shift: (\'%s\')\n", debugstr_aw(param));
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
ConOutResPaging(TRUE,STRING_SHIFT_HELP); ConOutResPaging(TRUE,STRING_SHIFT_HELP);
return 0; return 0;
} }
nErrorLevel = 0; nErrorLevel = 0;
if (bc == NULL) if (bc == NULL)
{ {
/* not in batch - error!! */ /* not in batch - error!! */
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
if (!_tcsicmp (param, _T("down"))) if (!_tcsicmp (param, _T("down")))
{ {
if (bc->shiftlevel[0]) if (bc->shiftlevel[0])
for (; i <= 9; i++) for (; i <= 9; i++)
bc->shiftlevel[i]--; bc->shiftlevel[i]--;
} }
else /* shift up */ else /* shift up */
{ {
if (*param == _T('/')) if (*param == _T('/'))
{ {
if (param[1] < '0' || param[1] > '9') if (param[1] < '0' || param[1] > '9')
{ {
error_invalid_switch(param[1]); error_invalid_switch(param[1]);
return 1; return 1;
} }
i = param[1] - '0'; i = param[1] - '0';
} }
for (; i < 9; i++) for (; i < 9; i++)
bc->shiftlevel[i] = bc->shiftlevel[i + 1]; bc->shiftlevel[i] = bc->shiftlevel[i + 1];
bc->shiftlevel[i]++; bc->shiftlevel[i]++;
} }
return 0; return 0;
} }
/* EOF */ /* EOF */

View file

@ -7,8 +7,8 @@
* 24-Jul-1999 (Eric Kohl) * 24-Jul-1999 (Eric Kohl)
* Started. * Started.
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #include "precomp.h"
@ -19,303 +19,302 @@
* in place. (It's moved back one character, to make room for the nul) */ * in place. (It's moved back one character, to make room for the nul) */
static TCHAR *GetParameter(TCHAR **pPointer) static TCHAR *GetParameter(TCHAR **pPointer)
{ {
BOOL bInQuote = FALSE; BOOL bInQuote = FALSE;
TCHAR *start = *pPointer; TCHAR *start = *pPointer;
TCHAR *p; TCHAR *p;
for (p = start; *p; p++) for (p = start; *p; p++)
{ {
if (!bInQuote && (*p == _T('/') || _istspace(*p))) if (!bInQuote && (*p == _T('/') || _istspace(*p)))
break; break;
bInQuote ^= (*p == _T('"')); bInQuote ^= (*p == _T('"'));
p[-1] = *p; p[-1] = *p;
} }
p[-1] = _T('\0'); p[-1] = _T('\0');
*pPointer = p; *pPointer = p;
return start - 1; return start - 1;
} }
INT cmd_start (LPTSTR Rest) INT cmd_start (LPTSTR Rest)
{ {
TCHAR szFullName[CMDLINE_LENGTH]; TCHAR szFullName[CMDLINE_LENGTH];
TCHAR szUnquotedName[CMDLINE_LENGTH]; TCHAR szUnquotedName[CMDLINE_LENGTH];
TCHAR *param = NULL; TCHAR *param = NULL;
TCHAR *dot; TCHAR *dot;
INT size; INT size;
LPTSTR comspec; LPTSTR comspec;
BOOL bWait = FALSE; BOOL bWait = FALSE;
BOOL bBat = FALSE; BOOL bBat = FALSE;
BOOL bCreate = FALSE; BOOL bCreate = FALSE;
TCHAR szFullCmdLine [CMDLINE_LENGTH]; TCHAR szFullCmdLine [CMDLINE_LENGTH];
PROCESS_INFORMATION prci; PROCESS_INFORMATION prci;
STARTUPINFO stui; STARTUPINFO stui;
#ifdef UNICODE #ifdef UNICODE
DWORD dwCreationFlags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT; DWORD dwCreationFlags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT;
#else #else
DWORD dwCreationFlags = CREATE_NEW_CONSOLE; DWORD dwCreationFlags = CREATE_NEW_CONSOLE;
#endif #endif
DWORD dwAffinityMask = 0; DWORD dwAffinityMask = 0;
LPTSTR lpTitle = NULL; LPTSTR lpTitle = NULL;
LPTSTR lpDirectory = NULL; LPTSTR lpDirectory = NULL;
LPTSTR lpEnvironment = NULL; LPTSTR lpEnvironment = NULL;
WORD wShowWindow = SW_SHOWNORMAL; WORD wShowWindow = SW_SHOWNORMAL;
while (1) while (1)
{ {
if (_istspace(*Rest)) if (_istspace(*Rest))
{ {
Rest++; Rest++;
} }
else if (*Rest == _T('"') && !lpTitle) else if (*Rest == _T('"') && !lpTitle)
{ {
lpTitle = GetParameter(&Rest); lpTitle = GetParameter(&Rest);
StripQuotes(lpTitle); StripQuotes(lpTitle);
} }
else if (*Rest == L'/') else if (*Rest == L'/')
{ {
LPTSTR option; LPTSTR option;
Rest++; Rest++;
option = GetParameter(&Rest); option = GetParameter(&Rest);
if (*option == _T('?')) if (*option == _T('?'))
{ {
ConOutResPaging(TRUE,STRING_START_HELP1); ConOutResPaging(TRUE,STRING_START_HELP1);
return 0; return 0;
} }
else if (_totupper(*option) == _T('D')) else if (_totupper(*option) == _T('D'))
{ {
lpDirectory = option + 1; lpDirectory = option + 1;
if (!*lpDirectory) if (!*lpDirectory)
{ {
while (_istspace(*Rest)) while (_istspace(*Rest))
Rest++; Rest++;
lpDirectory = GetParameter(&Rest); lpDirectory = GetParameter(&Rest);
} }
StripQuotes(lpDirectory); StripQuotes(lpDirectory);
} }
else if (_totupper(*option) == _T('I')) else if (_totupper(*option) == _T('I'))
{ {
/* rest of the option is apparently ignored */ /* rest of the option is apparently ignored */
lpEnvironment = lpOriginalEnvironment; lpEnvironment = lpOriginalEnvironment;
} }
else if (!_tcsicmp(option, _T("MIN"))) else if (!_tcsicmp(option, _T("MIN")))
{ {
wShowWindow = SW_MINIMIZE; wShowWindow = SW_MINIMIZE;
} }
else if (!_tcsicmp(option, _T("MAX"))) else if (!_tcsicmp(option, _T("MAX")))
{ {
wShowWindow = SW_MAXIMIZE; wShowWindow = SW_MAXIMIZE;
} }
else if (!_tcsicmp(option, _T("AFFINITY"))) else if (!_tcsicmp(option, _T("AFFINITY")))
{ {
TCHAR *end; TCHAR *end;
while (_istspace(*Rest)) while (_istspace(*Rest))
Rest++; Rest++;
option = GetParameter(&Rest); option = GetParameter(&Rest);
/* Affinity mask is given in hexadecimal */ /* Affinity mask is given in hexadecimal */
dwAffinityMask = _tcstoul(option, &end, 16); dwAffinityMask = _tcstoul(option, &end, 16);
if (*end != _T('\0') || dwAffinityMask == 0 || if (*end != _T('\0') || dwAffinityMask == 0 ||
dwAffinityMask == (DWORD)-1) dwAffinityMask == (DWORD)-1)
{ {
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, option); ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, option);
return 1; return 1;
} }
dwCreationFlags |= CREATE_SUSPENDED; dwCreationFlags |= CREATE_SUSPENDED;
} }
else if (!_tcsicmp(option, _T("B"))) else if (!_tcsicmp(option, _T("B")))
{ {
dwCreationFlags &= ~CREATE_NEW_CONSOLE; dwCreationFlags &= ~CREATE_NEW_CONSOLE;
dwCreationFlags |= CREATE_NEW_PROCESS_GROUP; dwCreationFlags |= CREATE_NEW_PROCESS_GROUP;
} }
else if (!_tcsicmp(option, _T("LOW"))) else if (!_tcsicmp(option, _T("LOW")))
{ {
dwCreationFlags |= IDLE_PRIORITY_CLASS; dwCreationFlags |= IDLE_PRIORITY_CLASS;
} }
else if (!_tcsicmp(option, _T("NORMAL"))) else if (!_tcsicmp(option, _T("NORMAL")))
{ {
dwCreationFlags |= NORMAL_PRIORITY_CLASS; dwCreationFlags |= NORMAL_PRIORITY_CLASS;
} }
else if (!_tcsicmp(option, _T("HIGH"))) else if (!_tcsicmp(option, _T("HIGH")))
{ {
dwCreationFlags |= HIGH_PRIORITY_CLASS; dwCreationFlags |= HIGH_PRIORITY_CLASS;
} }
else if (!_tcsicmp(option, _T("REALTIME"))) else if (!_tcsicmp(option, _T("REALTIME")))
{ {
dwCreationFlags |= REALTIME_PRIORITY_CLASS; dwCreationFlags |= REALTIME_PRIORITY_CLASS;
} }
else if (!_tcsicmp(option, _T("ABOVENORMAL"))) else if (!_tcsicmp(option, _T("ABOVENORMAL")))
{ {
dwCreationFlags |= ABOVE_NORMAL_PRIORITY_CLASS; dwCreationFlags |= ABOVE_NORMAL_PRIORITY_CLASS;
} }
else if (!_tcsicmp(option, _T("BELOWNORMAL"))) else if (!_tcsicmp(option, _T("BELOWNORMAL")))
{ {
dwCreationFlags |= BELOW_NORMAL_PRIORITY_CLASS; dwCreationFlags |= BELOW_NORMAL_PRIORITY_CLASS;
} }
else if (!_tcsicmp(option, _T("SEPARATE"))) else if (!_tcsicmp(option, _T("SEPARATE")))
{ {
dwCreationFlags |= CREATE_SEPARATE_WOW_VDM; dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
} }
else if (!_tcsicmp(option, _T("SHARED"))) else if (!_tcsicmp(option, _T("SHARED")))
{ {
dwCreationFlags |= CREATE_SHARED_WOW_VDM; dwCreationFlags |= CREATE_SHARED_WOW_VDM;
} }
else if (!_tcsicmp(option, _T("W")) || else if (!_tcsicmp(option, _T("W")) ||
!_tcsicmp(option, _T("WAIT"))) !_tcsicmp(option, _T("WAIT")))
{ {
bWait = TRUE; bWait = TRUE;
} }
else else
{ {
ConErrResPrintf(STRING_TYPE_ERROR1, option); ConErrResPrintf(STRING_TYPE_ERROR1, option);
return 0; return 0;
} }
} }
else else
{ {
/* It's not an option - must be the beginning of /* It's not an option - must be the beginning of
* the actual command. Leave the loop. */ * the actual command. Leave the loop. */
break; break;
} }
} }
/* get comspec */ /* get comspec */
comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR)); comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
if (comspec == NULL) if (comspec == NULL)
{ {
error_out_of_memory(); error_out_of_memory();
return 1; return 1;
} }
SetLastError(0); SetLastError(0);
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, MAX_PATH); size = GetEnvironmentVariable (_T("COMSPEC"), comspec, MAX_PATH);
if(GetLastError() == ERROR_ENVVAR_NOT_FOUND) if(GetLastError() == ERROR_ENVVAR_NOT_FOUND)
{ {
_tcscpy(comspec, _T("cmd")); _tcscpy(comspec, _T("cmd"));
} }
else else
{ {
if (size > MAX_PATH) if (size > MAX_PATH)
{ {
LPTSTR Oldcomspec = comspec; LPTSTR Oldcomspec = comspec;
comspec = cmd_realloc(comspec,size * sizeof(TCHAR) ); comspec = cmd_realloc(comspec,size * sizeof(TCHAR) );
if (comspec==NULL) if (comspec==NULL)
{ {
cmd_free(Oldcomspec); cmd_free(Oldcomspec);
return 1; return 1;
} }
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, size); size = GetEnvironmentVariable (_T("COMSPEC"), comspec, size);
} }
} }
nErrorLevel = 0; nErrorLevel = 0;
if (!*Rest) if (!*Rest)
{ {
Rest = _T("cmd.exe"); Rest = _T("cmd.exe");
} }
else else
/* Parsing the command that gets called by start, and it's parameters */ /* Parsing the command that gets called by start, and it's parameters */
{ {
BOOL bInside = FALSE; BOOL bInside = FALSE;
INT i; INT i;
/* find the end of the command and put the arguments in param */ /* find the end of the command and put the arguments in param */
for (i = 0; Rest[i]; i++) for (i = 0; Rest[i]; i++)
{ {
if (Rest[i] == _T('\"')) if (Rest[i] == _T('\"'))
bInside = !bInside; bInside = !bInside;
if (_istspace(Rest[i]) && !bInside) if (_istspace(Rest[i]) && !bInside)
{ {
param = &Rest[i+1]; param = &Rest[i+1];
Rest[i] = _T('\0'); Rest[i] = _T('\0');
break; break;
} }
} }
} }
_tcscpy(szUnquotedName, Rest); _tcscpy(szUnquotedName, Rest);
StripQuotes(szUnquotedName); StripQuotes(szUnquotedName);
/* get the PATH environment variable and parse it */ /* get the PATH environment variable and parse it */
/* search the PATH environment variable for the binary */ /* search the PATH environment variable for the binary */
if (SearchForExecutable(szUnquotedName, szFullName)) if (SearchForExecutable(szUnquotedName, szFullName))
{ {
/* check if this is a .BAT or .CMD file */ /* check if this is a .BAT or .CMD file */
dot = _tcsrchr(szFullName, _T('.')); dot = _tcsrchr(szFullName, _T('.'));
if (dot && (!_tcsicmp(dot, _T(".bat")) || !_tcsicmp(dot, _T(".cmd")))) if (dot && (!_tcsicmp(dot, _T(".bat")) || !_tcsicmp(dot, _T(".cmd"))))
{ {
bBat = TRUE; bBat = TRUE;
_stprintf(szFullCmdLine, _T("\"%s\" /K %s"), comspec, Rest); _stprintf(szFullCmdLine, _T("\"%s\" /K %s"), comspec, Rest);
TRACE ("[BATCH: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest)); TRACE ("[BATCH: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
} }
else else
{ {
TRACE ("[EXEC: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest)); TRACE ("[EXEC: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
_tcscpy(szFullCmdLine, szFullName); _tcscpy(szFullCmdLine, szFullName);
} }
/* build command line for CreateProcess() */ /* build command line for CreateProcess() */
if (param != NULL) if (param != NULL)
{ {
_tcsncat(szFullCmdLine, _T(" "), CMDLINE_LENGTH - _tcslen(szFullCmdLine)); _tcsncat(szFullCmdLine, _T(" "), CMDLINE_LENGTH - _tcslen(szFullCmdLine));
_tcsncat(szFullCmdLine, param, CMDLINE_LENGTH - _tcslen(szFullCmdLine)); _tcsncat(szFullCmdLine, param, CMDLINE_LENGTH - _tcslen(szFullCmdLine));
} }
/* fill startup info */ /* fill startup info */
memset (&stui, 0, sizeof (STARTUPINFO)); memset (&stui, 0, sizeof (STARTUPINFO));
stui.cb = sizeof (STARTUPINFO); stui.cb = sizeof (STARTUPINFO);
stui.dwFlags = STARTF_USESHOWWINDOW; stui.dwFlags = STARTF_USESHOWWINDOW;
stui.lpTitle = lpTitle; stui.lpTitle = lpTitle;
stui.wShowWindow = wShowWindow; stui.wShowWindow = wShowWindow;
bCreate = CreateProcess(bBat ? comspec : szFullName, bCreate = CreateProcess(bBat ? comspec : szFullName,
szFullCmdLine, NULL, NULL, TRUE, dwCreationFlags, szFullCmdLine, NULL, NULL, TRUE, dwCreationFlags,
lpEnvironment, lpDirectory, &stui, &prci); lpEnvironment, lpDirectory, &stui, &prci);
if (bCreate) if (bCreate)
{ {
if (dwAffinityMask) if (dwAffinityMask)
{ {
SetProcessAffinityMask(prci.hProcess, dwAffinityMask); SetProcessAffinityMask(prci.hProcess, dwAffinityMask);
ResumeThread(prci.hThread); ResumeThread(prci.hThread);
} }
CloseHandle(prci.hThread); CloseHandle(prci.hThread);
} }
} }
else else
{ {
/* The file name did not seem to be valid, but maybe it's actually a /* 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. */ * directory or URL, so we still want to pass it to ShellExecute. */
_tcscpy(szFullName, szUnquotedName); _tcscpy(szFullName, szUnquotedName);
} }
if (!bCreate) if (!bCreate)
{ {
/* CreateProcess didn't work; try ShellExecute */ /* CreateProcess didn't work; try ShellExecute */
DWORD flags = SEE_MASK_NOCLOSEPROCESS; DWORD flags = SEE_MASK_NOCLOSEPROCESS;
if (!(dwCreationFlags & CREATE_NEW_CONSOLE)) if (!(dwCreationFlags & CREATE_NEW_CONSOLE))
flags |= SEE_MASK_NO_CONSOLE; flags |= SEE_MASK_NO_CONSOLE;
prci.hProcess = RunFile(flags, szFullName, param, lpDirectory, wShowWindow); prci.hProcess = RunFile(flags, szFullName, param, lpDirectory, wShowWindow);
} }
if (prci.hProcess != NULL) if (prci.hProcess != NULL)
{ {
if (bWait) if (bWait)
{ {
DWORD dwExitCode; DWORD dwExitCode;
WaitForSingleObject (prci.hProcess, INFINITE); WaitForSingleObject (prci.hProcess, INFINITE);
GetExitCodeProcess (prci.hProcess, &dwExitCode); GetExitCodeProcess (prci.hProcess, &dwExitCode);
nErrorLevel = (INT)dwExitCode; nErrorLevel = (INT)dwExitCode;
} }
CloseHandle (prci.hProcess); CloseHandle (prci.hProcess);
/* Get New code page if it has change */ /* Get New code page if it has change */
InputCodePage= GetConsoleCP(); InputCodePage= GetConsoleCP();
OutputCodePage = GetConsoleOutputCP(); OutputCodePage = GetConsoleOutputCP();
} }
else else
{ {
ErrorMessage(GetLastError (), ErrorMessage(GetLastError (),
_T("Error executing CreateProcess()!!\n")); _T("Error executing CreateProcess()!!\n"));
} }
cmd_free(comspec);
cmd_free(comspec); return 0;
return 0;
} }
#endif #endif

View file

@ -7,7 +7,6 @@
* 07-Oct-1999 (Paolo Pantaleo) * 07-Oct-1999 (Paolo Pantaleo)
* Started. * Started.
* *
*
*/ */
/* /*
@ -37,52 +36,52 @@
typedef struct _CLRTABLE typedef struct _CLRTABLE
{ {
LPTSTR name; LPTSTR name;
WORD val; WORD val;
} CLRTABLE; } CLRTABLE;
CLRTABLE clrtable[] = CLRTABLE clrtable[] =
{ {
{_T("bla"), 0 }, {_T("bla"), 0 },
{_T("blu"), _B }, {_T("blu"), _B },
{_T("gre"), _G }, {_T("gre"), _G },
{_T("cya"), _B|_G }, {_T("cya"), _B|_G },
{_T("red"), _R }, {_T("red"), _R },
{_T("mag"), _B|_R }, {_T("mag"), _B|_R },
{_T("yel"), _R|_G }, {_T("yel"), _R|_G },
{_T("whi"), _R|_G|_B }, {_T("whi"), _R|_G|_B },
{_T("gra"), _I }, {_T("gra"), _I },
{_T("0") , 0 }, {_T("0") , 0 },
{_T("2") , _G }, {_T("2") , _G },
{_T("3") , _B|_G }, {_T("3") , _B|_G },
{_T("4") , _R }, {_T("4") , _R },
{_T("5") , _B|_R }, {_T("5") , _B|_R },
{_T("6") , _R|_G }, {_T("6") , _R|_G },
{_T("7") , _R|_G|_B }, {_T("7") , _R|_G|_B },
{_T("8") , _I }, {_T("8") , _I },
{_T("9") , _I|_B }, {_T("9") , _I|_B },
{_T("10") , _I|_G }, {_T("10") , _I|_G },
{_T("11") , _I|_B|_G }, {_T("11") , _I|_B|_G },
{_T("12") , _I|_R }, {_T("12") , _I|_R },
{_T("13") , _I|_B|_R }, {_T("13") , _I|_B|_R },
{_T("14") , _I|_R|_G }, {_T("14") , _I|_R|_G },
{_T("15") , _I|_R|_G|_B }, {_T("15") , _I|_R|_G|_B },
/* /*
* Note that 1 is at the end of list * 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 */ /* Cyan synonym */
{_T("aqu"), _B|_G }, {_T("aqu"), _B|_G },
/* Magenta synonym */ /* Magenta synonym */
{_T("pur"), _B|_R }, {_T("pur"), _B|_R },
{_T("") ,0}, {_T("") ,0},
}; };
@ -93,28 +92,28 @@ CLRTABLE clrtable[] =
static static
INT chop_blank(LPTSTR *arg_str) INT chop_blank(LPTSTR *arg_str)
{ {
LPTSTR str; LPTSTR str;
str = _tcschr(*arg_str,_T(' ')); str = _tcschr(*arg_str,_T(' '));
if(!str) if(!str)
{ {
str = _tcschr (*arg_str, _T('\0')); str = _tcschr (*arg_str, _T('\0'));
if(str != NULL) if(str != NULL)
*arg_str=str; *arg_str=str;
return CP_BLANK_NOT_FOUND; return CP_BLANK_NOT_FOUND;
} }
while(_istspace(*str)) while(_istspace(*str))
str++; str++;
if (*str == _T('\0')) if (*str == _T('\0'))
{ {
*arg_str=str; *arg_str=str;
return CP_END_OF_STRING; 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 static
WORD hex_clr(LPTSTR str) WORD hex_clr(LPTSTR str)
{ {
WORD ret= (WORD)-1; WORD ret= (WORD)-1;
TCHAR ch; TCHAR ch;
ch = str[1]; ch = str[1];
if(_istdigit(ch)) if(_istdigit(ch))
ret = ch-_T('0'); ret = ch-_T('0');
else else
{ {
ch=_totupper(ch); ch=_totupper(ch);
if( ch >= _T('A') && ch <= _T('F') ) if( ch >= _T('A') && ch <= _T('F') )
ret = ch-_T('A')+10; ret = ch-_T('A')+10;
else else
return (WORD)-1; return (WORD)-1;
} }
ch = str[0]; ch = str[0];
if(_istdigit(ch)) if(_istdigit(ch))
ret |= (ch-_T('0')) << 4; ret |= (ch-_T('0')) << 4;
else else
{ {
ch=_totupper(ch); ch=_totupper(ch);
if( ch >= _T('A') && ch <= _T('F') ) if( ch >= _T('A') && ch <= _T('F') )
ret |= (ch-_T('A')+10) <<4; ret |= (ch-_T('A')+10) <<4;
else else
return (WORD)-1; return (WORD)-1;
} }
return ret; return ret;
} }
@ -167,13 +166,13 @@ WORD hex_clr(LPTSTR str)
static static
WORD txt_clr(LPTSTR str) WORD txt_clr(LPTSTR str)
{ {
INT i; INT i;
for(i = 0; *(clrtable[i].name); i++) for(i = 0; *(clrtable[i].name); i++)
if (_tcsnicmp(str, clrtable[i].name, _tcslen(clrtable[i].name)) == 0) if (_tcsnicmp(str, clrtable[i].name, _tcslen(clrtable[i].name)) == 0)
return clrtable[i].val; return clrtable[i].val;
return (WORD)-1; return (WORD)-1;
} }
@ -181,58 +180,58 @@ WORD txt_clr(LPTSTR str)
static static
WORD str_to_color(LPTSTR* arg_str) WORD str_to_color(LPTSTR* arg_str)
{ {
LPTSTR str; LPTSTR str;
BOOL bBri; BOOL bBri;
WORD tmp_clr,ret_clr; WORD tmp_clr,ret_clr;
str = *arg_str; str = *arg_str;
if (!(*str)) if (!(*str))
return (WORD)-1; return (WORD)-1;
/* foreground */ /* foreground */
bBri = FALSE; bBri = FALSE;
if (_tcsnicmp(str,_T("bri"),3) == 0) if (_tcsnicmp(str,_T("bri"),3) == 0)
{ {
bBri = TRUE; bBri = TRUE;
if (chop_blank(&str)) if (chop_blank(&str))
return (WORD)-1; return (WORD)-1;
} }
if ((tmp_clr = txt_clr(str)) == (WORD)-1) if ((tmp_clr = txt_clr(str)) == (WORD)-1)
{ {
return (WORD)-1; return (WORD)-1;
} }
/* skip spaces and "on" keyword */ /* skip spaces and "on" keyword */
if (chop_blank(&str) || chop_blank(&str)) if (chop_blank(&str) || chop_blank(&str))
return (WORD)-1; return (WORD)-1;
ret_clr = tmp_clr | (bBri << 3); ret_clr = tmp_clr | (bBri << 3);
/* background */ /* background */
bBri = FALSE; bBri = FALSE;
if(_tcsnicmp(str,_T("bri"),3) == 0 ) if(_tcsnicmp(str,_T("bri"),3) == 0 )
{ {
bBri = TRUE; bBri = TRUE;
if(chop_blank(&str)) if(chop_blank(&str))
return (WORD)-1; return (WORD)-1;
} }
if( (tmp_clr = txt_clr(str)) == (WORD)-1 ) if( (tmp_clr = txt_clr(str)) == (WORD)-1 )
return (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 */ /* NOTE: See the note on SC_HEX in the StringToColor()'s description */
return /* SC_HEX | */ ret_clr | tmp_clr << 4 | bBri << 7; 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) BOOL StringToColor(LPWORD lpColor, LPTSTR*str)
{ {
WORD wRet; WORD wRet;
wRet = str_to_color (str); wRet = str_to_color (str);
if (wRet == (WORD)-1) if (wRet == (WORD)-1)
{ {
wRet=hex_clr (*str); wRet=hex_clr (*str);
chop_blank (str); chop_blank (str);
if (wRet == (WORD)-1) if (wRet == (WORD)-1)
return FALSE; return FALSE;
} }
*lpColor = wRet; *lpColor = wRet;
return TRUE; return TRUE;
} }
/* EOF */ /* EOF */

View file

@ -20,8 +20,8 @@
* 04-Feb-1999 (Eric Kohl) * 04-Feb-1999 (Eric Kohl)
* Fixed time input bug. * Fixed time input bug.
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc. * Remove all hardcoded strings in En.rc.
*/ */
#include "precomp.h" #include "precomp.h"
@ -31,187 +31,187 @@
static BOOL ParseTime (LPTSTR s) static BOOL ParseTime (LPTSTR s)
{ {
SYSTEMTIME t; SYSTEMTIME t;
LPTSTR p = s; LPTSTR p = s;
if (!*s) if (!*s)
return TRUE; return TRUE;
GetLocalTime (&t); GetLocalTime (&t);
t.wHour = 0; t.wHour = 0;
t.wMinute = 0; t.wMinute = 0;
t.wSecond = 0; t.wSecond = 0;
t.wMilliseconds = 0; t.wMilliseconds = 0;
// first get hour // first get hour
if (_istdigit(*p)) if (_istdigit(*p))
{ {
while (_istdigit(*p)) while (_istdigit(*p))
{ {
t.wHour = t.wHour * 10 + *p - _T('0'); t.wHour = t.wHour * 10 + *p - _T('0');
p++; p++;
} }
} }
else else
return FALSE; return FALSE;
// get time separator // get time separator
if (*p != cTimeSeparator) if (*p != cTimeSeparator)
return FALSE; return FALSE;
p++; p++;
// now get minutes // now get minutes
if (_istdigit(*p)) if (_istdigit(*p))
{ {
while (_istdigit(*p)) while (_istdigit(*p))
{ {
t.wMinute = t.wMinute * 10 + *p - _T('0'); t.wMinute = t.wMinute * 10 + *p - _T('0');
p++; p++;
} }
} }
else else
return FALSE; return FALSE;
// get time separator // get time separator
if (*p != cTimeSeparator) if (*p != cTimeSeparator)
return FALSE; return FALSE;
p++; p++;
// now get seconds // now get seconds
if (_istdigit(*p)) if (_istdigit(*p))
{ {
while (_istdigit(*p)) while (_istdigit(*p))
{ {
t.wSecond = t.wSecond * 10 + *p - _T('0'); t.wSecond = t.wSecond * 10 + *p - _T('0');
p++; p++;
} }
} }
else else
return FALSE; return FALSE;
// get decimal separator // get decimal separator
if (*p == cDecimalSeparator) if (*p == cDecimalSeparator)
{ {
p++; p++;
// now get hundreths // now get hundreths
if (_istdigit(*p)) if (_istdigit(*p))
{ {
while (_istdigit(*p)) while (_istdigit(*p))
{ {
// t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0'); // t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
p++; p++;
} }
// t.wMilliseconds *= 10; // t.wMilliseconds *= 10;
} }
} }
/* special case: 12 hour format */ /* special case: 12 hour format */
if (nTimeFormat == 0) if (nTimeFormat == 0)
{ {
if (_totupper(*s) == _T('P')) if (_totupper(*s) == _T('P'))
{ {
t.wHour += 12; t.wHour += 12;
} }
if ((_totupper(*s) == _T('A')) && (t.wHour == 12)) if ((_totupper(*s) == _T('A')) && (t.wHour == 12))
{ {
t.wHour = 0; t.wHour = 0;
} }
} }
if (t.wHour > 23 || t.wMinute > 60 || t.wSecond > 60 || t.wMilliseconds > 999) if (t.wHour > 23 || t.wMinute > 60 || t.wSecond > 60 || t.wMilliseconds > 999)
return FALSE; return FALSE;
SetLocalTime (&t); SetLocalTime (&t);
return TRUE; return TRUE;
} }
INT cmd_time (LPTSTR param) INT cmd_time (LPTSTR param)
{ {
LPTSTR *arg; LPTSTR *arg;
INT argc; INT argc;
INT i; INT i;
INT nTimeString = -1; INT nTimeString = -1;
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
ConOutResPaging(TRUE,STRING_TIME_HELP1); ConOutResPaging(TRUE,STRING_TIME_HELP1);
return 0; return 0;
} }
nErrorLevel = 0; nErrorLevel = 0;
/* build parameter array */ /* build parameter array */
arg = split (param, &argc, FALSE, FALSE); arg = split (param, &argc, FALSE, FALSE);
/* check for options */ /* check for options */
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
if (_tcsicmp (arg[i], _T("/t")) == 0) if (_tcsicmp (arg[i], _T("/t")) == 0)
{ {
/* Display current time in short format */ /* Display current time in short format */
SYSTEMTIME st; SYSTEMTIME st;
TCHAR szTime[20]; TCHAR szTime[20];
GetLocalTime(&st); GetLocalTime(&st);
FormatTime(szTime, &st); FormatTime(szTime, &st);
ConOutPuts(szTime); ConOutPuts(szTime);
freep(arg); freep(arg);
return 0; return 0;
} }
if ((*arg[i] != _T('/')) && (nTimeString == -1)) if ((*arg[i] != _T('/')) && (nTimeString == -1))
nTimeString = i; nTimeString = i;
} }
if (nTimeString == -1) if (nTimeString == -1)
{ {
ConOutResPrintf(STRING_LOCALE_HELP1); ConOutResPrintf(STRING_LOCALE_HELP1);
ConOutPrintf(_T(": %s\n"), GetTimeString()); ConOutPrintf(_T(": %s\n"), GetTimeString());
} }
while (1) while (1)
{ {
if (nTimeString == -1) if (nTimeString == -1)
{ {
TCHAR s[40]; 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(' ')) while (*s && s[_tcslen (s) - 1] < _T(' '))
s[_tcslen(s) - 1] = _T('\0'); s[_tcslen(s) - 1] = _T('\0');
if (ParseTime (s)) if (ParseTime (s))
{ {
freep (arg); freep (arg);
return 0; return 0;
} }
} }
else else
{ {
if (ParseTime (arg[nTimeString])) if (ParseTime (arg[nTimeString]))
{ {
freep (arg); freep (arg);
return 0; return 0;
} }
/* force input the next time around. */ /* force input the next time around. */
nTimeString = -1; nTimeString = -1;
} }
ConErrResPuts(STRING_TIME_ERROR1); ConErrResPuts(STRING_TIME_ERROR1);
nErrorLevel = 1; nErrorLevel = 1;
} }
freep (arg); freep (arg);
return 0; return 0;
} }
#endif #endif

View file

@ -30,189 +30,189 @@
static VOID static VOID
PrintElapsedTime (DWORD time,INT format) 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) switch (format)
{ {
case 0: case 0:
ConOutResPrintf(STRING_TIMER_HELP1, time); ConOutResPrintf(STRING_TIMER_HELP1, time);
break; break;
case 1: case 1:
ms = time % 1000; ms = time % 1000;
time /= 1000; time /= 1000;
s = time % 60; s = time % 60;
time /=60; time /=60;
m = time % 60; m = time % 60;
h = time / 60; h = time / 60;
ConOutResPrintf(STRING_TIMER_HELP2, ConOutResPrintf(STRING_TIMER_HELP2,
h, cTimeSeparator, h, cTimeSeparator,
m, cTimeSeparator, m, cTimeSeparator,
s, cDecimalSeparator, ms/10); s, cDecimalSeparator, ms/10);
break; break;
} }
} }
INT CommandTimer (LPTSTR param) INT CommandTimer (LPTSTR param)
{ {
// all timers are kept // all timers are kept
static DWORD clksT[10]; static DWORD clksT[10];
// timers status // timers status
// set all the clocks off by default // set all the clocks off by default
static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE, static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE}; FALSE,FALSE,FALSE,FALSE,FALSE,FALSE};
// TRUE if /S in command line // TRUE if /S in command line
BOOL bS = FALSE; BOOL bS = FALSE;
// avoid to set clk_n more than once // avoid to set clk_n more than once
BOOL bCanNSet = TRUE; BOOL bCanNSet = TRUE;
INT NewClkStatus = NCS_NOT_SPECIFIED; INT NewClkStatus = NCS_NOT_SPECIFIED;
// the clock number specified on the command line // the clock number specified on the command line
// 1 by default // 1 by default
INT clk_n=1; INT clk_n=1;
// output format // output format
INT iFormat=1; INT iFormat=1;
// command line parsing variables // command line parsing variables
INT argc; INT argc;
LPTSTR *p; LPTSTR *p;
INT i; INT i;
if (_tcsncmp (param, _T("/?"), 2) == 0) if (_tcsncmp (param, _T("/?"), 2) == 0)
{ {
ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator); ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator);
return 0; return 0;
} }
nErrorLevel = 0; nErrorLevel = 0;
p = split (param, &argc, FALSE, FALSE); p = split (param, &argc, FALSE, FALSE);
//read options //read options
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
//set timer on //set timer on
if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED) if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED)
{ {
NewClkStatus = NCS_ON; NewClkStatus = NCS_ON;
continue; continue;
} }
//set timer off //set timer off
if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED) if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED)
{ {
NewClkStatus = NCS_OFF; NewClkStatus = NCS_OFF;
continue; continue;
} }
// other options // other options
if (p[i][0] == _T('/')) if (p[i][0] == _T('/'))
{ {
// set timer number // set timer number
if (_istdigit(p[i][1]) && bCanNSet) if (_istdigit(p[i][1]) && bCanNSet)
{ {
clk_n = p[i][1] - _T('0'); clk_n = p[i][1] - _T('0');
bCanNSet = FALSE; bCanNSet = FALSE;
continue; continue;
} }
// set s(plit) option // set s(plit) option
if (_totupper(p[i][1]) == _T('S')) if (_totupper(p[i][1]) == _T('S'))
{ {
bS = TRUE; bS = TRUE;
continue; continue;
} }
// specify format // specify format
if (_totupper(p[i][1]) == _T('F')) if (_totupper(p[i][1]) == _T('F'))
{ {
iFormat = p[i][2] - _T('0'); iFormat = p[i][2] - _T('0');
continue; continue;
} }
} }
} }
// do stuff (start/stop/read timer) // do stuff (start/stop/read timer)
if(NewClkStatus == NCS_ON) if(NewClkStatus == NCS_ON)
{ {
cT=GetTickCount(); cT=GetTickCount();
cS=TRUE; cS=TRUE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
ConOutPuts(GetTimeString()); ConOutPuts(GetTimeString());
freep(p); freep(p);
return 0; return 0;
} }
if(bS) if(bS)
{ {
if(cS) if(cS)
{ {
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
ConOutPrintf(_T("%s\n"), GetTimeString()); ConOutPrintf(_T("%s\n"), GetTimeString());
PrintElapsedTime(GetTickCount()-cT, iFormat); PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p); freep(p);
return 0; return 0;
} }
cT=GetTickCount(); cT=GetTickCount();
cS=TRUE; cS=TRUE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
ConOutPuts(GetTimeString()); ConOutPuts(GetTimeString());
freep(p); freep(p);
return 0; return 0;
} }
if (NewClkStatus == NCS_NOT_SPECIFIED) if (NewClkStatus == NCS_NOT_SPECIFIED)
{ {
if (cS) if (cS)
{ {
cS=FALSE; cS=FALSE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
ConOutPrintf(_T("%s\n"), GetTimeString()); ConOutPrintf(_T("%s\n"), GetTimeString());
PrintElapsedTime(GetTickCount()-cT, iFormat); PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p); freep(p);
return 0; return 0;
} }
cT=GetTickCount(); cT=GetTickCount();
cS=TRUE; cS=TRUE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
ConOutPuts(GetTimeString()); ConOutPuts(GetTimeString());
freep(p); freep(p);
return 0; return 0;
} }
if (NewClkStatus == NCS_OFF) if (NewClkStatus == NCS_OFF)
{ {
if (cS) if (cS)
{ {
cS=FALSE; cS=FALSE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
ConOutPrintf(_T("%s\n"), GetTimeString()); ConOutPrintf(_T("%s\n"), GetTimeString());
PrintElapsedTime(GetTickCount()-cT, iFormat); PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p); freep(p);
return 0; return 0;
} }
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
ConOutPuts(GetTimeString()); ConOutPuts(GetTimeString());
freep(p); freep(p);
return 0; return 0;
} }
freep(p); freep(p);
return 0; return 0;
} }
#endif /* INCLUDE_CMD_TIMER */ #endif /* INCLUDE_CMD_TIMER */

View file

@ -3,10 +3,10 @@
* *
* *
* History: * History:
* 1999-02-11 Emanuele Aliberti * 1999-02-11 Emanuele Aliberti
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #include "precomp.h"
@ -16,19 +16,18 @@
INT cmd_title (LPTSTR param) INT cmd_title (LPTSTR param)
{ {
/* Do nothing if no args */
if (*param == _T('\0'))
return 0;
/* Do nothing if no args */ /* Asking help? */
if (*param == _T('\0')) if (!_tcsncmp(param, _T("/?"), 2))
return 0; {
ConOutResPaging(TRUE,STRING_TITLE_HELP);
return 0;
}
/* Asking help? */ return SetConsoleTitle (param);
if (!_tcsncmp(param, _T("/?"), 2))
{
ConOutResPaging(TRUE,STRING_TITLE_HELP);
return 0;
}
return SetConsoleTitle (param);
} }
#endif /* def INCLUDE_CMD_TITLE */ #endif /* def INCLUDE_CMD_TITLE */

View file

@ -22,8 +22,8 @@
* 19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>) * 19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
* Added multiple file support (copied from y.c) * Added multiple file support (copied from y.c)
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #include "precomp.h"
@ -33,108 +33,108 @@
INT cmd_type (LPTSTR param) INT cmd_type (LPTSTR param)
{ {
TCHAR buff[256]; TCHAR buff[256];
HANDLE hFile, hConsoleOut; HANDLE hFile, hConsoleOut;
DWORD dwRet; DWORD dwRet;
INT argc,i; INT argc,i;
LPTSTR *argv; LPTSTR *argv;
LPTSTR errmsg; LPTSTR errmsg;
BOOL bPaging = FALSE; BOOL bPaging = FALSE;
BOOL bFirstTime = TRUE; BOOL bFirstTime = TRUE;
hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE); hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE);
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
ConOutResPaging(TRUE,STRING_TYPE_HELP1); ConOutResPaging(TRUE,STRING_TYPE_HELP1);
return 0; return 0;
} }
if (!*param) if (!*param)
{ {
error_req_param_missing (); error_req_param_missing ();
return 1; return 1;
} }
argv = split (param, &argc, TRUE, FALSE); argv = split (param, &argc, TRUE, FALSE);
for(i = 0; i < argc; i++) for(i = 0; i < argc; i++)
{ {
if(*argv[i] == _T('/') && _tcslen(argv[i]) >= 2 && _totupper(argv[i][1]) == _T('P')) if(*argv[i] == _T('/') && _tcslen(argv[i]) >= 2 && _totupper(argv[i][1]) == _T('P'))
{ {
bPaging = TRUE; bPaging = TRUE;
} }
} }
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
if (_T('/') == argv[i][0] && _totupper(argv[i][1]) != _T('P')) if (_T('/') == argv[i][0] && _totupper(argv[i][1]) != _T('P'))
{ {
ConErrResPrintf(STRING_TYPE_ERROR1, argv[i] + 1); ConErrResPrintf(STRING_TYPE_ERROR1, argv[i] + 1);
continue; continue;
} }
nErrorLevel = 0; nErrorLevel = 0;
hFile = CreateFile(argv[i], hFile = CreateFile(argv[i],
GENERIC_READ, GENERIC_READ,
FILE_SHARE_READ,NULL, FILE_SHARE_READ,NULL,
OPEN_EXISTING, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL); FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile == INVALID_HANDLE_VALUE) if(hFile == INVALID_HANDLE_VALUE)
{ {
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_FROM_SYSTEM,
NULL, NULL,
GetLastError(), GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &errmsg, (LPTSTR) &errmsg,
0, 0,
NULL); NULL);
ConErrPrintf (_T("%s - %s"), argv[i], errmsg); ConErrPrintf (_T("%s - %s"), argv[i], errmsg);
LocalFree (errmsg); LocalFree (errmsg);
nErrorLevel = 1; nErrorLevel = 1;
continue; continue;
} }
if (bPaging) if (bPaging)
{ {
while (FileGetString (hFile, buff, sizeof(buff) / sizeof(TCHAR))) while (FileGetString (hFile, buff, sizeof(buff) / sizeof(TCHAR)))
{ {
if (ConOutPrintfPaging(bFirstTime, _T("%s"), buff) == 1) if (ConOutPrintfPaging(bFirstTime, _T("%s"), buff) == 1)
{ {
bCtrlBreak = FALSE; bCtrlBreak = FALSE;
CloseHandle(hFile); CloseHandle(hFile);
freep(argv); freep(argv);
return 0; return 0;
} }
bFirstTime = FALSE; bFirstTime = FALSE;
} }
} }
else else
{ {
while (ReadFile(hFile, buff, sizeof(buff), &dwRet, NULL) && dwRet > 0) while (ReadFile(hFile, buff, sizeof(buff), &dwRet, NULL) && dwRet > 0)
{ {
WriteFile(hConsoleOut, buff, dwRet, &dwRet, NULL); WriteFile(hConsoleOut, buff, dwRet, &dwRet, NULL);
if (bCtrlBreak) if (bCtrlBreak)
{ {
bCtrlBreak = FALSE; bCtrlBreak = FALSE;
CloseHandle(hFile); CloseHandle(hFile);
freep(argv); freep(argv);
return 0; return 0;
} }
} }
} }
ConOutPuts(_T("\n")); ConOutPuts(_T("\n"));
CloseHandle(hFile); CloseHandle(hFile);
} }
freep (argv); freep (argv);
return 0; return 0;
} }
#endif #endif

View file

@ -27,101 +27,98 @@
VOID ShortVersion (VOID) VOID ShortVersion (VOID)
{ {
OSVERSIONINFO VersionInfo; OSVERSIONINFO VersionInfo;
ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_RELEASE_STR), _T(KERNEL_VERSION_BUILD_STR)); ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_RELEASE_STR), _T(KERNEL_VERSION_BUILD_STR));
VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
memset(VersionInfo.szCSDVersion, 0, sizeof(VersionInfo.szCSDVersion)); memset(VersionInfo.szCSDVersion, 0, sizeof(VersionInfo.szCSDVersion));
if (GetVersionEx(&VersionInfo)) if (GetVersionEx(&VersionInfo))
{ {
LPTSTR RosVersion; LPTSTR RosVersion;
SIZE_T RosVersionLen; SIZE_T RosVersionLen;
RosVersion = VersionInfo.szCSDVersion + _tcslen(VersionInfo.szCSDVersion) + 1; RosVersion = VersionInfo.szCSDVersion + _tcslen(VersionInfo.szCSDVersion) + 1;
RosVersionLen = sizeof(VersionInfo.szCSDVersion) / sizeof(VersionInfo.szCSDVersion[0]) - RosVersionLen = sizeof(VersionInfo.szCSDVersion) / sizeof(VersionInfo.szCSDVersion[0]) -
(RosVersion - VersionInfo.szCSDVersion); (RosVersion - VersionInfo.szCSDVersion);
if (7 <= RosVersionLen && 0 == _tcsnicmp(RosVersion, _T("ReactOS"), 7)) if (7 <= RosVersionLen && 0 == _tcsnicmp(RosVersion, _T("ReactOS"), 7))
{ {
ConOutResPrintf(STRING_VERSION_RUNVER, RosVersion); ConOutResPrintf(STRING_VERSION_RUNVER, RosVersion);
} }
} }
ConOutPuts (_T("\n")); ConOutPuts (_T("\n"));
} }
#ifdef INCLUDE_CMD_VER #ifdef INCLUDE_CMD_VER
/* /*
* display shell version info internal command. * display shell version info internal command.
*
*
*/ */
INT cmd_ver (LPTSTR param) INT cmd_ver (LPTSTR param)
{ {
INT i; INT i;
nErrorLevel = 0; nErrorLevel = 0;
if (_tcsstr (param, _T("/?")) != NULL) if (_tcsstr (param, _T("/?")) != NULL)
{ {
ConOutResPaging(TRUE,STRING_VERSION_HELP1); ConOutResPaging(TRUE,STRING_VERSION_HELP1);
return 0; return 0;
} }
ShortVersion(); ShortVersion();
/* Basic copyright notice */ /* Basic copyright notice */
if (param[0] != _T('\0')) 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.")); for (i = 0; param[i]; i++)
ConOutPuts (_T("Copyright (C) 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team")); {
/* skip spaces */
if (param[i] == _T(' '))
continue;
for (i = 0; param[i]; i++) if (param[i] == _T('/'))
{ {
/* skip spaces */ /* is this a lone '/' ? */
if (param[i] == _T(' ')) if (param[i + 1] == 0)
continue; {
error_invalid_switch (_T(' '));
return 1;
}
continue;
}
if (param[i] == _T('/')) if (_totupper (param[i]) == _T('W'))
{ {
/* is this a lone '/' ? */ /* Warranty notice */
if (param[i + 1] == 0) ConOutResPuts(STRING_VERSION_HELP3);
{ }
error_invalid_switch (_T(' ')); else if (_totupper (param[i]) == _T('R'))
return 1; {
} /* Redistribution notice */
continue; ConOutResPuts(STRING_VERSION_HELP4);
} }
else if (_totupper (param[i]) == _T('C'))
if (_totupper (param[i]) == _T('W')) {
{ /* Developer listing */
/* Warranty notice */ ConOutResPuts(STRING_VERSION_HELP6);
ConOutResPuts(STRING_VERSION_HELP3); ConOutResPuts(STRING_FREEDOS_DEV);
} ConOutResPuts(STRING_VERSION_HELP7);
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); ConOutResPuts(STRING_REACTOS_DEV);
} }
else else
{ {
error_invalid_switch ((TCHAR)_totupper (param[i])); error_invalid_switch ((TCHAR)_totupper (param[i]));
return 1; return 1;
} }
} }
ConOutResPuts(STRING_VERSION_HELP5); ConOutResPuts(STRING_VERSION_HELP5);
} }
return 0; return 0;
} }
#endif #endif

View file

@ -14,8 +14,8 @@
* 20-Jan-1999 (Eric Kohl) * 20-Jan-1999 (Eric Kohl)
* Unicode and redirection ready! * Unicode and redirection ready!
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #include "precomp.h"
@ -29,19 +29,19 @@ static BOOL bVerify = FALSE;
INT cmd_verify (LPTSTR param) INT cmd_verify (LPTSTR param)
{ {
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
ConOutResPaging(TRUE,STRING_VERIFY_HELP1); ConOutResPaging(TRUE,STRING_VERIFY_HELP1);
return 0; return 0;
} }
if (!OnOffCommand(param, &bVerify, STRING_VERIFY_HELP2)) if (!OnOffCommand(param, &bVerify, STRING_VERIFY_HELP2))
{ {
ConErrResPuts(STRING_VERIFY_HELP3); ConErrResPuts(STRING_VERIFY_HELP3);
return nErrorLevel = 1; return nErrorLevel = 1;
} }
return nErrorLevel = 0; return nErrorLevel = 0;
} }
#endif #endif

View file

@ -28,85 +28,87 @@
static INT static INT
PrintVolumeHeader (LPTSTR pszRootPath) PrintVolumeHeader (LPTSTR pszRootPath)
{ {
TCHAR szVolName[80]; TCHAR szVolName[80];
DWORD dwSerialNr; DWORD dwSerialNr;
/* get the volume information of the drive */ /* get the volume information of the drive */
if(!GetVolumeInformation (pszRootPath, if(!GetVolumeInformation(pszRootPath,
szVolName, szVolName,
80, 80,
&dwSerialNr, &dwSerialNr,
NULL, NULL,
NULL, NULL,
NULL, NULL,
0)) 0))
{ {
ErrorMessage (GetLastError (), _T("")); ErrorMessage(GetLastError (), _T(""));
return 1; return 1;
} }
/* print drive info */ /* print drive info */
if (szVolName[0] != '\0') if (szVolName[0] != '\0')
{ {
ConOutResPrintf(STRING_VOL_HELP1, pszRootPath[0],szVolName); ConOutResPrintf(STRING_VOL_HELP1, pszRootPath[0],szVolName);
} }
else else
{ {
ConOutResPrintf(STRING_VOL_HELP2, pszRootPath[0]); ConOutResPrintf(STRING_VOL_HELP2, pszRootPath[0]);
} }
/* print the volume serial number */ /* print the volume serial number */
ConOutResPrintf(STRING_VOL_HELP3, HIWORD(dwSerialNr), LOWORD(dwSerialNr)); ConOutResPrintf(STRING_VOL_HELP3, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
return 0; return 0;
} }
INT cmd_vol (LPTSTR param) INT cmd_vol (LPTSTR param)
{ {
TCHAR szRootPath[] = _T("A:\\"); TCHAR szRootPath[] = _T("A:\\");
TCHAR szPath[MAX_PATH]; TCHAR szPath[MAX_PATH];
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp(param, _T("/?"), 2))
{ {
ConOutResPaging(TRUE,STRING_VOL_HELP4); ConOutResPaging(TRUE,STRING_VOL_HELP4);
return 0; return 0;
} }
nErrorLevel = 0; nErrorLevel = 0;
if (param[0] == _T('\0')) if (param[0] == _T('\0'))
{ {
GetCurrentDirectory (MAX_PATH, szPath); GetCurrentDirectory(MAX_PATH, szPath);
szRootPath[0] = szPath[0]; szRootPath[0] = szPath[0];
} }
else else
{ {
_tcsupr (param); _tcsupr (param);
if (param[1] == _T(':')) if (param[1] == _T(':'))
szRootPath[0] = param[0]; {
else szRootPath[0] = param[0];
{ }
error_invalid_drive (); else
nErrorLevel = 1; {
return 1; error_invalid_drive ();
} nErrorLevel = 1;
} return 1;
}
}
if (!IsValidPathName (szRootPath)) if (!IsValidPathName (szRootPath))
{ {
error_invalid_drive (); error_invalid_drive ();
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
/* print the header */ /* print the header */
if (!PrintVolumeHeader (szRootPath)) if (!PrintVolumeHeader (szRootPath))
{ {
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
return 0; return 0;
} }
#endif #endif

View file

@ -69,7 +69,7 @@
* Some minor changes and improvements. * Some minor changes and improvements.
* *
* 10-Jul-2004 (Jens Collin <jens.collin@lakhei.com>) * 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 BOOL
SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pPathExt, LPTSTR pDirectory) SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pPathExt, LPTSTR pDirectory)
{ {
TCHAR szPathBuffer[CMDLINE_LENGTH], *pszPathEnd; TCHAR szPathBuffer[CMDLINE_LENGTH], *pszPathEnd;
LPTSTR s,f; LPTSTR s,f;
/* initialize full name buffer */ /* initialize full name buffer */
*pFullName = _T('\0'); *pFullName = _T('\0');
TRACE ("SearchForExecutableSingle: \'%s\' in dir: \'%s\'\n", TRACE ("SearchForExecutableSingle: \'%s\' in dir: \'%s\'\n",
debugstr_aw(pFileName), debugstr_aw(pDirectory)); debugstr_aw(pFileName), debugstr_aw(pDirectory));
pszPathEnd = szPathBuffer; pszPathEnd = szPathBuffer;
if (pDirectory != NULL) if (pDirectory != NULL)
{ {
_tcscpy(szPathBuffer, pDirectory); _tcscpy(szPathBuffer, pDirectory);
pszPathEnd += _tcslen(pszPathEnd); pszPathEnd += _tcslen(pszPathEnd);
*pszPathEnd++ = _T('\\'); *pszPathEnd++ = _T('\\');
} }
_tcscpy(pszPathEnd, pFileName); _tcscpy(pszPathEnd, pFileName);
pszPathEnd += _tcslen(pszPathEnd); pszPathEnd += _tcslen(pszPathEnd);
if (IsExistingFile (szPathBuffer)) if (IsExistingFile (szPathBuffer))
{ {
TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer)); TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer));
_tcscpy (pFullName, szPathBuffer); _tcscpy (pFullName, szPathBuffer);
return TRUE; return TRUE;
} }
s = pPathExt; s = pPathExt;
while (s && *s) while (s && *s)
{ {
f = _tcschr (s, _T(';')); f = _tcschr (s, _T(';'));
if (f) if (f)
{ {
_tcsncpy (pszPathEnd, s, (size_t)(f-s)); _tcsncpy (pszPathEnd, s, (size_t)(f-s));
pszPathEnd[f-s] = _T('\0'); pszPathEnd[f-s] = _T('\0');
s = f + 1; s = f + 1;
} }
else else
{ {
_tcscpy (pszPathEnd, s); _tcscpy (pszPathEnd, s);
s = NULL; s = NULL;
} }
if (IsExistingFile (szPathBuffer)) if (IsExistingFile (szPathBuffer))
{ {
TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer)); TRACE ("Found: \'%s\'\n", debugstr_aw(szPathBuffer));
_tcscpy (pFullName, szPathBuffer); _tcscpy (pFullName, szPathBuffer);
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
} }
BOOL BOOL
SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName) SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
{ {
static TCHAR pszDefaultPathExt[] = _T(".com;.exe;.bat;.cmd"); static TCHAR pszDefaultPathExt[] = _T(".com;.exe;.bat;.cmd");
LPTSTR pszPathExt, pszPath; LPTSTR pszPathExt, pszPath;
LPTSTR pCh; LPTSTR pCh;
DWORD dwBuffer; DWORD dwBuffer;
TRACE ("SearchForExecutable: \'%s\'\n", debugstr_aw(pFileName)); TRACE ("SearchForExecutable: \'%s\'\n", debugstr_aw(pFileName));
/* load environment varable PATHEXT */ /* load environment varable PATHEXT */
pszPathExt = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); pszPathExt = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE); dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE);
if (dwBuffer > ENV_BUFFER_SIZE) if (dwBuffer > ENV_BUFFER_SIZE)
{ {
pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR)); pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR));
GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, dwBuffer); GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, dwBuffer);
_tcslwr(pszPathExt); _tcslwr(pszPathExt);
} }
else if (0 == dwBuffer) else if (0 == dwBuffer)
{ {
_tcscpy(pszPathExt, pszDefaultPathExt); _tcscpy(pszPathExt, pszDefaultPathExt);
} }
else else
{ {
_tcslwr(pszPathExt); _tcslwr(pszPathExt);
} }
/* Check if valid directly on specified path */ /* Check if valid directly on specified path */
if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, NULL)) if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, NULL))
{ {
cmd_free(pszPathExt); cmd_free(pszPathExt);
return TRUE; return TRUE;
} }
/* If an explicit directory was given, stop here - no need to search PATH. */ /* If an explicit directory was given, stop here - no need to search PATH. */
if (pFileName[1] == _T(':') || _tcschr(pFileName, _T('\\'))) if (pFileName[1] == _T(':') || _tcschr(pFileName, _T('\\')))
{ {
cmd_free(pszPathExt); cmd_free(pszPathExt);
return FALSE; return FALSE;
} }
/* load environment varable PATH into buffer */ /* load environment varable PATH into buffer */
pszPath = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); pszPath = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE); dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE);
if (dwBuffer > ENV_BUFFER_SIZE) if (dwBuffer > ENV_BUFFER_SIZE)
{ {
pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR)); pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR));
GetEnvironmentVariable (_T("PATH"), pszPath, dwBuffer); 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 */ /* search in PATH */
pCh = _tcstok(pszPath, _T(";")); pCh = _tcstok(pszPath, _T(";"));
while (pCh) while (pCh)
{ {
if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, pCh)) if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, pCh))
{ {
cmd_free(pszPath); cmd_free(pszPath);
cmd_free(pszPathExt); cmd_free(pszPathExt);
return TRUE; return TRUE;
} }
pCh = _tcstok(NULL, _T(";")); pCh = _tcstok(NULL, _T(";"));
} }
cmd_free(pszPath); cmd_free(pszPath);
cmd_free(pszPathExt); cmd_free(pszPathExt);
return FALSE; return FALSE;
} }
/* EOF */ /* EOF */

View file

@ -3,170 +3,168 @@
* *
* clone from 4nt activate command * clone from 4nt activate command
* *
* 10 Sep 1999 (Paolo Pantaleo) * 10 Sep 1999 (Paolo Pantaleo)
* started (window command in WINDOW.c) * 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 * activate and window in a single file using mainly the same code
* (nice size optimization :) * (nice size optimization :)
* *
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
* Remove all hardcode string to En.rc * Remove all hardcoded strings in En.rc
*/ */
#include "precomp.h" #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_MIN 0x01
#define A_MAX 0x02 #define A_MAX 0x02
#define A_RESTORE 0x04 #define A_RESTORE 0x04
#define A_POS 0x08 #define A_POS 0x08
#define A_SIZE 0x10 #define A_SIZE 0x10
#define A_CLOSE 0x20 #define A_CLOSE 0x20
/*service funciton to perform actions on windows /*
* service function to perform actions on windows
param is a string to parse for options/actions *
hWnd is the handle of window on wich perform actions * 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) static INT ServiceActivate (LPTSTR param, HWND hWnd)
{ {
LPTSTR *p = 0, p_tmp; LPTSTR *p = 0, p_tmp;
INT argc = 0, i; INT argc = 0, i;
INT iAction = 0; INT iAction = 0;
LPTSTR title = 0; LPTSTR title = 0;
WINDOWPLACEMENT wp; WINDOWPLACEMENT wp;
RECT pos; RECT pos;
LPTSTR tmp; LPTSTR tmp;
if (*param)
p = split(param, &argc, FALSE);
if (*param) for (i = 0; i < argc; i++)
p = split(param, &argc, FALSE); {
p_tmp = p[i];
if (*p_tmp == _T('/'))
p_tmp++;
for (i = 0; i < argc; i++) if (_tcsicmp(p_tmp, _T("min")) == 0)
{ {
p_tmp = p[i]; iAction |= A_MIN;
if (*p_tmp == _T('/')) continue;
p_tmp++; }
if (_tcsicmp(p_tmp, _T("min")) == 0) if (_tcsicmp(p_tmp, _T("max")) == 0)
{ {
iAction |= A_MIN; iAction |= A_MAX;
continue; continue;
} }
if (_tcsicmp(p_tmp, _T("max")) == 0) if (_tcsicmp(p_tmp, _T("restore")) == 0)
{ {
iAction |= A_MAX; iAction |= A_RESTORE;
continue; continue;
} }
if (_tcsicmp(p_tmp, _T("restore")) == 0) if (_tcsicmp(p_tmp, _T("close")) == 0)
{ {
iAction |= A_RESTORE; iAction |= A_CLOSE;
continue; continue;
} }
if (_tcsicmp(p_tmp, _T("close")) == 0) if (_tcsnicmp(p_tmp, _T("pos"), 3) == 0)
{ {
iAction |= A_CLOSE; iAction |= A_POS;
continue; tmp = p_tmp+3;
} if (*tmp == _T('='))
tmp++;
if (_tcsnicmp(p_tmp, _T("pos"), 3) == 0) pos.left= _ttoi(tmp);
{ if(!(tmp=_tcschr(tmp, _T(','))))
iAction |= A_POS; {
tmp = p_tmp+3; error_invalid_parameter_format(p[i]);
if (*tmp == _T('=')) freep(p);
tmp++; return 1;
}
pos.left= _ttoi(tmp); pos.top = _ttoi (++tmp);
if(!(tmp=_tcschr(tmp, _T(',')))) if(!(tmp=_tcschr(tmp, _T(','))))
{ {
error_invalid_parameter_format(p[i]); error_invalid_parameter_format(p[i]);
freep(p); freep(p);
return 1; return 1;
} }
pos.top = _ttoi (++tmp); pos.right = _ttoi(++tmp) + pos.left;
if(!(tmp=_tcschr(tmp, _T(',')))) if (!(tmp = _tcschr(tmp, _T(','))))
{ {
error_invalid_parameter_format(p[i]); error_invalid_parameter_format(p[i]);
freep(p); freep(p);
return 1; return 1;
} }
pos.bottom = _ttoi(++tmp) + pos.top;
continue;
}
pos.right = _ttoi(++tmp) + pos.left; if (_tcsnicmp(p_tmp, _T("size"), 4)==0)
if (!(tmp = _tcschr(tmp, _T(',')))) {
{ iAction |=A_SIZE;
error_invalid_parameter_format(p[i]); continue;
freep(p); }
return 1;
}
pos.bottom = _ttoi(++tmp) + pos.top;
continue;
}
if (_tcsnicmp(p_tmp, _T("size"), 4)==0) /* none of them=window title */
{ if (title)
iAction |=A_SIZE; {
continue; error_invalid_parameter_format(p[i]);
} freep(p);
return 1;
}
/* none of them=window title */ if (p_tmp[0] == _T('"'))
if (title) {
{ title = (p_tmp + 1);
error_invalid_parameter_format(p[i]); *_tcschr(p_tmp + 1, _T('"')) = 0;
freep(p); continue;
return 1; }
} title = p_tmp;
}
if (p_tmp[0] == _T('"')) if (title)
{ SetWindowText(hWnd, title);
title = (p_tmp + 1);
*_tcschr(p_tmp + 1, _T('"')) = 0;
continue;
}
title = p_tmp;
}
if (title) wp.length = sizeof(WINDOWPLACEMENT);
SetWindowText(hWnd, title); GetWindowPlacement(hWnd, &wp);
wp.length = sizeof(WINDOWPLACEMENT); if (iAction & A_POS)
GetWindowPlacement(hWnd, &wp); wp.rcNormalPosition = pos;
if (iAction & A_POS) if (iAction & A_MIN)
wp.rcNormalPosition = pos; wp.showCmd = SW_MINIMIZE;
if (iAction & A_MIN) if (iAction & A_MAX)
wp.showCmd = SW_MINIMIZE; wp.showCmd = SW_SHOWMAXIMIZED;
if (iAction & A_MAX) /* if no actions are specified default is SW_RESTORE */
wp.showCmd = SW_SHOWMAXIMIZED; if ((iAction & A_RESTORE) || (!iAction))
wp.showCmd = SW_RESTORE;
/*if no actions are specified default is SW_RESTORE*/ if (iAction & A_CLOSE)
if ((iAction & A_RESTORE) || (!iAction)) {
wp.showCmd = SW_RESTORE; FIXME("!!!FIXME: CLOSE Not implemented!!!\n");
}
if (iAction & A_CLOSE) wp.length = sizeof(WINDOWPLACEMENT);
{ SetWindowPlacement(hWnd, &wp);
FIXME("!!!FIXME: CLOSE Not implemented!!!\n");
}
wp.length = sizeof(WINDOWPLACEMENT); if (p)
SetWindowPlacement(hWnd, &wp); freep(p);
if (p) return 0;
freep(p);
return 0;
} }
@ -174,54 +172,54 @@ static INT ServiceActivate (LPTSTR param, HWND hWnd)
INT CommandWindow (LPTSTR param) 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); ConOutResPaging(TRUE,STRING_WINDOW_HELP1);
return 0; return 0;
} }
hwnd = GetConsoleWindow(); hwnd = GetConsoleWindow();
Sleep(0); Sleep(0);
return ServiceActivate(param, hwnd); return ServiceActivate(param, hwnd);
} }
INT CommandActivate (LPTSTR param) INT CommandActivate (LPTSTR param)
{ {
HWND hwnd; HWND hwnd;
LPTSTR *arg; LPTSTR *arg;
INT argc; INT argc;
if (_tcsncmp (param, _T("/?"), 2) == 0) if (_tcsncmp (param, _T("/?"), 2) == 0)
{ {
ConOutResPaging(TRUE,STRING_WINDOW_HELP2); ConOutResPaging(TRUE,STRING_WINDOW_HELP2);
return 0; return 0;
} }
if(!(*param)) if(!(*param))
return 1; return 1;
/*Split the user input into array*/ /* Split the user input into array */
arg = split (param, &argc, FALSE); arg = split (param, &argc, FALSE);
if(argc < 2) if(argc < 2)
{ {
if(arg != NULL) if(arg != NULL)
freep(arg); freep(arg);
} }
hwnd = FindWindow(NULL, arg[0]); hwnd = FindWindow(NULL, arg[0]);
if (hwnd == NULL) if (hwnd == NULL)
{ {
if(arg != NULL) if(arg != NULL)
freep(arg); freep(arg);
ConErrResPuts(STRING_WINDOW_ERROR1); ConErrResPuts(STRING_WINDOW_ERROR1);
return 1; return 1;
} }
if(arg != NULL) if(arg != NULL)
freep(arg); 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) */