mirror of
https://github.com/reactos/reactos.git
synced 2025-05-11 13:27:47 +00:00
[CMD]: Continue refactoring to lay out the way to using the CONUTILS library in CMD.
svn path=/trunk/; revision=76003
This commit is contained in:
parent
31530e9e62
commit
f23489fd32
3 changed files with 127 additions and 118 deletions
|
@ -50,6 +50,10 @@ BOOL IsConsoleHandle(HANDLE hHandle)
|
||||||
return GetConsoleMode(hHandle, &dwMode);
|
return GetConsoleMode(hHandle, &dwMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/********************* Console STREAM IN utility functions ********************/
|
||||||
|
|
||||||
VOID ConInDisable(VOID)
|
VOID ConInDisable(VOID)
|
||||||
{
|
{
|
||||||
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
@ -60,7 +64,6 @@ VOID ConInDisable(VOID)
|
||||||
SetConsoleMode(hInput, dwMode);
|
SetConsoleMode(hInput, dwMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID ConInEnable(VOID)
|
VOID ConInEnable(VOID)
|
||||||
{
|
{
|
||||||
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
@ -71,13 +74,11 @@ VOID ConInEnable(VOID)
|
||||||
SetConsoleMode(hInput, dwMode);
|
SetConsoleMode(hInput, dwMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID ConInFlush(VOID)
|
VOID ConInFlush(VOID)
|
||||||
{
|
{
|
||||||
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
|
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID ConInKey(PINPUT_RECORD lpBuffer)
|
VOID ConInKey(PINPUT_RECORD lpBuffer)
|
||||||
{
|
{
|
||||||
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
@ -96,7 +97,6 @@ VOID ConInKey(PINPUT_RECORD lpBuffer)
|
||||||
while (TRUE);
|
while (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID ConInString(LPTSTR lpInput, DWORD dwLength)
|
VOID ConInString(LPTSTR lpInput, DWORD dwLength)
|
||||||
{
|
{
|
||||||
DWORD dwOldMode;
|
DWORD dwOldMode;
|
||||||
|
@ -135,6 +135,10 @@ VOID ConInString(LPTSTR lpInput, DWORD dwLength)
|
||||||
SetConsoleMode(hFile, dwOldMode);
|
SetConsoleMode(hFile, dwOldMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/******************** Console STREAM OUT utility functions ********************/
|
||||||
|
|
||||||
static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
|
static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
|
||||||
{
|
{
|
||||||
DWORD dwNumBytes = 0;
|
DWORD dwNumBytes = 0;
|
||||||
|
@ -266,13 +270,6 @@ VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
|
||||||
ConWrite(szText, (DWORD)_tcslen(szText), nStdHandle);
|
ConWrite(szText, (DWORD)_tcslen(szText), nStdHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID ConOutResPaging(BOOL NewPage, UINT resID)
|
|
||||||
{
|
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
||||||
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
|
|
||||||
ConOutPrintfPaging(NewPage, szMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID ConOutResPuts(UINT resID)
|
VOID ConOutResPuts(UINT resID)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
@ -285,8 +282,7 @@ VOID ConOutPuts(LPTSTR szText)
|
||||||
ConPuts(szText, STD_OUTPUT_HANDLE);
|
ConPuts(szText, STD_OUTPUT_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID ConPrintfV(DWORD nStdHandle, LPTSTR szFormat, va_list arg_ptr)
|
||||||
VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
|
||||||
{
|
{
|
||||||
TCHAR szOut[OUTPUT_BUFFER_SIZE];
|
TCHAR szOut[OUTPUT_BUFFER_SIZE];
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
@ -295,89 +291,6 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
||||||
ConWrite(szOut, len, nStdHandle);
|
ConWrite(szOut, len, 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;
|
|
||||||
|
|
||||||
/* Reset LineCount and return if no string has been given */
|
|
||||||
if (szFormat == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Get the size of the visual screen that can be printed to */
|
|
||||||
if (!IsConsoleHandle(hOutput) || !GetConsoleScreenBufferInfo(hOutput, &csbi))
|
|
||||||
{
|
|
||||||
/* We assume it's a file handle */
|
|
||||||
ConPrintf(szFormat, arg_ptr, nStdHandle);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the number of lines currently displayed on screen, minus 1
|
|
||||||
* to account for the "press any key..." prompt from PagePrompt().
|
|
||||||
*/
|
|
||||||
ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top);
|
|
||||||
CharSL = csbi.dwCursorPosition.X;
|
|
||||||
|
|
||||||
/* Make sure the user doesn't have the screen too 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;
|
|
||||||
|
|
||||||
/* Prompt the user */
|
|
||||||
if (PagePrompt() != PROMPT_YES)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Recalculate 'ScreenLines' in case the user redimensions
|
|
||||||
// the window during the prompt.
|
|
||||||
|
|
||||||
/* Reset the number of lines being printed */
|
|
||||||
LineCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID ConErrFormatMessage(DWORD MessageId, ...)
|
VOID ConErrFormatMessage(DWORD MessageId, ...)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
@ -443,7 +356,7 @@ VOID ConOutResPrintf(UINT resID, ...)
|
||||||
|
|
||||||
va_start(arg_ptr, resID);
|
va_start(arg_ptr, resID);
|
||||||
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
|
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
|
||||||
ConPrintf(szMsg, arg_ptr, STD_OUTPUT_HANDLE);
|
ConPrintfV(STD_OUTPUT_HANDLE, szMsg, arg_ptr);
|
||||||
va_end(arg_ptr);
|
va_end(arg_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,27 +365,15 @@ VOID ConOutPrintf(LPTSTR szFormat, ...)
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
|
|
||||||
va_start(arg_ptr, szFormat);
|
va_start(arg_ptr, szFormat);
|
||||||
ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
|
ConPrintfV(STD_OUTPUT_HANDLE, szFormat, arg_ptr);
|
||||||
va_end(arg_ptr);
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID ConErrChar(TCHAR c)
|
VOID ConErrChar(TCHAR c)
|
||||||
{
|
{
|
||||||
ConWrite(&c, 1, STD_ERROR_HANDLE);
|
ConWrite(&c, 1, STD_ERROR_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID ConErrResPuts(UINT resID)
|
VOID ConErrResPuts(UINT resID)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
@ -485,7 +386,6 @@ VOID ConErrPuts(LPTSTR szText)
|
||||||
ConPuts(szText, STD_ERROR_HANDLE);
|
ConPuts(szText, STD_ERROR_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID ConErrResPrintf(UINT resID, ...)
|
VOID ConErrResPrintf(UINT resID, ...)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
@ -493,7 +393,7 @@ VOID ConErrResPrintf(UINT resID, ...)
|
||||||
|
|
||||||
va_start(arg_ptr, resID);
|
va_start(arg_ptr, resID);
|
||||||
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
|
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
|
||||||
ConPrintf(szMsg, arg_ptr, STD_ERROR_HANDLE);
|
ConPrintfV(STD_ERROR_HANDLE, szMsg, arg_ptr);
|
||||||
va_end(arg_ptr);
|
va_end(arg_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,11 +402,119 @@ VOID ConErrPrintf(LPTSTR szFormat, ...)
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
|
|
||||||
va_start(arg_ptr, szFormat);
|
va_start(arg_ptr, szFormat);
|
||||||
ConPrintf(szFormat, arg_ptr, STD_ERROR_HANDLE);
|
ConPrintfV(STD_ERROR_HANDLE, szFormat, arg_ptr);
|
||||||
va_end(arg_ptr);
|
va_end(arg_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************** Console PAGER functions ***************************/
|
||||||
|
|
||||||
|
INT ConPrintfVPaging(DWORD nStdHandle, BOOL NewPage, LPTSTR szFormat, va_list arg_ptr)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* Reset LineCount and return if no string has been given */
|
||||||
|
if (szFormat == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Get the size of the visual screen that can be printed to */
|
||||||
|
if (!IsConsoleHandle(hOutput) || !GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||||
|
{
|
||||||
|
/* We assume it's a file handle */
|
||||||
|
ConPrintfV(nStdHandle, szFormat, arg_ptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the number of lines currently displayed on screen, minus 1
|
||||||
|
* to account for the "press any key..." prompt from PagePrompt().
|
||||||
|
*/
|
||||||
|
ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top);
|
||||||
|
CharSL = csbi.dwCursorPosition.X;
|
||||||
|
|
||||||
|
/* Make sure the user doesn't have the screen too small */
|
||||||
|
if (ScreenLines < 4)
|
||||||
|
{
|
||||||
|
ConPrintfV(nStdHandle, szFormat, arg_ptr);
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* Prompt the user */
|
||||||
|
if (PagePrompt() != PROMPT_YES)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Recalculate 'ScreenLines' in case the user redimensions
|
||||||
|
// the window during the prompt.
|
||||||
|
|
||||||
|
/* Reset the number of lines being printed */
|
||||||
|
LineCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT ConOutPrintfPaging(BOOL NewPage, LPTSTR szFormat, ...)
|
||||||
|
{
|
||||||
|
INT iReturn;
|
||||||
|
va_list arg_ptr;
|
||||||
|
|
||||||
|
va_start(arg_ptr, szFormat);
|
||||||
|
iReturn = ConPrintfVPaging(STD_OUTPUT_HANDLE, NewPage, szFormat, arg_ptr);
|
||||||
|
va_end(arg_ptr);
|
||||||
|
return iReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID ConOutResPaging(BOOL NewPage, UINT resID)
|
||||||
|
{
|
||||||
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
|
||||||
|
ConOutPrintfPaging(NewPage, szMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************** Console SCREEN functions **************************/
|
||||||
|
|
||||||
VOID SetCursorXY(SHORT x, SHORT y)
|
VOID SetCursorXY(SHORT x, SHORT y)
|
||||||
{
|
{
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
|
@ -568,6 +576,7 @@ VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle)
|
BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle)
|
||||||
{
|
{
|
||||||
/* Now really set the console title */
|
/* Now really set the console title */
|
||||||
|
|
|
@ -19,8 +19,8 @@ VOID ConInString (LPTSTR, DWORD);
|
||||||
|
|
||||||
VOID ConOutChar (TCHAR);
|
VOID ConOutChar (TCHAR);
|
||||||
VOID ConOutPuts (LPTSTR);
|
VOID ConOutPuts (LPTSTR);
|
||||||
VOID ConPrintf(LPTSTR, va_list, DWORD);
|
VOID ConPrintfV(DWORD, LPTSTR, va_list);
|
||||||
INT ConPrintfPaging(BOOL NewPage, LPTSTR, va_list, DWORD);
|
INT ConPrintfVPaging(DWORD nStdHandle, BOOL, LPTSTR, va_list);
|
||||||
VOID ConOutPrintf (LPTSTR, ...);
|
VOID ConOutPrintf (LPTSTR, ...);
|
||||||
INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
|
INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
|
||||||
VOID ConErrChar (TCHAR);
|
VOID ConErrChar (TCHAR);
|
||||||
|
|
|
@ -557,9 +557,9 @@ DirPrintf(LPDIRSWITCHFLAGS lpFlags, LPTSTR szFormat, ...)
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
va_start(arg_ptr, szFormat);
|
va_start(arg_ptr, szFormat);
|
||||||
if (lpFlags->bPause)
|
if (lpFlags->bPause)
|
||||||
iReturn = ConPrintfPaging(FALSE, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
|
iReturn = ConPrintfVPaging(STD_OUTPUT_HANDLE, FALSE, szFormat, arg_ptr);
|
||||||
else
|
else
|
||||||
ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
|
ConPrintfV(STD_OUTPUT_HANDLE, szFormat, arg_ptr);
|
||||||
va_end(arg_ptr);
|
va_end(arg_ptr);
|
||||||
return iReturn;
|
return iReturn;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue