2006-02-16 23:23:37 +00:00
|
|
|
/*
|
|
|
|
* CONSOLE.C - console input/output functions.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
2007-05-05 11:32:25 +00:00
|
|
|
* 20-Jan-1999 (Eric Kohl)
|
2006-02-16 23:23:37 +00:00
|
|
|
* started
|
|
|
|
*
|
|
|
|
* 03-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
|
|
|
* Remove all hardcode string to En.rc
|
|
|
|
*
|
|
|
|
* 01-Jul-2005 (Brandon Turner) <turnerb7@msu.edu>)
|
|
|
|
* Added ConPrintfPaging and ConOutPrintfPaging
|
2007-02-03 16:03:37 +00:00
|
|
|
*
|
|
|
|
* 02-Feb-2007 (Paolo Devoti) <devotip at gmail.com>)
|
|
|
|
* Fixed ConPrintfPaging
|
2006-02-16 23:23:37 +00:00
|
|
|
*/
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
#include <precomp.h>
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
#define OUTPUT_BUFFER_SIZE 4096
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
UINT InputCodePage;
|
|
|
|
UINT OutputCodePage;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConInDisable (VOID)
|
|
|
|
{
|
|
|
|
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
DWORD dwMode;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
GetConsoleMode (hInput, &dwMode);
|
|
|
|
dwMode &= ~ENABLE_PROCESSED_INPUT;
|
|
|
|
SetConsoleMode (hInput, dwMode);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConInEnable (VOID)
|
|
|
|
{
|
|
|
|
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
DWORD dwMode;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
GetConsoleMode (hInput, &dwMode);
|
|
|
|
dwMode |= ENABLE_PROCESSED_INPUT;
|
|
|
|
SetConsoleMode (hInput, dwMode);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConInFlush (VOID)
|
|
|
|
{
|
|
|
|
FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE));
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConInKey (PINPUT_RECORD lpBuffer)
|
|
|
|
{
|
|
|
|
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
DWORD dwRead;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
if (hInput == INVALID_HANDLE_VALUE)
|
2008-05-15 20:02:05 +00:00
|
|
|
WARN ("Invalid input handle!!!\n");
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
ReadConsoleInput (hInput, lpBuffer, 1, &dwRead);
|
|
|
|
if ((lpBuffer->EventType == KEY_EVENT) &&
|
|
|
|
(lpBuffer->Event.KeyEvent.bKeyDown == TRUE))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConInString (LPTSTR lpInput, DWORD dwLength)
|
|
|
|
{
|
|
|
|
DWORD dwOldMode;
|
2009-03-31 04:06:47 +00:00
|
|
|
DWORD dwRead = 0;
|
2006-02-16 23:23:37 +00:00
|
|
|
HANDLE hFile;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
LPTSTR p;
|
|
|
|
PCHAR pBuf;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
#ifdef _UNICODE
|
2009-03-31 04:06:47 +00:00
|
|
|
pBuf = (PCHAR)cmd_alloc(dwLength - 1);
|
2006-02-16 23:23:37 +00:00
|
|
|
#else
|
|
|
|
pBuf = lpInput;
|
|
|
|
#endif
|
|
|
|
ZeroMemory (lpInput, dwLength * sizeof(TCHAR));
|
|
|
|
hFile = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
GetConsoleMode (hFile, &dwOldMode);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
SetConsoleMode (hFile, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2009-03-31 04:06:47 +00:00
|
|
|
ReadFile (hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
#ifdef _UNICODE
|
2009-03-31 04:06:47 +00:00
|
|
|
MultiByteToWideChar(InputCodePage, 0, pBuf, dwRead, lpInput, dwLength - 1);
|
|
|
|
cmd_free(pBuf);
|
2006-02-16 23:23:37 +00:00
|
|
|
#endif
|
2009-03-31 04:06:47 +00:00
|
|
|
for (p = lpInput; *p; p++)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
|
|
|
if (*p == _T('\x0d'))
|
|
|
|
{
|
|
|
|
*p = _T('\0');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
SetConsoleMode (hFile, dwOldMode);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2009-03-28 19:36:22 +00:00
|
|
|
static VOID ConWrite(TCHAR *str, DWORD len, DWORD nStdHandle)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
2009-03-28 19:36:22 +00:00
|
|
|
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
|
2009-08-02 17:38:27 +00:00
|
|
|
WCHAR *buffer = cmd_alloc(len * sizeof(WCHAR));
|
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
error_out_of_memory();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-28 19:36:22 +00:00
|
|
|
len = MultiByteToWideChar(OutputCodePage, 0, str, len, buffer, len, NULL, NULL);
|
|
|
|
str = (PVOID)buffer;
|
|
|
|
#endif
|
|
|
|
WriteFile(hOutput, str, len * sizeof(WCHAR), &dwWritten, NULL);
|
2009-08-02 17:38:27 +00:00
|
|
|
#ifndef _UNICODE
|
|
|
|
cmd_free(buffer);
|
|
|
|
#endif
|
2009-03-28 19:36:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-16 23:23:37 +00:00
|
|
|
#ifdef _UNICODE
|
2009-08-02 17:38:27 +00:00
|
|
|
CHAR *buffer = cmd_alloc(len * MB_LEN_MAX * sizeof(CHAR));
|
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
error_out_of_memory();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-28 19:36:22 +00:00
|
|
|
len = WideCharToMultiByte(OutputCodePage, 0, str, len, buffer, len * MB_LEN_MAX, NULL, NULL);
|
|
|
|
str = (PVOID)buffer;
|
2006-02-16 23:23:37 +00:00
|
|
|
#endif
|
2009-03-28 19:36:22 +00:00
|
|
|
WriteFile(hOutput, str, len, &dwWritten, NULL);
|
2009-08-02 17:38:27 +00:00
|
|
|
#ifdef _UNICODE
|
|
|
|
cmd_free(buffer);
|
|
|
|
#endif
|
2009-03-28 19:36:22 +00:00
|
|
|
}
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConOutChar (TCHAR c)
|
|
|
|
{
|
2009-03-28 19:36:22 +00:00
|
|
|
ConWrite(&c, 1, STD_OUTPUT_HANDLE);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
|
|
|
|
{
|
2009-03-28 19:36:22 +00:00
|
|
|
ConWrite(szText, _tcslen(szText), nStdHandle);
|
|
|
|
ConWrite(_T("\n"), 1, nStdHandle);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConOutResPaging(BOOL NewPage, UINT resID)
|
|
|
|
{
|
2007-03-04 23:18:28 +00:00
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
ConOutPrintfPaging(NewPage, szMsg);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConOutResPuts (UINT resID)
|
|
|
|
{
|
2007-03-04 23:18:28 +00:00
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
|
|
|
|
ConPuts(szMsg, STD_OUTPUT_HANDLE);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConOutPuts (LPTSTR szText)
|
|
|
|
{
|
|
|
|
ConPuts(szText, STD_OUTPUT_HANDLE);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
|
|
|
{
|
|
|
|
TCHAR szOut[OUTPUT_BUFFER_SIZE];
|
2009-03-28 19:36:22 +00:00
|
|
|
ConWrite(szOut, _vstprintf(szOut, szFormat, arg_ptr), nStdHandle);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
|
|
|
|
{
|
|
|
|
INT len;
|
2007-02-11 13:05:50 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2006-02-16 23:23:37 +00:00
|
|
|
TCHAR szOut[OUTPUT_BUFFER_SIZE];
|
|
|
|
DWORD dwWritten;
|
2008-07-27 14:03:44 +00:00
|
|
|
HANDLE hOutput = GetStdHandle(nStdHandle);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
/* used to count number of lines since last pause */
|
2006-02-16 23:23:37 +00:00
|
|
|
static int LineCount = 0;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
/* used to see how big the screen is */
|
2007-10-19 23:21:45 +00:00
|
|
|
int ScreenLines = 0;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
/* chars since start of line */
|
2008-07-27 14:03:44 +00:00
|
|
|
int CharSL;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2008-07-27 14:03:44 +00:00
|
|
|
int from = 0, i = 0;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
if(NewPage == TRUE)
|
|
|
|
LineCount = 0;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
/* rest LineCount and return if no string have been given */
|
|
|
|
if (szFormat == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
//get the size of the visual screen that can be printed too
|
2008-07-27 14:03:44 +00:00
|
|
|
if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
|
2007-03-04 23:18:28 +00:00
|
|
|
{
|
|
|
|
// we assuming its a file handle
|
|
|
|
ConPrintf(szFormat, arg_ptr, nStdHandle);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-16 23:23:37 +00:00
|
|
|
//subtract 2 to account for "press any key..." and for the blank line at the end of PagePrompt()
|
|
|
|
ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top) - 4;
|
2008-07-27 14:03:44 +00:00
|
|
|
CharSL = csbi.dwCursorPosition.X;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
//make sure they didnt make the screen to small
|
2006-02-16 23:23:37 +00:00
|
|
|
if(ScreenLines<4)
|
2007-03-04 23:18:28 +00:00
|
|
|
{
|
2007-03-04 23:26:30 +00:00
|
|
|
ConPrintf(szFormat, arg_ptr, nStdHandle);
|
2007-03-04 23:18:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
len = _vstprintf (szOut, szFormat, arg_ptr);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2008-07-27 14:03:44 +00:00
|
|
|
while (i < len)
|
2007-02-03 16:03:37 +00:00
|
|
|
{
|
2008-07-27 14:03:44 +00:00
|
|
|
// Search until the end of a line is reached
|
|
|
|
if (szOut[i++] != _T('\n') && ++CharSL < csbi.dwSize.X)
|
|
|
|
continue;
|
2007-02-03 16:03:37 +00:00
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
LineCount++;
|
2007-03-04 23:18:28 +00:00
|
|
|
CharSL=0;
|
2007-02-03 16:03:37 +00:00
|
|
|
|
2007-03-04 23:18:28 +00:00
|
|
|
if(LineCount >= ScreenLines)
|
|
|
|
{
|
2008-07-27 14:03:44 +00:00
|
|
|
WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
|
|
|
|
from = i;
|
2007-02-03 16:03:37 +00:00
|
|
|
|
2007-03-04 23:18:28 +00:00
|
|
|
if(PagePrompt() != PROMPT_YES)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
//reset the number of lines being printed
|
2007-03-04 23:18:28 +00:00
|
|
|
LineCount = 0;
|
|
|
|
}
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2008-07-27 14:03:44 +00:00
|
|
|
WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConErrFormatMessage (DWORD MessageId, ...)
|
|
|
|
{
|
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
DWORD ret;
|
|
|
|
LPTSTR text;
|
|
|
|
va_list arg_ptr;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
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);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
va_end (arg_ptr);
|
|
|
|
if(ret > 0)
|
|
|
|
{
|
|
|
|
ConErrPuts (text);
|
|
|
|
LocalFree(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
ConErrPrintf(szMsg);
|
|
|
|
}
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConOutFormatMessage (DWORD MessageId, ...)
|
|
|
|
{
|
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
DWORD ret;
|
|
|
|
LPTSTR text;
|
|
|
|
va_list arg_ptr;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
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);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
va_end (arg_ptr);
|
|
|
|
if(ret > 0)
|
|
|
|
{
|
|
|
|
ConErrPuts (text);
|
|
|
|
LocalFree(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
ConErrPrintf(szMsg);
|
|
|
|
}
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2008-07-26 22:49:49 +00:00
|
|
|
VOID ConOutResPrintf (UINT resID, ...)
|
|
|
|
{
|
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
va_list arg_ptr;
|
|
|
|
|
|
|
|
va_start (arg_ptr, resID);
|
|
|
|
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
ConPrintf(szMsg, arg_ptr, STD_OUTPUT_HANDLE);
|
|
|
|
va_end (arg_ptr);
|
|
|
|
}
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConOutPrintf (LPTSTR szFormat, ...)
|
|
|
|
{
|
|
|
|
va_list arg_ptr;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
va_start (arg_ptr, szFormat);
|
|
|
|
ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
|
|
|
|
va_end (arg_ptr);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
INT ConOutPrintfPaging (BOOL NewPage, LPTSTR szFormat, ...)
|
|
|
|
{
|
|
|
|
INT iReturn;
|
|
|
|
va_list arg_ptr;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
va_start (arg_ptr, szFormat);
|
|
|
|
iReturn = ConPrintfPaging(NewPage, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
|
|
|
|
va_end (arg_ptr);
|
|
|
|
return iReturn;
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConErrChar (TCHAR c)
|
|
|
|
{
|
2009-03-28 19:36:22 +00:00
|
|
|
ConWrite(&c, 1, STD_ERROR_HANDLE);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConErrResPuts (UINT resID)
|
|
|
|
{
|
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
2007-03-04 23:18:28 +00:00
|
|
|
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
|
2006-02-16 23:23:37 +00:00
|
|
|
ConPuts(szMsg, STD_ERROR_HANDLE);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConErrPuts (LPTSTR szText)
|
|
|
|
{
|
|
|
|
ConPuts(szText, STD_ERROR_HANDLE);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2008-07-26 22:49:49 +00:00
|
|
|
VOID ConErrResPrintf (UINT resID, ...)
|
|
|
|
{
|
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
va_list arg_ptr;
|
|
|
|
|
|
|
|
va_start (arg_ptr, resID);
|
|
|
|
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
ConPrintf(szMsg, arg_ptr, STD_ERROR_HANDLE);
|
|
|
|
va_end (arg_ptr);
|
|
|
|
}
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID ConErrPrintf (LPTSTR szFormat, ...)
|
|
|
|
{
|
|
|
|
va_list arg_ptr;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
va_start (arg_ptr, szFormat);
|
|
|
|
ConPrintf(szFormat, arg_ptr, STD_ERROR_HANDLE);
|
|
|
|
va_end (arg_ptr);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID SetCursorXY (SHORT x, SHORT y)
|
|
|
|
{
|
|
|
|
COORD coPos;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
coPos.X = x;
|
|
|
|
coPos.Y = y;
|
|
|
|
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID GetCursorXY (PSHORT x, PSHORT y)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2009-03-29 19:17:45 +00:00
|
|
|
GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
*x = csbi.dwCursorPosition.X;
|
|
|
|
*y = csbi.dwCursorPosition.Y;
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
SHORT GetCursorX (VOID)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2009-03-29 19:17:45 +00:00
|
|
|
GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
return csbi.dwCursorPosition.X;
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
SHORT GetCursorY (VOID)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2009-03-29 19:17:45 +00:00
|
|
|
GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
return csbi.dwCursorPosition.Y;
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID GetScreenSize (PSHORT maxx, PSHORT maxy)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2009-03-29 19:17:45 +00:00
|
|
|
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
|
|
|
|
{
|
|
|
|
csbi.dwSize.X = 80;
|
|
|
|
csbi.dwSize.Y = 25;
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
if (maxx)
|
|
|
|
*maxx = csbi.dwSize.X;
|
|
|
|
if (maxy)
|
|
|
|
*maxy = csbi.dwSize.Y;
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
VOID SetCursorType (BOOL bInsert, BOOL bVisible)
|
|
|
|
{
|
|
|
|
CONSOLE_CURSOR_INFO cci;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
cci.dwSize = bInsert ? 10 : 99;
|
|
|
|
cci.bVisible = bVisible;
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci);
|
|
|
|
}
|
2007-03-04 23:18:28 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
/* EOF */
|