Author: hbelusca
Date: Sat Sep 30 19:52:30 2017
New Revision: 76007
URL:
http://svn.reactos.org/svn/reactos?rev=76007&view=rev
Log:
[CMD]: Continue refactoring to lay out the way to using the CONUTILS library in CMD. Part
2/x
Modified:
trunk/reactos/base/shell/cmd/console.c
trunk/reactos/base/shell/cmd/console.h
trunk/reactos/base/shell/cmd/error.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 19:52:30 2017
@@ -139,7 +139,7 @@
/******************** Console STREAM OUT utility functions ********************/
-static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
+static VOID ConWrite(DWORD nStdHandle, TCHAR *str, DWORD len)
{
DWORD dwNumBytes = 0;
HANDLE hOutput = GetStdHandle(nStdHandle);
@@ -260,26 +260,26 @@
}
}
-VOID ConOutChar(TCHAR c)
-{
- ConWrite(&c, 1, STD_OUTPUT_HANDLE);
-}
-
-VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
-{
- ConWrite(szText, (DWORD)_tcslen(szText), nStdHandle);
-}
-
-VOID ConOutResPuts(UINT resID)
+VOID ConPuts(DWORD nStdHandle, LPTSTR szText)
+{
+ ConWrite(nStdHandle, szText, (DWORD)_tcslen(szText));
+}
+
+VOID ConResPuts(DWORD nStdHandle, UINT resID)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
- ConPuts(szMsg, STD_OUTPUT_HANDLE);
-}
-
-VOID ConOutPuts(LPTSTR szText)
-{
- ConPuts(szText, STD_OUTPUT_HANDLE);
+ ConPuts(nStdHandle, szMsg);
+}
+
+VOID ConOutChar(TCHAR c)
+{
+ ConWrite(STD_OUTPUT_HANDLE, &c, 1);
+}
+
+VOID ConErrChar(TCHAR c)
+{
+ ConWrite(STD_ERROR_HANDLE, &c, 1);
}
VOID ConPrintfV(DWORD nStdHandle, LPTSTR szFormat, va_list arg_ptr)
@@ -288,12 +288,31 @@
DWORD len;
len = (DWORD)_vstprintf(szOut, szFormat, arg_ptr);
- ConWrite(szOut, len, nStdHandle);
-}
-
-VOID ConErrFormatMessage(DWORD MessageId, ...)
+ ConWrite(nStdHandle, szOut, len);
+}
+
+VOID ConPrintf(DWORD nStdHandle, LPTSTR szFormat, ...)
+{
+ va_list arg_ptr;
+
+ va_start(arg_ptr, szFormat);
+ ConPrintfV(nStdHandle, szFormat, arg_ptr);
+ va_end(arg_ptr);
+}
+
+VOID ConResPrintf(DWORD nStdHandle, UINT resID, ...)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
+ va_list arg_ptr;
+
+ va_start(arg_ptr, resID);
+ LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
+ ConPrintfV(nStdHandle, szMsg, arg_ptr);
+ va_end(arg_ptr);
+}
+
+VOID ConFormatMessage(DWORD nStdHandle, DWORD MessageId, ...)
+{
DWORD ret;
LPTSTR text;
va_list arg_ptr;
@@ -303,107 +322,20 @@
NULL,
MessageId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &text,
+ (LPTSTR)&text,
0,
&arg_ptr);
-
va_end(arg_ptr);
+
if (ret > 0)
{
- ConErrPuts(text);
+ ConPuts(nStdHandle, text);
LocalFree(text);
}
else
{
- LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, ARRAYSIZE(szMsg));
- 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, ARRAYSIZE(szMsg));
- 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, ARRAYSIZE(szMsg));
- ConPrintfV(STD_OUTPUT_HANDLE, szMsg, arg_ptr);
- va_end(arg_ptr);
-}
-
-VOID ConOutPrintf(LPTSTR szFormat, ...)
-{
- va_list arg_ptr;
-
- va_start(arg_ptr, szFormat);
- ConPrintfV(STD_OUTPUT_HANDLE, szFormat, arg_ptr);
- va_end(arg_ptr);
-}
-
-VOID ConErrChar(TCHAR c)
-{
- ConWrite(&c, 1, STD_ERROR_HANDLE);
-}
-
-VOID ConErrResPuts(UINT resID)
-{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
- ConPuts(szMsg, STD_ERROR_HANDLE);
-}
-
-VOID ConErrPuts(LPTSTR szText)
-{
- 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, ARRAYSIZE(szMsg));
- ConPrintfV(STD_ERROR_HANDLE, szMsg, arg_ptr);
- va_end(arg_ptr);
-}
-
-VOID ConErrPrintf(LPTSTR szFormat, ...)
-{
- va_list arg_ptr;
-
- va_start(arg_ptr, szFormat);
- ConPrintfV(STD_ERROR_HANDLE, szFormat, arg_ptr);
- va_end(arg_ptr);
+ ConResPrintf(nStdHandle, STRING_CONSOLE_ERROR, MessageId);
+ }
}
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 19:52:30 2017
@@ -17,17 +17,51 @@
VOID ConInKey (PINPUT_RECORD);
VOID ConInString (LPTSTR, DWORD);
+
VOID ConOutChar (TCHAR);
-VOID ConOutPuts (LPTSTR);
+VOID ConErrChar (TCHAR);
VOID ConPrintfV(DWORD, LPTSTR, va_list);
+
+VOID ConPuts(DWORD nStdHandle, LPTSTR szText);
+VOID ConPrintf(DWORD nStdHandle, LPTSTR szFormat, ...);
+VOID ConResPuts(DWORD nStdHandle, UINT resID);
+VOID ConResPrintf(DWORD nStdHandle, UINT resID, ...);
+VOID ConFormatMessage(DWORD nStdHandle, DWORD MessageId, ...);
+
+#define ConOutPuts(szStr) \
+ ConPuts(STD_OUTPUT_HANDLE, (szStr))
+
+#define ConErrPuts(szStr) \
+ ConPuts(STD_ERROR_HANDLE, (szStr))
+
+#define ConOutResPuts(uID) \
+ ConResPuts(STD_OUTPUT_HANDLE, (uID))
+
+#define ConErrResPuts(uID) \
+ ConResPuts(STD_ERROR_HANDLE, (uID))
+
+#define ConOutPrintf(szStr, ...) \
+ ConPrintf(STD_OUTPUT_HANDLE, (szStr), ##__VA_ARGS__)
+
+#define ConErrPrintf(szStr, ...) \
+ ConPrintf(STD_ERROR_HANDLE, (szStr), ##__VA_ARGS__)
+
+#define ConOutResPrintf(uID, ...) \
+ ConResPrintf(STD_OUTPUT_HANDLE, (uID), ##__VA_ARGS__)
+
+#define ConErrResPrintf(uID, ...) \
+ ConResPrintf(STD_ERROR_HANDLE, (uID), ##__VA_ARGS__)
+
+#define ConOutFormatMessage(MessageId, ...) \
+ ConFormatMessage(STD_OUTPUT_HANDLE, (MessageId), ##__VA_ARGS__)
+
+#define ConErrFormatMessage(MessageId, ...) \
+ ConFormatMessage(STD_ERROR_HANDLE, (MessageId), ##__VA_ARGS__)
+
+
INT ConPrintfVPaging(DWORD nStdHandle, BOOL, LPTSTR, va_list);
-VOID ConOutPrintf (LPTSTR, ...);
INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
-VOID ConErrChar (TCHAR);
-VOID ConErrPuts (LPTSTR);
-VOID ConErrPrintf (LPTSTR, ...);
-VOID ConOutFormatMessage (DWORD MessageId, ...);
-VOID ConErrFormatMessage (DWORD MessageId, ...);
+VOID ConOutResPaging(BOOL NewPage, UINT resID);
SHORT GetCursorX (VOID);
SHORT GetCursorY (VOID);
@@ -36,12 +70,6 @@
VOID GetScreenSize (PSHORT, PSHORT);
VOID SetCursorType (BOOL, BOOL);
-
-VOID ConOutResPuts (UINT resID);
-VOID ConErrResPuts (UINT resID);
-VOID ConOutResPrintf (UINT resID, ...);
-VOID ConErrResPrintf (UINT resID, ...);
-VOID ConOutResPaging(BOOL NewPage, UINT resID);
BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle);
Modified: trunk/reactos/base/shell/cmd/error.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/error.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/error.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/error.c [iso-8859-1] Sat Sep 30 19:52:30 2017
@@ -53,6 +53,7 @@
}
/* Fall back just in case the error is not defined */
+ LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, ARRAYSIZE(szMsg));
if (szFormat)
ConErrPrintf(_T("%s -- %s\n"), szMsg, szMessage);
else