Author: hbelusca
Date: Sat Sep 30 15:28:06 2017
New Revision: 76003
URL:
http://svn.reactos.org/svn/reactos?rev=76003&view=rev
Log:
[CMD]: Continue refactoring to lay out the way to using the CONUTILS library in CMD.
Modified:
trunk/reactos/base/shell/cmd/console.c
trunk/reactos/base/shell/cmd/console.h
trunk/reactos/base/shell/cmd/dir.c
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] Sat Sep 30 15:28:06 2017
@@ -50,6 +50,10 @@
return GetConsoleMode(hHandle, &dwMode);
}
+
+
+/********************* Console STREAM IN utility functions ********************/
+
VOID ConInDisable(VOID)
{
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
@@ -60,7 +64,6 @@
SetConsoleMode(hInput, dwMode);
}
-
VOID ConInEnable(VOID)
{
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
@@ -71,12 +74,10 @@
SetConsoleMode(hInput, dwMode);
}
-
-VOID ConInFlush (VOID)
+VOID ConInFlush(VOID)
{
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
}
-
VOID ConInKey(PINPUT_RECORD lpBuffer)
{
@@ -95,7 +96,6 @@
}
while (TRUE);
}
-
VOID ConInString(LPTSTR lpInput, DWORD dwLength)
{
@@ -134,6 +134,10 @@
SetConsoleMode(hFile, dwOldMode);
}
+
+
+
+/******************** Console STREAM OUT utility functions ********************/
static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
{
@@ -266,13 +270,6 @@
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)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
@@ -285,97 +282,13 @@
ConPuts(szText, STD_OUTPUT_HANDLE);
}
-
-VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
+VOID ConPrintfV(DWORD nStdHandle, LPTSTR szFormat, va_list arg_ptr)
{
TCHAR szOut[OUTPUT_BUFFER_SIZE];
DWORD len;
len = (DWORD)_vstprintf(szOut, szFormat, arg_ptr);
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, ...)
@@ -443,7 +356,7 @@
va_start(arg_ptr, resID);
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);
}
@@ -452,26 +365,14 @@
va_list arg_ptr;
va_start(arg_ptr, szFormat);
- ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
+ ConPrintfV(STD_OUTPUT_HANDLE, szFormat, 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)
{
ConWrite(&c, 1, STD_ERROR_HANDLE);
}
-
VOID ConErrResPuts(UINT resID)
{
@@ -485,7 +386,6 @@
ConPuts(szText, STD_ERROR_HANDLE);
}
-
VOID ConErrResPrintf(UINT resID, ...)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
@@ -493,7 +393,7 @@
va_start(arg_ptr, resID);
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);
}
@@ -502,10 +402,118 @@
va_list arg_ptr;
va_start(arg_ptr, szFormat);
- ConPrintf(szFormat, arg_ptr, STD_ERROR_HANDLE);
+ ConPrintfV(STD_ERROR_HANDLE, szFormat, 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)
{
@@ -565,6 +573,7 @@
if (maxx) *maxx = csbi.dwSize.X;
if (maxy) *maxy = csbi.dwSize.Y;
}
+
Modified: trunk/reactos/base/shell/cmd/console.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/console.h?r…
==============================================================================
--- trunk/reactos/base/shell/cmd/console.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/console.h [iso-8859-1] Sat Sep 30 15:28:06 2017
@@ -19,8 +19,8 @@
VOID ConOutChar (TCHAR);
VOID ConOutPuts (LPTSTR);
-VOID ConPrintf(LPTSTR, va_list, DWORD);
-INT ConPrintfPaging(BOOL NewPage, LPTSTR, va_list, DWORD);
+VOID ConPrintfV(DWORD, LPTSTR, va_list);
+INT ConPrintfVPaging(DWORD nStdHandle, BOOL, LPTSTR, va_list);
VOID ConOutPrintf (LPTSTR, ...);
INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
VOID ConErrChar (TCHAR);
Modified: trunk/reactos/base/shell/cmd/dir.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/dir.c?rev=7…
==============================================================================
--- trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] Sat Sep 30 15:28:06 2017
@@ -557,9 +557,9 @@
va_list arg_ptr;
va_start(arg_ptr, szFormat);
if (lpFlags->bPause)
- iReturn = ConPrintfPaging(FALSE, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
+ iReturn = ConPrintfVPaging(STD_OUTPUT_HANDLE, FALSE, szFormat, arg_ptr);
else
- ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
+ ConPrintfV(STD_OUTPUT_HANDLE, szFormat, arg_ptr);
va_end(arg_ptr);
return iReturn;
}