ReactOS  0.4.14-dev-843-g15bc263
console.c File Reference
#include <usetup.h>
#include <blue/ntddblue.h>
#include "keytrans.h"
#include <debug.h>
Include dependency graph for console.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL WINAPI AllocConsole (VOID)
 
BOOL WINAPI AttachConsole (IN DWORD dwProcessId)
 
BOOL WINAPI FreeConsole (VOID)
 
BOOL WINAPI WriteConsole (IN HANDLE hConsoleOutput, IN const VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, IN LPVOID lpReserved)
 
HANDLE WINAPI GetStdHandle (IN DWORD nStdHandle)
 
BOOL WINAPI FlushConsoleInputBuffer (IN HANDLE hConsoleInput)
 
BOOL WINAPI PeekConsoleInput (IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead)
 
BOOL WINAPI ReadConsoleInput (IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead)
 
BOOL WINAPI WriteConsoleOutputCharacterA (HANDLE hConsoleOutput, IN LPCSTR lpCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
 
BOOL WINAPI WriteConsoleOutputCharacterW (HANDLE hConsoleOutput, IN LPCWSTR lpCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
 
BOOL WINAPI FillConsoleOutputAttribute (IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
 
BOOL WINAPI FillConsoleOutputCharacterA (IN HANDLE hConsoleOutput, IN CHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
 
BOOL WINAPI GetConsoleScreenBufferInfo (IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
 
BOOL WINAPI SetConsoleCursorInfo (IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
 
BOOL WINAPI SetConsoleCursorPosition (IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
 
BOOL WINAPI SetConsoleTextAttribute (IN HANDLE hConsoleOutput, IN WORD wAttributes)
 
BOOL WINAPI SetConsoleOutputCP (IN UINT wCodepage)
 

Variables

static BOOLEAN InputQueueEmpty
 
static BOOLEAN WaitForInput
 
static KEYBOARD_INPUT_DATA InputDataQueue
 
static IO_STATUS_BLOCK InputIosb
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 34 of file console.c.

Function Documentation

◆ AllocConsole()

BOOL WINAPI AllocConsole ( VOID  )

Definition at line 48 of file console.c.

49 {
51  UNICODE_STRING ScreenName = RTL_CONSTANT_STRING(L"\\??\\BlueScreen");
52  UNICODE_STRING KeyboardName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardClass0");
55  ULONG Enable;
56 
57  /* Open the screen */
59  &ScreenName,
60  0,
61  NULL,
62  NULL);
67  FILE_OPEN,
69  if (!NT_SUCCESS(Status))
70  return FALSE;
71 
72  /* Enable it */
73  Enable = TRUE;
75  NULL,
76  NULL,
77  NULL,
80  &Enable,
81  sizeof(Enable),
82  NULL,
83  0);
84  if (!NT_SUCCESS(Status))
85  {
87  return FALSE;
88  }
89 
90  /* Open the keyboard */
92  &KeyboardName,
93  0,
94  NULL,
95  NULL);
100  FILE_OPEN,
101  0);
102  if (!NT_SUCCESS(Status))
103  {
105  return FALSE;
106  }
107 
108  /* Reset the queue state */
111 
112  return TRUE;
113 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
HANDLE StdInput
Definition: consup.c:36
static BOOLEAN WaitForInput
Definition: console.c:40
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
HANDLE StdOutput
Definition: consup.c:37
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static BOOLEAN InputQueueEmpty
Definition: console.c:39
static const WCHAR L[]
Definition: oid.c:1250
#define IOCTL_CONSOLE_RESET_SCREEN
Definition: ntddblue.h:4
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by _tWinMain(), cmd_ctty(), CONSOLE_Init(), DoTest(), main(), START_TEST(), test_Console(), TUIInitialize(), and wWinMain().

◆ AttachConsole()

BOOL WINAPI AttachConsole ( IN DWORD  dwProcessId)

Definition at line 118 of file console.c.

120 {
121  return FALSE;
122 }

◆ FillConsoleOutputAttribute()

BOOL WINAPI FillConsoleOutputAttribute ( IN HANDLE  hConsoleOutput,
IN WORD  wAttribute,
IN DWORD  nLength,
IN COORD  dwWriteCoord,
OUT LPDWORD  lpNumberOfAttrsWritten 
)

Definition at line 496 of file console.c.

502 {
506 
507  Buffer.wAttribute = wAttribute;
508  Buffer.nLength = nLength;
509  Buffer.dwCoord = dwWriteCoord;
510 
511  Status = NtDeviceIoControlFile(hConsoleOutput,
512  NULL,
513  NULL,
514  NULL,
515  &IoStatusBlock,
517  &Buffer,
518  sizeof(OUTPUT_ATTRIBUTE),
519  &Buffer,
520  sizeof(OUTPUT_ATTRIBUTE));
521  if (!NT_SUCCESS(Status))
522  return FALSE;
523 
524  *lpNumberOfAttrsWritten = Buffer.dwTransfered;
525  return TRUE;
526 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ DWORD nLength
Definition: wincon.h:461
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:13
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by TConsole::ClearBOLine(), TConsole::ClearBOScreen(), TConsole::ClearEOLine(), TConsole::ClearEOScreen(), TConsole::ClearLine(), TConsole::ClearScreen(), ClearScreen(), TConsole::ClearWindow(), ConClearScreen(), ConSetScreenColor(), CONSOLE_ClearScreen(), CONSOLE_InvertTextXY(), CONSOLE_NormalTextXY(), CONSOLE_SetHighlightedTextXY(), CONSOLE_SetInputTextXY(), CONSOLE_SetInvertedTextXY(), CONSOLE_SetStatusTextXV(), ConsolePager(), DisplayScreen(), TMouse::doMouse(), DrawFileSystemList(), DrawListEntries(), DrawProgressBar(), TMouse::move_mouse(), PopupError(), PrintDiskData(), PrintEmptyLine(), PrintInfoLine(), PrintPartitionData(), test_cp932(), test_FillConsoleOutputAttribute(), wmain(), WriteStringAt(), and TConsole::WriteText().

◆ FillConsoleOutputCharacterA()

BOOL WINAPI FillConsoleOutputCharacterA ( IN HANDLE  hConsoleOutput,
IN CHAR  cCharacter,
IN DWORD  nLength,
IN COORD  dwWriteCoord,
OUT LPDWORD  lpNumberOfCharsWritten 
)

Definition at line 531 of file console.c.

537 {
541 
542  Buffer.cCharacter = cCharacter;
543  Buffer.nLength = nLength;
544  Buffer.dwCoord = dwWriteCoord;
545 
546  Status = NtDeviceIoControlFile(hConsoleOutput,
547  NULL,
548  NULL,
549  NULL,
550  &IoStatusBlock,
552  &Buffer,
553  sizeof(OUTPUT_CHARACTER),
554  &Buffer,
555  sizeof(OUTPUT_CHARACTER));
556  if (!NT_SUCCESS(Status))
557  return FALSE;
558 
559  *lpNumberOfCharsWritten = Buffer.dwTransfered;
560  return TRUE;
561 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ DWORD nLength
Definition: wincon.h:461
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER
Definition: ntddblue.h:18
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by CONSOLE_ClearScreen(), CONSOLE_ClearStatusTextX(), CONSOLE_ClearTextXY(), CONSOLE_PrintTextXYN(), CONSOLE_SetInputTextXY(), CONSOLE_SetStatusTextXV(), CONSOLE_SetUnderlinedTextXY(), DrawBorder(), DrawBox(), DrawFileSystemList(), DrawListEntries(), DrawListFrame(), DrawPartitionList(), DrawProgressBar(), DrawScrollBarGenericList(), DrawThickBorder(), PopupError(), PrintDiskData(), PrintEmptyLine(), PrintPartitionData(), ProgressSetStep(), and test_FillConsoleOutputCharacterA().

◆ FlushConsoleInputBuffer()

BOOL WINAPI FlushConsoleInputBuffer ( IN HANDLE  hConsoleInput)

Definition at line 191 of file console.c.

193 {
197  KEYBOARD_INPUT_DATA InputData;
198 
199  /* Cancel any pending read */
200  if (WaitForInput)
201  NtCancelIoFile(hConsoleInput, &IoStatusBlock);
202 
203  /* Reset the queue state */
206 
207  /* Flush the keyboard buffer */
208  do
209  {
210  Offset.QuadPart = 0;
211  Status = NtReadFile(hConsoleInput,
212  NULL,
213  NULL,
214  NULL,
215  &IoStatusBlock,
216  &InputData,
217  sizeof(InputData),
218  &Offset,
219  NULL);
220  if (Status == STATUS_PENDING)
221  {
222  Timeout.QuadPart = -100;
223  Status = NtWaitForSingleObject(hConsoleInput, FALSE, &Timeout);
224  if (Status == STATUS_TIMEOUT)
225  {
226  NtCancelIoFile(hConsoleInput, &IoStatusBlock);
227  return TRUE;
228  }
229  }
230  } while (NT_SUCCESS(Status));
231  return FALSE;
232 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
static BOOLEAN WaitForInput
Definition: console.c:40
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static BOOLEAN InputQueueEmpty
Definition: console.c:39
Status
Definition: gdiplustypes.h:24
static ULONG Timeout
Definition: ping.c:61
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI NtCancelIoFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: file.c:4018
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by ConInFlush(), CONSOLE_Flush(), ConsolePager(), FlushFileBuffers(), CConsole::FlushInputBuffer(), getline(), gl_cleanup(), gl_getpass(), InputChar(), InputWait(), CConsole::ReadLine(), ReadString(), test_WriteConsoleInputA(), test_WriteConsoleInputW(), testWaitForConsoleInput(), and wmain().

◆ FreeConsole()

BOOL WINAPI FreeConsole ( VOID  )

Definition at line 127 of file console.c.

128 {
129  /* Reset the queue state */
132 
134  NtClose(StdInput);
135 
138 
139  return TRUE;
140 }
#define TRUE
Definition: types.h:120
HANDLE StdInput
Definition: consup.c:36
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
static BOOLEAN WaitForInput
Definition: console.c:40
HANDLE StdOutput
Definition: consup.c:37
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static BOOLEAN InputQueueEmpty
Definition: console.c:39

Referenced by cmd_ctty(), RunUSetup(), and START_TEST().

◆ GetConsoleScreenBufferInfo()

BOOL WINAPI GetConsoleScreenBufferInfo ( IN HANDLE  hConsoleOutput,
OUT PCONSOLE_SCREEN_BUFFER_INFO  lpConsoleScreenBufferInfo 
)

Definition at line 566 of file console.c.

569 {
572 
573  Status = NtDeviceIoControlFile(hConsoleOutput,
574  NULL,
575  NULL,
576  NULL,
577  &IoStatusBlock,
579  NULL,
580  0,
581  lpConsoleScreenBufferInfo,
583  return NT_SUCCESS(Status);
584 }
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:6

Referenced by AttachToConsoleInternal(), TConsole::ClearBOLine(), TConsole::ClearEOLine(), TConsole::ClearLine(), ConClearLine(), ConClearScreen(), ConGetDefaultAttributes(), ConGetScreenInfo(), ConSetScreenColor(), CONSOLE_GetCursorX(), CONSOLE_GetCursorXY(), CONSOLE_GetCursorY(), CONSOLE_Init(), ConsolePager(), DisplayScreen(), doChild(), TMouse::doMouse_init(), GetCursorX(), GetCursorXY(), GetCursorY(), GetScreenColumns(), GetScreenSize(), CConsole::Init(), main(), newBuffer(), PrintInfoLine(), ReadCommand(), RecoveryConsole(), ResizeTextConsole(), restoreScreen(), saveScreen(), TScroller::ScrollBack(), SetConsoleCursorPosition(), SetConsoleState(), SetConsoleStateOld(), ShowConsoleStatus(), START_TEST(), TConsole::sync(), TConsole::TConsole(), test_Console(), test_cp855(), test_cp932(), test_GetConsoleFontInfo(), test_GetConsoleFontSize(), test_GetCurrentConsoleFont(), test_GetLargestConsoleWindowSize(), VgaConsoleInitialize(), wmain(), and write_status().

◆ GetStdHandle()

HANDLE WINAPI GetStdHandle ( IN DWORD  nStdHandle)

Definition at line 174 of file console.c.

176 {
177  switch (nStdHandle)
178  {
179  case STD_INPUT_HANDLE:
180  return StdInput;
181  case STD_OUTPUT_HANDLE:
182  return StdOutput;
183  default:
184  return INVALID_HANDLE_VALUE;
185  }
186 }
HANDLE StdInput
Definition: consup.c:36
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
HANDLE StdOutput
Definition: consup.c:37
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265

Referenced by __report_error(), _cputs(), _kbhit(), _putch(), _tmain(), _tpopen(), _tWinMain(), ask_confirm(), ata_open_file(), cfgets(), cgetchar(), cmd_type(), ConErrPrintf(), Confirm(), ConInDisable(), ConInEnable(), ConInFlush(), ConInKey(), ConInString(), ConOutPuts(), CONSOLE_GetCursorXY(), CONSOLE_Init(), ConsolePager(), CreateClientProcess(), DisplayError(), DisplayResourceText(), doChild(), DosCopyHandleTable(), EnumThreadProc(), ExecutePipeline(), ExtCabCallback(), GetCharacterTimeout(), GetCursorX(), GetCursorXY(), GetCursorY(), GetInputOutputHandles(), getline(), getpass(), GetScreenColumns(), GetScreenSize(), gl_cleanup(), gl_getpass(), CConsole::Init(), CPipedProcess::InitStartupInfo(), InputChar(), main(), msvcrt_init_io(), myprintf(), newBuffer(), output_error(), output_header(), output_line(), output_writeconsole(), OutputResult(), TANSIParser::ParseBuffer(), print_string(), PrintInfoLine(), printit(), ReadAndHandleOutput(), ReadCommand(), ReadFromConsole(), ReadString(), RecoveryConsole(), RestoreConsole(), restoreScreen(), saveScreen(), TScroller::ScrollBack(), scrollkeys(), SetCl(), SetConsoleOutputCP(), SetConsoleState(), SetConsoleStateOld(), SetCursorType(), SetCursorXY(), SetInsert(), ShowAppList(), ShowConsoleStatus(), start_server(), taskkill_vprintfW(), telProcessConsole(), test_DetachConsoleHandles(), test_DetachStdHandles(), test_file_inherit(), test_GetConsoleFontInfo(), test_GetConsoleFontSize(), test_GetConsoleScreenBufferInfoEx(), test_GetCurrentConsoleFont(), test_GetFileType(), test_GetLargestConsoleWindowSize(), test_GetSetStdHandle(), test_Handles(), test_invalid_stdin(), test_ReadConsole(), test_SetConsoleFont(), test_stdin(), test_stdio(), test_stdout_handle(), TMouse::TMouse(), TUIDisplayStatusMessage(), waitforkey(), wmain(), write_status(), XCOPY_DoCopy(), XCOPY_ProcessDestParm(), and XCOPY_wprintf().

◆ PeekConsoleInput()

BOOL WINAPI PeekConsoleInput ( IN HANDLE  hConsoleInput,
OUT PINPUT_RECORD  lpBuffer,
IN DWORD  nLength,
OUT LPDWORD  lpNumberOfEventsRead 
)

Definition at line 237 of file console.c.

242 {
245  KEYBOARD_INPUT_DATA InputData;
246 
247  if (InputQueueEmpty)
248  {
249  /* Read the keyboard for an event, without waiting */
250  if (!WaitForInput)
251  {
252  Offset.QuadPart = 0;
253  Status = NtReadFile(hConsoleInput,
254  NULL,
255  NULL,
256  NULL,
257  &InputIosb,
259  sizeof(InputDataQueue),
260  &Offset,
261  NULL);
262  if (!NT_SUCCESS(Status))
263  return FALSE;
264  if (Status == STATUS_PENDING)
265  {
266  /* No input yet, we will have to wait next time */
268  WaitForInput = TRUE;
269  return TRUE;
270  }
271  }
272  else
273  {
274  /*
275  * We already tried to read from the keyboard and are
276  * waiting for data, check whether something showed up.
277  */
278  Timeout.QuadPart = -100; // Wait just a little bit.
279  Status = NtWaitForSingleObject(hConsoleInput, FALSE, &Timeout);
280  if (Status == STATUS_TIMEOUT)
281  {
282  /* Nothing yet, continue waiting next time */
284  WaitForInput = TRUE;
285  return TRUE;
286  }
288  if (!NT_SUCCESS(Status))
289  return FALSE;
290  }
291 
292  /* We got something in the queue */
295  }
296 
297  /* Fetch from the queue but keep it inside */
298  InputData = InputDataQueue;
299 
300  lpBuffer->EventType = KEY_EVENT;
301  Status = IntTranslateKey(hConsoleInput, &InputData, &lpBuffer->Event.KeyEvent);
302  if (!NT_SUCCESS(Status))
303  return FALSE;
304 
306  return TRUE;
307 }
static KEYBOARD_INPUT_DATA InputDataQueue
Definition: console.c:41
#define TRUE
Definition: types.h:120
static IO_STATUS_BLOCK InputIosb
Definition: console.c:42
_In_ DWORD _Out_ LPDWORD lpNumberOfEventsRead
Definition: wincon.h:461
LONG NTSTATUS
Definition: precomp.h:26
static BOOLEAN WaitForInput
Definition: console.c:40
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
NTSTATUS IntTranslateKey(HANDLE hConsoleInput, PKEYBOARD_INPUT_DATA InputData, KEY_EVENT_RECORD *Event)
Definition: keytrans.c:417
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define KEY_EVENT
Definition: wincon.h:122
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static BOOLEAN InputQueueEmpty
Definition: console.c:39
Status
Definition: gdiplustypes.h:24
static ULONG Timeout
Definition: ping.c:61
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by _kbhit(), and CONSOLE_ConInKeyPeek().

◆ ReadConsoleInput()

BOOL WINAPI ReadConsoleInput ( IN HANDLE  hConsoleInput,
OUT PINPUT_RECORD  lpBuffer,
IN DWORD  nLength,
OUT LPDWORD  lpNumberOfEventsRead 
)

Definition at line 312 of file console.c.

317 {
320  KEYBOARD_INPUT_DATA InputData;
321 
322  if (InputQueueEmpty)
323  {
324  /* Read the keyboard and wait for an event, skipping the queue */
325  if (!WaitForInput)
326  {
327  Offset.QuadPart = 0;
328  Status = NtReadFile(hConsoleInput,
329  NULL,
330  NULL,
331  NULL,
332  &InputIosb,
334  sizeof(InputDataQueue),
335  &Offset,
336  NULL);
337  if (Status == STATUS_PENDING)
338  {
339  /* Block and wait for input */
340  WaitForInput = TRUE;
341  Status = NtWaitForSingleObject(hConsoleInput, FALSE, NULL);
344  }
345  if (!NT_SUCCESS(Status))
346  return FALSE;
347  }
348  else
349  {
350  /*
351  * We already tried to read from the keyboard and are
352  * waiting for data, block and wait for input.
353  */
354  Status = NtWaitForSingleObject(hConsoleInput, FALSE, NULL);
357  if (!NT_SUCCESS(Status))
358  return FALSE;
359  }
360  }
361 
362  /* Fetch from the queue and empty it */
363  InputData = InputDataQueue;
365 
366  lpBuffer->EventType = KEY_EVENT;
367  Status = IntTranslateKey(hConsoleInput, &InputData, &lpBuffer->Event.KeyEvent);
368  if (!NT_SUCCESS(Status))
369  return FALSE;
370 
372  return TRUE;
373 }
static KEYBOARD_INPUT_DATA InputDataQueue
Definition: console.c:41
#define TRUE
Definition: types.h:120
static IO_STATUS_BLOCK InputIosb
Definition: console.c:42
_In_ DWORD _Out_ LPDWORD lpNumberOfEventsRead
Definition: wincon.h:461
LONG NTSTATUS
Definition: precomp.h:26
static BOOLEAN WaitForInput
Definition: console.c:40
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
NTSTATUS IntTranslateKey(HANDLE hConsoleInput, PKEYBOARD_INPUT_DATA InputData, KEY_EVENT_RECORD *Event)
Definition: keytrans.c:417
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define KEY_EVENT
Definition: wincon.h:122
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static BOOLEAN InputQueueEmpty
Definition: console.c:39
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by ConInKey().

◆ SetConsoleCursorInfo()

BOOL WINAPI SetConsoleCursorInfo ( IN HANDLE  hConsoleOutput,
IN const CONSOLE_CURSOR_INFO lpConsoleCursorInfo 
)

Definition at line 589 of file console.c.

592 {
595 
596  Status = NtDeviceIoControlFile(hConsoleOutput,
597  NULL,
598  NULL,
599  NULL,
600  &IoStatusBlock,
602  (PCONSOLE_CURSOR_INFO)lpConsoleCursorInfo,
603  sizeof(CONSOLE_CURSOR_INFO),
604  NULL,
605  0);
606  return NT_SUCCESS(Status);
607 }
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define IOCTL_CONSOLE_SET_CURSOR_INFO
Definition: ntddblue.h:9
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

Referenced by CONSOLE_SetCursorType(), CConsole::Init(), TConsole::SetCursorSize(), SetCursorType(), CConsole::SetInsertMode(), VgaConsoleUpdateTextCursor(), VgaDetachFromConsole(), and CConsole::Write().

◆ SetConsoleCursorPosition()

BOOL WINAPI SetConsoleCursorPosition ( IN HANDLE  hConsoleOutput,
IN COORD  dwCursorPosition 
)

Definition at line 612 of file console.c.

615 {
616  CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo;
619 
620  Status = GetConsoleScreenBufferInfo(hConsoleOutput, &ConsoleScreenBufferInfo);
621  if (!NT_SUCCESS(Status))
622  return FALSE;
623 
624  ConsoleScreenBufferInfo.dwCursorPosition.X = dwCursorPosition.X;
625  ConsoleScreenBufferInfo.dwCursorPosition.Y = dwCursorPosition.Y;
626 
627  Status = NtDeviceIoControlFile(hConsoleOutput,
628  NULL,
629  NULL,
630  NULL,
631  &IoStatusBlock,
633  &ConsoleScreenBufferInfo,
635  NULL,
636  0);
637  return NT_SUCCESS(Status);
638 }
#define IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:7
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:566
ULONG X
Definition: bl.h:1340
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
ULONG Y
Definition: bl.h:1341

Referenced by ClearScreen(), ConClearLine(), ConClearScreen(), CONSOLE_SetCursorXY(), ConsolePager(), doChild(), CConsole::ReadLine(), TConsole::SetCursorPosition(), SetCursorXY(), TConsole::SetRawCursorPosition(), test_cp855(), test_cp932(), testCursor(), testEmptyWrite(), testScreenBuffer(), testWriteNotWrappedNotProcessed(), testWriteNotWrappedProcessed(), testWriteSimple(), testWriteWrappedNotProcessed(), testWriteWrappedProcessed(), VgaConsoleUpdateTextCursor(), CConsole::Write(), and TConsole::WriteString().

◆ SetConsoleOutputCP()

BOOL WINAPI SetConsoleOutputCP ( IN UINT  wCodepage)

Definition at line 666 of file console.c.

668 {
669  HANDLE hConsoleOutput;
672 
673  hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
674 
675  Status = NtDeviceIoControlFile(hConsoleOutput,
676  NULL,
677  NULL,
678  NULL,
679  &IoStatusBlock,
681  &wCodepage,
682  sizeof(ULONG),
683  NULL,
684  0);
685  return NT_SUCCESS(Status);
686 }
LONG NTSTATUS
Definition: precomp.h:26
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:174
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IOCTL_CONSOLE_LOADFONT
Definition: ntddblue.h:24
unsigned int ULONG
Definition: retypes.h:1

Referenced by doChild(), SetConsoleCodePage(), SetConsoleCPState(), test_Console(), test_cp855(), test_cp932(), testScreenBuffer(), and wmain().

◆ SetConsoleTextAttribute()

BOOL WINAPI SetConsoleTextAttribute ( IN HANDLE  hConsoleOutput,
IN WORD  wAttributes 
)

Definition at line 643 of file console.c.

646 {
649 
650  Status = NtDeviceIoControlFile(hConsoleOutput,
651  NULL,
652  NULL,
653  NULL,
654  &IoStatusBlock,
656  &wAttributes,
657  sizeof(USHORT),
658  NULL,
659  0);
660  return NT_SUCCESS(Status);
661 }
#define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE
Definition: ntddblue.h:16
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

Referenced by ConSetScreenColor(), main(), SetCl(), ShowAppList(), TConsole::TConsole(), testWrite(), TConsole::WriteString(), TConsole::WriteStringFast(), and TConsole::~TConsole().

◆ WriteConsole()

BOOL WINAPI WriteConsole ( IN HANDLE  hConsoleOutput,
IN const VOID lpBuffer,
IN DWORD  nNumberOfCharsToWrite,
OUT LPDWORD  lpNumberOfCharsWritten,
IN LPVOID  lpReserved 
)

Definition at line 145 of file console.c.

151 {
154 
155  Status = NtWriteFile(hConsoleOutput,
156  NULL,
157  NULL,
158  NULL,
159  &IoStatusBlock,
160  (PVOID)lpBuffer,
161  nNumberOfCharsToWrite,
162  NULL,
163  NULL);
164  if (!NT_SUCCESS(Status))
165  return FALSE;
166 
167  *lpNumberOfCharsWritten = IoStatusBlock.Information;
168  return TRUE;
169 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

◆ WriteConsoleOutputCharacterA()

BOOL WINAPI WriteConsoleOutputCharacterA ( HANDLE  hConsoleOutput,
IN LPCSTR  lpCharacter,
IN DWORD  nLength,
IN COORD  dwWriteCoord,
OUT LPDWORD  lpNumberOfCharsWritten 
)

Definition at line 378 of file console.c.

384 {
386  PCHAR Buffer;
387  COORD *pCoord;
388  PCHAR pText;
390 
392  0,
393  nLength + sizeof(COORD));
394  pCoord = (COORD *)Buffer;
395  pText = (PCHAR)(pCoord + 1);
396 
397  *pCoord = dwWriteCoord;
398  memcpy(pText, lpCharacter, nLength);
399 
400  Status = NtDeviceIoControlFile(hConsoleOutput,
401  NULL,
402  NULL,
403  NULL,
404  &IoStatusBlock,
406  NULL,
407  0,
408  Buffer,
409  nLength + sizeof(COORD));
410 
412  if (!NT_SUCCESS(Status))
413  return FALSE;
414 
415  *lpNumberOfCharsWritten = IoStatusBlock.Information;
416  return TRUE;
417 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
LPCSTR pText
Definition: txtscale.cpp:79
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ DWORD nLength
Definition: wincon.h:461
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define PCHAR
Definition: match.c:90
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: bl.h:1338
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER
Definition: ntddblue.h:20
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by CONSOLE_PrintTextXY(), CONSOLE_PrintTextXYN(), CONSOLE_SetHighlightedTextXY(), CONSOLE_SetInvertedTextXY(), CONSOLE_SetStatusTextXV(), CONSOLE_SetTextXY(), CONSOLE_SetUnderlinedTextXY(), DrawListEntries(), DrawPartitionList(), DrawProgressBar(), PopupError(), PrintDiskData(), PrintPartitionData(), ProgressSetStep(), resetContent(), ShowPartitionSizeInputBox(), and test_WriteConsoleOutputCharacterA().

◆ WriteConsoleOutputCharacterW()

BOOL WINAPI WriteConsoleOutputCharacterW ( HANDLE  hConsoleOutput,
IN LPCWSTR  lpCharacter,
IN DWORD  nLength,
IN COORD  dwWriteCoord,
OUT LPDWORD  lpNumberOfCharsWritten 
)

Definition at line 422 of file console.c.

428 {
430  PCHAR Buffer;
431  COORD *pCoord;
432  PCHAR pText;
434 // ULONG i;
435 
438  ULONG OemLength;
439 
440  UnicodeString.Length = nLength * sizeof(WCHAR);
441  UnicodeString.MaximumLength = nLength * sizeof(WCHAR);
442  UnicodeString.Buffer = (PWSTR)lpCharacter;
443 
445 
446 
448  0,
449  OemLength + sizeof(COORD));
450 // nLength + sizeof(COORD));
451  if (Buffer== NULL)
452  return FALSE;
453 
454  pCoord = (COORD *)Buffer;
455  pText = (PCHAR)(pCoord + 1);
456 
457  *pCoord = dwWriteCoord;
458 
459  OemString.Length = 0;
460  OemString.MaximumLength = OemLength;
461  OemString.Buffer = pText;
462 
464  &UnicodeString,
465  FALSE);
466  if (!NT_SUCCESS(Status))
467  goto done;
468 
469  /* FIXME: use real unicode->oem conversion */
470 // for (i = 0; i < nLength; i++)
471 // pText[i] = (CHAR)lpCharacter[i];
472 
473  Status = NtDeviceIoControlFile(hConsoleOutput,
474  NULL,
475  NULL,
476  NULL,
477  &IoStatusBlock,
479  NULL,
480  0,
481  Buffer,
482  nLength + sizeof(COORD));
483 
484 done:
486  if (!NT_SUCCESS(Status))
487  return FALSE;
488 
489  *lpNumberOfCharsWritten = IoStatusBlock.Information;
490  return TRUE;
491 }
signed char * PCHAR
Definition: retypes.h:7
*BytesInOemString PCHAR OemString
Definition: rtlfuncs.h:1561
#define TRUE
Definition: types.h:120
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
LPCSTR pText
Definition: txtscale.cpp:79
uint16_t * PWSTR
Definition: typedefs.h:54
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ DWORD nLength
Definition: wincon.h:461
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
STRING OEM_STRING
Definition: umtypes.h:203
NTSYSAPI DWORD WINAPI RtlUnicodeStringToOemSize(const UNICODE_STRING *)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define PCHAR
Definition: match.c:90
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToOemString(POEM_STRING DestinationString, PCUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
Definition: bl.h:1338
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int ULONG
Definition: retypes.h:1
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER
Definition: ntddblue.h:20
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by CONSOLE_SetInputTextXY(), test_cp932(), test_WriteConsoleOutputCharacterW(), and WriteStringAt().

Variable Documentation

◆ InputDataQueue

KEYBOARD_INPUT_DATA InputDataQueue
static

Definition at line 41 of file console.c.

Referenced by PeekConsoleInput(), and ReadConsoleInput().

◆ InputIosb

IO_STATUS_BLOCK InputIosb
static

Definition at line 42 of file console.c.

Referenced by PeekConsoleInput(), and ReadConsoleInput().

◆ InputQueueEmpty

BOOLEAN InputQueueEmpty
static

◆ WaitForInput

BOOLEAN WaitForInput
static