Minor fixes.

svn path=/trunk/; revision=685
This commit is contained in:
Eric Kohl 1999-10-03 22:20:33 +00:00
parent 49f51f37f3
commit c2829c9869
20 changed files with 372 additions and 264 deletions

View file

@ -45,13 +45,13 @@ typedef struct tagALIAS
struct tagALIAS *next; struct tagALIAS *next;
LPTSTR lpName; LPTSTR lpName;
LPTSTR lpSubst; LPTSTR lpSubst;
WORD wUsed; DWORD dwUsed;
} ALIAS, *LPALIAS; } ALIAS, *LPALIAS;
static LPALIAS lpFirst = NULL; static LPALIAS lpFirst = NULL;
static LPALIAS lpLast = NULL; static LPALIAS lpLast = NULL;
static WORD wUsed = 0; static DWORD dwUsed = 0;
/* module internal functions */ /* module internal functions */
@ -159,7 +159,7 @@ AddAlias (LPTSTR name, LPTSTR subst)
/* it's necessary for recursive substitution */ /* it's necessary for recursive substitution */
partstrlwr (ptr->lpSubst); partstrlwr (ptr->lpSubst);
ptr->wUsed = 0; ptr->dwUsed = 0;
/* Alias table must be sorted! /* Alias table must be sorted!
* Here a little example: * Here a little example:
@ -208,6 +208,34 @@ AddAlias (LPTSTR name, LPTSTR subst)
} }
VOID InitializeAlias (VOID)
{
lpFirst = NULL;
lpLast = NULL;
dwUsed = 0;
}
VOID DestroyAlias (VOID)
{
while (lpFirst->next != NULL)
{
lpLast = lpFirst;
lpFirst = lpLast->next;
free (lpLast->lpName);
free (lpLast->lpSubst);
free (lpLast);
}
free (lpFirst->lpName);
free (lpFirst->lpSubst);
free (lpFirst);
lpFirst = NULL;
lpLast = NULL;
dwUsed = 0;
}
/* specified routines */ /* specified routines */
VOID ExpandAlias (LPTSTR cmd, INT maxlen) VOID ExpandAlias (LPTSTR cmd, INT maxlen)
{ {
@ -218,13 +246,13 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen)
short d = 1; short d = 1;
LPALIAS ptr = lpFirst; LPALIAS ptr = lpFirst;
wUsed++; dwUsed++;
if (wUsed == 0) if (dwUsed == 0)
{ {
while (ptr) while (ptr)
ptr->wUsed = 0; ptr->dwUsed = 0;
ptr = lpFirst; ptr = lpFirst;
wUsed = 1; dwUsed = 1;
} }
/* skipping white spaces */ /* skipping white spaces */
@ -249,7 +277,7 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen)
len = _tcslen (ptr->lpName); len = _tcslen (ptr->lpName);
if (!_tcsncmp (&cmd[n], ptr->lpName, len) && if (!_tcsncmp (&cmd[n], ptr->lpName, len) &&
(_istspace (cmd[n + len]) || cmd[n + len] == _T('\0')) && (_istspace (cmd[n + len]) || cmd[n + len] == _T('\0')) &&
ptr->wUsed != wUsed) ptr->dwUsed != dwUsed)
{ {
m = _tcslen (ptr->lpSubst); m = _tcslen (ptr->lpSubst);
if ((int)(_tcslen (cmd) - len + m - n) > maxlen) if ((int)(_tcslen (cmd) - len + m - n) > maxlen)
@ -263,7 +291,7 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen)
memmove (&cmd[m], &cmd[n + len], (_tcslen(&cmd[n + len]) + 1) * sizeof (TCHAR)); memmove (&cmd[m], &cmd[n + len], (_tcslen(&cmd[n + len]) + 1) * sizeof (TCHAR));
for (i = 0; i < m; i++) for (i = 0; i < m; i++)
cmd[i] = ptr->lpSubst[i]; cmd[i] = ptr->lpSubst[i];
ptr->wUsed = wUsed; ptr->dwUsed = dwUsed;
/* whitespaces are removed! */ /* whitespaces are removed! */
n = 0; n = 0;
d = 1; d = 1;
@ -275,7 +303,7 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen)
} }
VOID CommandAlias (LPTSTR cmd, LPTSTR param) INT CommandAlias (LPTSTR cmd, LPTSTR param)
{ {
LPTSTR ptr; LPTSTR ptr;
@ -297,18 +325,18 @@ VOID CommandAlias (LPTSTR cmd, LPTSTR param)
" ALIAS da=" " ALIAS da="
// "Type ALIAS without a parameter to display the alias list.\n" // "Type ALIAS without a parameter to display the alias list.\n"
)); ));
return; return 0;
} }
if (param[0] == _T('\0')) if (param[0] == _T('\0'))
{ {
PrintAlias (); PrintAlias ();
return; return 0;
} }
/* error if no '=' found */ /* error if no '=' found */
if ((ptr = _tcschr (param, _T('='))) == 0) if ((ptr = _tcschr (param, _T('='))) == 0)
return; return 1;
/* Split rest into name and substitute */ /* Split rest into name and substitute */
*ptr++ = _T('\0'); *ptr++ = _T('\0');
@ -320,6 +348,6 @@ VOID CommandAlias (LPTSTR cmd, LPTSTR param)
else else
AddAlias (param, ptr); AddAlias (param, ptr);
return; return 0;
} }
#endif #endif

View file

@ -189,7 +189,7 @@ ChangeAttribute (LPTSTR pszPath, LPTSTR pszFile, DWORD dwMask,
} }
INT cmd_attrib (LPTSTR cmd, LPTSTR param) INT CommandAttrib (LPTSTR cmd, LPTSTR param)
{ {
LPTSTR *arg; LPTSTR *arg;
INT argc, i; INT argc, i;
@ -326,9 +326,10 @@ INT cmd_attrib (LPTSTR cmd, LPTSTR param)
} }
_tcscpy (szFileName, _T("*.*")); _tcscpy (szFileName, _T("*.*"));
PrintAttribute (szPath, szFileName, bRecurse); PrintAttribute (szPath, szFileName, bRecurse);
freep (arg);
return 0;
} }
else
{
/* get full file name */ /* get full file name */
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
@ -347,10 +348,8 @@ INT cmd_attrib (LPTSTR cmd, LPTSTR param)
dwAttrib, bRecurse, bDirectories); dwAttrib, bRecurse, bDirectories);
} }
} }
}
freep (arg); freep (arg);
return 0; return 0;
} }

View file

@ -1,4 +1,5 @@
/* /* $Id: batch.c,v 1.3 1999/10/03 22:20:32 ekohl Exp $
*
* BATCH.C - batch file processor for CMD.EXE. * BATCH.C - batch file processor for CMD.EXE.
* *
* *
@ -107,7 +108,6 @@ LPTSTR FindArg (INT n)
} }
/* HBP_002 { FOR command support */
/* /*
* Batch_params builds a parameter list in newlay allocated memory. * Batch_params builds a parameter list in newlay allocated memory.
* The parameters consist of null terminated strings with a final * The parameters consist of null terminated strings with a final
@ -163,8 +163,6 @@ LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
return dp; return dp;
} }
/* HBP_002 } */
/* /*
* If a batch file is current, exits it, freeing the context block and * If a batch file is current, exits it, freeing the context block and
@ -182,7 +180,7 @@ VOID ExitBatch (LPTSTR msg)
DebugPrintf ("ExitBatch: (\'%s\')\n", msg); DebugPrintf ("ExitBatch: (\'%s\')\n", msg);
#endif #endif
if (bc) if (bc != NULL)
{ {
LPBATCH_CONTEXT t = bc; LPBATCH_CONTEXT t = bc;
@ -195,28 +193,19 @@ VOID ExitBatch (LPTSTR msg)
if (bc->params) if (bc->params)
free(bc->params); free(bc->params);
/* HBP_002 { FOR command support */
if (bc->forproto) if (bc->forproto)
free(bc->forproto); free(bc->forproto);
if (bc->ffind) if (bc->ffind)
free(bc->ffind); free(bc->ffind);
/* HBP_002 } */
/* HBP_003 { fix echo restore */
/* Preserve echo state across batch calls */ /* Preserve echo state across batch calls */
bEcho = bc->bEcho; bEcho = bc->bEcho;
/* HBP_003 fix echo restore } */
bc = bc->prev; bc = bc->prev;
free(t); free(t);
} }
/* HBP_001 } */
if (msg && *msg) if (msg && *msg)
ConOutPrintf ("%s\n", msg); ConOutPrintf ("%s\n", msg);
} }
@ -248,14 +237,10 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
return FALSE; return FALSE;
} }
/* HBP_002 { FOR command support */
/* Kill any and all FOR contexts */ /* Kill any and all FOR contexts */
while (bc && bc->forvar) while (bc && bc->forvar)
ExitBatch (NULL); ExitBatch (NULL);
/* HBP_002 } */
if (bc == NULL) if (bc == NULL)
{ {
/* No curent batch file, create a new context */ /* No curent batch file, create a new context */
@ -263,7 +248,6 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
if (n == NULL) if (n == NULL)
{ {
/* JPP 20-Jul-1998 added error checking */
error_out_of_memory (); error_out_of_memory ();
return FALSE; return FALSE;
} }
@ -280,15 +264,17 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
} }
bc->hBatchFile = hFile; bc->hBatchFile = hFile;
bc->bEcho = bEcho; /* Preserve echo across batch calls [HBP_001] */ bc->bEcho = bEcho; /* Preserve echo across batch calls */
bc->shiftlevel = 0; bc->shiftlevel = 0;
/* HBP_002 { FOR command support */
bc->ffind = NULL; bc->ffind = NULL;
bc->forvar = _T('\0'); bc->forvar = _T('\0');
bc->forproto = NULL; bc->forproto = NULL;
bc->params = BatchParams (firstword, param); bc->params = BatchParams (firstword, param);
/* HBP_002 } */
#ifdef _DEBUG
DebugPrintf ("Batch: returns TRUE\n");
#endif
return TRUE; return TRUE;
} }
@ -330,7 +316,6 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
return NULL; return NULL;
} }
/* HBP_002 { FOR command support */
/* No batch */ /* No batch */
if (bc == NULL) if (bc == NULL)
return NULL; return NULL;
@ -368,7 +353,7 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
/* For first find, allocate a find first block */ /* For first find, allocate a find first block */
if ((bc->ffind = (LPWIN32_FIND_DATA)malloc (sizeof (WIN32_FIND_DATA))) == NULL) if ((bc->ffind = (LPWIN32_FIND_DATA)malloc (sizeof (WIN32_FIND_DATA))) == NULL)
{ {
error_out_of_memory(); /* JPP 20-Jul-1998 added error checking */ error_out_of_memory();
return NULL; return NULL;
} }
@ -409,8 +394,6 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
return textline; return textline;
} }
/* HBP_002 } */
if (!FileGetString (bc->hBatchFile, textline, sizeof (textline))) if (!FileGetString (bc->hBatchFile, textline, sizeof (textline)))
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -459,3 +442,5 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
return first; return first;
} }
/* EOF */

View file

@ -1,4 +1,5 @@
/* /* $Id: call.c,v 1.3 1999/10/03 22:20:33 ekohl Exp $
*
* CALL.C - call internal batch command. * CALL.C - call internal batch command.
* *
* *
@ -90,3 +91,5 @@ INT cmd_call (LPTSTR cmd, LPTSTR param)
return 0; return 0;
} }
/* EOF */

View file

@ -21,10 +21,12 @@
#include "cmd.h" #include "cmd.h"
VOID CommandChcp (LPTSTR cmd, LPTSTR param) INT CommandChcp (LPTSTR cmd, LPTSTR param)
{ {
LPTSTR *arg; LPTSTR *arg;
INT args; INT args;
UINT uOldCodePage;
UINT uNewCodePage;
/* print help */ /* print help */
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
@ -33,28 +35,25 @@ VOID CommandChcp (LPTSTR cmd, LPTSTR param)
"CHCP [nnn]\n\n" "CHCP [nnn]\n\n"
" nnn Specifies the active code page number.\n\n" " nnn Specifies the active code page number.\n\n"
"Type CHCP without a parameter to display the active code page number.")); "Type CHCP without a parameter to display the active code page number."));
return; return 0;
} }
/* get parameters */
arg = split (param, &args);
if (args == 0) if (args == 0)
{ {
/* display active code page number */ /* display active code page number */
ConOutPrintf ("Active code page: %u\n", GetConsoleCP ()); ConOutPrintf ("Active code page: %u\n", GetConsoleCP ());
return 0;
} }
else if (args >= 2)
if (args >= 2)
{ {
/* too many parameters */ /* too many parameters */
ConErrPrintf ("Invalid parameter format - %s\n", param); ConErrPrintf ("Invalid parameter format - %s\n", param);
return 1;
} }
else
{
/* set active code page number */
UINT uOldCodePage; /* get parameters */
UINT uNewCodePage; arg = split (param, &args);
/* save old code page */ /* save old code page */
uOldCodePage = GetConsoleCP (); uOldCodePage = GetConsoleCP ();
@ -64,10 +63,10 @@ VOID CommandChcp (LPTSTR cmd, LPTSTR param)
if (uNewCodePage == 0) if (uNewCodePage == 0)
{ {
ConErrPrintf ("Parameter format incorrect - %s\n", arg[0]); ConErrPrintf ("Parameter format incorrect - %s\n", arg[0]);
freep (arg);
return 1;
} }
else
{
if (!SetConsoleCP (uNewCodePage)) if (!SetConsoleCP (uNewCodePage))
{ {
ConErrPrintf ("Invalid code page\n"); ConErrPrintf ("Invalid code page\n");
@ -77,12 +76,10 @@ VOID CommandChcp (LPTSTR cmd, LPTSTR param)
SetConsoleOutputCP (uNewCodePage); SetConsoleOutputCP (uNewCodePage);
InitLocale (); InitLocale ();
} }
}
}
freep (arg); freep (arg);
return; return 0;
} }
#endif /* INCLUDE_CMD_CHCP */ #endif /* INCLUDE_CMD_CHCP */

View file

@ -52,10 +52,6 @@ GetCharacterTimeout (LPTCH ch, DWORD dwMilliseconds)
hInput = GetStdHandle (STD_INPUT_HANDLE); hInput = GetStdHandle (STD_INPUT_HANDLE);
#ifdef _DEBUG
if (hInput == INVALID_HANDLE_VALUE)
DebugPrintf ("Invalid input handle!!!\n");
#endif
//if the timeout experied return GC_TIMEOUT //if the timeout experied return GC_TIMEOUT
if (WaitForSingleObject (hInput, dwMilliseconds) == WAIT_TIMEOUT) if (WaitForSingleObject (hInput, dwMilliseconds) == WAIT_TIMEOUT)
return GC_TIMEOUT; return GC_TIMEOUT;
@ -284,25 +280,25 @@ loop:
switch (GCret) switch (GCret)
{ {
case GC_TIMEOUT: case GC_TIMEOUT:
#ifdef DEBUG #ifdef _DEBUG
DebugPrintf (_T("GC_TIMEOUT\n")); DebugPrintf (_T("GC_TIMEOUT\n"));
DebugPrintf (_T("elapsed %d msecs\n"), GetTickCount () - clk); DebugPrintf (_T("elapsed %d msecs\n"), GetTickCount () - clk);
#endif /* DEBUG */ #endif /* _DEBUG */
break; break;
case GC_NOKEY: case GC_NOKEY:
#ifdef DEBUG #ifdef _DEBUG
DebugPrintf(_T("GC_NOKEY\n")); DebugPrintf(_T("GC_NOKEY\n"));
DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk); DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk);
#endif /* DEBUG */ #endif /* _DEBUG */
goto loop; goto loop;
case GC_KEYREAD: case GC_KEYREAD:
#ifdef DEBUG #ifdef _DEBUG
DebugPrintf(_T("GC_KEYREAD\n")); DebugPrintf(_T("GC_KEYREAD\n"));
DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk); DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk);
DebugPrintf(_T("read %c"), Ch); DebugPrintf(_T("read %c"), Ch);
#endif /* DEBUG */ #endif /* _DEBUG */
if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1) if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1)
{ {
Beep (440, 50); Beep (440, 50);
@ -312,10 +308,10 @@ loop:
break; break;
} }
#ifdef DEBUG #ifdef _DEBUG
DebugPrintf(_T("exiting waiting loop after %d msecs\n"), DebugPrintf(_T("exiting wait loop after %d msecs\n"),
GetTickCount () - clk); GetTickCount () - clk);
#endif /* DEBUG */ #endif /* _DEBUG */
val = IsKeyInString (lpOptions, cDefault, bCaseSensitive); val = IsKeyInString (lpOptions, cDefault, bCaseSensitive);
ConOutPrintf (_T("%c\n"), lpOptions[val]); ConOutPrintf (_T("%c\n"), lpOptions[val]);
@ -324,9 +320,9 @@ loop:
freep (arg); freep (arg);
#ifdef DEBUG #ifdef _DEBUG
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel); DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
#endif /* DEBUG */ #endif /* _DEBUG */
return 0; return 0;
} }

View file

@ -332,8 +332,10 @@ DoCommand (LPTSTR line)
* full input/output redirection and piping are supported * full input/output redirection and piping are supported
*/ */
VOID ParseCommandLine (LPTSTR s) VOID ParseCommandLine (LPTSTR cmd)
{ {
TCHAR cmdline[CMDLINE_LENGTH];
LPTSTR s;
#ifdef FEATURE_REDIRECTION #ifdef FEATURE_REDIRECTION
TCHAR in[CMDLINE_LENGTH] = ""; TCHAR in[CMDLINE_LENGTH] = "";
TCHAR out[CMDLINE_LENGTH] = ""; TCHAR out[CMDLINE_LENGTH] = "";
@ -350,9 +352,12 @@ VOID ParseCommandLine (LPTSTR s)
HANDLE hOldConErr; HANDLE hOldConErr;
#endif /* FEATURE_REDIRECTION */ #endif /* FEATURE_REDIRECTION */
_tcscpy (cmdline, cmd);
s = &cmdline[0];
#ifdef _DEBUG #ifdef _DEBUG
DebugPrintf ("ParseCommandLine: (\'%s\')]\n", s); DebugPrintf ("ParseCommandLine: (\'%s\')]\n", s);
#endif /* _DEBUG */ #endif /* DEBUG */
#ifdef FEATURE_ALIASES #ifdef FEATURE_ALIASES
/* expand all aliases */ /* expand all aliases */
@ -658,8 +663,6 @@ ProcessInput (BOOL bFlag)
LPTSTR tp; LPTSTR tp;
LPTSTR ip; LPTSTR ip;
LPTSTR cp; LPTSTR cp;
/* JPP 19980807 - changed name so not to conflict with echo global */
BOOL bEchoThisLine; BOOL bEchoThisLine;
do do
@ -835,8 +838,10 @@ ShowCommands (VOID)
* argv - command-line parameters * argv - command-line parameters
* *
*/ */
static VOID Initialize (int argc, char *argv[]) static VOID
Initialize (int argc, char *argv[])
{ {
TCHAR commandline[CMDLINE_LENGTH];
INT i; INT i;
/* Added by Rob Lake 06/16/98. This enables the command.com /* Added by Rob Lake 06/16/98. This enables the command.com
@ -863,13 +868,7 @@ static VOID Initialize (int argc, char *argv[])
hOut = GetStdHandle (STD_OUTPUT_HANDLE); hOut = GetStdHandle (STD_OUTPUT_HANDLE);
hIn = GetStdHandle (STD_INPUT_HANDLE); hIn = GetStdHandle (STD_INPUT_HANDLE);
#ifdef INCLUDE_CMD_CHDIR if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2))
InitLastPath ();
#endif
if (argc >= 2)
{
if (!_tcsncmp (argv[1], _T("/?"), 2))
{ {
ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter\n\n" ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter\n\n"
"CMD [/P][/C]...\n\n" "CMD [/P][/C]...\n\n"
@ -877,7 +876,19 @@ static VOID Initialize (int argc, char *argv[])
" /C ...")); " /C ..."));
ExitProcess (0); ExitProcess (0);
} }
else
ShortVersion ();
ShowCommands ();
#ifdef INCLUDE_CMD_CHDIR
InitLastPath ();
#endif
#ifdef FATURE_ALIASES
InitializeAlias ();
#endif
if (argc >= 2)
{ {
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
@ -893,24 +904,23 @@ static VOID Initialize (int argc, char *argv[])
#endif #endif
} }
else else
ParseCommandLine ("\\autoexec.bat"); {
ParseCommandLine (_T("\\autoexec.bat"));
}
bCanExit = FALSE; bCanExit = FALSE;
} }
else if (!_tcsicmp (argv[i], _T("/c"))) else if (!_tcsicmp (argv[i], _T("/c")))
{ {
/* This just runs a program and exits, RL: 06/16,21/98 */ /* This just runs a program and exits, RL: 06/16,21/98 */
char commandline[CMDLINE_LENGTH];
++i; ++i;
strcpy(commandline, argv[i]); _tcscpy (commandline, argv[i]);
while (argv[++i]) while (argv[++i])
{ {
strcat(commandline, " "); _tcscat (commandline, " ");
strcat(commandline, argv[i]); _tcscat (commandline, argv[i]);
} }
ParseCommandLine(commandline); ParseCommandLine(commandline);
/* HBP_003 { Fix return value when /C used }*/
ExitProcess (ProcessInput (TRUE)); ExitProcess (ProcessInput (TRUE));
} }
@ -920,10 +930,35 @@ static VOID Initialize (int argc, char *argv[])
/* process /t (color) argument */ /* process /t (color) argument */
wDefColor = (WORD)strtoul (&argv[i][3], NULL, 16); wDefColor = (WORD)strtoul (&argv[i][3], NULL, 16);
wColor = wDefColor; wColor = wDefColor;
SetScreenColor (wColor);
} }
#endif #endif
} }
} }
/* run cmdstart.bat */
if (IsValidFileName (_T("cmdstart.bat")))
{
ParseCommandLine (_T("cmdstart.bat"));
}
else if (IsValidFileName (_T("\\cmdstart.bat")))
{
ParseCommandLine (_T("\\cmdstart.bat"));
}
else
{
/* try to run cmdstart.bat from install dir */
LPTSTR p;
_tcscpy (commandline, argv[0]);
p = _tcsrchr (commandline, _T('\\')) + 1;
_tcscpy (p, _T("cmdstart.bat"));
if (IsValidFileName (_T("commandline")))
{
ConErrPrintf ("Running %s...\n", commandline);
ParseCommandLine (commandline);
}
} }
#ifdef FEATURE_DIR_STACK #ifdef FEATURE_DIR_STACK
@ -931,14 +966,6 @@ static VOID Initialize (int argc, char *argv[])
InitDirectoryStack (); InitDirectoryStack ();
#endif #endif
#ifdef INCLUDE_CMD_COLOR
/* set default colors */
SetScreenColor (wColor);
#endif
ShortVersion ();
ShowCommands ();
/* Set COMSPEC environment variable */ /* Set COMSPEC environment variable */
#ifndef __REACTOS__ #ifndef __REACTOS__
if (argv) if (argv)
@ -952,8 +979,39 @@ static VOID Initialize (int argc, char *argv[])
} }
static VOID Cleanup (VOID) static VOID Cleanup (int argc, char *argv[])
{ {
/* run cmdexit.bat */
if (IsValidFileName (_T("cmdexit.bat")))
{
ConErrPrintf ("Running cmdexit.bat...\n");
ParseCommandLine (_T("cmdexit.bat"));
}
else if (IsValidFileName (_T("\\cmdexit.bat")))
{
ConErrPrintf ("Running \\cmdexit.bat...\n");
ParseCommandLine (_T("\\cmdexit.bat"));
}
else
{
/* try to run cmdexit.bat from install dir */
TCHAR commandline[CMDLINE_LENGTH];
LPTSTR p;
_tcscpy (commandline, argv[0]);
p = _tcsrchr (commandline, _T('\\')) + 1;
_tcscpy (p, _T("cmdexit.bat"));
if (IsValidFileName (_T("commandline")))
{
ConErrPrintf ("Running %s...\n", commandline);
ParseCommandLine (commandline);
}
}
#ifdef FEATURE_ALIASES
DestroyAlias ();
#endif
#ifdef FEATURE_DIECTORY_STACK #ifdef FEATURE_DIECTORY_STACK
/* destroy directory stack */ /* destroy directory stack */
@ -994,7 +1052,7 @@ int main (int argc, char *argv[])
nExitCode = ProcessInput (FALSE); nExitCode = ProcessInput (FALSE);
/* do the cleanup */ /* do the cleanup */
Cleanup (); Cleanup (argc, argv);
FreeConsole (); FreeConsole ();
return nExitCode; return nExitCode;

View file

@ -78,21 +78,20 @@ extern SHORT maxx;
extern SHORT maxy; extern SHORT maxy;
extern OSVERSIONINFO osvi; extern OSVERSIONINFO osvi;
void command(char *); void command(char *);
VOID ParseCommandLine (LPTSTR); VOID ParseCommandLine (LPTSTR);
int c_brk(void); int c_brk(void);
/* Prototypes for ALIAS.C */ /* Prototypes for ALIAS.C */
VOID InitializeAlias (VOID);
VOID DestroyAlias (VOID);
VOID ExpandAlias (LPTSTR, INT); VOID ExpandAlias (LPTSTR, INT);
VOID CommandAlias (LPTSTR, LPTSTR); INT CommandAlias (LPTSTR, LPTSTR);
/* Prototypes for ATTRIB.C */ /* Prototypes for ATTRIB.C */
INT cmd_attrib (LPTSTR, LPTSTR); INT CommandAttrib (LPTSTR, LPTSTR);
/* Prototypes for BEEP.C */ /* Prototypes for BEEP.C */
@ -104,7 +103,7 @@ INT cmd_call (LPTSTR, LPTSTR);
/* Prototypes for CHCP.C */ /* Prototypes for CHCP.C */
VOID CommandChcp (LPTSTR, LPTSTR); INT CommandChcp (LPTSTR, LPTSTR);
/* Prototypes for CHOICE.C */ /* Prototypes for CHOICE.C */
@ -189,12 +188,15 @@ INT cmd_dir (LPTSTR, LPTSTR);
VOID InitDirectoryStack (VOID); VOID InitDirectoryStack (VOID);
VOID DestroyDirectoryStack (VOID); VOID DestroyDirectoryStack (VOID);
INT GetDirectoryStackDepth (VOID); INT GetDirectoryStackDepth (VOID);
VOID CommandPushd (LPTSTR, LPTSTR); INT CommandPushd (LPTSTR, LPTSTR);
INT cmd_popd (LPTSTR, LPTSTR); INT CommandPopd (LPTSTR, LPTSTR);
/* Prototypes for ECHO.C */ /* Prototypes for ECHO.C */
INT cmd_echo (LPTSTR, LPTSTR); INT CommandEcho (LPTSTR, LPTSTR);
INT CommandEchos (LPTSTR, LPTSTR);
INT CommandEchoerr (LPTSTR, LPTSTR);
INT CommandEchoserr (LPTSTR, LPTSTR);
/* Prototypes for ERROR.C */ /* Prototypes for ERROR.C */
@ -249,9 +251,9 @@ VOID FreeLastPath (VOID);
INT cmd_chdir (LPTSTR, LPTSTR); INT cmd_chdir (LPTSTR, LPTSTR);
INT cmd_mkdir (LPTSTR, LPTSTR); INT cmd_mkdir (LPTSTR, LPTSTR);
INT cmd_rmdir (LPTSTR, LPTSTR); INT cmd_rmdir (LPTSTR, LPTSTR);
INT internal_exit (LPTSTR, LPTSTR); INT CommandExit (LPTSTR, LPTSTR);
VOID CommandRem (LPTSTR, LPTSTR); INT CommandRem (LPTSTR, LPTSTR);
VOID CommandShowCommands (LPTSTR, LPTSTR); INT CommandShowCommands (LPTSTR, LPTSTR);
/* Prototypes for LABEL.C */ /* Prototypes for LABEL.C */
@ -367,6 +369,7 @@ INT cmd_vol (LPTSTR, LPTSTR);
BOOL SearchForExecutable (LPCTSTR, LPTSTR); BOOL SearchForExecutable (LPCTSTR, LPTSTR);
/* Prototypes for WINDOW.C */ /* Prototypes for WINDOW.C */
INT CommandActivate (LPTSTR, LPTSTR);
INT CommandWindow (LPTSTR, LPTSTR); INT CommandWindow (LPTSTR, LPTSTR);

View file

@ -122,11 +122,7 @@ ClearCommandLine (LPTSTR str, INT maxlen, SHORT orgx, SHORT orgy)
SetCursorXY (orgx, orgy); SetCursorXY (orgx, orgy);
for (count = 0; count < (INT)_tcslen (str); count++) for (count = 0; count < (INT)_tcslen (str); count++)
ConOutChar (_T(' ')); ConOutChar (_T(' '));
#ifndef __REACTOS__
_tcsnset (str, _T('\0'), maxlen); _tcsnset (str, _T('\0'), maxlen);
#else
memset (str, 0, maxlen * sizeof(TCHAR));
#endif
SetCursorXY (orgx, orgy); SetCursorXY (orgx, orgy);
} }

