From e4bcefde7d5db72706b0719b173f2e76a49b3574 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 30 Mar 1999 22:06:36 +0000 Subject: [PATCH] Fixed bugs and improved del command. svn path=/trunk/; revision=352 --- reactos/apps/utils/cmd/cmd.h | 5 +- reactos/apps/utils/cmd/del.c | 186 ++++++++++++++++++++++------- reactos/apps/utils/cmd/dir.c | 18 +-- reactos/apps/utils/cmd/history.txt | 10 +- reactos/apps/utils/cmd/makefile | 10 +- reactos/apps/utils/cmd/readme.txt | 6 +- reactos/apps/utils/cmd/ros.c | 18 --- reactos/apps/utils/cmd/todo.txt | 2 - rosapps/cmd/cmd.h | 5 +- rosapps/cmd/del.c | 186 ++++++++++++++++++++++------- rosapps/cmd/dir.c | 18 +-- rosapps/cmd/history.txt | 10 +- rosapps/cmd/makefile | 10 +- rosapps/cmd/readme.txt | 6 +- rosapps/cmd/ros.c | 18 --- rosapps/cmd/todo.txt | 2 - 16 files changed, 350 insertions(+), 160 deletions(-) diff --git a/reactos/apps/utils/cmd/cmd.h b/reactos/apps/utils/cmd/cmd.h index 9c35a460955..7ce80014f6c 100644 --- a/reactos/apps/utils/cmd/cmd.h +++ b/reactos/apps/utils/cmd/cmd.h @@ -30,7 +30,7 @@ #include -#define CMD_VER "0.1 pre 1" +#define CMD_VER "0.1 pre 2" #ifdef _MSC_VER #define SHELLVER "Version " CMD_VER " [" __DATE__ ", msc]" @@ -58,8 +58,7 @@ #define ERROR_E2BIG "ERROR: Argument list too long" #define ERROR_EINVAL "ERROR: Invalid argument" -#define SHELLINFO "ReactOS Command Line Interface" -#define USAGE "usage" +#define SHELLINFO "ReactOS Command Line Interface" #define D_ON "on" diff --git a/reactos/apps/utils/cmd/del.c b/reactos/apps/utils/cmd/del.c index 2095ac414be..9b581ff1b63 100644 --- a/reactos/apps/utils/cmd/del.c +++ b/reactos/apps/utils/cmd/del.c @@ -21,8 +21,11 @@ * 21-Jan-1999 (Eric Kohl ) * Started major rewrite using a new structure. * - * 03-Jan-1999 (Eric Kohl ) + * 03-Feb-1999 (Eric Kohl ) * First working version. + * + * 30-Mar-1999 (Eric Kohl ) + * Added quiet ("/Q"), wipe ("/W") and zap ("/Z") option. */ #include "config.h" @@ -33,7 +36,6 @@ #include #include #include -#include #include "cmd.h" @@ -44,13 +46,30 @@ #define PROMPT_BREAK 3 +enum +{ + DEL_ATTRIBUTES = 0x001, /* /A : not implemented */ + DEL_ERROR = 0x002, /* /E : not implemented */ + DEL_NOTHING = 0x004, /* /N */ + DEL_PROMPT = 0x008, /* /P : not implemented */ + DEL_QUIET = 0x010, /* /Q */ + DEL_SUBDIR = 0x020, /* /S : not implemented */ + DEL_TOTAL = 0x040, /* /T */ + DEL_WIPE = 0x080, /* /W */ + DEL_EMPTYDIR = 0x100, /* /X : not implemented */ + DEL_YES = 0x200, /* /Y : not implemented */ + DEL_ZAP = 0x400 /* /Z */ +}; + + + static BOOL ConfirmDeleteAll (VOID) { TCHAR inp[10]; LPTSTR p; - ConOutPrintf ("All files in directory will be deleted!\n" - "Are you sure (Y/N)? "); + ConOutPrintf (_T("All files in directory will be deleted!\n" + "Are you sure (Y/N)? ")); ConInString (inp, 10); _tcsupr (inp); @@ -101,46 +120,49 @@ static INT Prompt (LPTSTR str) } +static BOOL +RemoveFile (LPTSTR lpFileName, DWORD dwFlags) +{ + if (dwFlags & DEL_WIPE) + { + + /* FIXME: Wipe the given file */ + + } + + return DeleteFile (lpFileName); +} + INT cmd_del (LPTSTR cmd, LPTSTR param) { LPTSTR *arg = NULL; INT args; INT i; - INT nEvalArgs = 0; /* nunber of evaluated arguments */ - BOOL bNothing = FALSE; - BOOL bQuiet = FALSE; - BOOL bPrompt = FALSE; + INT nEvalArgs = 0; /* nunber of evaluated arguments */ + DWORD dwFlags = 0; + DWORD dwFiles = 0; HANDLE hFile; WIN32_FIND_DATA f; -// DWORD dwAttributes; - if (!_tcsncmp (param, _T("/?"), 2)) { -/* - ConOutPuts (_T("Deletes one or more files.\n\n" - "DEL [drive:][path]filename [/P]\n" - "DELETE [drive:][path]filename [/P]\n" - "ERASE [drive:][path]filename [/P]\n\n" - " [drive:][path]filename Specifies the file(s) to delete. Specify multiple\n" - " files by using wildcards.\n" - " /P Prompts for confirmation before deleting each file.")); -*/ - ConOutPuts (_T("Deletes one or more files.\n" "\n" - "DEL [/N /P /Q] file ...\n" - "DELETE [/N /P /Q] file ...\n" - "ERASE [/N /P /Q] file ...\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" - " /Q Quiet." + " /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; @@ -160,15 +182,31 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) switch (_totupper (arg[i][1])) { case _T('N'): - bNothing = TRUE; + dwFlags |= DEL_NOTHING; break; case _T('P'): - bPrompt = TRUE; + dwFlags |= DEL_PROMPT; break; case _T('Q'): - bQuiet = TRUE; + dwFlags |= DEL_QUIET; + break; + + case _T('S'): + dwFlags |= DEL_SUBDIR; + break; + + case _T('T'): + dwFlags |= DEL_TOTAL; + break; + + case _T('W'): + dwFlags |= DEL_WIPE; + break; + + case _T('Z'): + dwFlags |= DEL_ZAP; break; } @@ -200,14 +238,14 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) if (*arg[i] != _T('/')) { #ifdef _DEBUG - ConErrPrintf ("File: %s\n", arg[i]); + ConErrPrintf (_T("File: %s\n"), arg[i]); #endif if (_tcschr (arg[i], _T('*')) || _tcschr (arg[i], _T('?'))) { /* wildcards in filespec */ #ifdef _DEBUG - ConErrPrintf ("Wildcards!\n\n"); + ConErrPrintf (_T("Wildcards!\n\n")); #endif hFile = FindFirstFile (arg[i], &f); @@ -220,18 +258,46 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) do { + /* ignore "." and ".." */ if (!_tcscmp (f.cFileName, _T(".")) || !_tcscmp (f.cFileName, _T(".."))) continue; -#ifdef _DEBUG - ConErrPrintf ("Delete file: %s\n", f.cFileName); -#endif + if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) + ConErrPrintf (_T("Deleting: %s\n"), f.cFileName); - if (!bNothing) + /* delete the file */ + if (!(dwFlags & DEL_NOTHING)) { - if (!DeleteFile (f.cFileName)) - ErrorMessage (GetLastError(), _T("")); + if (RemoveFile (f.cFileName, dwFlags)) + { + dwFiles++; + } + else + { + if (dwFlags & DEL_ZAP) + { + if (SetFileAttributes (arg[i], 0)) + { + if (RemoveFile (arg[i], dwFlags)) + { + dwFiles++; + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } } @@ -242,15 +308,45 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) else { /* no wildcards in filespec */ + #ifdef _DEBUG - ConErrPrintf ("No Wildcards!\n"); - ConErrPrintf ("Delete file: %s\n", arg[i]); + ConErrPrintf (_T("No Wildcards!\n")); #endif - if (!bNothing) + if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) + ConOutPrintf (_T("Deleting %s\n"), arg[i]); + + if (!(dwFlags & DEL_NOTHING)) { - if (!DeleteFile (arg[i])) - ErrorMessage (GetLastError(), _T("")); + if (RemoveFile (arg[i], dwFlags)) + { + dwFiles++; + } + else + { + if (dwFlags & DEL_ZAP) + { + if (SetFileAttributes (arg[i], 0)) + { + if (RemoveFile (arg[i], dwFlags)) + { + dwFiles++; + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } } } } @@ -266,6 +362,16 @@ 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" : ""); + } + return 0; } diff --git a/reactos/apps/utils/cmd/dir.c b/reactos/apps/utils/cmd/dir.c index 19c7c7b83a4..b1830444c73 100644 --- a/reactos/apps/utils/cmd/dir.c +++ b/reactos/apps/utils/cmd/dir.c @@ -237,7 +237,7 @@ DirReadParam (LPTSTR line, LPTSTR *param, LPDWORD lpFlags) { if (_totupper (*line) == _T('S')) *lpFlags |= DIR_RECURSE; - else if (_toupper (*line) == _T('P')) + else if (_totupper (*line) == _T('P')) *lpFlags |= DIR_PAGE; else if (_totupper (*line) == _T('W')) *lpFlags |= DIR_WIDE; @@ -811,8 +811,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) count = 0; } - uliSize.u.LowPart += file.nFileSizeLow; - uliSize.u.HighPart += file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; bytecount.QuadPart += uliSize.QuadPart; } else if (dwFlags & DIR_BARE) @@ -842,8 +842,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) if (IncLine (pLine, dwFlags)) return 1; - uliSize.u.LowPart += file.nFileSizeLow; - uliSize.u.HighPart += file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; bytecount.QuadPart += uliSize.QuadPart; } else @@ -867,8 +867,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) { ULARGE_INTEGER uliSize; - uliSize.u.LowPart = file.nFileSizeLow; - uliSize.u.HighPart = file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; ConvertULargeInteger (uliSize, buffer, sizeof(buffer)); ConOutPrintf (_T(" %20s"), buffer); @@ -919,8 +919,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) { ULARGE_INTEGER uliSize; - uliSize.u.LowPart = file.nFileSizeLow; - uliSize.u.HighPart = file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; ConvertULargeInteger (uliSize, buffer, sizeof(buffer)); ConOutPrintf (_T(" %10s "), buffer); diff --git a/reactos/apps/utils/cmd/history.txt b/reactos/apps/utils/cmd/history.txt index 7b0769bb53c..4fc998935ee 100644 --- a/reactos/apps/utils/cmd/history.txt +++ b/reactos/apps/utils/cmd/history.txt @@ -342,4 +342,12 @@ o ATTRIB and DEL can handle multiple filenames now. o Fixed handling of environment variables. o Added CHCP command. o Fixed keyboard input bug. -o Rewrote DEL and MOVE commands. \ No newline at end of file +o Rewrote DEL and MOVE commands. + +30-Mar-1999 ReactOS CMD version 0.1 pre 2 (Eric Kohl ) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +o Cleaned up DIR command. +o Searching for executables in the right order. +o Fixed some little but nasty bugs. +o Added TITLE command. Thanks to Emanuele Aliberti! +o Added "/Q", "/W" and "/Z" options to DEL command. diff --git a/reactos/apps/utils/cmd/makefile b/reactos/apps/utils/cmd/makefile index 0553027a0d7..18dd00a147f 100644 --- a/reactos/apps/utils/cmd/makefile +++ b/reactos/apps/utils/cmd/makefile @@ -8,10 +8,12 @@ # target: executable (not tested/experimental) all: cmd.exe -OBJECTS = ../common/crt0.o cmd.o attrib.o alias.o batch.o beep.o call.o chcp.o cls.o cmdinput.o cmdtable.o\ - color.o console.o copy.o date.o del.o dir.o dirstack.o echo.o error.o filecomp.o for.o goto.o history.o if.o\ - internal.o label.o locale.o misc.o move.o path.o pause.o prompt.o redir.o ren.o ros.o set.o shift.o time.o title.o type.o ver.o\ - verify.o vol.o where.o +OBJECTS = ../common/crt0.o cmd.o attrib.o alias.o batch.o beep.o call.o \ + chcp.o cls.o cmdinput.o cmdtable.o color.o console.o copy.o date.o \ + del.o dir.o dirstack.o echo.o error.o filecomp.o for.o goto.o \ + history.o if.o internal.o label.o locale.o misc.o move.o path.o \ + pause.o prompt.o redir.o ren.o set.o shift.o time.o title.o type.o \ + ver.o verify.o vol.o where.o LIBS= ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a diff --git a/reactos/apps/utils/cmd/readme.txt b/reactos/apps/utils/cmd/readme.txt index b76a3a77baf..26b7ae4cf2a 100644 --- a/reactos/apps/utils/cmd/readme.txt +++ b/reactos/apps/utils/cmd/readme.txt @@ -1,5 +1,5 @@ -ReactOS Command Line Interface "CMD" version 0.0.4 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +ReactOS Command Line Interface "CMD" version 0.1 pre 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is the fourth pre-alpha release of CMD.EXE for ReactOS. It was converted from the FreeDOS COMMAND.COM. @@ -7,7 +7,7 @@ It was converted from the FreeDOS COMMAND.COM. Warning!! Warning!! Warning!! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This is a pre-alpha version! Many features have not been tested! +This is an alpha version! Many features have not been tested! Be careful when you use commands that write to your disk drives, they might destroy your files or the file system!!! diff --git a/reactos/apps/utils/cmd/ros.c b/reactos/apps/utils/cmd/ros.c index 5c5cfcc8e2d..c8c02e2b74d 100644 --- a/reactos/apps/utils/cmd/ros.c +++ b/reactos/apps/utils/cmd/ros.c @@ -90,22 +90,4 @@ _makepath( char *path, const char *drive, const char *dir, const char *fname, co } } -#if 0 -int getch(void) -{ - DWORD NumberOfCharsRead = 0; - DWORD dwWritten; - char c; - - ReadConsoleA (GetStdHandle (STD_INPUT_HANDLE), &c, 1, &NumberOfCharsRead, NULL); - - if ( c == 10 ) - c = 13; - - WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), &c, 1, &dwWritten, NULL); - - return c; -} -#endif - #endif \ No newline at end of file diff --git a/reactos/apps/utils/cmd/todo.txt b/reactos/apps/utils/cmd/todo.txt index bcffe59a323..15400c1a1a1 100644 --- a/reactos/apps/utils/cmd/todo.txt +++ b/reactos/apps/utils/cmd/todo.txt @@ -2,8 +2,6 @@ Things to do ~~~~~~~~~~~~ Fix bugs :) -Rewrite DIR command (Unicode aware / new structure). - Optimize the code! For size and speed. There are numerous places where the code is hardly optimal for either. diff --git a/rosapps/cmd/cmd.h b/rosapps/cmd/cmd.h index 9c35a460955..7ce80014f6c 100644 --- a/rosapps/cmd/cmd.h +++ b/rosapps/cmd/cmd.h @@ -30,7 +30,7 @@ #include -#define CMD_VER "0.1 pre 1" +#define CMD_VER "0.1 pre 2" #ifdef _MSC_VER #define SHELLVER "Version " CMD_VER " [" __DATE__ ", msc]" @@ -58,8 +58,7 @@ #define ERROR_E2BIG "ERROR: Argument list too long" #define ERROR_EINVAL "ERROR: Invalid argument" -#define SHELLINFO "ReactOS Command Line Interface" -#define USAGE "usage" +#define SHELLINFO "ReactOS Command Line Interface" #define D_ON "on" diff --git a/rosapps/cmd/del.c b/rosapps/cmd/del.c index 2095ac414be..9b581ff1b63 100644 --- a/rosapps/cmd/del.c +++ b/rosapps/cmd/del.c @@ -21,8 +21,11 @@ * 21-Jan-1999 (Eric Kohl ) * Started major rewrite using a new structure. * - * 03-Jan-1999 (Eric Kohl ) + * 03-Feb-1999 (Eric Kohl ) * First working version. + * + * 30-Mar-1999 (Eric Kohl ) + * Added quiet ("/Q"), wipe ("/W") and zap ("/Z") option. */ #include "config.h" @@ -33,7 +36,6 @@ #include #include #include -#include #include "cmd.h" @@ -44,13 +46,30 @@ #define PROMPT_BREAK 3 +enum +{ + DEL_ATTRIBUTES = 0x001, /* /A : not implemented */ + DEL_ERROR = 0x002, /* /E : not implemented */ + DEL_NOTHING = 0x004, /* /N */ + DEL_PROMPT = 0x008, /* /P : not implemented */ + DEL_QUIET = 0x010, /* /Q */ + DEL_SUBDIR = 0x020, /* /S : not implemented */ + DEL_TOTAL = 0x040, /* /T */ + DEL_WIPE = 0x080, /* /W */ + DEL_EMPTYDIR = 0x100, /* /X : not implemented */ + DEL_YES = 0x200, /* /Y : not implemented */ + DEL_ZAP = 0x400 /* /Z */ +}; + + + static BOOL ConfirmDeleteAll (VOID) { TCHAR inp[10]; LPTSTR p; - ConOutPrintf ("All files in directory will be deleted!\n" - "Are you sure (Y/N)? "); + ConOutPrintf (_T("All files in directory will be deleted!\n" + "Are you sure (Y/N)? ")); ConInString (inp, 10); _tcsupr (inp); @@ -101,46 +120,49 @@ static INT Prompt (LPTSTR str) } +static BOOL +RemoveFile (LPTSTR lpFileName, DWORD dwFlags) +{ + if (dwFlags & DEL_WIPE) + { + + /* FIXME: Wipe the given file */ + + } + + return DeleteFile (lpFileName); +} + INT cmd_del (LPTSTR cmd, LPTSTR param) { LPTSTR *arg = NULL; INT args; INT i; - INT nEvalArgs = 0; /* nunber of evaluated arguments */ - BOOL bNothing = FALSE; - BOOL bQuiet = FALSE; - BOOL bPrompt = FALSE; + INT nEvalArgs = 0; /* nunber of evaluated arguments */ + DWORD dwFlags = 0; + DWORD dwFiles = 0; HANDLE hFile; WIN32_FIND_DATA f; -// DWORD dwAttributes; - if (!_tcsncmp (param, _T("/?"), 2)) { -/* - ConOutPuts (_T("Deletes one or more files.\n\n" - "DEL [drive:][path]filename [/P]\n" - "DELETE [drive:][path]filename [/P]\n" - "ERASE [drive:][path]filename [/P]\n\n" - " [drive:][path]filename Specifies the file(s) to delete. Specify multiple\n" - " files by using wildcards.\n" - " /P Prompts for confirmation before deleting each file.")); -*/ - ConOutPuts (_T("Deletes one or more files.\n" "\n" - "DEL [/N /P /Q] file ...\n" - "DELETE [/N /P /Q] file ...\n" - "ERASE [/N /P /Q] file ...\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" - " /Q Quiet." + " /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; @@ -160,15 +182,31 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) switch (_totupper (arg[i][1])) { case _T('N'): - bNothing = TRUE; + dwFlags |= DEL_NOTHING; break; case _T('P'): - bPrompt = TRUE; + dwFlags |= DEL_PROMPT; break; case _T('Q'): - bQuiet = TRUE; + dwFlags |= DEL_QUIET; + break; + + case _T('S'): + dwFlags |= DEL_SUBDIR; + break; + + case _T('T'): + dwFlags |= DEL_TOTAL; + break; + + case _T('W'): + dwFlags |= DEL_WIPE; + break; + + case _T('Z'): + dwFlags |= DEL_ZAP; break; } @@ -200,14 +238,14 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) if (*arg[i] != _T('/')) { #ifdef _DEBUG - ConErrPrintf ("File: %s\n", arg[i]); + ConErrPrintf (_T("File: %s\n"), arg[i]); #endif if (_tcschr (arg[i], _T('*')) || _tcschr (arg[i], _T('?'))) { /* wildcards in filespec */ #ifdef _DEBUG - ConErrPrintf ("Wildcards!\n\n"); + ConErrPrintf (_T("Wildcards!\n\n")); #endif hFile = FindFirstFile (arg[i], &f); @@ -220,18 +258,46 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) do { + /* ignore "." and ".." */ if (!_tcscmp (f.cFileName, _T(".")) || !_tcscmp (f.cFileName, _T(".."))) continue; -#ifdef _DEBUG - ConErrPrintf ("Delete file: %s\n", f.cFileName); -#endif + if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) + ConErrPrintf (_T("Deleting: %s\n"), f.cFileName); - if (!bNothing) + /* delete the file */ + if (!(dwFlags & DEL_NOTHING)) { - if (!DeleteFile (f.cFileName)) - ErrorMessage (GetLastError(), _T("")); + if (RemoveFile (f.cFileName, dwFlags)) + { + dwFiles++; + } + else + { + if (dwFlags & DEL_ZAP) + { + if (SetFileAttributes (arg[i], 0)) + { + if (RemoveFile (arg[i], dwFlags)) + { + dwFiles++; + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } } @@ -242,15 +308,45 @@ INT cmd_del (LPTSTR cmd, LPTSTR param) else { /* no wildcards in filespec */ + #ifdef _DEBUG - ConErrPrintf ("No Wildcards!\n"); - ConErrPrintf ("Delete file: %s\n", arg[i]); + ConErrPrintf (_T("No Wildcards!\n")); #endif - if (!bNothing) + if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) + ConOutPrintf (_T("Deleting %s\n"), arg[i]); + + if (!(dwFlags & DEL_NOTHING)) { - if (!DeleteFile (arg[i])) - ErrorMessage (GetLastError(), _T("")); + if (RemoveFile (arg[i], dwFlags)) + { + dwFiles++; + } + else + { + if (dwFlags & DEL_ZAP) + { + if (SetFileAttributes (arg[i], 0)) + { + if (RemoveFile (arg[i], dwFlags)) + { + dwFiles++; + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } + else + { + ErrorMessage (GetLastError(), _T("")); + } + } } } } @@ -266,6 +362,16 @@ 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" : ""); + } + return 0; } diff --git a/rosapps/cmd/dir.c b/rosapps/cmd/dir.c index 19c7c7b83a4..b1830444c73 100644 --- a/rosapps/cmd/dir.c +++ b/rosapps/cmd/dir.c @@ -237,7 +237,7 @@ DirReadParam (LPTSTR line, LPTSTR *param, LPDWORD lpFlags) { if (_totupper (*line) == _T('S')) *lpFlags |= DIR_RECURSE; - else if (_toupper (*line) == _T('P')) + else if (_totupper (*line) == _T('P')) *lpFlags |= DIR_PAGE; else if (_totupper (*line) == _T('W')) *lpFlags |= DIR_WIDE; @@ -811,8 +811,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) count = 0; } - uliSize.u.LowPart += file.nFileSizeLow; - uliSize.u.HighPart += file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; bytecount.QuadPart += uliSize.QuadPart; } else if (dwFlags & DIR_BARE) @@ -842,8 +842,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) if (IncLine (pLine, dwFlags)) return 1; - uliSize.u.LowPart += file.nFileSizeLow; - uliSize.u.HighPart += file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; bytecount.QuadPart += uliSize.QuadPart; } else @@ -867,8 +867,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) { ULARGE_INTEGER uliSize; - uliSize.u.LowPart = file.nFileSizeLow; - uliSize.u.HighPart = file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; ConvertULargeInteger (uliSize, buffer, sizeof(buffer)); ConOutPrintf (_T(" %20s"), buffer); @@ -919,8 +919,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags) { ULARGE_INTEGER uliSize; - uliSize.u.LowPart = file.nFileSizeLow; - uliSize.u.HighPart = file.nFileSizeHigh; + uliSize.u.LowPart = file.nFileSizeLow; + uliSize.u.HighPart = file.nFileSizeHigh; ConvertULargeInteger (uliSize, buffer, sizeof(buffer)); ConOutPrintf (_T(" %10s "), buffer); diff --git a/rosapps/cmd/history.txt b/rosapps/cmd/history.txt index 7b0769bb53c..4fc998935ee 100644 --- a/rosapps/cmd/history.txt +++ b/rosapps/cmd/history.txt @@ -342,4 +342,12 @@ o ATTRIB and DEL can handle multiple filenames now. o Fixed handling of environment variables. o Added CHCP command. o Fixed keyboard input bug. -o Rewrote DEL and MOVE commands. \ No newline at end of file +o Rewrote DEL and MOVE commands. + +30-Mar-1999 ReactOS CMD version 0.1 pre 2 (Eric Kohl ) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +o Cleaned up DIR command. +o Searching for executables in the right order. +o Fixed some little but nasty bugs. +o Added TITLE command. Thanks to Emanuele Aliberti! +o Added "/Q", "/W" and "/Z" options to DEL command. diff --git a/rosapps/cmd/makefile b/rosapps/cmd/makefile index 0553027a0d7..18dd00a147f 100644 --- a/rosapps/cmd/makefile +++ b/rosapps/cmd/makefile @@ -8,10 +8,12 @@ # target: executable (not tested/experimental) all: cmd.exe -OBJECTS = ../common/crt0.o cmd.o attrib.o alias.o batch.o beep.o call.o chcp.o cls.o cmdinput.o cmdtable.o\ - color.o console.o copy.o date.o del.o dir.o dirstack.o echo.o error.o filecomp.o for.o goto.o history.o if.o\ - internal.o label.o locale.o misc.o move.o path.o pause.o prompt.o redir.o ren.o ros.o set.o shift.o time.o title.o type.o ver.o\ - verify.o vol.o where.o +OBJECTS = ../common/crt0.o cmd.o attrib.o alias.o batch.o beep.o call.o \ + chcp.o cls.o cmdinput.o cmdtable.o color.o console.o copy.o date.o \ + del.o dir.o dirstack.o echo.o error.o filecomp.o for.o goto.o \ + history.o if.o internal.o label.o locale.o misc.o move.o path.o \ + pause.o prompt.o redir.o ren.o set.o shift.o time.o title.o type.o \ + ver.o verify.o vol.o where.o LIBS= ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a diff --git a/rosapps/cmd/readme.txt b/rosapps/cmd/readme.txt index b76a3a77baf..26b7ae4cf2a 100644 --- a/rosapps/cmd/readme.txt +++ b/rosapps/cmd/readme.txt @@ -1,5 +1,5 @@ -ReactOS Command Line Interface "CMD" version 0.0.4 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +ReactOS Command Line Interface "CMD" version 0.1 pre 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is the fourth pre-alpha release of CMD.EXE for ReactOS. It was converted from the FreeDOS COMMAND.COM. @@ -7,7 +7,7 @@ It was converted from the FreeDOS COMMAND.COM. Warning!! Warning!! Warning!! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This is a pre-alpha version! Many features have not been tested! +This is an alpha version! Many features have not been tested! Be careful when you use commands that write to your disk drives, they might destroy your files or the file system!!! diff --git a/rosapps/cmd/ros.c b/rosapps/cmd/ros.c index 5c5cfcc8e2d..c8c02e2b74d 100644 --- a/rosapps/cmd/ros.c +++ b/rosapps/cmd/ros.c @@ -90,22 +90,4 @@ _makepath( char *path, const char *drive, const char *dir, const char *fname, co } } -#if 0 -int getch(void) -{ - DWORD NumberOfCharsRead = 0; - DWORD dwWritten; - char c; - - ReadConsoleA (GetStdHandle (STD_INPUT_HANDLE), &c, 1, &NumberOfCharsRead, NULL); - - if ( c == 10 ) - c = 13; - - WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), &c, 1, &dwWritten, NULL); - - return c; -} -#endif - #endif \ No newline at end of file diff --git a/rosapps/cmd/todo.txt b/rosapps/cmd/todo.txt index bcffe59a323..15400c1a1a1 100644 --- a/rosapps/cmd/todo.txt +++ b/rosapps/cmd/todo.txt @@ -2,8 +2,6 @@ Things to do ~~~~~~~~~~~~ Fix bugs :) -Rewrite DIR command (Unicode aware / new structure). - Optimize the code! For size and speed. There are numerous places where the code is hardly optimal for either.