Author: hbelusca
Date: Sun Jun 30 12:52:54 2013
New Revision: 59386
URL:
http://svn.reactos.org/svn/reactos?rev=59386&view=rev
Log:
[CMD]
Fix whitespace (part 5bis/6) (convert tabs into 4-space indent).
Modified:
trunk/reactos/base/shell/cmd/batch.c
trunk/reactos/base/shell/cmd/console.c
trunk/reactos/base/shell/cmd/del.c
Modified: trunk/reactos/base/shell/cmd/batch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/batch.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/batch.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/batch.c [iso-8859-1] Sun Jun 30 12:52:54 2013
@@ -54,8 +54,8 @@
* 23-Feb-2001 (Carl Nettelblad <cnettel(a)hem.passagen.es>)
* Fixes made to get "for" working.
*
- * 02-Apr-2005 (Magnus Olsen) <magnus(a)greatlord.com>)
- * Remove all hardcode string to En.rc
+ * 02-Apr-2005 (Magnus Olsen <magnus(a)greatlord.com>)
+ * Remove all hardcoded strings in En.rc
*/
#include "precomp.h"
@@ -65,7 +65,7 @@
*/
LPBATCH_CONTEXT bc = NULL;
-BOOL bEcho = TRUE; /* The echo flag */
+BOOL bEcho = TRUE; /* The echo flag */
@@ -82,24 +82,24 @@
LPTSTR FindArg(TCHAR Char, BOOL *IsParam0)
{
- LPTSTR pp;
- INT n = Char - _T('0');
-
- TRACE ("FindArg: (%d)\n", n);
-
- if (n < 0 || n > 9)
- return NULL;
-
- n = bc->shiftlevel[n];
- *IsParam0 = (n == 0);
- pp = bc->params;
-
- /* Step up the strings till we reach the end */
- /* or the one we want */
- while (*pp && n--)
- pp += _tcslen (pp) + 1;
-
- return pp;
+ LPTSTR pp;
+ INT n = Char - _T('0');
+
+ TRACE ("FindArg: (%d)\n", n);
+
+ if (n < 0 || n > 9)
+ return NULL;
+
+ n = bc->shiftlevel[n];
+ *IsParam0 = (n == 0);
+ pp = bc->params;
+
+ /* Step up the strings till we reach the end */
+ /* or the one we want */
+ while (*pp && n--)
+ pp += _tcslen (pp) + 1;
+
+ return pp;
}
@@ -108,51 +108,51 @@
* The parameters consist of null terminated strings with a final
* NULL character signalling the end of the parameters.
*
-*/
+ */
LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
{
- LPTSTR dp = (LPTSTR)cmd_alloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR));
-
- /* JPP 20-Jul-1998 added error checking */
- if (dp == NULL)
- {
- error_out_of_memory();
- return NULL;
- }
-
- if (s1 && *s1)
- {
- s1 = _stpcpy (dp, s1);
- *s1++ = _T('\0');
- }
- else
- s1 = dp;
-
- while (*s2)
- {
- BOOL inquotes = FALSE;
-
- /* Find next parameter */
- while (_istspace(*s2) || (*s2 && _tcschr(_T(",;="), *s2)))
- s2++;
- if (!*s2)
- break;
-
- /* Copy it */
- do
- {
- if (!inquotes && (_istspace(*s2) || _tcschr(_T(",;="), *s2)))
- break;
- inquotes ^= (*s2 == _T('"'));
- *s1++ = *s2++;
- } while (*s2);
- *s1++ = _T('\0');
- }
-
- *s1 = _T('\0');
-
- return dp;
+ LPTSTR dp = (LPTSTR)cmd_alloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR));
+
+ /* JPP 20-Jul-1998 added error checking */
+ if (dp == NULL)
+ {
+ error_out_of_memory();
+ return NULL;
+ }
+
+ if (s1 && *s1)
+ {
+ s1 = _stpcpy (dp, s1);
+ *s1++ = _T('\0');
+ }
+ else
+ s1 = dp;
+
+ while (*s2)
+ {
+ BOOL inquotes = FALSE;
+
+ /* Find next parameter */
+ while (_istspace(*s2) || (*s2 && _tcschr(_T(",;="), *s2)))
+ s2++;
+ if (!*s2)
+ break;
+
+ /* Copy it */
+ do
+ {
+ if (!inquotes && (_istspace(*s2) || _tcschr(_T(",;="),
*s2)))
+ break;
+ inquotes ^= (*s2 == _T('"'));
+ *s1++ = *s2++;
+ } while (*s2);
+ *s1++ = _T('\0');
+ }
+
+ *s1 = _T('\0');
+
+ return dp;
}
/*
@@ -160,16 +160,16 @@
*/
VOID ClearBatch()
{
- TRACE ("ClearBatch mem = %08x free = %d\n", bc->mem, bc->memfree);
-
- if (bc->mem && bc->memfree)
- cmd_free(bc->mem);
-
- if (bc->raw_params)
- cmd_free(bc->raw_params);
-
- if (bc->params)
- cmd_free(bc->params);
+ TRACE ("ClearBatch mem = %08x free = %d\n", bc->mem,
bc->memfree);
+
+ if (bc->mem && bc->memfree)
+ cmd_free(bc->mem);
+
+ if (bc->raw_params)
+ cmd_free(bc->raw_params);
+
+ if (bc->params)
+ cmd_free(bc->params);
}
/*
@@ -184,20 +184,20 @@
VOID ExitBatch()
{
- ClearBatch();
-
- TRACE ("ExitBatch\n");
-
- UndoRedirection(bc->RedirList, NULL);
- FreeRedirection(bc->RedirList);
-
- /* Preserve echo state across batch calls */
- bEcho = bc->bEcho;
-
- while (bc->setlocal)
- cmd_endlocal(_T(""));
-
- bc = bc->prev;
+ ClearBatch();
+
+ TRACE ("ExitBatch\n");
+
+ UndoRedirection(bc->RedirList, NULL);
+ FreeRedirection(bc->RedirList);
+
+ /* Preserve echo state across batch calls */
+ bEcho = bc->bEcho;
+
+ while (bc->setlocal)
+ cmd_endlocal(_T(""));
+
+ bc = bc->prev;
}
/*
@@ -206,26 +206,26 @@
*/
void BatchFile2Mem(HANDLE hBatchFile)
{
- TRACE ("BatchFile2Mem ()\n");
-
- bc->memsize = GetFileSize(hBatchFile, NULL);
- bc->mem = (char *)cmd_alloc(bc->memsize+1); /* 1 extra for '\0' */
-
- /* if memory is available, read it in and close the file */
- if (bc->mem != NULL)
- {
- TRACE ("BatchFile2Mem memory %08x - %08x\n",bc->mem,bc->memsize);
- SetFilePointer (hBatchFile, 0, NULL, FILE_BEGIN);
- ReadFile(hBatchFile, (LPVOID)bc->mem, bc->memsize, &bc->memsize, NULL);
- bc->mem[bc->memsize]='\0'; /* end this, so you can dump it as a string
*/
- bc->memfree=TRUE; /* this one needs to be freed */
- }
- else
- {
- bc->memsize=0; /* this will prevent mem being accessed */
- bc->memfree=FALSE;
- }
- bc->mempos = 0; /* set position to the start */
+ TRACE ("BatchFile2Mem ()\n");
+
+ bc->memsize = GetFileSize(hBatchFile, NULL);
+ bc->mem = (char *)cmd_alloc(bc->memsize+1); /* 1 extra for '\0'
*/
+
+ /* if memory is available, read it in and close the file */
+ if (bc->mem != NULL)
+ {
+ TRACE ("BatchFile2Mem memory %08x -
%08x\n",bc->mem,bc->memsize);
+ SetFilePointer (hBatchFile, 0, NULL, FILE_BEGIN);
+ ReadFile(hBatchFile, (LPVOID)bc->mem, bc->memsize, &bc->memsize,
NULL);
+ bc->mem[bc->memsize]='\0'; /* end this, so you can dump it as a
string */
+ bc->memfree=TRUE; /* this one needs to be freed */
+ }
+ else
+ {
+ bc->memsize=0; /* this will prevent mem being accessed */
+ bc->memfree=FALSE;
+ }
+ bc->mempos = 0; /* set position to the start */
}
/*
@@ -234,97 +234,96 @@
* The firstword parameter is the full filename of the batch file.
*
*/
-
INT Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
{
- BATCH_CONTEXT new;
- LPFOR_CONTEXT saved_fc;
- INT i;
- INT ret = 0;
- BOOL same_fn = FALSE;
-
- HANDLE hFile = 0;
- SetLastError(0);
- if (bc && bc->mem)
- {
- TCHAR fpname[MAX_PATH];
- GetFullPathName(fullname, sizeof(fpname) / sizeof(TCHAR), fpname, NULL);
- if (_tcsicmp(bc->BatchFilePath,fpname)==0)
- same_fn=TRUE;
- }
- TRACE ("Batch: (\'%s\', \'%s\', \'%s\') same_fn =
%d\n",
- debugstr_aw(fullname), debugstr_aw(firstword), debugstr_aw(param), same_fn);
-
- if (!same_fn)
- {
- hFile = CreateFile (fullname, GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ |
FILE_SHARE_DELETE, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
- FILE_FLAG_SEQUENTIAL_SCAN, NULL);
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- ConErrResPuts(STRING_BATCH_ERROR);
- return 1;
- }
- }
-
- if (bc != NULL && Cmd == bc->current)
- {
- /* Then we are transferring to another batch */
- ClearBatch();
- AddBatchRedirection(&Cmd->Redirections);
- }
- else
- {
- struct _SETLOCAL *setlocal = NULL;
-
- if (Cmd == NULL)
- {
- /* This is a CALL. CALL will set errorlevel to our return value, so
- * in order to keep the value of errorlevel unchanged in the case
- * of calling an empty batch file, we must return that same value. */
- ret = nErrorLevel;
- }
- else if (bc)
- {
- /* If a batch file runs another batch file as part of a compound command
- * (e.g. "x.bat & somethingelse") then the first file gets terminated.
*/
-
- /* Get its SETLOCAL stack so it can be migrated to the new context */
- setlocal = bc->setlocal;
- bc->setlocal = NULL;
- ExitBatch();
- }
-
- /* Create a new context. This function will not
- * return until this context has been exited */
- new.prev = bc;
- /* copy some fields in the new structure if it is the same file */
- if (same_fn) {
- new.mem = bc->mem;
- new.memsize = bc->memsize;
- new.mempos = 0;
- new.memfree = FALSE; /* don't free this, being used before this */
- }
- bc = &new;
- bc->RedirList = NULL;
- bc->setlocal = setlocal;
- }
-
- GetFullPathName(fullname, sizeof(bc->BatchFilePath) / sizeof(TCHAR),
bc->BatchFilePath, NULL);
- /* if a new batch file, load it into memory and close the file */
- if (!same_fn)
- {
- BatchFile2Mem(hFile);
- CloseHandle(hFile);
- }
-
- bc->mempos = 0; /* goto begin of batch file */
- bc->bEcho = bEcho; /* Preserve echo across batch calls */
- for (i = 0; i < 10; i++)
- bc->shiftlevel[i] = i;
-
- bc->params = BatchParams (firstword, param);
+ BATCH_CONTEXT new;
+ LPFOR_CONTEXT saved_fc;
+ INT i;
+ INT ret = 0;
+ BOOL same_fn = FALSE;
+
+ HANDLE hFile = 0;
+ SetLastError(0);
+ if (bc && bc->mem)
+ {
+ TCHAR fpname[MAX_PATH];
+ GetFullPathName(fullname, sizeof(fpname) / sizeof(TCHAR), fpname, NULL);
+ if (_tcsicmp(bc->BatchFilePath,fpname)==0)
+ same_fn=TRUE;
+ }
+ TRACE ("Batch: (\'%s\', \'%s\', \'%s\') same_fn =
%d\n",
+ debugstr_aw(fullname), debugstr_aw(firstword), debugstr_aw(param), same_fn);
+
+ if (!same_fn)
+ {
+ hFile = CreateFile(fullname, GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ |
FILE_SHARE_DELETE, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
+ FILE_FLAG_SEQUENTIAL_SCAN, NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ ConErrResPuts(STRING_BATCH_ERROR);
+ return 1;
+ }
+ }
+
+ if (bc != NULL && Cmd == bc->current)
+ {
+ /* Then we are transferring to another batch */
+ ClearBatch();
+ AddBatchRedirection(&Cmd->Redirections);
+ }
+ else
+ {
+ struct _SETLOCAL *setlocal = NULL;
+
+ if (Cmd == NULL)
+ {
+ /* This is a CALL. CALL will set errorlevel to our return value, so
+ * in order to keep the value of errorlevel unchanged in the case
+ * of calling an empty batch file, we must return that same value. */
+ ret = nErrorLevel;
+ }
+ else if (bc)
+ {
+ /* If a batch file runs another batch file as part of a compound command
+ * (e.g. "x.bat & somethingelse") then the first file gets
terminated. */
+
+ /* Get its SETLOCAL stack so it can be migrated to the new context */
+ setlocal = bc->setlocal;
+ bc->setlocal = NULL;
+ ExitBatch();
+ }
+
+ /* Create a new context. This function will not
+ * return until this context has been exited */
+ new.prev = bc;
+ /* copy some fields in the new structure if it is the same file */
+ if (same_fn) {
+ new.mem = bc->mem;
+ new.memsize = bc->memsize;
+ new.mempos = 0;
+ new.memfree = FALSE; /* don't free this, being used before this */
+ }
+ bc = &new;
+ bc->RedirList = NULL;
+ bc->setlocal = setlocal;
+ }
+
+ GetFullPathName(fullname, sizeof(bc->BatchFilePath) / sizeof(TCHAR),
bc->BatchFilePath, NULL);
+ /* if a new batch file, load it into memory and close the file */
+ if (!same_fn)
+ {
+ BatchFile2Mem(hFile);
+ CloseHandle(hFile);
+ }
+
+ bc->mempos = 0; /* goto begin of batch file */
+ bc->bEcho = bEcho; /* Preserve echo across batch calls */
+ for (i = 0; i < 10; i++)
+ bc->shiftlevel[i] = i;
+
+ bc->params = BatchParams (firstword, param);
//
// Allocate enough memory to hold the params and copy them over without
modifications
//
@@ -335,58 +334,58 @@
return 1;
}
- /* Check if this is a "CALL :label" */
- if (*firstword == _T(':'))
- cmd_goto(firstword);
-
- /* If we are calling from inside a FOR, hide the FOR variables */
- saved_fc = fc;
- fc = NULL;
-
- /* If we have created a new context, don't return
- * until this batch file has completed. */
- while (bc == &new && !bExit)
- {
- Cmd = ParseCommand(NULL);
- if (!Cmd)
- continue;
-
- /* JPP 19980807 */
- /* Echo batch file line */
- if (bEcho && !bDisableBatchEcho && Cmd->Type != C_QUIET)
- {
- if (!bIgnoreEcho)
- ConOutChar(_T('\n'));
- PrintPrompt();
- EchoCommand(Cmd);
- ConOutChar(_T('\n'));
- }
-
- bc->current = Cmd;
- ret = ExecuteCommand(Cmd);
- FreeCommand(Cmd);
- }
-
- TRACE ("Batch: returns TRUE\n");
-
- fc = saved_fc;
- return ret;
+ /* Check if this is a "CALL :label" */
+ if (*firstword == _T(':'))
+ cmd_goto(firstword);
+
+ /* If we are calling from inside a FOR, hide the FOR variables */
+ saved_fc = fc;
+ fc = NULL;
+
+ /* If we have created a new context, don't return
+ * until this batch file has completed. */
+ while (bc == &new && !bExit)
+ {
+ Cmd = ParseCommand(NULL);
+ if (!Cmd)
+ continue;
+
+ /* JPP 19980807 */
+ /* Echo batch file line */
+ if (bEcho && !bDisableBatchEcho && Cmd->Type != C_QUIET)
+ {
+ if (!bIgnoreEcho)
+ ConOutChar(_T('\n'));
+ PrintPrompt();
+ EchoCommand(Cmd);
+ ConOutChar(_T('\n'));
+ }
+
+ bc->current = Cmd;
+ ret = ExecuteCommand(Cmd);
+ FreeCommand(Cmd);
+ }
+
+ TRACE ("Batch: returns TRUE\n");
+
+ fc = saved_fc;
+ return ret;
}
VOID AddBatchRedirection(REDIRECTION **RedirList)
{
- REDIRECTION **ListEnd;
-
- /* Prepend the list to the batch context's list */
- ListEnd = RedirList;
- while (*ListEnd)
- ListEnd = &(*ListEnd)->Next;
- *ListEnd = bc->RedirList;
- bc->RedirList = *RedirList;
-
- /* Null out the pointer so that the list will not be cleared prematurely.
- * These redirections should persist until the batch file exits. */
- *RedirList = NULL;
+ REDIRECTION **ListEnd;
+
+ /* Prepend the list to the batch context's list */
+ ListEnd = RedirList;
+ while (*ListEnd)
+ ListEnd = &(*ListEnd)->Next;
+ *ListEnd = bc->RedirList;
+ bc->RedirList = *RedirList;
+
+ /* Null out the pointer so that the list will not be cleared prematurely.
+ * These redirections should persist until the batch file exits. */
+ *RedirList = NULL;
}
/*
@@ -395,41 +394,41 @@
*/
BOOL BatchGetString (LPTSTR lpBuffer, INT nBufferLength)
{
- LPSTR lpString;
- INT len = 0;
+ LPSTR lpString;
+ INT len = 0;
#ifdef _UNICODE
- lpString = cmd_alloc(nBufferLength);
+ lpString = cmd_alloc(nBufferLength);
#else
- lpString = lpBuffer;
+ lpString = lpBuffer;
#endif
- /* read all chars from memory until a '\n' is encountered */
- if (bc->mem)
- {
- for (; (bc->mempos < bc->memsize && len < (nBufferLength-1));
len++)
- {
- lpString[len] = bc->mem[bc->mempos++];
- if (lpString[len] == '\n' )
- {
- len++;
- break;
- }
- }
- }
-
- if (!len)
- {
+ /* read all chars from memory until a '\n' is encountered */
+ if (bc->mem)
+ {
+ for (; (bc->mempos < bc->memsize && len <
(nBufferLength-1)); len++)
+ {
+ lpString[len] = bc->mem[bc->mempos++];
+ if (lpString[len] == '\n' )
+ {
+ len++;
+ break;
+ }
+ }
+ }
+
+ if (!len)
+ {
#ifdef _UNICODE
- cmd_free(lpString);
+ cmd_free(lpString);
#endif
- return FALSE;
- }
-
- lpString[len++] = '\0';
+ return FALSE;
+ }
+
+ lpString[len++] = '\0';
#ifdef _UNICODE
- MultiByteToWideChar(OutputCodePage, 0, lpString, -1, lpBuffer, len);
- cmd_free(lpString);
+ MultiByteToWideChar(OutputCodePage, 0, lpString, -1, lpBuffer, len);
+ cmd_free(lpString);
#endif
- return TRUE;
+ return TRUE;
}
/*
@@ -442,30 +441,30 @@
*/
LPTSTR ReadBatchLine ()
{
- TRACE ("ReadBatchLine ()\n");
-
- /* User halt */
- if (CheckCtrlBreak (BREAK_BATCHFILE))
- {
- while (bc)
- ExitBatch();
- return NULL;
- }
-
- if (!BatchGetString (textline, sizeof (textline) / sizeof (textline[0]) - 1))
- {
- TRACE ("ReadBatchLine(): Reached EOF!\n");
- /* End of file.... */
- ExitBatch();
- return NULL;
- }
-
- TRACE ("ReadBatchLine(): textline: \'%s\'\n", debugstr_aw(textline));
-
- if (textline[_tcslen(textline) - 1] != _T('\n'))
- _tcscat(textline, _T("\n"));
-
- return textline;
+ TRACE ("ReadBatchLine ()\n");
+
+ /* User halt */
+ if (CheckCtrlBreak (BREAK_BATCHFILE))
+ {
+ while (bc)
+ ExitBatch();
+ return NULL;
+ }
+
+ if (!BatchGetString (textline, sizeof (textline) / sizeof (textline[0]) - 1))
+ {
+ TRACE ("ReadBatchLine(): Reached EOF!\n");
+ /* End of file.... */
+ ExitBatch();
+ return NULL;
+ }
+
+ TRACE ("ReadBatchLine(): textline: \'%s\'\n",
debugstr_aw(textline));
+
+ if (textline[_tcslen(textline) - 1] != _T('\n'))
+ _tcscat(textline, _T("\n"));
+
+ return textline;
}
/* EOF */
Modified: trunk/reactos/base/shell/cmd/console.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/console.c?r…
==============================================================================
--- trunk/reactos/base/shell/cmd/console.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/console.c [iso-8859-1] Sun Jun 30 12:52:54 2013
@@ -7,13 +7,13 @@
* 20-Jan-1999 (Eric Kohl)
* started
*
- * 03-Apr-2005 (Magnus Olsen) <magnus(a)greatlord.com>)
- * Remove all hardcode string to En.rc
- *
- * 01-Jul-2005 (Brandon Turner) <turnerb7(a)msu.edu>)
+ * 03-Apr-2005 (Magnus Olsen) <magnus(a)greatlord.com>
+ * Remove all hardcoded strings in En.rc
+ *
+ * 01-Jul-2005 (Brandon Turner) <turnerb7(a)msu.edu>
* Added ConPrintfPaging and ConOutPrintfPaging
*
- * 02-Feb-2007 (Paolo Devoti) <devotip at gmail.com>)
+ * 02-Feb-2007 (Paolo Devoti) <devotip at gmail.com>
* Fixed ConPrintfPaging
*/
@@ -28,441 +28,441 @@
VOID ConInDisable (VOID)
{
- HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
- DWORD dwMode;
-
- GetConsoleMode (hInput, &dwMode);
- dwMode &= ~ENABLE_PROCESSED_INPUT;
- SetConsoleMode (hInput, dwMode);
+ HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
+ DWORD dwMode;
+
+ GetConsoleMode (hInput, &dwMode);
+ dwMode &= ~ENABLE_PROCESSED_INPUT;
+ SetConsoleMode (hInput, dwMode);
}
VOID ConInEnable (VOID)
{
- HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
- DWORD dwMode;
-
- GetConsoleMode (hInput, &dwMode);
- dwMode |= ENABLE_PROCESSED_INPUT;
- SetConsoleMode (hInput, dwMode);
+ HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
+ DWORD dwMode;
+
+ GetConsoleMode (hInput, &dwMode);
+ dwMode |= ENABLE_PROCESSED_INPUT;
+ SetConsoleMode (hInput, dwMode);
}
VOID ConInFlush (VOID)
{
- FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE));
+ FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE));
}
VOID ConInKey (PINPUT_RECORD lpBuffer)
{
- HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
- DWORD dwRead;
-
- if (hInput == INVALID_HANDLE_VALUE)
- WARN ("Invalid input handle!!!\n");
-
- do
- {
- ReadConsoleInput (hInput, lpBuffer, 1, &dwRead);
- if ((lpBuffer->EventType == KEY_EVENT) &&
- (lpBuffer->Event.KeyEvent.bKeyDown == TRUE))
- break;
- }
- while (TRUE);
+ HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
+ DWORD dwRead;
+
+ if (hInput == INVALID_HANDLE_VALUE)
+ WARN ("Invalid input handle!!!\n");
+
+ do
+ {
+ ReadConsoleInput (hInput, lpBuffer, 1, &dwRead);
+ if ((lpBuffer->EventType == KEY_EVENT) &&
+ (lpBuffer->Event.KeyEvent.bKeyDown == TRUE))
+ break;
+ }
+ while (TRUE);
}
VOID ConInString (LPTSTR lpInput, DWORD dwLength)
{
- DWORD dwOldMode;
- DWORD dwRead = 0;
- HANDLE hFile;
-
- LPTSTR p;
- PCHAR pBuf;
+ DWORD dwOldMode;
+ DWORD dwRead = 0;
+ HANDLE hFile;
+
+ LPTSTR p;
+ PCHAR pBuf;
#ifdef _UNICODE
- pBuf = (PCHAR)cmd_alloc(dwLength - 1);
+ pBuf = (PCHAR)cmd_alloc(dwLength - 1);
#else
- pBuf = lpInput;
-#endif
- ZeroMemory (lpInput, dwLength * sizeof(TCHAR));
- hFile = GetStdHandle (STD_INPUT_HANDLE);
- GetConsoleMode (hFile, &dwOldMode);
-
- SetConsoleMode (hFile, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
-
- ReadFile (hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
+ pBuf = lpInput;
+#endif
+ ZeroMemory (lpInput, dwLength * sizeof(TCHAR));
+ hFile = GetStdHandle (STD_INPUT_HANDLE);
+ GetConsoleMode (hFile, &dwOldMode);
+
+ SetConsoleMode (hFile, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
+
+ ReadFile (hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
#ifdef _UNICODE
- MultiByteToWideChar(InputCodePage, 0, pBuf, dwRead, lpInput, dwLength - 1);
- cmd_free(pBuf);
-#endif
- for (p = lpInput; *p; p++)
- {
- if (*p == _T('\x0d'))
- {
- *p = _T('\0');
- break;
- }
- }
-
- SetConsoleMode (hFile, dwOldMode);
+ MultiByteToWideChar(InputCodePage, 0, pBuf, dwRead, lpInput, dwLength - 1);
+ cmd_free(pBuf);
+#endif
+ for (p = lpInput; *p; p++)
+ {
+ if (*p == _T('\x0d'))
+ {
+ *p = _T('\0');
+ break;
+ }
+ }
+
+ SetConsoleMode (hFile, dwOldMode);
}
static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
{
- DWORD dwWritten;
- HANDLE hOutput = GetStdHandle(nStdHandle);
-
- if (WriteConsole(hOutput, str, len, &dwWritten, NULL))
- return;
-
- /* We're writing to a file or pipe instead of the console. Convert the
- * string from TCHARs to the desired output format, if the two differ */
- if (bUnicodeOutput)
- {
+ DWORD dwWritten;
+ HANDLE hOutput = GetStdHandle(nStdHandle);
+
+ if (WriteConsole(hOutput, str, len, &dwWritten, NULL))
+ return;
+
+ /* We're writing to a file or pipe instead of the console. Convert the
+ * string from TCHARs to the desired output format, if the two differ */
+ if (bUnicodeOutput)
+ {
#ifndef _UNICODE
- WCHAR *buffer = cmd_alloc(len * sizeof(WCHAR));
- if (!buffer)
- {
- error_out_of_memory();
- return;
- }
- len = MultiByteToWideChar(OutputCodePage, 0, str, len, buffer, len);
- str = (PVOID)buffer;
-#endif
- WriteFile(hOutput, str, len * sizeof(WCHAR), &dwWritten, NULL);
+ WCHAR *buffer = cmd_alloc(len * sizeof(WCHAR));
+ if (!buffer)
+ {
+ error_out_of_memory();
+ return;
+ }
+ len = MultiByteToWideChar(OutputCodePage, 0, str, len, buffer, len);
+ str = (PVOID)buffer;
+#endif
+ WriteFile(hOutput, str, len * sizeof(WCHAR), &dwWritten, NULL);
#ifndef _UNICODE
- cmd_free(buffer);
-#endif
- }
- else
- {
+ cmd_free(buffer);
+#endif
+ }
+ else
+ {
#ifdef _UNICODE
- CHAR *buffer = cmd_alloc(len * MB_LEN_MAX * sizeof(CHAR));
- if (!buffer)
- {
- error_out_of_memory();
- return;
- }
- len = WideCharToMultiByte(OutputCodePage, 0, str, len, buffer, len * MB_LEN_MAX, NULL,
NULL);
- str = (PVOID)buffer;
-#endif
- WriteFile(hOutput, str, len, &dwWritten, NULL);
+ CHAR *buffer = cmd_alloc(len * MB_LEN_MAX * sizeof(CHAR));
+ if (!buffer)
+ {
+ error_out_of_memory();
+ return;
+ }
+ len = WideCharToMultiByte(OutputCodePage, 0, str, len, buffer, len * MB_LEN_MAX,
NULL, NULL);
+ str = (PVOID)buffer;
+#endif
+ WriteFile(hOutput, str, len, &dwWritten, NULL);
#ifdef _UNICODE
- cmd_free(buffer);
-#endif
- }
+ cmd_free(buffer);
+#endif
+ }
}
VOID ConOutChar (TCHAR c)
{
- ConWrite(&c, 1, STD_OUTPUT_HANDLE);
+ ConWrite(&c, 1, STD_OUTPUT_HANDLE);
}
VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
{
- ConWrite(szText, _tcslen(szText), nStdHandle);
+ ConWrite(szText, _tcslen(szText), nStdHandle);
}
VOID ConOutResPaging(BOOL NewPage, UINT resID)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
- ConOutPrintfPaging(NewPage, szMsg);
+ TCHAR szMsg[RC_STRING_MAX_SIZE];
+ LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
+ ConOutPrintfPaging(NewPage, szMsg);
}
VOID ConOutResPuts (UINT resID)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
-
- ConPuts(szMsg, STD_OUTPUT_HANDLE);
+ TCHAR szMsg[RC_STRING_MAX_SIZE];
+ LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
+
+ ConPuts(szMsg, STD_OUTPUT_HANDLE);
}
VOID ConOutPuts (LPTSTR szText)
{
- ConPuts(szText, STD_OUTPUT_HANDLE);
+ ConPuts(szText, STD_OUTPUT_HANDLE);
}
VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
{
- TCHAR szOut[OUTPUT_BUFFER_SIZE];
- ConWrite(szOut, _vstprintf(szOut, szFormat, arg_ptr), nStdHandle);
+ TCHAR szOut[OUTPUT_BUFFER_SIZE];
+ ConWrite(szOut, _vstprintf(szOut, szFormat, arg_ptr), nStdHandle);
}
INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
{
- INT len;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- TCHAR szOut[OUTPUT_BUFFER_SIZE];
- DWORD dwWritten;
- HANDLE hOutput = GetStdHandle(nStdHandle);
-
- /* used to count number of lines since last pause */
- static int LineCount = 0;
-
- /* used to see how big the screen is */
- int ScreenLines = 0;
-
- /* chars since start of line */
- int CharSL;
-
- int from = 0, i = 0;
-
- if(NewPage == TRUE)
- LineCount = 0;
-
- /* rest LineCount and return if no string have been given */
- if (szFormat == NULL)
- return 0;
-
-
- //get the size of the visual screen that can be printed too
- if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
- {
- // we assuming its a file handle
- ConPrintf(szFormat, arg_ptr, nStdHandle);
- return 0;
- }
- //subtract 2 to account for "press any key..." and for the blank line at the
end of PagePrompt()
- ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top) - 4;
- CharSL = csbi.dwCursorPosition.X;
-
- //make sure they didnt make the screen to small
- if(ScreenLines<4)
- {
- ConPrintf(szFormat, arg_ptr, nStdHandle);
- return 0;
- }
-
- len = _vstprintf (szOut, szFormat, arg_ptr);
-
- while (i < len)
- {
- // Search until the end of a line is reached
- if (szOut[i++] != _T('\n') && ++CharSL < csbi.dwSize.X)
- continue;
-
- LineCount++;
- CharSL=0;
-
- if(LineCount >= ScreenLines)
- {
- WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
- from = i;
-
- if(PagePrompt() != PROMPT_YES)
- {
- return 1;
- }
- //reset the number of lines being printed
- LineCount = 0;
- }
- }
-
- WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
-
- return 0;
+ INT len;
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+ TCHAR szOut[OUTPUT_BUFFER_SIZE];
+ DWORD dwWritten;
+ HANDLE hOutput = GetStdHandle(nStdHandle);
+
+ /* used to count number of lines since last pause */
+ static int LineCount = 0;
+
+ /* used to see how big the screen is */
+ int ScreenLines = 0;
+
+ /* chars since start of line */
+ int CharSL;
+
+ int from = 0, i = 0;
+
+ if(NewPage == TRUE)
+ LineCount = 0;
+
+ /* rest LineCount and return if no string have been given */
+ if (szFormat == NULL)
+ return 0;
+
+
+ //get the size of the visual screen that can be printed too
+ if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
+ {
+ // we assuming its a file handle
+ ConPrintf(szFormat, arg_ptr, nStdHandle);
+ return 0;
+ }
+ //subtract 2 to account for "press any key..." and for the blank line at
the end of PagePrompt()
+ ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top) - 4;
+ CharSL = csbi.dwCursorPosition.X;
+
+ //make sure they didnt make the screen to small
+ if(ScreenLines<4)
+ {
+ ConPrintf(szFormat, arg_ptr, nStdHandle);
+ return 0;
+ }
+
+ len = _vstprintf (szOut, szFormat, arg_ptr);
+
+ while (i < len)
+ {
+ // Search until the end of a line is reached
+ if (szOut[i++] != _T('\n') && ++CharSL < csbi.dwSize.X)
+ continue;
+
+ LineCount++;
+ CharSL=0;
+
+ if(LineCount >= ScreenLines)
+ {
+ WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
+ from = i;
+
+ if(PagePrompt() != PROMPT_YES)
+ {
+ return 1;
+ }
+ //reset the number of lines being printed
+ LineCount = 0;
+ }
+ }
+
+ WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
+
+ return 0;
}
VOID ConErrFormatMessage (DWORD MessageId, ...)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- DWORD ret;
- LPTSTR text;
- va_list arg_ptr;
-
- va_start (arg_ptr, MessageId);
- ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- MessageId,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &text,
- 0,
- &arg_ptr);
-
- va_end (arg_ptr);
- if(ret > 0)
- {
- ConErrPuts (text);
- LocalFree(text);
- }
- else
- {
- LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, RC_STRING_MAX_SIZE);
- ConErrPrintf(szMsg);
- }
+ TCHAR szMsg[RC_STRING_MAX_SIZE];
+ DWORD ret;
+ LPTSTR text;
+ va_list arg_ptr;
+
+ va_start (arg_ptr, MessageId);
+ ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ MessageId,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &text,
+ 0,
+ &arg_ptr);
+
+ va_end (arg_ptr);
+ if(ret > 0)
+ {
+ ConErrPuts (text);
+ LocalFree(text);
+ }
+ else
+ {
+ LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, RC_STRING_MAX_SIZE);
+ ConErrPrintf(szMsg);
+ }
}
VOID ConOutFormatMessage (DWORD MessageId, ...)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- DWORD ret;
- LPTSTR text;
- va_list arg_ptr;
-
- va_start (arg_ptr, MessageId);
- ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- MessageId,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &text,
- 0,
- &arg_ptr);
-
- va_end (arg_ptr);
- if(ret > 0)
- {
- ConErrPuts (text);
- LocalFree(text);
- }
- else
- {
- LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, RC_STRING_MAX_SIZE);
- ConErrPrintf(szMsg);
- }
+ TCHAR szMsg[RC_STRING_MAX_SIZE];
+ DWORD ret;
+ LPTSTR text;
+ va_list arg_ptr;
+
+ va_start (arg_ptr, MessageId);
+ ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ MessageId,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &text,
+ 0,
+ &arg_ptr);
+
+ va_end (arg_ptr);
+ if(ret > 0)
+ {
+ ConErrPuts (text);
+ LocalFree(text);
+ }
+ else
+ {
+ LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, RC_STRING_MAX_SIZE);
+ ConErrPrintf(szMsg);
+ }
}
VOID ConOutResPrintf (UINT resID, ...)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- va_list arg_ptr;
-
- va_start (arg_ptr, resID);
- LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
- ConPrintf(szMsg, arg_ptr, STD_OUTPUT_HANDLE);
- va_end (arg_ptr);
+ TCHAR szMsg[RC_STRING_MAX_SIZE];
+ va_list arg_ptr;
+
+ va_start (arg_ptr, resID);
+ LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
+ ConPrintf(szMsg, arg_ptr, STD_OUTPUT_HANDLE);
+ va_end (arg_ptr);
}
VOID ConOutPrintf (LPTSTR szFormat, ...)
{
- va_list arg_ptr;
-
- va_start (arg_ptr, szFormat);
- ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
- va_end (arg_ptr);
+ va_list arg_ptr;
+
+ va_start (arg_ptr, szFormat);
+ ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
+ va_end (arg_ptr);
}
INT ConOutPrintfPaging (BOOL NewPage, LPTSTR szFormat, ...)
{
- INT iReturn;
- va_list arg_ptr;
-
- va_start (arg_ptr, szFormat);
- iReturn = ConPrintfPaging(NewPage, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
- va_end (arg_ptr);
- return iReturn;
+ INT iReturn;
+ va_list arg_ptr;
+
+ va_start (arg_ptr, szFormat);
+ iReturn = ConPrintfPaging(NewPage, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
+ va_end (arg_ptr);
+ return iReturn;
}
VOID ConErrChar (TCHAR c)
{
- ConWrite(&c, 1, STD_ERROR_HANDLE);
+ ConWrite(&c, 1, STD_ERROR_HANDLE);
}
VOID ConErrResPuts (UINT resID)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
- ConPuts(szMsg, STD_ERROR_HANDLE);
+ TCHAR szMsg[RC_STRING_MAX_SIZE];
+ LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
+ ConPuts(szMsg, STD_ERROR_HANDLE);
}
VOID ConErrPuts (LPTSTR szText)
{
- ConPuts(szText, STD_ERROR_HANDLE);
+ ConPuts(szText, STD_ERROR_HANDLE);
}
VOID ConErrResPrintf (UINT resID, ...)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- va_list arg_ptr;
-
- va_start (arg_ptr, resID);
- LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
- ConPrintf(szMsg, arg_ptr, STD_ERROR_HANDLE);
- va_end (arg_ptr);
+ TCHAR szMsg[RC_STRING_MAX_SIZE];
+ va_list arg_ptr;
+
+ va_start (arg_ptr, resID);
+ LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
+ ConPrintf(szMsg, arg_ptr, STD_ERROR_HANDLE);
+ va_end (arg_ptr);
}
VOID ConErrPrintf (LPTSTR szFormat, ...)
{
- va_list arg_ptr;
-
- va_start (arg_ptr, szFormat);
- ConPrintf(szFormat, arg_ptr, STD_ERROR_HANDLE);
- va_end (arg_ptr);
+ va_list arg_ptr;
+
+ va_start (arg_ptr, szFormat);
+ ConPrintf(szFormat, arg_ptr, STD_ERROR_HANDLE);
+ va_end (arg_ptr);
}
VOID SetCursorXY (SHORT x, SHORT y)
{
- COORD coPos;
-
- coPos.X = x;
- coPos.Y = y;
- SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
+ COORD coPos;
+
+ coPos.X = x;
+ coPos.Y = y;
+ SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
}
VOID GetCursorXY (PSHORT x, PSHORT y)
{
- CONSOLE_SCREEN_BUFFER_INFO csbi;
-
- GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
-
- *x = csbi.dwCursorPosition.X;
- *y = csbi.dwCursorPosition.Y;
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+ GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
+
+ *x = csbi.dwCursorPosition.X;
+ *y = csbi.dwCursorPosition.Y;
}
SHORT GetCursorX (VOID)
{
- CONSOLE_SCREEN_BUFFER_INFO csbi;
-
- GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
-
- return csbi.dwCursorPosition.X;
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+ GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
+
+ return csbi.dwCursorPosition.X;
}
SHORT GetCursorY (VOID)
{
- CONSOLE_SCREEN_BUFFER_INFO csbi;
-
- GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
-
- return csbi.dwCursorPosition.Y;
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+ GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
+
+ return csbi.dwCursorPosition.Y;
}
VOID GetScreenSize (PSHORT maxx, PSHORT maxy)
{
- CONSOLE_SCREEN_BUFFER_INFO csbi;
-
- if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
- {
- csbi.dwSize.X = 80;
- csbi.dwSize.Y = 25;
- }
-
- if (maxx)
- *maxx = csbi.dwSize.X;
- if (maxy)
- *maxy = csbi.dwSize.Y;
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+ if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
+ {
+ csbi.dwSize.X = 80;
+ csbi.dwSize.Y = 25;
+ }
+
+ if (maxx)
+ *maxx = csbi.dwSize.X;
+ if (maxy)
+ *maxy = csbi.dwSize.Y;
}
VOID SetCursorType (BOOL bInsert, BOOL bVisible)
{
- CONSOLE_CURSOR_INFO cci;
-
- cci.dwSize = bInsert ? 10 : 99;
- cci.bVisible = bVisible;
-
- SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci);
+ CONSOLE_CURSOR_INFO cci;
+
+ cci.dwSize = bInsert ? 10 : 99;
+ cci.bVisible = bVisible;
+
+ SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci);
}
/* EOF */
Modified: trunk/reactos/base/shell/cmd/del.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/del.c?rev=5…
==============================================================================
--- trunk/reactos/base/shell/cmd/del.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/del.c [iso-8859-1] Sun Jun 30 12:52:54 2013
@@ -52,28 +52,28 @@
enum
{
- DEL_ATTRIBUTES = 0x001, /* /A */
- DEL_NOTHING = 0x004, /* /N */
- DEL_PROMPT = 0x008, /* /P */
- DEL_QUIET = 0x010, /* /Q */
- DEL_SUBDIR = 0x020, /* /S */
- DEL_TOTAL = 0x040, /* /T */
- DEL_WIPE = 0x080, /* /W */
- DEL_EMPTYDIR = 0x100, /* /X : not implemented */
- DEL_YES = 0x200, /* /Y */
- DEL_FORCE = 0x800 /* /F */
+ DEL_ATTRIBUTES = 0x001, /* /A */
+ DEL_NOTHING = 0x004, /* /N */
+ DEL_PROMPT = 0x008, /* /P */
+ DEL_QUIET = 0x010, /* /Q */
+ DEL_SUBDIR = 0x020, /* /S */
+ DEL_TOTAL = 0x040, /* /T */
+ DEL_WIPE = 0x080, /* /W */
+ DEL_EMPTYDIR = 0x100, /* /X : not implemented */
+ DEL_YES = 0x200, /* /Y */
+ DEL_FORCE = 0x800 /* /F */
};
enum
{
- ATTR_ARCHIVE = 0x001, /* /A:A */
- ATTR_HIDDEN = 0x002, /* /A:H */
- ATTR_SYSTEM = 0x004, /* /A:S */
- ATTR_READ_ONLY = 0x008, /* /A:R */
- ATTR_N_ARCHIVE = 0x010, /* /A:-A */
- ATTR_N_HIDDEN = 0x020, /* /A:-H */
- ATTR_N_SYSTEM = 0x040, /* /A:-S */
- ATTR_N_READ_ONLY = 0x080 /* /A:-R */
+ ATTR_ARCHIVE = 0x001, /* /A:A */
+ ATTR_HIDDEN = 0x002, /* /A:H */
+ ATTR_SYSTEM = 0x004, /* /A:S */
+ ATTR_READ_ONLY = 0x008, /* /A:R */
+ ATTR_N_ARCHIVE = 0x010, /* /A:-A */
+ ATTR_N_HIDDEN = 0x020, /* /A:-H */
+ ATTR_N_SYSTEM = 0x040, /* /A:-S */
+ ATTR_N_READ_ONLY = 0x080 /* /A:-R */
};
static TCHAR szDeleteWipe[RC_STRING_MAX_SIZE];
@@ -83,471 +83,460 @@
static VOID LoadStrings(VOID)
{
- LoadString( CMD_ModuleHandle, STRING_DELETE_WIPE, szDeleteWipe,
RC_STRING_MAX_SIZE);
- GetModuleFileName(NULL, CMDPath, MAX_PATH);
- StringsLoaded = TRUE;
+ LoadString( CMD_ModuleHandle, STRING_DELETE_WIPE, szDeleteWipe, RC_STRING_MAX_SIZE);
+ GetModuleFileName(NULL, CMDPath, MAX_PATH);
+ StringsLoaded = TRUE;
}
static BOOL
RemoveFile (LPTSTR lpFileName, DWORD dwFlags, WIN32_FIND_DATA* f)
{
- /*This function is called by CommandDelete and
- does the actual process of deleting the single
- file*/
- if(CheckCtrlBreak(BREAK_INPUT))
- return 1;
-
- /*check to see if it is read only and if this is done based on /A
- if it is done by file name, access is denied. However, if it is done
- using the /A switch you must un-read only the file and allow it to be
- deleted*/
- if((dwFlags & DEL_ATTRIBUTES) || (dwFlags & DEL_FORCE))
- {
- if(f->dwFileAttributes & FILE_ATTRIBUTE_READONLY)
- {
- /*setting file to normal, not saving old attrs first
- because the file is going to be deleted anyways
- so the only thing that matters is that it isn't
- read only.*/
- SetFileAttributes(lpFileName,FILE_ATTRIBUTE_NORMAL);
- }
- }
-
- if (dwFlags & DEL_WIPE)
- {
-
- HANDLE file;
- DWORD temp;
+ /*This function is called by CommandDelete and
+ does the actual process of deleting the single
+ file*/
+ if (CheckCtrlBreak(BREAK_INPUT))
+ return 1;
+
+ /*check to see if it is read only and if this is done based on /A
+ if it is done by file name, access is denied. However, if it is done
+ using the /A switch you must un-read only the file and allow it to be
+ deleted*/
+ if ((dwFlags & DEL_ATTRIBUTES) || (dwFlags & DEL_FORCE))
+ {
+ if (f->dwFileAttributes & FILE_ATTRIBUTE_READONLY)
+ {
+ /*setting file to normal, not saving old attrs first
+ because the file is going to be deleted anyways
+ so the only thing that matters is that it isn't
+ read only.*/
+ SetFileAttributes(lpFileName,FILE_ATTRIBUTE_NORMAL);
+ }
+ }
+
+ if (dwFlags & DEL_WIPE)
+ {
+ HANDLE file;
+ DWORD temp;
#define BufferSize 65536
- BYTE buffer[BufferSize];
- LONGLONG i;
- LARGE_INTEGER FileSize;
-
- FileSize.u.HighPart = f->nFileSizeHigh;
- FileSize.u.LowPart = f->nFileSizeLow;
-
- for(i = 0; i < BufferSize; i++)
- {
- buffer[i]=rand() % 256;
- }
- file = CreateFile (lpFileName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_FLAG_WRITE_THROUGH, NULL);
- if (file != INVALID_HANDLE_VALUE)
- {
- for(i = 0; i < (FileSize.QuadPart - BufferSize); i +=
BufferSize)
- {
- WriteFile (file, buffer, BufferSize, &temp, NULL);
- ConOutPrintf (_T("%I64d%% %s\r"),(i *
(LONGLONG)100)/FileSize.QuadPart,szDeleteWipe);
- }
- WriteFile (file, buffer, (DWORD)(FileSize.QuadPart - i), &temp, NULL);
- ConOutPrintf (_T("100%% %s\n"),szDeleteWipe);
- CloseHandle (file);
- }
- }
-
- return DeleteFile (lpFileName);
+ BYTE buffer[BufferSize];
+ LONGLONG i;
+ LARGE_INTEGER FileSize;
+
+ FileSize.u.HighPart = f->nFileSizeHigh;
+ FileSize.u.LowPart = f->nFileSizeLow;
+
+ for(i = 0; i < BufferSize; i++)
+ {
+ buffer[i]=rand() % 256;
+ }
+ file = CreateFile (lpFileName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_FLAG_WRITE_THROUGH, NULL);
+ if (file != INVALID_HANDLE_VALUE)
+ {
+ for(i = 0; i < (FileSize.QuadPart - BufferSize); i += BufferSize)
+ {
+ WriteFile (file, buffer, BufferSize, &temp, NULL);
+ ConOutPrintf (_T("%I64d%% %s\r"),(i *
(LONGLONG)100)/FileSize.QuadPart,szDeleteWipe);
+ }
+ WriteFile (file, buffer, (DWORD)(FileSize.QuadPart - i), &temp, NULL);
+ ConOutPrintf (_T("100%% %s\n"),szDeleteWipe);
+ CloseHandle (file);
+ }
+ }
+
+ return DeleteFile (lpFileName);
}
static DWORD
DeleteFiles(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
{
- TCHAR szFullPath[MAX_PATH];
- TCHAR szFileName[MAX_PATH];
- LPTSTR pFilePart;
- HANDLE hFile;
- WIN32_FIND_DATA f;
- BOOL bExclusion;
- INT res;
- DWORD dwFiles = 0;
-
- _tcscpy(szFileName, FileName);
-
- if(_tcschr (szFileName, _T('*')) == NULL &&
- IsExistingDirectory (szFileName))
- {
- /* If it doesnt have a \ at the end already then on needs to be added */
- if(szFileName[_tcslen(szFileName) - 1] != _T('\\'))
- _tcscat (szFileName, _T("\\"));
- /* Add a wildcard after the \ */
- _tcscat (szFileName, _T("*"));
- }
-
- if(!_tcscmp (szFileName, _T("*")) ||
- !_tcscmp (szFileName, _T("*.*")) ||
- (szFileName[_tcslen(szFileName) - 2] == _T('\\') &&
szFileName[_tcslen(szFileName) - 1] == _T('*')))
- {
- /* well, the user wants to delete everything but if they didnt yes
DEL_YES, DEL_QUIET, or DEL_PROMPT
- then we are going to want to make sure that in fact they want to do that.
*/
-
- if (!((*dwFlags & DEL_YES) || (*dwFlags & DEL_QUIET) || (*dwFlags &
DEL_PROMPT)))
- {
- res = FilePromptYNA (STRING_DEL_HELP2);
- if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
- return 0x80000000;
- if(res == PROMPT_ALL)
- *dwFlags |= DEL_YES;
- }
- }
-
- GetFullPathName (szFileName,
- MAX_PATH,
- szFullPath,
- &pFilePart);
+ TCHAR szFullPath[MAX_PATH];
+ TCHAR szFileName[MAX_PATH];
+ LPTSTR pFilePart;
+ HANDLE hFile;
+ WIN32_FIND_DATA f;
+ BOOL bExclusion;
+ INT res;
+ DWORD dwFiles = 0;
+
+ _tcscpy(szFileName, FileName);
+
+ if (_tcschr (szFileName, _T('*')) == NULL &&
+ IsExistingDirectory (szFileName))
+ {
+ /* If it doesnt have a \ at the end already then on needs to be added */
+ if (szFileName[_tcslen(szFileName) - 1] != _T('\\'))
+ _tcscat (szFileName, _T("\\"));
+ /* Add a wildcard after the \ */
+ _tcscat (szFileName, _T("*"));
+ }
+
+ if (!_tcscmp (szFileName, _T("*")) ||
+ !_tcscmp (szFileName, _T("*.*")) ||
+ (szFileName[_tcslen(szFileName) - 2] == _T('\\') &&
szFileName[_tcslen(szFileName) - 1] == _T('*')))
+ {
+ /* well, the user wants to delete everything but if they didnt yes DEL_YES,
DEL_QUIET, or DEL_PROMPT
+ then we are going to want to make sure that in fact they want to do that. */
+
+ if (!((*dwFlags & DEL_YES) || (*dwFlags & DEL_QUIET) || (*dwFlags &
DEL_PROMPT)))
+ {
+ res = FilePromptYNA (STRING_DEL_HELP2);
+ if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
+ return 0x80000000;
+ if (res == PROMPT_ALL)
+ *dwFlags |= DEL_YES;
+ }
+ }
+
+ GetFullPathName(szFileName,
+ MAX_PATH,
+ szFullPath,
+ &pFilePart);
+
+ hFile = FindFirstFile(szFullPath, &f);
+ if (hFile != INVALID_HANDLE_VALUE)
+ {
+ do
+ {
+ bExclusion = FALSE;
+
+ /*if it is going to be excluded by - no need to check attrs*/
+ if (*dwFlags & DEL_ATTRIBUTES && !bExclusion)
+ {
+ /*save if file attr check if user doesnt care about that attr anyways*/
+ if (dwAttrFlags & ATTR_ARCHIVE && !(f.dwFileAttributes &
FILE_ATTRIBUTE_ARCHIVE))
+ bExclusion = TRUE;
+ if (dwAttrFlags & ATTR_HIDDEN && !(f.dwFileAttributes &
FILE_ATTRIBUTE_HIDDEN))
+ bExclusion = TRUE;
+ if (dwAttrFlags & ATTR_SYSTEM && !(f.dwFileAttributes &
FILE_ATTRIBUTE_SYSTEM))
+ bExclusion = TRUE;
+ if (dwAttrFlags & ATTR_READ_ONLY && !(f.dwFileAttributes
& FILE_ATTRIBUTE_READONLY))
+ bExclusion = TRUE;
+ if (dwAttrFlags & ATTR_N_ARCHIVE && (f.dwFileAttributes &
FILE_ATTRIBUTE_ARCHIVE))
+ bExclusion = TRUE;
+ if (dwAttrFlags & ATTR_N_HIDDEN && (f.dwFileAttributes &
FILE_ATTRIBUTE_HIDDEN))
+ bExclusion = TRUE;
+ if (dwAttrFlags & ATTR_N_SYSTEM && (f.dwFileAttributes &
FILE_ATTRIBUTE_SYSTEM))
+ bExclusion = TRUE;
+ if (dwAttrFlags & ATTR_N_READ_ONLY && (f.dwFileAttributes
& FILE_ATTRIBUTE_READONLY))
+ bExclusion = TRUE;
+ }
+ if (bExclusion) continue;
+
+ /* ignore directories */
+ if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
+
+ _tcscpy (pFilePart, f.cFileName);
+
+ /* We cant delete ourselves */
+ if (!_tcscmp (CMDPath,szFullPath)) continue;
+
+ TRACE("Full filename: %s\n", debugstr_aw(szFullPath));
+
+ /* ask for deleting */
+ if (*dwFlags & DEL_PROMPT)
+ {
+ ConErrResPrintf(STRING_DEL_ERROR5, szFullPath);
+
+ res = FilePromptYN (STRING_DEL_ERROR6);
+
+ if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
+ {
+ nErrorLevel = 0;
+ continue;
+ }
+ }
+
+ /*user cant ask it to be quiet and tell you what it did*/
+ if (!(*dwFlags & DEL_QUIET) && !(*dwFlags & DEL_TOTAL))
+ {
+ ConErrResPrintf(STRING_DEL_ERROR7, szFullPath);
+ }
+
+ /* delete the file */
+ if (*dwFlags & DEL_NOTHING) continue;
+
+ if (RemoveFile (szFullPath, *dwFlags, &f))
+ {
+ dwFiles++;
+ }
+ else
+ {
+ ErrorMessage (GetLastError(), _T(""));
+// FindClose(hFile);
+// return -1;
+ }
+ }
+ while (FindNextFile (hFile, &f));
+ FindClose (hFile);
+ }
+ else error_sfile_not_found(szFullPath);
+ return dwFiles;
+}
+
+static DWORD
+ProcessDirectory(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
+{
+ TCHAR szFullPath[MAX_PATH];
+ LPTSTR pFilePart;
+ LPTSTR pSearchPart;
+ HANDLE hFile;
+ WIN32_FIND_DATA f;
+ DWORD dwFiles = 0;
+
+ GetFullPathName(FileName,
+ MAX_PATH,
+ szFullPath,
+ &pFilePart);
+
+ dwFiles = DeleteFiles(szFullPath, dwFlags, dwAttrFlags);
+ if (dwFiles & 0x80000000) return dwFiles;
+
+ if (*dwFlags & DEL_SUBDIR)
+ {
+ /* Get just the file name */
+ pSearchPart = _tcsrchr(FileName,_T('\\'));
+ if (pSearchPart != NULL)
+ pSearchPart++;
+ else
+ pSearchPart = FileName;
+
+ /* Get the full path to the file */
+ GetFullPathName (FileName,MAX_PATH,szFullPath,NULL);
+
+ /* strip the filename off of it */
+ pFilePart = _tcsrchr(szFullPath, _T('\\'));
+ if (pFilePart == NULL)
+ {
+ pFilePart = szFullPath;
+ }
+ else
+ {
+ pFilePart++;
+ }
+
+ _tcscpy(pFilePart, _T("*"));
hFile = FindFirstFile(szFullPath, &f);
if (hFile != INVALID_HANDLE_VALUE)
{
- do
- {
- bExclusion = FALSE;
-
- /*if it is going to be excluded by - no need to check attrs*/
- if(*dwFlags & DEL_ATTRIBUTES && !bExclusion)
- {
-
- /*save if file attr check if user doesnt care about that attr anyways*/
- if(dwAttrFlags & ATTR_ARCHIVE && !(f.dwFileAttributes &
FILE_ATTRIBUTE_ARCHIVE))
- bExclusion = TRUE;
- if(dwAttrFlags & ATTR_HIDDEN && !(f.dwFileAttributes &
FILE_ATTRIBUTE_HIDDEN))
- bExclusion = TRUE;
- if(dwAttrFlags & ATTR_SYSTEM && !(f.dwFileAttributes &
FILE_ATTRIBUTE_SYSTEM))
- bExclusion = TRUE;
- if(dwAttrFlags & ATTR_READ_ONLY && !(f.dwFileAttributes &
FILE_ATTRIBUTE_READONLY))
- bExclusion = TRUE;
- if(dwAttrFlags & ATTR_N_ARCHIVE && (f.dwFileAttributes &
FILE_ATTRIBUTE_ARCHIVE))
- bExclusion = TRUE;
- if(dwAttrFlags & ATTR_N_HIDDEN && (f.dwFileAttributes &
FILE_ATTRIBUTE_HIDDEN))
- bExclusion = TRUE;
- if(dwAttrFlags & ATTR_N_SYSTEM && (f.dwFileAttributes &
FILE_ATTRIBUTE_SYSTEM))
- bExclusion = TRUE;
- if(dwAttrFlags & ATTR_N_READ_ONLY && (f.dwFileAttributes &
FILE_ATTRIBUTE_READONLY))
- bExclusion = TRUE;
- }
- if(bExclusion)
- continue;
-
- /* ignore directories */
- if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- continue;
-
-
- _tcscpy (pFilePart, f.cFileName);
-
- /* We cant delete ourselves */
- if(!_tcscmp (CMDPath,szFullPath))
- continue;
-
-
- TRACE("Full filename: %s\n", debugstr_aw(szFullPath));
-
- /* ask for deleting */
- if (*dwFlags & DEL_PROMPT)
- {
- ConErrResPrintf(STRING_DEL_ERROR5, szFullPath);
-
- res = FilePromptYN (STRING_DEL_ERROR6);
-
- if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
- {
- nErrorLevel = 0;
- continue;
- }
- }
-
- /*user cant ask it to be quiet and tell you what it did*/
- if (!(*dwFlags & DEL_QUIET) && !(*dwFlags & DEL_TOTAL))
- {
- ConErrResPrintf(STRING_DEL_ERROR7, szFullPath);
- }
-
- /* delete the file */
- if(*dwFlags & DEL_NOTHING)
- continue;
-
- if(RemoveFile (szFullPath, *dwFlags, &f))
- dwFiles++;
- else
+ do
+ {
+ if (!(f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
+ !_tcscmp(f.cFileName, _T(".")) ||
+ !_tcscmp(f.cFileName, _T("..")))
+ continue;
+
+ _tcscpy(pFilePart, f.cFileName);
+ _tcscat(pFilePart, _T("\\"));
+ _tcscat(pFilePart, pSearchPart);
+
+ dwFiles +=ProcessDirectory(szFullPath, dwFlags, dwAttrFlags);
+ if (dwFiles & 0x80000000)
+ {
+ break;
+ }
+ }
+ while (FindNextFile (hFile, &f));
+ FindClose (hFile);
+ }
+ }
+ return dwFiles;
+}
+
+
+
+INT CommandDelete (LPTSTR param)
+{
+ /*cmd is the command that was given, in this case it will always be "del"
or "delete"
+ param is whatever is given after the command*/
+
+ LPTSTR *arg = NULL;
+ INT args;
+ INT i;
+ INT nEvalArgs = 0; /* nunber of evaluated arguments */
+ DWORD dwFlags = 0;
+ DWORD dwAttrFlags = 0;
+ DWORD dwFiles = 0;
+ LONG ch;
+ TCHAR szOrginalArg[MAX_PATH];
+
+ /*checks the first two chars of param to see if it is /?
+ this however allows the following command to not show help
+ "del frog.txt /?" */
+
+ if (!StringsLoaded)
+ {
+ LoadStrings();
+ }
+
+ if (!_tcsncmp (param, _T("/?"), 2))
+ {
+ ConOutResPaging(TRUE,STRING_DEL_HELP1);
+ return 0;
+ }
+
+ nErrorLevel = 0;
+
+ arg = split (param, &args, FALSE, FALSE);
+
+ if (args == 0)
+ {
+ /* only command given */
+ error_req_param_missing ();
+ freep (arg);
+ return 1;
+ }
+ /* check for options anywhere in command line */
+ for (i = 0; i < args; i++)
+ {
+ if (*arg[i] == _T('/'))
+ {
+ /*found a command, but check to make sure it has something after it*/
+ if (_tcslen (arg[i]) >= 2)
+ {
+ ch = _totupper (arg[i][1]);
+ if (ch == _T('N'))
+ {
+ dwFlags |= DEL_NOTHING;
+ }
+ else if (ch == _T('P'))
+ {
+ dwFlags |= DEL_PROMPT;
+ }
+ else if (ch == _T('Q'))
+ {
+ dwFlags |= DEL_QUIET;
+ }
+ else if (ch == _T('F'))
+ {
+ dwFlags |= DEL_FORCE;
+ }
+ else if (ch == _T('S'))
+ {
+ dwFlags |= DEL_SUBDIR;
+ }
+ else if (ch == _T('T'))
+ {
+ dwFlags |= DEL_TOTAL;
+ }
+ else if (ch == _T('W'))
+ {
+ dwFlags |= DEL_WIPE;
+ }
+ else if (ch == _T('Y'))
+ {
+ dwFlags |= DEL_YES;
+ }
+ else if (ch == _T('A'))
+ {
+ dwFlags |= DEL_ATTRIBUTES;
+ /*the proper syntax for /A has a min of 4 chars
+ i.e. /A:R or /A:-H */
+ if (_tcslen (arg[i]) < 4)
+ {
+ error_invalid_parameter_format(arg[i]);
+ return 0;
+ }
+ ch = _totupper (arg[i][3]);
+ if (_tcslen (arg[i]) == 4)
+ {
+ if (ch == _T('A'))
{
- ErrorMessage (GetLastError(), _T(""));
-// FindClose(hFile);
-// return -1;
- }
- }
- while (FindNextFile (hFile, &f));
- FindClose (hFile);
- }
- else error_sfile_not_found(szFullPath);
- return dwFiles;
+ dwAttrFlags |= ATTR_ARCHIVE;
+ }
+ if (ch == _T('H'))
+ {
+ dwAttrFlags |= ATTR_HIDDEN;
+ }
+ if (ch == _T('S'))
+ {
+ dwAttrFlags |= ATTR_SYSTEM;
+ }
+ if (ch == _T('R'))
+ {
+ dwAttrFlags |= ATTR_READ_ONLY;
+ }
+ }
+ if (_tcslen (arg[i]) == 5)
+ {
+ if (ch == _T('-'))
+ {
+ ch = _totupper (arg[i][4]);
+ if (ch == _T('A'))
+ {
+ dwAttrFlags |= ATTR_N_ARCHIVE;
+ }
+ if (ch == _T('H'))
+ {
+ dwAttrFlags |= ATTR_N_HIDDEN;
+ }
+ if (ch == _T('S'))
+ {
+ dwAttrFlags |= ATTR_N_SYSTEM;
+ }
+ if (ch == _T('R'))
+ {
+ dwAttrFlags |= ATTR_N_READ_ONLY;
+ }
+ }
+ }
+ }
+ }
+
+ nEvalArgs++;
+ }
+ }
+
+ /* there are only options on the command line --> error!!!
+ there is the same number of args as there is flags, so none of the args were
filenames*/
+ if (args == nEvalArgs)
+ {
+ error_req_param_missing ();
+ freep (arg);
+ return 1;
+ }
+
+ /* keep quiet within batch files */
+ if (bc != NULL) dwFlags |= DEL_QUIET;
+
+ /* check for filenames anywhere in command line */
+ for (i = 0; i < args && !(dwFiles & 0x80000000); i++)
+ {
+ /*this checks to see if it is a flag; if it isn't, we assume it is a file
name*/
+ if ((*arg[i] == _T('/')) || (*arg[i] == _T('-')))
+ continue;
+
+ /* We want to make a copies of the argument */
+ if (_tcslen(arg[i]) == 2 && arg[i][1] == _T(':'))
+ {
+ /* Check for C: D: ... */
+ GetRootPath(arg[i], szOrginalArg, MAX_PATH);
+ }
+ else
+ {
+ _tcscpy(szOrginalArg,arg[i]);
+ }
+ dwFiles += ProcessDirectory(szOrginalArg, &dwFlags, dwAttrFlags);
+ }
+
+ freep (arg);
+
+ /*Based on MS cmd, we only tell what files are being deleted when /S is used */
+ if (dwFlags & DEL_TOTAL)
+ {
+ dwFiles &= 0x7fffffff;
+ if (dwFiles < 2)
+ {
+ ConOutResPrintf(STRING_DEL_HELP3, dwFiles);
+ }
+ else
+ {
+ ConOutResPrintf(STRING_DEL_HELP4, dwFiles);
+ }
+ }
+
+ return 0;
}
-static DWORD
-ProcessDirectory(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
-{
- TCHAR szFullPath[MAX_PATH];
- LPTSTR pFilePart;
- LPTSTR pSearchPart;
- HANDLE hFile;
- WIN32_FIND_DATA f;
- DWORD dwFiles = 0;
-
- GetFullPathName (FileName,
- MAX_PATH,
- szFullPath,
- &pFilePart);
-
- dwFiles = DeleteFiles(szFullPath, dwFlags, dwAttrFlags);
- if (dwFiles & 0x80000000)
- return dwFiles;
-
- if (*dwFlags & DEL_SUBDIR)
- {
- /* Get just the file name */
- pSearchPart = _tcsrchr(FileName,_T('\\'));
- if(pSearchPart != NULL)
- pSearchPart++;
- else
- pSearchPart = FileName;
-
- /* Get the full path to the file */
- GetFullPathName (FileName,MAX_PATH,szFullPath,NULL);
-
- /* strip the filename off of it */
- pFilePart = _tcsrchr(szFullPath, _T('\\'));
- if (pFilePart == NULL)
- {
- pFilePart = szFullPath;
- }
- else
- {
- pFilePart++;
- }
-
- _tcscpy(pFilePart, _T("*"));
-
- hFile = FindFirstFile(szFullPath, &f);
- if (hFile != INVALID_HANDLE_VALUE)
- {
- do
- {
- if (!(f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
- !_tcscmp(f.cFileName, _T(".")) ||
- !_tcscmp(f.cFileName, _T("..")))
- continue;
-
- _tcscpy(pFilePart, f.cFileName);
- _tcscat(pFilePart, _T("\\"));
- _tcscat(pFilePart, pSearchPart);
-
- dwFiles +=ProcessDirectory(szFullPath, dwFlags,
dwAttrFlags);
- if (dwFiles & 0x80000000)
- {
- break;
- }
- }
- while (FindNextFile (hFile, &f));
- FindClose (hFile);
- }
- }
- return dwFiles;
-}
-
-
-
-INT CommandDelete (LPTSTR param)
-{
- /*cmd is the command that was given, in this case it will always be "del" or
"delete"
- param is whatever is given after the command*/
-
- LPTSTR *arg = NULL;
- INT args;
- INT i;
- INT nEvalArgs = 0; /* nunber of evaluated arguments */
- DWORD dwFlags = 0;
- DWORD dwAttrFlags = 0;
- DWORD dwFiles = 0;
- LONG ch;
- TCHAR szOrginalArg[MAX_PATH];
-
- /*checks the first two chars of param to see if it is /?
- this however allows the following command to not show help
- "del frog.txt /?" */
-
- if (!StringsLoaded)
- {
- LoadStrings();
- }
-
- if (!_tcsncmp (param, _T("/?"), 2))
- {
- ConOutResPaging(TRUE,STRING_DEL_HELP1);
- return 0;
- }
-
- nErrorLevel = 0;
-
- arg = split (param, &args, FALSE, FALSE);
-
- if (args == 0)
- {
- /* only command given */
- error_req_param_missing ();
- freep (arg);
- return 1;
- }
- /* check for options anywhere in command line */
- for (i = 0; i < args; i++)
- {
- if (*arg[i] == _T('/'))
- {
- /*found a command, but check to make sure it has something after it*/
- if (_tcslen (arg[i]) >= 2)
- {
- ch = _totupper (arg[i][1]);
- if (ch == _T('N'))
- {
- dwFlags |= DEL_NOTHING;
- }
- else if (ch == _T('P'))
- {
- dwFlags |= DEL_PROMPT;
- }
- else if (ch == _T('Q'))
- {
- dwFlags |= DEL_QUIET;
- }
- else if (ch == _T('F'))
- {
- dwFlags |= DEL_FORCE;
- }
- else if (ch == _T('S'))
- {
- dwFlags |= DEL_SUBDIR;
- }
- else if (ch == _T('T'))
- {
- dwFlags |= DEL_TOTAL;
- }
- else if (ch == _T('W'))
- {
- dwFlags |= DEL_WIPE;
- }
- else if (ch == _T('Y'))
- {
- dwFlags |= DEL_YES;
- }
- else if (ch == _T('A'))
- {
-
- dwFlags |= DEL_ATTRIBUTES;
- /*the proper syntax for /A has a min of 4 chars
- i.e. /A:R or /A:-H */
- if (_tcslen (arg[i]) < 4)
- {
- error_invalid_parameter_format(arg[i]);
- return 0;
- }
- ch = _totupper (arg[i][3]);
- if (_tcslen (arg[i]) == 4)
- {
- if(ch == _T('A'))
- {
- dwAttrFlags |= ATTR_ARCHIVE;
- }
- if(ch == _T('H'))
- {
- dwAttrFlags |= ATTR_HIDDEN;
- }
- if(ch == _T('S'))
- {
- dwAttrFlags |= ATTR_SYSTEM;
- }
- if(ch == _T('R'))
- {
- dwAttrFlags |= ATTR_READ_ONLY;
- }
- }
- if (_tcslen (arg[i]) == 5)
- {
- if(ch == _T('-'))
- {
- ch = _totupper (arg[i][4]);
- if(ch == _T('A'))
- {
- dwAttrFlags |= ATTR_N_ARCHIVE;
- }
- if(ch == _T('H'))
- {
- dwAttrFlags |= ATTR_N_HIDDEN;
- }
- if(ch == _T('S'))
- {
- dwAttrFlags |= ATTR_N_SYSTEM;
- }
- if(ch == _T('R'))
- {
- dwAttrFlags |= ATTR_N_READ_ONLY;
- }
- }
- }
- }
- }
-
- nEvalArgs++;
- }
- }
-
- /* there are only options on the command line --> error!!!
- there is the same number of args as there is flags, so none of the args were
filenames*/
- if (args == nEvalArgs)
- {
- error_req_param_missing ();
- freep (arg);
- return 1;
- }
-
- /* keep quiet within batch files */
- if (bc != NULL)
- dwFlags |= DEL_QUIET;
-
- /* check for filenames anywhere in command line */
- for (i = 0; i < args && !(dwFiles & 0x80000000); i++)
- {
-
- /*this checks to see if it is a flag; if it isn't, we assume it is a file
name*/
- if((*arg[i] == _T('/')) || (*arg[i] == _T('-')))
- continue;
-
- /* We want to make a copies of the argument */
- if(_tcslen(arg[i]) == 2 && arg[i][1] == _T(':'))
- {
- /* Check for C: D: ... */
- GetRootPath(arg[i],szOrginalArg,MAX_PATH);
- }
- else
- {
- _tcscpy(szOrginalArg,arg[i]);
- }
- dwFiles += ProcessDirectory(szOrginalArg, &dwFlags, dwAttrFlags);
-
- }
-
- freep (arg);
-
- /*Based on MS cmd, we only tell what files are being deleted when /S is used */
- if (dwFlags & DEL_TOTAL)
- {
- dwFiles &= 0x7fffffff;
- if (dwFiles < 2)
- {
- ConOutResPrintf(STRING_DEL_HELP3, dwFiles);
- }
- else
- {
- ConOutResPrintf(STRING_DEL_HELP4, dwFiles);
- }
- }
-
- return 0;
-}
-
#endif