View file

@ -32,12 +32,16 @@ COMMAND cmds[] =
{ {
{_T("?"), 0, CommandShowCommands}, {_T("?"), 0, CommandShowCommands},
#ifdef INCLUDE_CMD_ACTIVATE
{_T("activate"), 0, CommandActivate},
#endif
#ifdef FEATURE_ALIASES #ifdef FEATURE_ALIASES
{_T("alias"), 0, CommandAlias}, {_T("alias"), 0, CommandAlias},
#endif #endif
#ifdef INCLUDE_CMD_ATTRIB #ifdef INCLUDE_CMD_ATTRIB
{_T("attrib"), 0, cmd_attrib}, {_T("attrib"), 0, CommandAttrib},
#endif #endif
#ifdef INCLUDE_CMD_BEEP #ifdef INCLUDE_CMD_BEEP
@ -99,13 +103,16 @@ COMMAND cmds[] =
{_T("dir"), CMD_SPECIAL, cmd_dir}, {_T("dir"), CMD_SPECIAL, cmd_dir},
#endif #endif
{_T("echo"), 0, cmd_echo}, {_T("echo"), 0, CommandEcho},
{_T("echos"), 0, CommandEchos},
{_T("echoerr"), 0, CommandEchoerr},
{_T("echoserr"), 0, CommandEchoserr},
#ifdef INCLUDE_CMD_DEL #ifdef INCLUDE_CMD_DEL
{_T("erase"), 0, cmd_del}, {_T("erase"), 0, cmd_del},
#endif #endif
{_T("exit"), 0, internal_exit}, {_T("exit"), 0, CommandExit},
{_T("for"), 0, cmd_for}, {_T("for"), 0, cmd_for},
@ -147,7 +154,7 @@ COMMAND cmds[] =
#endif #endif
#ifdef FEATURE_DIRECTORY_STACK #ifdef FEATURE_DIRECTORY_STACK
{_T("popd"), 0, cmd_popd}, {_T("popd"), 0, CommandPopd},
#endif #endif
#ifdef INCLUDE_CMD_PROMPT #ifdef INCLUDE_CMD_PROMPT

View file

@ -21,8 +21,8 @@
#endif /* __REACTOS__ */ #endif /* __REACTOS__ */
/* JPP 20 Jul 1998 - define DEBUG to add debugging code */ /* JPP 20 Jul 1998 - define _DEBUG to add debugging code */
/*#define DEBUG */ /* #define _DEBUG */
/* Define to enable the alias command, and aliases.*/ /* Define to enable the alias command, and aliases.*/
@ -57,6 +57,9 @@
/* #define LOCALE_DEFAULT */ /* United States locale */ /* #define LOCALE_DEFAULT */ /* United States locale */
#endif #endif
#ifndef __REACTOS__
#define INCLUDE_CMD_ACTIVATE
#endif
#define INCLUDE_CMD_ATTRIB #define INCLUDE_CMD_ATTRIB
/*#define INCLUDE_CMD_BREAK*/ /*#define INCLUDE_CMD_BREAK*/
#define INCLUDE_CMD_CHCP #define INCLUDE_CMD_CHCP

View file

@ -1,4 +1,5 @@
/* /* $Id: console.c,v 1.10 1999/10/03 22:20:33 ekohl Exp $
*
* CONSOLE.C - console input/output functions. * CONSOLE.C - console input/output functions.
* *
* *
@ -33,7 +34,11 @@ VOID DebugPrintf (LPTSTR szFormat, ...)
_vstprintf (szOut, szFormat, arg_ptr); _vstprintf (szOut, szFormat, arg_ptr);
va_end (arg_ptr); va_end (arg_ptr);
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL); WriteFile (GetStdHandle (STD_OUTPUT_HANDLE),
szOut,
_tcslen(szOut) * sizeof(TCHAR),
&dwWritten,
NULL);
#if 0 #if 0
OutputDebugString (szOut); OutputDebugString (szOut);
#endif #endif
@ -50,7 +55,7 @@ VOID ConInDummy (VOID)
#ifdef _DEBUG #ifdef _DEBUG
if (hInput == INVALID_HANDLE_VALUE) if (hInput == INVALID_HANDLE_VALUE)
DebugPrintf ("Invalid input handle!!!\n"); DebugPrintf ("Invalid input handle!!!\n");
#endif #endif /* _DEBUG */
ReadConsoleInput (hInput, &dummy, 1, &dwRead); ReadConsoleInput (hInput, &dummy, 1, &dwRead);
} }
@ -69,7 +74,7 @@ VOID ConInKey (PINPUT_RECORD lpBuffer)
#ifdef _DEBUG #ifdef _DEBUG
if (hInput == INVALID_HANDLE_VALUE) if (hInput == INVALID_HANDLE_VALUE)
DebugPrintf ("Invalid input handle!!!\n"); DebugPrintf ("Invalid input handle!!!\n");
#endif #endif /* _DEBUG */
do do
{ {
@ -118,7 +123,11 @@ VOID ConOutChar (TCHAR c)
{ {
DWORD dwWritten; DWORD dwWritten;
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), &c, 1, &dwWritten, NULL); WriteFile (GetStdHandle (STD_OUTPUT_HANDLE),
&c,
sizeof(TCHAR),
&dwWritten,
NULL);
} }
@ -126,25 +135,34 @@ VOID ConOutPuts (LPTSTR szText)
{ {
DWORD dwWritten; DWORD dwWritten;
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL); WriteFile (GetStdHandle (STD_OUTPUT_HANDLE),
#if 0 szText,
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\x0a\x0d", 2, &dwWritten, NULL); _tcslen(szText) * sizeof(TCHAR),
#endif &dwWritten,
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL); NULL);
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE),
_T("\n"),
sizeof(TCHAR),
&dwWritten,
NULL);
} }
VOID ConOutPrintf (LPTSTR szFormat, ...) VOID ConOutPrintf (LPTSTR szFormat, ...)
{ {
DWORD dwWritten;
TCHAR szOut[OUTPUT_BUFFER_SIZE]; TCHAR szOut[OUTPUT_BUFFER_SIZE];
DWORD dwWritten;
va_list arg_ptr; va_list arg_ptr;
va_start (arg_ptr, szFormat); va_start (arg_ptr, szFormat);
_vstprintf (szOut, szFormat, arg_ptr); _vstprintf (szOut, szFormat, arg_ptr);
va_end (arg_ptr); va_end (arg_ptr);
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL); WriteFile (GetStdHandle (STD_OUTPUT_HANDLE),
szOut,
_tcslen(szOut) * sizeof(TCHAR),
&dwWritten,
NULL);
} }
@ -152,7 +170,11 @@ VOID ConErrChar (TCHAR c)
{ {
DWORD dwWritten; DWORD dwWritten;
WriteFile (GetStdHandle (STD_ERROR_HANDLE), &c, 1, &dwWritten, NULL); WriteFile (GetStdHandle (STD_ERROR_HANDLE),
&c,
sizeof(TCHAR),
&dwWritten,
NULL);
} }
@ -160,25 +182,34 @@ VOID ConErrPuts (LPTSTR szText)
{ {
DWORD dwWritten; DWORD dwWritten;
WriteFile (GetStdHandle (STD_ERROR_HANDLE), szText, _tcslen(szText), &dwWritten, NULL); WriteFile (GetStdHandle (STD_ERROR_HANDLE),
#if 0 szText,
WriteFile (GetStdHandle (STD_ERROR_HANDLE), "\x0a\x0d", 2, &dwWritten, NULL); _tcslen(szText) * sizeof(TCHAR),
#endif &dwWritten,
WriteFile (GetStdHandle (STD_ERROR_HANDLE), "\n", 1, &dwWritten, NULL); NULL);
WriteFile (GetStdHandle (STD_ERROR_HANDLE),
_T ("\n"),
sizeof(TCHAR),
&dwWritten,
NULL);
} }
VOID ConErrPrintf (LPTSTR szFormat, ...) VOID ConErrPrintf (LPTSTR szFormat, ...)
{ {
DWORD dwWritten;
TCHAR szOut[OUTPUT_BUFFER_SIZE]; TCHAR szOut[OUTPUT_BUFFER_SIZE];
DWORD dwWritten;
va_list arg_ptr; va_list arg_ptr;
va_start (arg_ptr, szFormat); va_start (arg_ptr, szFormat);
_vstprintf (szOut, szFormat, arg_ptr); _vstprintf (szOut, szFormat, arg_ptr);
va_end (arg_ptr); va_end (arg_ptr);
WriteFile (GetStdHandle (STD_ERROR_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL); WriteFile (GetStdHandle (STD_ERROR_HANDLE),
szOut,
_tcslen(szOut) * sizeof(TCHAR),
&dwWritten,
NULL);
} }
@ -245,3 +276,5 @@ VOID SetCursorType (BOOL bInsert, BOOL bVisible)
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci); SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci);
} }
/* EOF */

