1999-03-20 20:28:42 +00:00
|
|
|
/*
|
|
|
|
* CONSOLE.C - console input/output functions.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
|
|
|
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* started
|
|
|
|
*/
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
#include "config.h"
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
1999-03-21 21:32:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
VOID DebugPrintf (LPTSTR szFormat, ...)
|
|
|
|
{
|
|
|
|
TCHAR szOut[512];
|
|
|
|
va_list arg_ptr;
|
1999-08-28 23:30:50 +00:00
|
|
|
DWORD dwWritten;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
va_start (arg_ptr, szFormat);
|
1999-03-21 21:32:45 +00:00
|
|
|
_vstprintf (szOut, szFormat, arg_ptr);
|
1999-03-20 20:28:42 +00:00
|
|
|
va_end (arg_ptr);
|
|
|
|
|
1999-04-14 23:48:27 +00:00
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL);
|
1999-04-20 20:25:56 +00:00
|
|
|
#if 0
|
|
|
|
OutputDebugString (szOut);
|
|
|
|
#endif
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
#endif /* _DEBUG */
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConInDummy (VOID)
|
|
|
|
{
|
|
|
|
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
INPUT_RECORD dummy;
|
|
|
|
DWORD dwRead;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (hInput == INVALID_HANDLE_VALUE)
|
|
|
|
DebugPrintf ("Invalid input handle!!!\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ReadConsoleInput (hInput, &dummy, 1, &dwRead);
|
|
|
|
}
|
|
|
|
|
1999-08-21 21:54:30 +00:00
|
|
|
VOID ConInFlush (VOID)
|
|
|
|
{
|
|
|
|
FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE));
|
|
|
|
}
|
|
|
|
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
VOID ConInKey (PINPUT_RECORD lpBuffer)
|
|
|
|
{
|
|
|
|
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
DWORD dwRead;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (hInput == INVALID_HANDLE_VALUE)
|
|
|
|
DebugPrintf ("Invalid input handle!!!\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ReadConsoleInput (hInput, lpBuffer, 1, &dwRead);
|
|
|
|
if ((lpBuffer->EventType == KEY_EVENT) &&
|
|
|
|
(lpBuffer->Event.KeyEvent.bKeyDown == TRUE))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConInString (LPTSTR lpInput, DWORD dwLength)
|
|
|
|
{
|
|
|
|
DWORD dwOldMode;
|
|
|
|
DWORD dwRead;
|
|
|
|
HANDLE hFile;
|
|
|
|
|
|
|
|
LPTSTR p;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
ZeroMemory (lpInput, dwLength * sizeof(TCHAR));
|
|
|
|
hFile = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
GetConsoleMode (hFile, &dwOldMode);
|
|
|
|
|
|
|
|
SetConsoleMode (hFile, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
|
|
|
|
|
|
|
|
ReadFile (hFile, lpInput, dwLength, &dwRead, NULL);
|
|
|
|
|
|
|
|
p = lpInput;
|
|
|
|
for (i = 0; i < dwRead; i++, p++)
|
|
|
|
{
|
|
|
|
if (*p == _T('\x0d'))
|
|
|
|
{
|
|
|
|
*p = _T('\0');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetConsoleMode (hFile, dwOldMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConOutChar (TCHAR c)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), &c, 1, &dwWritten, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConOutPuts (LPTSTR szText)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL);
|
1999-04-20 20:25:56 +00:00
|
|
|
#if 0
|
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\x0a\x0d", 2, &dwWritten, NULL);
|
|
|
|
#endif
|
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL);
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConOutPrintf (LPTSTR szFormat, ...)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
TCHAR szOut[256];
|
|
|
|
va_list arg_ptr;
|
|
|
|
|
|
|
|
va_start (arg_ptr, szFormat);
|
1999-03-21 21:32:45 +00:00
|
|
|
_vstprintf (szOut, szFormat, arg_ptr);
|
1999-03-20 20:28:42 +00:00
|
|
|
va_end (arg_ptr);
|
|
|
|
|
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConErrChar (TCHAR c)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
WriteFile (GetStdHandle (STD_ERROR_HANDLE), &c, 1, &dwWritten, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConErrPuts (LPTSTR szText)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
WriteFile (GetStdHandle (STD_ERROR_HANDLE), szText, _tcslen(szText), &dwWritten, NULL);
|
1999-04-20 20:25:56 +00:00
|
|
|
#if 0
|
|
|
|
WriteFile (GetStdHandle (STD_ERROR_HANDLE), "\x0a\x0d", 2, &dwWritten, NULL);
|
|
|
|
#endif
|
|
|
|
WriteFile (GetStdHandle (STD_ERROR_HANDLE), "\n", 1, &dwWritten, NULL);
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID ConErrPrintf (LPTSTR szFormat, ...)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
TCHAR szOut[4096];
|
|
|
|
va_list arg_ptr;
|
|
|
|
|
|
|
|
va_start (arg_ptr, szFormat);
|
1999-03-21 21:32:45 +00:00
|
|
|
_vstprintf (szOut, szFormat, arg_ptr);
|
1999-03-20 20:28:42 +00:00
|
|
|
va_end (arg_ptr);
|
|
|
|
|
|
|
|
WriteFile (GetStdHandle (STD_ERROR_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
VOID SetCursorXY (SHORT x, SHORT y)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
COORD coPos;
|
|
|
|
|
|
|
|
coPos.X = x;
|
|
|
|
coPos.Y = y;
|
|
|
|
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
VOID GetCursorXY (PSHORT x, PSHORT y)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
|
|
|
|
|
|
|
|
*x = csbi.dwCursorPosition.X;
|
|
|
|
*y = csbi.dwCursorPosition.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SHORT GetCursorX (VOID)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
|
|
|
|
|
|
|
|
return csbi.dwCursorPosition.X;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
SHORT GetCursorY (VOID)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
|
|
|
|
|
|
|
|
return csbi.dwCursorPosition.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID GetScreenSize (PSHORT maxx, PSHORT maxy)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
|
|
|
|
|
|
|
|
if (maxx)
|
|
|
|
*maxx = csbi.dwSize.X;
|
|
|
|
if (maxy)
|
|
|
|
*maxy = csbi.dwSize.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID SetCursorType (BOOL bInsert, BOOL bVisible)
|
|
|
|
{
|
|
|
|
CONSOLE_CURSOR_INFO cci;
|
|
|
|
|
1999-08-21 21:54:30 +00:00
|
|
|
cci.dwSize = bInsert ? 10 : 99;
|
1999-03-20 20:28:42 +00:00
|
|
|
cci.bVisible = bVisible;
|
|
|
|
|
1999-04-20 20:25:56 +00:00
|
|
|
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci);
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|