mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 10:35:28 +00:00
[CMD]: Continue refactoring to lay out the way to using the CONUTILS library in CMD. Part 2/x
svn path=/trunk/; revision=76007
This commit is contained in:
parent
e97875595e
commit
03f438982b
3 changed files with 81 additions and 120 deletions
|
@ -139,7 +139,7 @@ VOID ConInString(LPTSTR lpInput, DWORD dwLength)
|
|||
|
||||
/******************** 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 @@ static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
|
|||
}
|
||||
}
|
||||
|
||||
VOID ConOutChar(TCHAR c)
|
||||
VOID ConPuts(DWORD nStdHandle, LPTSTR szText)
|
||||
{
|
||||
ConWrite(&c, 1, STD_OUTPUT_HANDLE);
|
||||
ConWrite(nStdHandle, szText, (DWORD)_tcslen(szText));
|
||||
}
|
||||
|
||||
VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
|
||||
{
|
||||
ConWrite(szText, (DWORD)_tcslen(szText), nStdHandle);
|
||||
}
|
||||
|
||||
VOID ConOutResPuts(UINT resID)
|
||||
VOID ConResPuts(DWORD nStdHandle, UINT resID)
|
||||
{
|
||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||
LoadString(CMD_ModuleHandle, resID, szMsg, ARRAYSIZE(szMsg));
|
||||
ConPuts(szMsg, STD_OUTPUT_HANDLE);
|
||||
ConPuts(nStdHandle, szMsg);
|
||||
}
|
||||
|
||||
VOID ConOutPuts(LPTSTR szText)
|
||||
VOID ConOutChar(TCHAR c)
|
||||
{
|
||||
ConPuts(szText, STD_OUTPUT_HANDLE);
|
||||
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 @@ VOID ConPrintfV(DWORD nStdHandle, LPTSTR szFormat, va_list arg_ptr)
|
|||
DWORD len;
|
||||
|
||||
len = (DWORD)_vstprintf(szOut, szFormat, arg_ptr);
|
||||
ConWrite(szOut, len, nStdHandle);
|
||||
ConWrite(nStdHandle, szOut, len);
|
||||
}
|
||||
|
||||
VOID ConErrFormatMessage(DWORD MessageId, ...)
|
||||
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,109 +322,22 @@ VOID ConErrFormatMessage(DWORD MessageId, ...)
|
|||
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);
|
||||
ConResPrintf(nStdHandle, STRING_CONSOLE_ERROR, MessageId);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************** Console PAGER functions ***************************/
|
||||
|
|
|
@ -17,17 +17,51 @@ VOID ConInFlush (VOID);
|
|||
VOID ConInKey (PINPUT_RECORD);
|
||||
VOID ConInString (LPTSTR, DWORD);
|
||||
|
||||
|
||||
VOID ConOutChar (TCHAR);
|
||||
VOID ConOutPuts (LPTSTR);
|
||||
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);
|
||||
VOID ConErrPuts (LPTSTR);
|
||||
VOID ConErrPrintf (LPTSTR, ...);
|
||||
VOID ConOutFormatMessage (DWORD MessageId, ...);
|
||||
VOID ConErrFormatMessage (DWORD MessageId, ...);
|
||||
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);
|
||||
INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
|
||||
VOID ConOutResPaging(BOOL NewPage, UINT resID);
|
||||
|
||||
SHORT GetCursorX (VOID);
|
||||
SHORT GetCursorY (VOID);
|
||||
|
@ -37,12 +71,6 @@ VOID SetCursorXY (SHORT, SHORT);
|
|||
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);
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...)
|
|||
}
|
||||
|
||||
/* 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
|
||||
|
|
Loading…
Reference in a new issue