View file

@ -4,7 +4,7 @@
* clone from 4nt delay command * clone from 4nt delay command
* *
* 30 Aug 1999 * 30 Aug 1999
* started - Dr.F <dfaustus@freemail.it> * started - Paolo Pantaleo <paolopan@freemail.it>
* *
* *
*/ */

View file

@ -121,7 +121,7 @@ INT GetDirectoryStackDepth (VOID)
/* /*
* pushd command * pushd command
*/ */
VOID CommandPushd (LPTSTR first, LPTSTR rest) INT CommandPushd (LPTSTR first, LPTSTR rest)
{ {
TCHAR curPath[MAX_PATH]; TCHAR curPath[MAX_PATH];
TCHAR newPath[MAX_PATH]; TCHAR newPath[MAX_PATH];
@ -133,7 +133,7 @@ VOID CommandPushd (LPTSTR first, LPTSTR rest)
"changes to the specified directory.\n\n" "changes to the specified directory.\n\n"
"PUSHD [path | ..]\n\n" "PUSHD [path | ..]\n\n"
" path Specifies the directory to make the current directory")); " path Specifies the directory to make the current directory"));
return; return 0;
} }
if (rest[0] != _T('\0')) if (rest[0] != _T('\0'))
@ -144,19 +144,19 @@ VOID CommandPushd (LPTSTR first, LPTSTR rest)
GetCurrentDirectory (MAX_PATH, curPath); GetCurrentDirectory (MAX_PATH, curPath);
if (PushDirectory (curPath)) if (PushDirectory (curPath))
return; return 0;
if (bChangePath) if (bChangePath)
SetCurrentDirectory (newPath); SetCurrentDirectory (newPath);
return; return 0;
} }
/* /*
* popd command * popd command
*/ */
INT cmd_popd (LPTSTR first, LPTSTR rest) INT CommandPopd (LPTSTR first, LPTSTR rest)
{ {
TCHAR szPath[MAX_PATH]; TCHAR szPath[MAX_PATH];

View file

@ -440,17 +440,15 @@ INT cmd_rmdir (LPTSTR cmd, LPTSTR param)
* set the exitflag to true * set the exitflag to true
* *
*/ */
INT internal_exit (LPTSTR cmd, LPTSTR param) INT CommandExit (LPTSTR cmd, LPTSTR param)
{ {
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
ConOutPuts (_T("Exits the command line interpreter.\n\nEXIT")); ConOutPuts (_T("Exits the command line interpreter.\n\nEXIT"));
} return 0;
else
{
bExit = TRUE;
} }
bExit = TRUE;
return 0; return 0;
} }
@ -460,7 +458,7 @@ INT internal_exit (LPTSTR cmd, LPTSTR param)
* does nothing * does nothing
* *
*/ */
VOID CommandRem (LPTSTR cmd, LPTSTR param) INT CommandRem (LPTSTR cmd, LPTSTR param)
{ {
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
@ -468,12 +466,12 @@ VOID CommandRem (LPTSTR cmd, LPTSTR param)
"REM [Comment]")); "REM [Comment]"));
} }
return; return 0;
} }
#endif /* INCLUDE_CMD_REM */ #endif /* INCLUDE_CMD_REM */
VOID CommandShowCommands (LPTSTR cmd, LPTSTR param) INT CommandShowCommands (LPTSTR cmd, LPTSTR param)
{ {
LPCOMMAND cmdptr; LPCOMMAND cmdptr;
INT y; INT y;
@ -496,7 +494,7 @@ VOID CommandShowCommands (LPTSTR cmd, LPTSTR param)
if (y != 0) if (y != 0)
ConOutChar (_T('\n')); ConOutChar (_T('\n'));
return; return 0;
} }
/* EOF */ /* EOF */

View file

@ -50,3 +50,5 @@ else
endif endif
include ../rules.mak include ../rules.mak
# EOF

View file

@ -279,13 +279,13 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
while ((--nBufferLength > 0) && while ((--nBufferLength > 0) &&
ReadFile(hFile, &ch, 1, &dwRead, NULL) && dwRead) ReadFile(hFile, &ch, 1, &dwRead, NULL) && dwRead)
{ {
*lpString++ = ch;
if (ch == _T('\r')) if (ch == _T('\r'))
{ {
/* overread '\n' */ /* overread '\n' */
ReadFile (hFile, &ch, 1, &dwRead, NULL); ReadFile (hFile, &ch, 1, &dwRead, NULL);
break; break;
} }
*lpString++ = ch;
} }
if (!dwRead && lpString == lpBuffer) if (!dwRead && lpString == lpBuffer)

View file

@ -4,7 +4,7 @@
* clone from 4nt msgbox command * clone from 4nt msgbox command
* *
* 25 Aug 1999 * 25 Aug 1999
* started - Dr.F <dfaustus@freemail.it> * started - Paolo Pantaleo <paolopan@freemail.it>
*/ */
#include "config.h" #include "config.h"

View file

@ -4,7 +4,7 @@
* clone from 4nt msgbox command * clone from 4nt msgbox command
* *
* 30 Aug 1999 * 30 Aug 1999
* started - Dr.F <dfaustus@freemail.it> * started - Paolo Pantaleo <paolopan@freemail.it>
* *
* *
*/ */

View file

@ -4,7 +4,7 @@
* clone from 4nt timer command * clone from 4nt timer command
* *
* 20 Aug 1999 * 20 Aug 1999
* started - Dr.F <dfaustus@freemail.it> * started - Paolo Pantaleo <paolopan@freemail.it>
*/ */
#include "config.h" #include "config.h"