From c2829c98691090a07bebd5462265a99b1e706413 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 3 Oct 1999 22:20:33 +0000 Subject: [PATCH] Minor fixes. svn path=/trunk/; revision=685 --- rosapps/cmd/alias.c | 60 ++++++++++---- rosapps/cmd/attrib.c | 63 ++++++++------- rosapps/cmd/batch.c | 37 +++------ rosapps/cmd/call.c | 5 +- rosapps/cmd/chcp.c | 65 ++++++++-------- rosapps/cmd/choice.c | 60 +++++++------- rosapps/cmd/cmd.c | 172 +++++++++++++++++++++++++++-------------- rosapps/cmd/cmd.h | 27 ++++--- rosapps/cmd/cmdinput.c | 4 - rosapps/cmd/cmdtable.c | 17 ++-- rosapps/cmd/config.h | 7 +- rosapps/cmd/console.c | 73 ++++++++++++----- rosapps/cmd/delay.c | 2 +- rosapps/cmd/dirstack.c | 18 ++--- rosapps/cmd/internal.c | 16 ++-- rosapps/cmd/makefile | 2 + rosapps/cmd/misc.c | 2 +- rosapps/cmd/msgbox.c | 2 +- rosapps/cmd/screen.c | 2 +- rosapps/cmd/timer.c | 2 +- 20 files changed, 372 insertions(+), 264 deletions(-) diff --git a/rosapps/cmd/alias.c b/rosapps/cmd/alias.c index ad77a45ca31..aed0c0c2a6c 100644 --- a/rosapps/cmd/alias.c +++ b/rosapps/cmd/alias.c @@ -45,13 +45,13 @@ typedef struct tagALIAS struct tagALIAS *next; LPTSTR lpName; LPTSTR lpSubst; - WORD wUsed; + DWORD dwUsed; } ALIAS, *LPALIAS; static LPALIAS lpFirst = NULL; static LPALIAS lpLast = NULL; -static WORD wUsed = 0; +static DWORD dwUsed = 0; /* module internal functions */ @@ -159,7 +159,7 @@ AddAlias (LPTSTR name, LPTSTR subst) /* it's necessary for recursive substitution */ partstrlwr (ptr->lpSubst); - ptr->wUsed = 0; + ptr->dwUsed = 0; /* Alias table must be sorted! * 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 */ VOID ExpandAlias (LPTSTR cmd, INT maxlen) { @@ -218,13 +246,13 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen) short d = 1; LPALIAS ptr = lpFirst; - wUsed++; - if (wUsed == 0) + dwUsed++; + if (dwUsed == 0) { while (ptr) - ptr->wUsed = 0; + ptr->dwUsed = 0; ptr = lpFirst; - wUsed = 1; + dwUsed = 1; } /* skipping white spaces */ @@ -234,7 +262,7 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen) partstrlwr (&cmd[n]); if (!_tcsncmp (&cmd[n], _T("NOALIAS"), 7) && - (_istspace (cmd[n + 7]) || cmd[n + 7] == _T('\0'))) + (_istspace (cmd[n + 7]) || cmd[n + 7] == _T('\0'))) { memmove (cmd, &cmd[n + 7], (_tcslen (&cmd[n + 7]) + 1) * sizeof (TCHAR)); return; @@ -248,8 +276,8 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen) { len = _tcslen (ptr->lpName); if (!_tcsncmp (&cmd[n], ptr->lpName, len) && - (_istspace (cmd[n + len]) || cmd[n + len] == _T('\0')) && - ptr->wUsed != wUsed) + (_istspace (cmd[n + len]) || cmd[n + len] == _T('\0')) && + ptr->dwUsed != dwUsed) { m = _tcslen (ptr->lpSubst); 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)); for (i = 0; i < m; i++) cmd[i] = ptr->lpSubst[i]; - ptr->wUsed = wUsed; + ptr->dwUsed = dwUsed; /* whitespaces are removed! */ n = 0; 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; @@ -297,18 +325,18 @@ VOID CommandAlias (LPTSTR cmd, LPTSTR param) " ALIAS da=" // "Type ALIAS without a parameter to display the alias list.\n" )); - return; + return 0; } if (param[0] == _T('\0')) { PrintAlias (); - return; + return 0; } /* error if no '=' found */ if ((ptr = _tcschr (param, _T('='))) == 0) - return; + return 1; /* Split rest into name and substitute */ *ptr++ = _T('\0'); @@ -320,6 +348,6 @@ VOID CommandAlias (LPTSTR cmd, LPTSTR param) else AddAlias (param, ptr); - return; + return 0; } #endif diff --git a/rosapps/cmd/attrib.c b/rosapps/cmd/attrib.c index ebdda49b471..805c5fca49e 100644 --- a/rosapps/cmd/attrib.c +++ b/rosapps/cmd/attrib.c @@ -102,11 +102,11 @@ PrintAttribute (LPTSTR pszPath, LPTSTR pszFile, BOOL bRecurse) _tcscpy (pszFileName, findData.cFileName); ConOutPrintf (_T("%c %c%c%c %s\n"), - (findData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? _T('A') : _T(' '), - (findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? _T('S') : _T(' '), - (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? _T('H') : _T(' '), - (findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? _T('R') : _T(' '), - szFullName); + (findData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? _T('A') : _T(' '), + (findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? _T('S') : _T(' '), + (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? _T('H') : _T(' '), + (findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? _T('R') : _T(' '), + szFullName); } while (FindNextFile (hFind, &findData)); FindClose (hFind); @@ -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; INT argc, i; @@ -316,41 +316,40 @@ INT cmd_attrib (LPTSTR cmd, LPTSTR param) if (argc == 0) { - DWORD len; + DWORD len; - len = GetCurrentDirectory (MAX_PATH, szPath); - if (szPath[len-1] != _T('\\')) - { - szPath[len] = _T('\\'); - szPath[len + 1] = 0; - } + len = GetCurrentDirectory (MAX_PATH, szPath); + if (szPath[len-1] != _T('\\')) + { + szPath[len] = _T('\\'); + szPath[len + 1] = 0; + } _tcscpy (szFileName, _T("*.*")); PrintAttribute (szPath, szFileName, bRecurse); + freep (arg); + return 0; } - else - { - /* get full file name */ - for (i = 0; i < argc; i++) - { - if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/'))) - { - LPTSTR p; - GetFullPathName (arg[i], MAX_PATH, szPath, NULL); - p = _tcsrchr (szPath, _T('\\')) + 1; - _tcscpy (szFileName, p); - *p = _T('\0'); - if (dwMask == 0) - PrintAttribute (szPath, szFileName, bRecurse); - else - ChangeAttribute (szPath, szFileName, dwMask, - dwAttrib, bRecurse, bDirectories); - } + /* get full file name */ + for (i = 0; i < argc; i++) + { + if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/'))) + { + LPTSTR p; + GetFullPathName (arg[i], MAX_PATH, szPath, NULL); + p = _tcsrchr (szPath, _T('\\')) + 1; + _tcscpy (szFileName, p); + *p = _T('\0'); + + if (dwMask == 0) + PrintAttribute (szPath, szFileName, bRecurse); + else + ChangeAttribute (szPath, szFileName, dwMask, + dwAttrib, bRecurse, bDirectories); } } freep (arg); - return 0; } diff --git a/rosapps/cmd/batch.c b/rosapps/cmd/batch.c index 36df898a38b..4bac607da06 100644 --- a/rosapps/cmd/batch.c +++ b/rosapps/cmd/batch.c @@ -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. * * @@ -107,7 +108,6 @@ LPTSTR FindArg (INT n) } -/* HBP_002 { FOR command support */ /* * Batch_params builds a parameter list in newlay allocated memory. * The parameters consist of null terminated strings with a final @@ -163,8 +163,6 @@ LPTSTR BatchParams (LPTSTR s1, LPTSTR s2) return dp; } -/* HBP_002 } */ - /* * 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); #endif - if (bc) + if (bc != NULL) { LPBATCH_CONTEXT t = bc; @@ -195,28 +193,19 @@ VOID ExitBatch (LPTSTR msg) if (bc->params) free(bc->params); -/* HBP_002 { FOR command support */ - if (bc->forproto) free(bc->forproto); if (bc->ffind) free(bc->ffind); -/* HBP_002 } */ - -/* HBP_003 { fix echo restore */ /* Preserve echo state across batch calls */ bEcho = bc->bEcho; -/* HBP_003 fix echo restore } */ - bc = bc->prev; free(t); } -/* HBP_001 } */ - if (msg && *msg) ConOutPrintf ("%s\n", msg); } @@ -248,14 +237,10 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param) return FALSE; } -/* HBP_002 { FOR command support */ - /* Kill any and all FOR contexts */ while (bc && bc->forvar) ExitBatch (NULL); -/* HBP_002 } */ - if (bc == NULL) { /* No curent batch file, create a new context */ @@ -263,7 +248,6 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param) if (n == NULL) { - /* JPP 20-Jul-1998 added error checking */ error_out_of_memory (); return FALSE; } @@ -280,15 +264,17 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param) } bc->hBatchFile = hFile; - bc->bEcho = bEcho; /* Preserve echo across batch calls [HBP_001] */ + bc->bEcho = bEcho; /* Preserve echo across batch calls */ bc->shiftlevel = 0; - /* HBP_002 { FOR command support */ bc->ffind = NULL; bc->forvar = _T('\0'); bc->forproto = NULL; bc->params = BatchParams (firstword, param); - /* HBP_002 } */ + +#ifdef _DEBUG + DebugPrintf ("Batch: returns TRUE\n"); +#endif return TRUE; } @@ -330,7 +316,6 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho) return NULL; } - /* HBP_002 { FOR command support */ /* No batch */ if (bc == NULL) return NULL; @@ -368,7 +353,7 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho) /* For first find, allocate a find first block */ 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; } @@ -409,8 +394,6 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho) return textline; } - /* HBP_002 } */ - if (!FileGetString (bc->hBatchFile, textline, sizeof (textline))) { #ifdef _DEBUG @@ -459,3 +442,5 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho) return first; } + +/* EOF */ diff --git a/rosapps/cmd/call.c b/rosapps/cmd/call.c index 6777b177c4f..02f7f97c8e8 100644 --- a/rosapps/cmd/call.c +++ b/rosapps/cmd/call.c @@ -1,4 +1,5 @@ -/* +/* $Id: call.c,v 1.3 1999/10/03 22:20:33 ekohl Exp $ + * * CALL.C - call internal batch command. * * @@ -90,3 +91,5 @@ INT cmd_call (LPTSTR cmd, LPTSTR param) return 0; } + +/* EOF */ diff --git a/rosapps/cmd/chcp.c b/rosapps/cmd/chcp.c index 289c115a0e9..88bde4efdeb 100644 --- a/rosapps/cmd/chcp.c +++ b/rosapps/cmd/chcp.c @@ -21,10 +21,12 @@ #include "cmd.h" -VOID CommandChcp (LPTSTR cmd, LPTSTR param) +INT CommandChcp (LPTSTR cmd, LPTSTR param) { LPTSTR *arg; INT args; + UINT uOldCodePage; + UINT uNewCodePage; /* print help */ if (!_tcsncmp (param, _T("/?"), 2)) @@ -33,56 +35,51 @@ VOID CommandChcp (LPTSTR cmd, LPTSTR param) "CHCP [nnn]\n\n" " nnn Specifies the active code page number.\n\n" "Type CHCP without a parameter to display the active code page number.")); - return; + return 0; } - /* get parameters */ - arg = split (param, &args); - if (args == 0) { /* display active code page number */ ConOutPrintf ("Active code page: %u\n", GetConsoleCP ()); + return 0; } - else if (args >= 2) + + if (args >= 2) { /* too many parameters */ ConErrPrintf ("Invalid parameter format - %s\n", param); + return 1; + } + + /* get parameters */ + arg = split (param, &args); + + /* save old code page */ + uOldCodePage = GetConsoleCP (); + + uNewCodePage = (UINT)_ttoi (arg[0]); + + if (uNewCodePage == 0) + { + ConErrPrintf ("Parameter format incorrect - %s\n", arg[0]); + freep (arg); + return 1; + } + + if (!SetConsoleCP (uNewCodePage)) + { + ConErrPrintf ("Invalid code page\n"); } else { - /* set active code page number */ - - UINT uOldCodePage; - UINT uNewCodePage; - - /* save old code page */ - uOldCodePage = GetConsoleCP (); - - uNewCodePage = (UINT)_ttoi (arg[0]); - - if (uNewCodePage == 0) - { - ConErrPrintf ("Parameter format incorrect - %s\n", arg[0]); - - } - else - { - if (!SetConsoleCP (uNewCodePage)) - { - ConErrPrintf ("Invalid code page\n"); - } - else - { - SetConsoleOutputCP (uNewCodePage); - InitLocale (); - } - } + SetConsoleOutputCP (uNewCodePage); + InitLocale (); } freep (arg); - return; + return 0; } #endif /* INCLUDE_CMD_CHCP */ \ No newline at end of file diff --git a/rosapps/cmd/choice.c b/rosapps/cmd/choice.c index 22614e86dd9..59e8ea92b7c 100644 --- a/rosapps/cmd/choice.c +++ b/rosapps/cmd/choice.c @@ -52,32 +52,28 @@ GetCharacterTimeout (LPTCH ch, DWORD dwMilliseconds) 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 (WaitForSingleObject (hInput, dwMilliseconds) == WAIT_TIMEOUT) - return GC_TIMEOUT; + //if the timeout experied return GC_TIMEOUT + if (WaitForSingleObject (hInput, dwMilliseconds) == WAIT_TIMEOUT) + return GC_TIMEOUT; - //otherwise get the event - ReadConsoleInput (hInput, &lpBuffer, 1, &dwRead); - - //if the event is a key pressed - if ((lpBuffer.EventType == KEY_EVENT) && - (lpBuffer.Event.KeyEvent.bKeyDown == TRUE)) - { - //read the key + //otherwise get the event + ReadConsoleInput (hInput, &lpBuffer, 1, &dwRead); + + //if the event is a key pressed + if ((lpBuffer.EventType == KEY_EVENT) && + (lpBuffer.Event.KeyEvent.bKeyDown == TRUE)) + { + //read the key #ifdef _UNICODE - *ch = lpBuffer.Event.KeyEvent.uChar.UnicodeChar; + *ch = lpBuffer.Event.KeyEvent.uChar.UnicodeChar; #else - *ch = lpBuffer.Event.KeyEvent.uChar.AsciiChar; + *ch = lpBuffer.Event.KeyEvent.uChar.AsciiChar; #endif - return GC_KEYREAD; - } + return GC_KEYREAD; + } - //else return no key - return GC_NOKEY; + //else return no key + return GC_NOKEY; } static INT @@ -284,25 +280,25 @@ loop: switch (GCret) { case GC_TIMEOUT: -#ifdef DEBUG +#ifdef _DEBUG DebugPrintf (_T("GC_TIMEOUT\n")); DebugPrintf (_T("elapsed %d msecs\n"), GetTickCount () - clk); -#endif /* DEBUG */ +#endif /* _DEBUG */ break; case GC_NOKEY: -#ifdef DEBUG +#ifdef _DEBUG DebugPrintf(_T("GC_NOKEY\n")); DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk); -#endif /* DEBUG */ +#endif /* _DEBUG */ goto loop; case GC_KEYREAD: -#ifdef DEBUG +#ifdef _DEBUG DebugPrintf(_T("GC_KEYREAD\n")); DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk); DebugPrintf(_T("read %c"), Ch); -#endif /* DEBUG */ +#endif /* _DEBUG */ if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1) { Beep (440, 50); @@ -312,10 +308,10 @@ loop: break; } -#ifdef DEBUG - DebugPrintf(_T("exiting waiting loop after %d msecs\n"), +#ifdef _DEBUG + DebugPrintf(_T("exiting wait loop after %d msecs\n"), GetTickCount () - clk); -#endif /* DEBUG */ +#endif /* _DEBUG */ val = IsKeyInString (lpOptions, cDefault, bCaseSensitive); ConOutPrintf (_T("%c\n"), lpOptions[val]); @@ -324,9 +320,9 @@ loop: freep (arg); -#ifdef DEBUG +#ifdef _DEBUG DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel); -#endif /* DEBUG */ +#endif /* _DEBUG */ return 0; } diff --git a/rosapps/cmd/cmd.c b/rosapps/cmd/cmd.c index d7e567563a6..494c039629a 100644 --- a/rosapps/cmd/cmd.c +++ b/rosapps/cmd/cmd.c @@ -219,7 +219,7 @@ Execute (LPTSTR first, LPTSTR rest) stui.dwFlags = STARTF_USESHOWWINDOW; stui.wShowWindow = SW_SHOWDEFAULT; -#ifndef __REACTOS__ +#ifndef __REACTOS__ if (CreateProcess (NULL, szFullCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &stui, &prci)) #else @@ -332,8 +332,10 @@ DoCommand (LPTSTR line) * 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 TCHAR in[CMDLINE_LENGTH] = ""; TCHAR out[CMDLINE_LENGTH] = ""; @@ -350,9 +352,12 @@ VOID ParseCommandLine (LPTSTR s) HANDLE hOldConErr; #endif /* FEATURE_REDIRECTION */ + _tcscpy (cmdline, cmd); + s = &cmdline[0]; + #ifdef _DEBUG DebugPrintf ("ParseCommandLine: (\'%s\')]\n", s); -#endif /* _DEBUG */ +#endif /* DEBUG */ #ifdef FEATURE_ALIASES /* expand all aliases */ @@ -658,8 +663,6 @@ ProcessInput (BOOL bFlag) LPTSTR tp; LPTSTR ip; LPTSTR cp; - - /* JPP 19980807 - changed name so not to conflict with echo global */ BOOL bEchoThisLine; do @@ -835,8 +838,10 @@ ShowCommands (VOID) * argv - command-line parameters * */ -static VOID Initialize (int argc, char *argv[]) +static VOID +Initialize (int argc, char *argv[]) { + TCHAR commandline[CMDLINE_LENGTH]; INT i; /* Added by Rob Lake 06/16/98. This enables the command.com @@ -863,66 +868,96 @@ static VOID Initialize (int argc, char *argv[]) hOut = GetStdHandle (STD_OUTPUT_HANDLE); hIn = GetStdHandle (STD_INPUT_HANDLE); + if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2)) + { + ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter\n\n" + "CMD [/P][/C]...\n\n" + " /P ...\n" + " /C ...")); + ExitProcess (0); + } + + ShortVersion (); + ShowCommands (); + #ifdef INCLUDE_CMD_CHDIR InitLastPath (); #endif +#ifdef FATURE_ALIASES + InitializeAlias (); +#endif + if (argc >= 2) { - if (!_tcsncmp (argv[1], _T("/?"), 2)) + for (i = 1; i < argc; i++) { - ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter\n\n" - "CMD [/P][/C]...\n\n" - " /P ...\n" - " /C ...")); - ExitProcess (0); - } - else - { - for (i = 1; i < argc; i++) + if (!_tcsicmp (argv[i], _T("/p"))) { - if (!_tcsicmp (argv[i], _T("/p"))) + if (!IsValidFileName (_T("\\autoexec.bat"))) { - if (!IsValidFileName (_T("\\autoexec.bat"))) - { #ifdef INCLUDE_CMD_DATE - cmd_date ("", ""); + cmd_date ("", ""); #endif #ifdef INCLUDE_CMD_TIME - cmd_time ("", ""); + cmd_time ("", ""); #endif - } - else - ParseCommandLine ("\\autoexec.bat"); - bCanExit = FALSE; } - else if (!_tcsicmp (argv[i], _T("/c"))) + else { - /* This just runs a program and exits, RL: 06/16,21/98 */ - char commandline[CMDLINE_LENGTH]; - ++i; - strcpy(commandline, argv[i]); - while (argv[++i]) - { - strcat(commandline, " "); - strcat(commandline, argv[i]); - } - - ParseCommandLine(commandline); - - /* HBP_003 { Fix return value when /C used }*/ - ExitProcess (ProcessInput (TRUE)); + ParseCommandLine (_T("\\autoexec.bat")); } + bCanExit = FALSE; + } + else if (!_tcsicmp (argv[i], _T("/c"))) + { + /* This just runs a program and exits, RL: 06/16,21/98 */ + ++i; + _tcscpy (commandline, argv[i]); + while (argv[++i]) + { + _tcscat (commandline, " "); + _tcscat (commandline, argv[i]); + } + + ParseCommandLine(commandline); + ExitProcess (ProcessInput (TRUE)); + } #ifdef INCLUDE_CMD_COLOR - else if (!_tcsnicmp (argv[i], _T("/t:"), 3)) - { - /* process /t (color) argument */ - wDefColor = (WORD)strtoul (&argv[i][3], NULL, 16); - wColor = wDefColor; - } -#endif + else if (!_tcsnicmp (argv[i], _T("/t:"), 3)) + { + /* process /t (color) argument */ + wDefColor = (WORD)strtoul (&argv[i][3], NULL, 16); + wColor = wDefColor; + SetScreenColor (wColor); } +#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); } } @@ -931,14 +966,6 @@ static VOID Initialize (int argc, char *argv[]) InitDirectoryStack (); #endif -#ifdef INCLUDE_CMD_COLOR - /* set default colors */ - SetScreenColor (wColor); -#endif - - ShortVersion (); - ShowCommands (); - /* Set COMSPEC environment variable */ #ifndef __REACTOS__ 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 /* destroy directory stack */ @@ -994,7 +1052,7 @@ int main (int argc, char *argv[]) nExitCode = ProcessInput (FALSE); /* do the cleanup */ - Cleanup (); + Cleanup (argc, argv); FreeConsole (); return nExitCode; diff --git a/rosapps/cmd/cmd.h b/rosapps/cmd/cmd.h index 28e25b7652e..6408428a431 100644 --- a/rosapps/cmd/cmd.h +++ b/rosapps/cmd/cmd.h @@ -78,21 +78,20 @@ extern SHORT maxx; extern SHORT maxy; extern OSVERSIONINFO osvi; - void command(char *); VOID ParseCommandLine (LPTSTR); int c_brk(void); - - /* Prototypes for ALIAS.C */ +VOID InitializeAlias (VOID); +VOID DestroyAlias (VOID); VOID ExpandAlias (LPTSTR, INT); -VOID CommandAlias (LPTSTR, LPTSTR); +INT CommandAlias (LPTSTR, LPTSTR); /* Prototypes for ATTRIB.C */ -INT cmd_attrib (LPTSTR, LPTSTR); +INT CommandAttrib (LPTSTR, LPTSTR); /* Prototypes for BEEP.C */ @@ -104,7 +103,7 @@ INT cmd_call (LPTSTR, LPTSTR); /* Prototypes for CHCP.C */ -VOID CommandChcp (LPTSTR, LPTSTR); +INT CommandChcp (LPTSTR, LPTSTR); /* Prototypes for CHOICE.C */ @@ -189,12 +188,15 @@ INT cmd_dir (LPTSTR, LPTSTR); VOID InitDirectoryStack (VOID); VOID DestroyDirectoryStack (VOID); INT GetDirectoryStackDepth (VOID); -VOID CommandPushd (LPTSTR, LPTSTR); -INT cmd_popd (LPTSTR, LPTSTR); +INT CommandPushd (LPTSTR, LPTSTR); +INT CommandPopd (LPTSTR, LPTSTR); /* 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 */ @@ -249,9 +251,9 @@ VOID FreeLastPath (VOID); INT cmd_chdir (LPTSTR, LPTSTR); INT cmd_mkdir (LPTSTR, LPTSTR); INT cmd_rmdir (LPTSTR, LPTSTR); -INT internal_exit (LPTSTR, LPTSTR); -VOID CommandRem (LPTSTR, LPTSTR); -VOID CommandShowCommands (LPTSTR, LPTSTR); +INT CommandExit (LPTSTR, LPTSTR); +INT CommandRem (LPTSTR, LPTSTR); +INT CommandShowCommands (LPTSTR, LPTSTR); /* Prototypes for LABEL.C */ @@ -367,6 +369,7 @@ INT cmd_vol (LPTSTR, LPTSTR); BOOL SearchForExecutable (LPCTSTR, LPTSTR); /* Prototypes for WINDOW.C */ +INT CommandActivate (LPTSTR, LPTSTR); INT CommandWindow (LPTSTR, LPTSTR); diff --git a/rosapps/cmd/cmdinput.c b/rosapps/cmd/cmdinput.c index 62dd3dcd275..df69ca6dc88 100644 --- a/rosapps/cmd/cmdinput.c +++ b/rosapps/cmd/cmdinput.c @@ -122,11 +122,7 @@ ClearCommandLine (LPTSTR str, INT maxlen, SHORT orgx, SHORT orgy) SetCursorXY (orgx, orgy); for (count = 0; count < (INT)_tcslen (str); count++) ConOutChar (_T(' ')); -#ifndef __REACTOS__ _tcsnset (str, _T('\0'), maxlen); -#else - memset (str, 0, maxlen * sizeof(TCHAR)); -#endif SetCursorXY (orgx, orgy); } diff --git a/rosapps/cmd/cmdtable.c b/rosapps/cmd/cmdtable.c index fc8a48366cb..8597984fa8d 100644 --- a/rosapps/cmd/cmdtable.c +++ b/rosapps/cmd/cmdtable.c @@ -32,12 +32,16 @@ COMMAND cmds[] = { {_T("?"), 0, CommandShowCommands}, +#ifdef INCLUDE_CMD_ACTIVATE + {_T("activate"), 0, CommandActivate}, +#endif + #ifdef FEATURE_ALIASES {_T("alias"), 0, CommandAlias}, #endif #ifdef INCLUDE_CMD_ATTRIB - {_T("attrib"), 0, cmd_attrib}, + {_T("attrib"), 0, CommandAttrib}, #endif #ifdef INCLUDE_CMD_BEEP @@ -99,13 +103,16 @@ COMMAND cmds[] = {_T("dir"), CMD_SPECIAL, cmd_dir}, #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 {_T("erase"), 0, cmd_del}, #endif - {_T("exit"), 0, internal_exit}, + {_T("exit"), 0, CommandExit}, {_T("for"), 0, cmd_for}, @@ -147,7 +154,7 @@ COMMAND cmds[] = #endif #ifdef FEATURE_DIRECTORY_STACK - {_T("popd"), 0, cmd_popd}, + {_T("popd"), 0, CommandPopd}, #endif #ifdef INCLUDE_CMD_PROMPT @@ -218,7 +225,7 @@ COMMAND cmds[] = #endif #ifdef INCLUDE_CMD_WINDOW - {_T("window"), 0, CommandWindow}, + {_T("window"), 0, CommandWindow}, #endif {NULL, 0, NULL} diff --git a/rosapps/cmd/config.h b/rosapps/cmd/config.h index 2a931032656..14bfd9a102e 100644 --- a/rosapps/cmd/config.h +++ b/rosapps/cmd/config.h @@ -21,8 +21,8 @@ #endif /* __REACTOS__ */ -/* JPP 20 Jul 1998 - define DEBUG to add debugging code */ -/*#define DEBUG */ +/* JPP 20 Jul 1998 - define _DEBUG to add debugging code */ +/* #define _DEBUG */ /* Define to enable the alias command, and aliases.*/ @@ -57,6 +57,9 @@ /* #define LOCALE_DEFAULT */ /* United States locale */ #endif +#ifndef __REACTOS__ +#define INCLUDE_CMD_ACTIVATE +#endif #define INCLUDE_CMD_ATTRIB /*#define INCLUDE_CMD_BREAK*/ #define INCLUDE_CMD_CHCP diff --git a/rosapps/cmd/console.c b/rosapps/cmd/console.c index 213758bb270..fb48811efb6 100644 --- a/rosapps/cmd/console.c +++ b/rosapps/cmd/console.c @@ -1,4 +1,5 @@ -/* +/* $Id: console.c,v 1.10 1999/10/03 22:20:33 ekohl Exp $ + * * CONSOLE.C - console input/output functions. * * @@ -33,7 +34,11 @@ VOID DebugPrintf (LPTSTR szFormat, ...) _vstprintf (szOut, szFormat, 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 OutputDebugString (szOut); #endif @@ -50,7 +55,7 @@ VOID ConInDummy (VOID) #ifdef _DEBUG if (hInput == INVALID_HANDLE_VALUE) DebugPrintf ("Invalid input handle!!!\n"); -#endif +#endif /* _DEBUG */ ReadConsoleInput (hInput, &dummy, 1, &dwRead); } @@ -69,7 +74,7 @@ VOID ConInKey (PINPUT_RECORD lpBuffer) #ifdef _DEBUG if (hInput == INVALID_HANDLE_VALUE) DebugPrintf ("Invalid input handle!!!\n"); -#endif +#endif /* _DEBUG */ do { @@ -118,7 +123,11 @@ VOID ConOutChar (TCHAR c) { 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; - WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL); -#if 0 - WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\x0a\x0d", 2, &dwWritten, NULL); -#endif - WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL); + WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), + szText, + _tcslen(szText) * sizeof(TCHAR), + &dwWritten, + NULL); + WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), + _T("\n"), + sizeof(TCHAR), + &dwWritten, + NULL); } VOID ConOutPrintf (LPTSTR szFormat, ...) { + TCHAR szOut[OUTPUT_BUFFER_SIZE]; DWORD dwWritten; - TCHAR szOut[OUTPUT_BUFFER_SIZE]; va_list arg_ptr; va_start (arg_ptr, szFormat); _vstprintf (szOut, szFormat, 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; - 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; - WriteFile (GetStdHandle (STD_ERROR_HANDLE), szText, _tcslen(szText), &dwWritten, NULL); -#if 0 - WriteFile (GetStdHandle (STD_ERROR_HANDLE), "\x0a\x0d", 2, &dwWritten, NULL); -#endif - WriteFile (GetStdHandle (STD_ERROR_HANDLE), "\n", 1, &dwWritten, NULL); + WriteFile (GetStdHandle (STD_ERROR_HANDLE), + szText, + _tcslen(szText) * sizeof(TCHAR), + &dwWritten, + NULL); + WriteFile (GetStdHandle (STD_ERROR_HANDLE), + _T ("\n"), + sizeof(TCHAR), + &dwWritten, + NULL); } VOID ConErrPrintf (LPTSTR szFormat, ...) { + TCHAR szOut[OUTPUT_BUFFER_SIZE]; DWORD dwWritten; - TCHAR szOut[OUTPUT_BUFFER_SIZE]; va_list arg_ptr; va_start (arg_ptr, szFormat); _vstprintf (szOut, szFormat, 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); } + +/* EOF */ \ No newline at end of file diff --git a/rosapps/cmd/delay.c b/rosapps/cmd/delay.c index 8ab2fe5620d..1c953ab6a9c 100644 --- a/rosapps/cmd/delay.c +++ b/rosapps/cmd/delay.c @@ -4,7 +4,7 @@ * clone from 4nt delay command * * 30 Aug 1999 - * started - Dr.F + * started - Paolo Pantaleo * * */ diff --git a/rosapps/cmd/dirstack.c b/rosapps/cmd/dirstack.c index e92fdfa3edd..98ad6ee02c7 100644 --- a/rosapps/cmd/dirstack.c +++ b/rosapps/cmd/dirstack.c @@ -121,7 +121,7 @@ INT GetDirectoryStackDepth (VOID) /* * pushd command */ -VOID CommandPushd (LPTSTR first, LPTSTR rest) +INT CommandPushd (LPTSTR first, LPTSTR rest) { TCHAR curPath[MAX_PATH]; TCHAR newPath[MAX_PATH]; @@ -130,10 +130,10 @@ VOID CommandPushd (LPTSTR first, LPTSTR rest) if (!_tcsncmp (rest, _T("/?"), 2)) { ConOutPuts (_T("Stores the current directory for use by the POPD command, then\n" - "changes to the specified directory.\n\n" - "PUSHD [path | ..]\n\n" - " path Specifies the directory to make the current directory")); - return; + "changes to the specified directory.\n\n" + "PUSHD [path | ..]\n\n" + " path Specifies the directory to make the current directory")); + return 0; } if (rest[0] != _T('\0')) @@ -144,26 +144,26 @@ VOID CommandPushd (LPTSTR first, LPTSTR rest) GetCurrentDirectory (MAX_PATH, curPath); if (PushDirectory (curPath)) - return; + return 0; if (bChangePath) SetCurrentDirectory (newPath); - return; + return 0; } /* * popd command */ -INT cmd_popd (LPTSTR first, LPTSTR rest) +INT CommandPopd (LPTSTR first, LPTSTR rest) { TCHAR szPath[MAX_PATH]; if (!_tcsncmp(rest, _T("/?"), 2)) { ConOutPuts (_T("Changes to the directory stored by the PUSHD command.\n\n" - "POPD")); + "POPD")); return 0; } diff --git a/rosapps/cmd/internal.c b/rosapps/cmd/internal.c index 804d1b601aa..8bdaa6c9a16 100644 --- a/rosapps/cmd/internal.c +++ b/rosapps/cmd/internal.c @@ -440,17 +440,15 @@ INT cmd_rmdir (LPTSTR cmd, LPTSTR param) * set the exitflag to true * */ -INT internal_exit (LPTSTR cmd, LPTSTR param) +INT CommandExit (LPTSTR cmd, LPTSTR param) { if (!_tcsncmp (param, _T("/?"), 2)) { ConOutPuts (_T("Exits the command line interpreter.\n\nEXIT")); - } - else - { - bExit = TRUE; + return 0; } + bExit = TRUE; return 0; } @@ -460,7 +458,7 @@ INT internal_exit (LPTSTR cmd, LPTSTR param) * does nothing * */ -VOID CommandRem (LPTSTR cmd, LPTSTR param) +INT CommandRem (LPTSTR cmd, LPTSTR param) { if (!_tcsncmp (param, _T("/?"), 2)) { @@ -468,12 +466,12 @@ VOID CommandRem (LPTSTR cmd, LPTSTR param) "REM [Comment]")); } - return; + return 0; } #endif /* INCLUDE_CMD_REM */ -VOID CommandShowCommands (LPTSTR cmd, LPTSTR param) +INT CommandShowCommands (LPTSTR cmd, LPTSTR param) { LPCOMMAND cmdptr; INT y; @@ -496,7 +494,7 @@ VOID CommandShowCommands (LPTSTR cmd, LPTSTR param) if (y != 0) ConOutChar (_T('\n')); - return; + return 0; } /* EOF */ \ No newline at end of file diff --git a/rosapps/cmd/makefile b/rosapps/cmd/makefile index 9a906c3b164..b9eb0bf5a9b 100644 --- a/rosapps/cmd/makefile +++ b/rosapps/cmd/makefile @@ -50,3 +50,5 @@ else endif include ../rules.mak + +# EOF diff --git a/rosapps/cmd/misc.c b/rosapps/cmd/misc.c index ccf16819eb6..ffe3b95b55d 100644 --- a/rosapps/cmd/misc.c +++ b/rosapps/cmd/misc.c @@ -279,13 +279,13 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength) while ((--nBufferLength > 0) && ReadFile(hFile, &ch, 1, &dwRead, NULL) && dwRead) { - *lpString++ = ch; if (ch == _T('\r')) { /* overread '\n' */ ReadFile (hFile, &ch, 1, &dwRead, NULL); break; } + *lpString++ = ch; } if (!dwRead && lpString == lpBuffer) diff --git a/rosapps/cmd/msgbox.c b/rosapps/cmd/msgbox.c index c04e2bba29e..284ccd2e1a6 100644 --- a/rosapps/cmd/msgbox.c +++ b/rosapps/cmd/msgbox.c @@ -4,7 +4,7 @@ * clone from 4nt msgbox command * * 25 Aug 1999 - * started - Dr.F + * started - Paolo Pantaleo */ #include "config.h" diff --git a/rosapps/cmd/screen.c b/rosapps/cmd/screen.c index d6a581b5278..c27671afc36 100644 --- a/rosapps/cmd/screen.c +++ b/rosapps/cmd/screen.c @@ -4,7 +4,7 @@ * clone from 4nt msgbox command * * 30 Aug 1999 - * started - Dr.F + * started - Paolo Pantaleo * * */ diff --git a/rosapps/cmd/timer.c b/rosapps/cmd/timer.c index 4b43f8b63da..f6e6300535f 100644 --- a/rosapps/cmd/timer.c +++ b/rosapps/cmd/timer.c @@ -4,7 +4,7 @@ * clone from 4nt timer command * * 20 Aug 1999 - * started - Dr.F + * started - Paolo Pantaleo */ #include "config.h"