mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 17:22:59 +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)
|
||||
{
|
||||
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
COORD coPos;
|
||||
DWORD dwWritten;
|
||||
|
@ -42,17 +43,22 @@ INT cmd_cls (LPTSTR param)
|
|||
return 0;
|
||||
}
|
||||
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
|
||||
if (GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||
{
|
||||
coPos.X = 0;
|
||||
coPos.Y = 0;
|
||||
FillConsoleOutputAttribute(hConsole, wColor,
|
||||
FillConsoleOutputAttribute(hOutput, csbi.wAttributes,
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos, &dwWritten);
|
||||
FillConsoleOutputCharacter(hConsole, _T(' '),
|
||||
FillConsoleOutputCharacter(hOutput, _T(' '),
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos, &dwWritten);
|
||||
SetConsoleCursorPosition(hConsole, coPos);
|
||||
SetConsoleCursorPosition(hOutput, coPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConOutChar(_T('\f'));
|
||||
}
|
||||
|
||||
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 */
|
||||
INT nErrorLevel = 0; /* Errorlevel of last launched external program */
|
||||
BOOL bChildProcessRunning = FALSE;
|
||||
BOOL bUnicodeOutput = FALSE;
|
||||
BOOL bDisableBatchEcho = FALSE;
|
||||
BOOL bDelayedExpansion = FALSE;
|
||||
DWORD dwChildProcessId = 0;
|
||||
|
@ -171,7 +172,6 @@ static NtQueryInformationProcessProc NtQueryInformationProcessPtr = NULL;
|
|||
static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr = NULL;
|
||||
|
||||
#ifdef INCLUDE_CMD_COLOR
|
||||
WORD wColor; /* current color */
|
||||
WORD wDefColor; /* default color */
|
||||
#endif
|
||||
|
||||
|
@ -1818,6 +1818,10 @@ Initialize()
|
|||
}
|
||||
bCanExit = FALSE;
|
||||
}
|
||||
else if (option == _T('A'))
|
||||
{
|
||||
bUnicodeOutput = FALSE;
|
||||
}
|
||||
else if (option == _T('C') || option == _T('K') || option == _T('R'))
|
||||
{
|
||||
/* Remainder of command line is a command to be run */
|
||||
|
@ -1840,10 +1844,13 @@ Initialize()
|
|||
{
|
||||
/* process /t (color) argument */
|
||||
wDefColor = (WORD)_tcstoul(&ptr[3], &ptr, 16);
|
||||
wColor = wDefColor;
|
||||
SetScreenColor (wColor, TRUE);
|
||||
SetScreenColor(wDefColor, TRUE);
|
||||
}
|
||||
#endif
|
||||
else if (option == _T('U'))
|
||||
{
|
||||
bUnicodeOutput = TRUE;
|
||||
}
|
||||
else if (option == _T('V'))
|
||||
{
|
||||
bDelayedExpansion = _tcsnicmp(&ptr[2], _T(":OFF"), 4);
|
||||
|
@ -1956,8 +1963,7 @@ int cmd_main (int argc, const TCHAR *argv[])
|
|||
ConErrFormatMessage(GetLastError());
|
||||
return(1);
|
||||
}
|
||||
wColor = Info.wAttributes;
|
||||
wDefColor = wColor;
|
||||
wDefColor = Info.wAttributes;
|
||||
|
||||
InputCodePage= GetConsoleCP();
|
||||
OutputCodePage = GetConsoleOutputCP();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
VOID SetScreenColor (WORD wColor, BOOL bNoFill)
|
||||
{
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
COORD coPos;
|
||||
|
@ -65,6 +66,8 @@ VOID SetScreenColor (WORD wColor, BOOL bNoFill)
|
|||
*/
|
||||
INT CommandColor (LPTSTR rest)
|
||||
{
|
||||
WORD wColor;
|
||||
|
||||
if (_tcsncmp (rest, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutResPaging(TRUE,STRING_COLOR_HELP1);
|
||||
|
@ -84,6 +87,7 @@ INT CommandColor (LPTSTR rest)
|
|||
|
||||
if ( _tcslen(&rest[0])==1)
|
||||
{
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if ( (_tcscmp(&rest[0], _T("0")) >=0 ) && (_tcscmp(&rest[0], _T("9")) <=0 ) )
|
||||
{
|
||||
SetConsoleTextAttribute (hConsole, (WORD)_ttoi(rest));
|
||||
|
|
|
@ -128,61 +128,45 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength)
|
|||
SetConsoleMode (hFile, dwOldMode);
|
||||
}
|
||||
|
||||
static VOID ConChar(TCHAR c, DWORD nStdHandle)
|
||||
static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
|
||||
{
|
||||
DWORD dwWritten;
|
||||
CHAR cc;
|
||||
#ifdef _UNICODE
|
||||
CHAR as[2];
|
||||
WCHAR ws[2];
|
||||
ws[0] = c;
|
||||
ws[1] = 0;
|
||||
WideCharToMultiByte( OutputCodePage, 0, ws, 2, as, 2, NULL, NULL);
|
||||
cc = as[0];
|
||||
#else
|
||||
cc = c;
|
||||
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[len];
|
||||
len = MultiByteToWideChar(OutputCodePage, 0, str, len, buffer, len, NULL, NULL);
|
||||
str = (PVOID)buffer;
|
||||
#endif
|
||||
WriteFile (GetStdHandle (nStdHandle),
|
||||
&cc,
|
||||
1,
|
||||
&dwWritten,
|
||||
NULL);
|
||||
WriteFile(hOutput, str, len * sizeof(WCHAR), &dwWritten, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
#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)
|
||||
{
|
||||
ConChar(c, STD_OUTPUT_HANDLE);
|
||||
ConWrite(&c, 1, STD_OUTPUT_HANDLE);
|
||||
}
|
||||
|
||||
VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
|
||||
{
|
||||
DWORD dwWritten;
|
||||
HANDLE hStdHandle;
|
||||
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
|
||||
ConWrite(szText, _tcslen(szText), nStdHandle);
|
||||
ConWrite(_T("\n"), 1, nStdHandle);
|
||||
}
|
||||
|
||||
VOID ConOutResPaging(BOOL NewPage, UINT resID)
|
||||
|
@ -208,28 +192,8 @@ VOID ConOutPuts (LPTSTR szText)
|
|||
|
||||
VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
||||
{
|
||||
INT len;
|
||||
PCHAR pBuf;
|
||||
TCHAR szOut[OUTPUT_BUFFER_SIZE];
|
||||
DWORD dwWritten;
|
||||
|
||||
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
|
||||
ConWrite(szOut, _vstprintf(szOut, szFormat, arg_ptr), 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)
|
||||
{
|
||||
ConChar(c, STD_ERROR_HANDLE);
|
||||
ConWrite(&c, 1, STD_ERROR_HANDLE);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue