mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 06:02:56 +00:00
- Implement CMD /A and /U switches.
- CLS: Fill console with current color rather than original; if standard output is not a console, print a form-feed character. - COLOR: If standard output is not a console, do nothing. svn path=/trunk/; revision=40272
This commit is contained in:
parent
23cb0510c4
commit
4e02761261
4 changed files with 62 additions and 82 deletions
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
INT cmd_cls (LPTSTR param)
|
INT cmd_cls (LPTSTR param)
|
||||||
{
|
{
|
||||||
|
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
DWORD dwWritten;
|
DWORD dwWritten;
|
||||||
|
@ -42,17 +43,22 @@ INT cmd_cls (LPTSTR param)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
if (GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||||
|
{
|
||||||
coPos.X = 0;
|
coPos.X = 0;
|
||||||
coPos.Y = 0;
|
coPos.Y = 0;
|
||||||
FillConsoleOutputAttribute(hConsole, wColor,
|
FillConsoleOutputAttribute(hOutput, csbi.wAttributes,
|
||||||
csbi.dwSize.X * csbi.dwSize.Y,
|
csbi.dwSize.X * csbi.dwSize.Y,
|
||||||
coPos, &dwWritten);
|
coPos, &dwWritten);
|
||||||
FillConsoleOutputCharacter(hConsole, _T(' '),
|
FillConsoleOutputCharacter(hOutput, _T(' '),
|
||||||
csbi.dwSize.X * csbi.dwSize.Y,
|
csbi.dwSize.X * csbi.dwSize.Y,
|
||||||
coPos, &dwWritten);
|
coPos, &dwWritten);
|
||||||
SetConsoleCursorPosition(hConsole, coPos);
|
SetConsoleCursorPosition(hOutput, coPos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ConOutChar(_T('\f'));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,7 @@ BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
|
||||||
BOOL bIgnoreEcho = FALSE; /* Set this to TRUE to prevent a newline, when executing a command */
|
BOOL bIgnoreEcho = FALSE; /* Set this to TRUE to prevent a newline, when executing a command */
|
||||||
INT nErrorLevel = 0; /* Errorlevel of last launched external program */
|
INT nErrorLevel = 0; /* Errorlevel of last launched external program */
|
||||||
BOOL bChildProcessRunning = FALSE;
|
BOOL bChildProcessRunning = FALSE;
|
||||||
|
BOOL bUnicodeOutput = FALSE;
|
||||||
BOOL bDisableBatchEcho = FALSE;
|
BOOL bDisableBatchEcho = FALSE;
|
||||||
BOOL bDelayedExpansion = FALSE;
|
BOOL bDelayedExpansion = FALSE;
|
||||||
DWORD dwChildProcessId = 0;
|
DWORD dwChildProcessId = 0;
|
||||||
|
@ -171,7 +172,6 @@ static NtQueryInformationProcessProc NtQueryInformationProcessPtr = NULL;
|
||||||
static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr = NULL;
|
static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr = NULL;
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_COLOR
|
#ifdef INCLUDE_CMD_COLOR
|
||||||
WORD wColor; /* current color */
|
|
||||||
WORD wDefColor; /* default color */
|
WORD wDefColor; /* default color */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1818,6 +1818,10 @@ Initialize()
|
||||||
}
|
}
|
||||||
bCanExit = FALSE;
|
bCanExit = FALSE;
|
||||||
}
|
}
|
||||||
|
else if (option == _T('A'))
|
||||||
|
{
|
||||||
|
bUnicodeOutput = FALSE;
|
||||||
|
}
|
||||||
else if (option == _T('C') || option == _T('K') || option == _T('R'))
|
else if (option == _T('C') || option == _T('K') || option == _T('R'))
|
||||||
{
|
{
|
||||||
/* Remainder of command line is a command to be run */
|
/* Remainder of command line is a command to be run */
|
||||||
|
@ -1840,10 +1844,13 @@ Initialize()
|
||||||
{
|
{
|
||||||
/* process /t (color) argument */
|
/* process /t (color) argument */
|
||||||
wDefColor = (WORD)_tcstoul(&ptr[3], &ptr, 16);
|
wDefColor = (WORD)_tcstoul(&ptr[3], &ptr, 16);
|
||||||
wColor = wDefColor;
|
SetScreenColor(wDefColor, TRUE);
|
||||||
SetScreenColor (wColor, TRUE);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
else if (option == _T('U'))
|
||||||
|
{
|
||||||
|
bUnicodeOutput = TRUE;
|
||||||
|
}
|
||||||
else if (option == _T('V'))
|
else if (option == _T('V'))
|
||||||
{
|
{
|
||||||
bDelayedExpansion = _tcsnicmp(&ptr[2], _T(":OFF"), 4);
|
bDelayedExpansion = _tcsnicmp(&ptr[2], _T(":OFF"), 4);
|
||||||
|
@ -1956,8 +1963,7 @@ int cmd_main (int argc, const TCHAR *argv[])
|
||||||
ConErrFormatMessage(GetLastError());
|
ConErrFormatMessage(GetLastError());
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
wColor = Info.wAttributes;
|
wDefColor = Info.wAttributes;
|
||||||
wDefColor = wColor;
|
|
||||||
|
|
||||||
InputCodePage= GetConsoleCP();
|
InputCodePage= GetConsoleCP();
|
||||||
OutputCodePage = GetConsoleOutputCP();
|
OutputCodePage = GetConsoleOutputCP();
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
VOID SetScreenColor (WORD wColor, BOOL bNoFill)
|
VOID SetScreenColor (WORD wColor, BOOL bNoFill)
|
||||||
{
|
{
|
||||||
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
DWORD dwWritten;
|
DWORD dwWritten;
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
|
@ -65,6 +66,8 @@ VOID SetScreenColor (WORD wColor, BOOL bNoFill)
|
||||||
*/
|
*/
|
||||||
INT CommandColor (LPTSTR rest)
|
INT CommandColor (LPTSTR rest)
|
||||||
{
|
{
|
||||||
|
WORD wColor;
|
||||||
|
|
||||||
if (_tcsncmp (rest, _T("/?"), 2) == 0)
|
if (_tcsncmp (rest, _T("/?"), 2) == 0)
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_COLOR_HELP1);
|
ConOutResPaging(TRUE,STRING_COLOR_HELP1);
|
||||||
|
@ -84,6 +87,7 @@ INT CommandColor (LPTSTR rest)
|
||||||
|
|
||||||
if ( _tcslen(&rest[0])==1)
|
if ( _tcslen(&rest[0])==1)
|
||||||
{
|
{
|
||||||
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
if ( (_tcscmp(&rest[0], _T("0")) >=0 ) && (_tcscmp(&rest[0], _T("9")) <=0 ) )
|
if ( (_tcscmp(&rest[0], _T("0")) >=0 ) && (_tcscmp(&rest[0], _T("9")) <=0 ) )
|
||||||
{
|
{
|
||||||
SetConsoleTextAttribute (hConsole, (WORD)_ttoi(rest));
|
SetConsoleTextAttribute (hConsole, (WORD)_ttoi(rest));
|
||||||
|
|
|
@ -128,61 +128,45 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength)
|
||||||
SetConsoleMode (hFile, dwOldMode);
|
SetConsoleMode (hFile, dwOldMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID ConChar(TCHAR c, DWORD nStdHandle)
|
static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
|
||||||
{
|
{
|
||||||
DWORD dwWritten;
|
DWORD dwWritten;
|
||||||
CHAR cc;
|
HANDLE hOutput = GetStdHandle(nStdHandle);
|
||||||
#ifdef _UNICODE
|
|
||||||
CHAR as[2];
|
if (WriteConsole(hOutput, str, len, &dwWritten, NULL))
|
||||||
WCHAR ws[2];
|
return;
|
||||||
ws[0] = c;
|
|
||||||
ws[1] = 0;
|
/* We're writing to a file or pipe instead of the console. Convert the
|
||||||
WideCharToMultiByte( OutputCodePage, 0, ws, 2, as, 2, NULL, NULL);
|
* string from TCHARs to the desired output format, if the two differ */
|
||||||
cc = as[0];
|
if (bUnicodeOutput)
|
||||||
#else
|
{
|
||||||
cc = c;
|
#ifndef _UNICODE
|
||||||
|
WCHAR buffer[len];
|
||||||
|
len = MultiByteToWideChar(OutputCodePage, 0, str, len, buffer, len, NULL, NULL);
|
||||||
|
str = (PVOID)buffer;
|
||||||
#endif
|
#endif
|
||||||
WriteFile (GetStdHandle (nStdHandle),
|
WriteFile(hOutput, str, len * sizeof(WCHAR), &dwWritten, NULL);
|
||||||
&cc,
|
}
|
||||||
1,
|
else
|
||||||
&dwWritten,
|
{
|
||||||
NULL);
|
#ifdef _UNICODE
|
||||||
|
CHAR buffer[len * MB_LEN_MAX];
|
||||||
|
len = WideCharToMultiByte(OutputCodePage, 0, str, len, buffer, len * MB_LEN_MAX, NULL, NULL);
|
||||||
|
str = (PVOID)buffer;
|
||||||
|
#endif
|
||||||
|
WriteFile(hOutput, str, len, &dwWritten, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID ConOutChar (TCHAR c)
|
VOID ConOutChar (TCHAR c)
|
||||||
{
|
{
|
||||||
ConChar(c, STD_OUTPUT_HANDLE);
|
ConWrite(&c, 1, STD_OUTPUT_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
|
VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
|
||||||
{
|
{
|
||||||
DWORD dwWritten;
|
ConWrite(szText, _tcslen(szText), nStdHandle);
|
||||||
HANDLE hStdHandle;
|
ConWrite(_T("\n"), 1, nStdHandle);
|
||||||
PCHAR pBuf;
|
|
||||||
INT len;
|
|
||||||
|
|
||||||
len = _tcslen(szText);
|
|
||||||
#ifdef _UNICODE
|
|
||||||
pBuf = cmd_alloc(len * 2 + 1);
|
|
||||||
len = WideCharToMultiByte(OutputCodePage, 0, szText, len + 1, pBuf, len * 2 + 1, NULL, NULL) - 1;
|
|
||||||
#else
|
|
||||||
pBuf = szText;
|
|
||||||
#endif
|
|
||||||
hStdHandle = GetStdHandle(nStdHandle);
|
|
||||||
|
|
||||||
WriteFile (hStdHandle,
|
|
||||||
pBuf,
|
|
||||||
len,
|
|
||||||
&dwWritten,
|
|
||||||
NULL);
|
|
||||||
WriteFile (hStdHandle,
|
|
||||||
_T("\n"),
|
|
||||||
1,
|
|
||||||
&dwWritten,
|
|
||||||
NULL);
|
|
||||||
#ifdef _UNICODE
|
|
||||||
cmd_free(pBuf);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID ConOutResPaging(BOOL NewPage, UINT resID)
|
VOID ConOutResPaging(BOOL NewPage, UINT resID)
|
||||||
|
@ -208,28 +192,8 @@ VOID ConOutPuts (LPTSTR szText)
|
||||||
|
|
||||||
VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
||||||
{
|
{
|
||||||
INT len;
|
|
||||||
PCHAR pBuf;
|
|
||||||
TCHAR szOut[OUTPUT_BUFFER_SIZE];
|
TCHAR szOut[OUTPUT_BUFFER_SIZE];
|
||||||
DWORD dwWritten;
|
ConWrite(szOut, _vstprintf(szOut, szFormat, arg_ptr), nStdHandle);
|
||||||
|
|
||||||
len = _vstprintf(szOut, szFormat, arg_ptr);
|
|
||||||
#ifdef _UNICODE
|
|
||||||
pBuf = cmd_alloc(len * 2 + 1);
|
|
||||||
len = WideCharToMultiByte(OutputCodePage, 0, szOut, len + 1, pBuf, len * 2 + 1, NULL, NULL) - 1;
|
|
||||||
#else
|
|
||||||
pBuf = szOut;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
WriteFile (GetStdHandle (nStdHandle),
|
|
||||||
pBuf,
|
|
||||||
len,
|
|
||||||
&dwWritten,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
#ifdef _UNICODE
|
|
||||||
cmd_free(pBuf);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
||||||
|
@ -398,7 +362,7 @@ INT ConOutPrintfPaging (BOOL NewPage, LPTSTR szFormat, ...)
|
||||||
|
|
||||||
VOID ConErrChar (TCHAR c)
|
VOID ConErrChar (TCHAR c)
|
||||||
{
|
{
|
||||||
ConChar(c, STD_ERROR_HANDLE);
|
ConWrite(&c, 1, STD_ERROR_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue