diff --git a/rosapps/cmd/alias.c b/rosapps/cmd/alias.c index aed0c0c2a6c..616cf3966b1 100644 --- a/rosapps/cmd/alias.c +++ b/rosapps/cmd/alias.c @@ -217,23 +217,26 @@ VOID InitializeAlias (VOID) VOID DestroyAlias (VOID) { - while (lpFirst->next != NULL) - { - lpLast = lpFirst; - lpFirst = lpLast->next; + if (lpFirst == NULL) + return; - free (lpLast->lpName); - free (lpLast->lpSubst); - free (lpLast); - } + while (lpFirst->next != NULL) + { + lpLast = lpFirst; + lpFirst = lpLast->next; - free (lpFirst->lpName); - free (lpFirst->lpSubst); - free (lpFirst); + free (lpLast->lpName); + free (lpLast->lpSubst); + free (lpLast); + } - lpFirst = NULL; - lpLast = NULL; - dwUsed = 0; + free (lpFirst->lpName); + free (lpFirst->lpSubst); + free (lpFirst); + + lpFirst = NULL; + lpLast = NULL; + dwUsed = 0; } /* specified routines */ diff --git a/rosapps/cmd/cmd.c b/rosapps/cmd/cmd.c index cefba09241a..238e7cce82c 100644 --- a/rosapps/cmd/cmd.c +++ b/rosapps/cmd/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.12 1999/10/22 20:35:02 ekohl Exp $ +/* $Id: cmd.c,v 1.13 1999/10/23 18:17:37 ekohl Exp $ * * CMD.C - command-line interface. * @@ -456,7 +456,7 @@ VOID ParseCommandLine (LPTSTR cmd) /* Set current stdout to temporary file */ hFile[1] = CreateFile (szFileName[1], GENERIC_WRITE, 0, NULL, - TRUNCATE_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL); + TRUNCATE_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL); SetStdHandle (STD_OUTPUT_HANDLE, hFile[1]); DoCommand (s); @@ -888,9 +888,6 @@ Initialize (int argc, char *argv[]) TCHAR commandline[CMDLINE_LENGTH]; INT i; - /* Added by Rob Lake 06/16/98. This enables the command.com - * to run the autoexec.bat at startup */ - #ifdef _DEBUG INT x; @@ -916,16 +913,18 @@ Initialize (int argc, char *argv[]) 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 ...")); + ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter.\n" + "\n" + "CMD [/[C|K] command][/P][/Q][/T:bf]\n" + "\n" + " /C command Runs the specified command and terminates.\n" + " /K command Runs the specified command and remains.\n" + " /P CMD becomes permanent and runs autoexec.bat\n" + " (cannot be terminated).\n" + " /T:bf Sets the background/foreground color (see COLOR command).")); ExitProcess (0); } - ShortVersion (); - ShowCommands (); - #ifdef INCLUDE_CMD_CHDIR InitLastPath (); #endif @@ -957,7 +956,7 @@ Initialize (int argc, char *argv[]) } 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 */ ++i; _tcscpy (commandline, argv[i]); while (argv[++i]) @@ -969,7 +968,19 @@ Initialize (int argc, char *argv[]) ParseCommandLine(commandline); ExitProcess (ProcessInput (TRUE)); } + else if (!_tcsicmp (argv[i], _T("/k"))) + { + /* This just runs a program and remains */ + ++i; + _tcscpy (commandline, argv[i]); + while (argv[++i]) + { + _tcscat (commandline, " "); + _tcscat (commandline, argv[i]); + } + ParseCommandLine(commandline); + } #ifdef INCLUDE_CMD_COLOR else if (!_tcsnicmp (argv[i], _T("/t:"), 3)) { @@ -982,6 +993,9 @@ Initialize (int argc, char *argv[]) } } + ShortVersion (); + ShowCommands (); + /* run cmdstart.bat */ if (IsValidFileName (_T("cmdstart.bat"))) { diff --git a/rosapps/cmd/cmd.h b/rosapps/cmd/cmd.h index 6408428a431..2ea98b72c41 100644 --- a/rosapps/cmd/cmd.h +++ b/rosapps/cmd/cmd.h @@ -172,7 +172,7 @@ INT cmd_date (LPTSTR, LPTSTR); /* Prototypes for DEL.C */ -INT cmd_del (LPTSTR, LPTSTR); +INT CommandDelete (LPTSTR, LPTSTR); /* Prototypes for DELAY.C */ @@ -190,6 +190,7 @@ VOID DestroyDirectoryStack (VOID); INT GetDirectoryStackDepth (VOID); INT CommandPushd (LPTSTR, LPTSTR); INT CommandPopd (LPTSTR, LPTSTR); +INT CommandDirs (LPTSTR, LPTSTR); /* Prototypes for ECHO.C */ diff --git a/rosapps/cmd/cmdtable.c b/rosapps/cmd/cmdtable.c index 8597984fa8d..7cbfbdeae4b 100644 --- a/rosapps/cmd/cmdtable.c +++ b/rosapps/cmd/cmdtable.c @@ -48,10 +48,6 @@ COMMAND cmds[] = {_T("beep"), 0, cmd_beep}, #endif -/* - {_T("break"), 0, cmd_break}, -*/ - {_T("call"), CMD_BATCHONLY, cmd_call}, #ifdef INCLUDE_CMD_CHDIR @@ -80,19 +76,13 @@ COMMAND cmds[] = {_T("copy"), 0, cmd_copy}, #endif -/* -#define INCLUDE_CMD_CTTY - {_T("ctty"), 0, cmd_ctty}, -#endif -*/ - #ifdef INCLUDE_CMD_DATE {_T("date"), 0, cmd_date}, #endif #ifdef INCLUDE_CMD_DEL - {_T("del"), 0, cmd_del}, - {_T("delete"), 0, cmd_del}, + {_T("del"), 0, CommandDelete}, + {_T("delete"), 0, CommandDelete}, #endif #ifdef INCLUDE_CMD_DELAY @@ -103,13 +93,17 @@ COMMAND cmds[] = {_T("dir"), CMD_SPECIAL, cmd_dir}, #endif +#ifdef FEATURE_DIRECTORY_STACK + {_T("dirs"), 0, CommandDirs}, +#endif + {_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}, + {_T("erase"), 0, CommandDelete}, #endif {_T("exit"), 0, CommandExit}, diff --git a/rosapps/cmd/config.h b/rosapps/cmd/config.h index 14bfd9a102e..7a34b7301e1 100644 --- a/rosapps/cmd/config.h +++ b/rosapps/cmd/config.h @@ -21,7 +21,7 @@ #endif /* __REACTOS__ */ -/* JPP 20 Jul 1998 - define _DEBUG to add debugging code */ +/* Define to enable debugging code */ /* #define _DEBUG */ @@ -61,14 +61,12 @@ #define INCLUDE_CMD_ACTIVATE #endif #define INCLUDE_CMD_ATTRIB -/*#define INCLUDE_CMD_BREAK*/ #define INCLUDE_CMD_CHCP #define INCLUDE_CMD_CHDIR #define INCLUDE_CMD_CHOICE #define INCLUDE_CMD_CLS #define INCLUDE_CMD_COLOR #define INCLUDE_CMD_COPY -/*#define INCLUDE_CMD_CTTY*/ #define INCLUDE_CMD_DATE #define INCLUDE_CMD_DEL #define INCLUDE_CMD_DELAY @@ -115,6 +113,4 @@ shift */ - - #endif /* _CONFIG_H_INCLUDED_ */ diff --git a/rosapps/cmd/console.c b/rosapps/cmd/console.c index 20e79bbc8cd..9792d15b8c0 100644 --- a/rosapps/cmd/console.c +++ b/rosapps/cmd/console.c @@ -1,4 +1,4 @@ -/* $Id: console.c,v 1.11 1999/10/22 20:35:02 ekohl Exp $ +/* $Id: console.c,v 1.12 1999/10/23 18:17:37 ekohl Exp $ * * CONSOLE.C - console input/output functions. * @@ -34,7 +34,7 @@ VOID DebugPrintf (LPTSTR szFormat, ...) _vstprintf (szOut, szFormat, arg_ptr); va_end (arg_ptr); - WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), + WriteFile (GetStdHandle (STD_ERROR_HANDLE), szOut, _tcslen(szOut) * sizeof(TCHAR), &dwWritten, @@ -277,4 +277,4 @@ VOID SetCursorType (BOOL bInsert, BOOL bVisible) SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci); } -/* EOF */ \ No newline at end of file +/* EOF */ diff --git a/rosapps/cmd/del.c b/rosapps/cmd/del.c index 91324f50ad2..34ffbf00a88 100644 --- a/rosapps/cmd/del.c +++ b/rosapps/cmd/del.c @@ -136,8 +136,10 @@ RemoveFile (LPTSTR lpFileName, DWORD dwFlags) } -INT cmd_del (LPTSTR cmd, LPTSTR param) +INT CommandDelete (LPTSTR cmd, LPTSTR param) { + TCHAR szFullPath[MAX_PATH]; + LPTSTR pFilePart; LPTSTR *arg = NULL; INT args; INT i; @@ -151,21 +153,20 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) if (!_tcsncmp (param, _T("/?"), 2)) { ConOutPuts (_T("Deletes one or more files.\n" - "\n" - "DEL [/N /P /T /Q /W /Z] file ...\n" - "DELETE [/N /P /T /Q /W /Z] file ...\n" - "ERASE [/N /P /T /Q /W /Z] file ...\n" - "\n" - " file Specifies the file(s) to delete.\n" - "\n" - " /N Nothing.\n" - " /P Prompts for confirmation before deleting each file.\n" - " (Not implemented yet!)\n" - " /T Display total number of deleted files and freed disk space.\n" - " /Q Quiet.\n" - " /W Wipe. Overwrite the file with zeros before deleting it.\n" - " /Z Zap (delete hidden, read-only and system files).\n" - )); + "\n" + "DEL [/N /P /T /Q /W /Z] file ...\n" + "DELETE [/N /P /T /Q /W /Z] file ...\n" + "ERASE [/N /P /T /Q /W /Z] file ...\n" + "\n" + " file Specifies the file(s) to delete.\n" + "\n" + " /N Nothing.\n" + " /P Prompts for confirmation before deleting each file.\n" + " (Not implemented yet!)\n" + " /T Display total number of deleted files and freed disk space.\n" + " /Q Quiet.\n" + " /W Wipe. Overwrite the file with zeros before deleting it.\n" + " /Z Zap (delete hidden, read-only and system files).\n")); return 0; } @@ -250,7 +251,17 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) ConErrPrintf (_T("Wildcards!\n\n")); #endif - hFile = FindFirstFile (arg[i], &f); + GetFullPathName (arg[i], + MAX_PATH, + szFullPath, + &pFilePart); + +#ifdef _DEBUG + ConErrPrintf (_T("Full path: %s\n"), szFullPath); + ConErrPrintf (_T("File part: %s\n"), pFilePart); +#endif + + hFile = FindFirstFile (szFullPath, &f); if (hFile == INVALID_HANDLE_VALUE) { error_file_not_found (); @@ -265,13 +276,19 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) !_tcscmp (f.cFileName, _T(".."))) continue; + _tcscpy (pFilePart, f.cFileName); + +#ifdef _DEBUG + ConErrPrintf (_T("Full filename: %s\n"), szFullPath); +#endif + if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) - ConErrPrintf (_T("Deleting: %s\n"), f.cFileName); + ConErrPrintf (_T("Deleting: %s\n"), szFullPath); /* delete the file */ if (!(dwFlags & DEL_NOTHING)) { - if (RemoveFile (f.cFileName, dwFlags)) + if (RemoveFile (szFullPath, dwFlags)) { dwFiles++; } @@ -279,9 +296,9 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) { if (dwFlags & DEL_ZAP) { - if (SetFileAttributes (arg[i], 0)) + if (SetFileAttributes (szFullPath, 0)) { - if (RemoveFile (arg[i], dwFlags)) + if (RemoveFile (szFullPath, dwFlags)) { dwFiles++; } @@ -301,8 +318,6 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) } } } - - } while (FindNextFile (hFile, &f)); FindClose (hFile); @@ -310,17 +325,22 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) else { /* no wildcards in filespec */ - #ifdef _DEBUG ConErrPrintf (_T("No Wildcards!\n")); #endif - + GetFullPathName (arg[i], + MAX_PATH, + szFullPath, + &pFilePart); +#ifdef _DEBUG + ConErrPrintf (_T("Full path: %s\n"), szFullPath); +#endif if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) - ConOutPrintf (_T("Deleting %s\n"), arg[i]); + ConOutPrintf (_T("Deleting %s\n"), szFullPath); if (!(dwFlags & DEL_NOTHING)) { - if (RemoveFile (arg[i], dwFlags)) + if (RemoveFile (szFullPath, dwFlags)) { dwFiles++; } @@ -328,9 +348,9 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) { if (dwFlags & DEL_ZAP) { - if (SetFileAttributes (arg[i], 0)) + if (SetFileAttributes (szFullPath, 0)) { - if (RemoveFile (arg[i], dwFlags)) + if (RemoveFile (szFullPath, dwFlags)) { dwFiles++; } @@ -364,14 +384,14 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) freep (arg); - if (!(dwFlags & DEL_QUIET)) { if (dwFiles == 0) ConOutPrintf (_T(" 0 files deleted\n")); else ConOutPrintf (_T(" %lu file%s deleted\n"), - dwFiles, (dwFiles == 1) ? "s" : ""); + dwFiles, + (dwFiles == 1) ? "s" : ""); } return 0; diff --git a/rosapps/cmd/dirstack.c b/rosapps/cmd/dirstack.c index 98ad6ee02c7..a910d32660e 100644 --- a/rosapps/cmd/dirstack.c +++ b/rosapps/cmd/dirstack.c @@ -9,6 +9,9 @@ * * 20-Jan-1999 (Eric Kohl ) * Unicode and redirection safe! + * + * 20-Jan-1999 (Eric Kohl ) + * Added DIRS command. */ #include "config.h" @@ -25,6 +28,7 @@ typedef struct tagDIRENTRY { + struct tagDIRENTRY *prev; struct tagDIRENTRY *next; LPTSTR pszPath; } DIRENTRY, *LPDIRENTRY; @@ -32,6 +36,7 @@ typedef struct tagDIRENTRY static INT nStackDepth; static LPDIRENTRY lpStackTop; +static LPDIRENTRY lpStackBottom; static INT @@ -46,7 +51,17 @@ PushDirectory (LPTSTR pszPath) return -1; } - lpDir->next = (lpStackTop) ? lpStackTop : NULL; + lpDir->prev = NULL; + if (lpStackTop == NULL) + { + lpDir->next = NULL; + lpStackBottom = lpDir; + } + else + { + lpDir->next = lpStackTop; + lpStackTop->prev = lpDir; + } lpStackTop = lpDir; lpDir->pszPath = (LPTSTR)malloc ((_tcslen(pszPath)+1)*sizeof(TCHAR)); @@ -75,6 +90,11 @@ PopDirectory (VOID) lpDir = lpStackTop; lpStackTop = lpDir->next; + if (lpStackTop != NULL) + lpStackTop->prev = NULL; + else + lpStackBottom = NULL; + free (lpDir->pszPath); free (lpDir); @@ -99,6 +119,7 @@ VOID InitDirectoryStack (VOID) { nStackDepth = 0; lpStackTop = NULL; + lpStackBottom = NULL; } @@ -178,4 +199,39 @@ INT CommandPopd (LPTSTR first, LPTSTR rest) return 0; } -#endif /* FEATURE_DIRECTORY_STACK */ \ No newline at end of file + +/* + * dirs command + */ +INT CommandDirs (LPTSTR first, LPTSTR rest) +{ + LPDIRENTRY lpDir; + + if (!_tcsncmp(rest, _T("/?"), 2)) + { + ConOutPuts (_T("Prints the contents of the directory stack.\n" + "\n" + "DIRS")); + return 0; + } + + + lpDir = lpStackBottom; + + if (lpDir == NULL) + { + ConOutPuts (_T("Directory stack empty")); + return 0; + } + + while (lpDir != NULL) + { + ConOutPuts (lpDir->pszPath); + + lpDir = lpDir->prev; + } + + return 0; +} + +#endif /* FEATURE_DIRECTORY_STACK */ diff --git a/rosapps/cmd/todo.txt b/rosapps/cmd/todo.txt index c514afce955..c1257593e93 100644 --- a/rosapps/cmd/todo.txt +++ b/rosapps/cmd/todo.txt @@ -10,7 +10,6 @@ Sorting in DIR command ("dir /o..."). ^S and ^Q to pause/resume displays. Improve DEL, COPY and MOVE commands. -BREAK command on command-line. Add wildcard support to REN. diff --git a/rosapps/cmd/where.c b/rosapps/cmd/where.c index 78ed109642a..21da7986382 100644 --- a/rosapps/cmd/where.c +++ b/rosapps/cmd/where.c @@ -97,6 +97,63 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName) INT n; LPTSTR p,s,f; + + /* initialize full name buffer */ + *pFullName = _T('\0'); + +#ifdef _DEBUG + DebugPrintf (_T("SearchForExecutable: \'%s\'\n"), pFileName); +#endif + + if (_tcschr (pFileName, _T('\\')) != NULL) + { + LPTSTR pFilePart; +#ifdef _DEBUG + DebugPrintf (_T("Absolute or relative path is given.\n")); +#endif + GetFullPathName (pFileName, + MAX_PATH, + szPathBuffer, + &pFilePart); + + if (_tcschr (pFilePart, _T('.')) != NULL) + { +#ifdef _DEBUG + DebugPrintf (_T("Filename extension!\n")); +#endif + _tcscpy (pFullName, szPathBuffer); + return TRUE; + + } + else + { +#ifdef _DEBUG + DebugPrintf (_T("No filename extension!\n")); +#endif + + p = szPathBuffer + _tcslen (szPathBuffer); + + for (n = 0; n < nExtCount; n++) + { + _tcscpy (p, ext[n]); + +#ifdef _DEBUG + DebugPrintf (_T("Testing: \'%s\'\n"), szPathBuffer); +#endif + + if (IsValidFileName (szPathBuffer)) + { +#ifdef _DEBUG + DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer); +#endif + _tcscpy (pFullName, szPathBuffer); + return TRUE; + } + } + return FALSE; + } + } + /* load environment varable PATH into buffer */ pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE); @@ -106,9 +163,6 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName) GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer * sizeof (TCHAR)); } - /* initialize full name buffer */ - *pFullName = _T('\0'); - if (!(p = _tcsrchr (pFileName, _T('.'))) || _tcschr (p + 1, _T('\\'))) {