ReactOS  0.4.12-dev-945-g5a2911d
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 {
50  UNICODE_STRING ScreenName = RTL_CONSTANT_STRING(L"\\??\\BlueScreen");
51  UNICODE_STRING KeyboardName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardClass0");
55 
56  /* Open the screen */
58  &ScreenName,
59  0,
60  NULL,
61  NULL);
66  FILE_OPEN,
68  if (!NT_SUCCESS(Status))
69  return FALSE;
70 
71  /* Open the keyboard */
73  &KeyboardName,
74  0,
75  NULL,
76  NULL);
81  FILE_OPEN,
82  0);
83  if (!NT_SUCCESS(Status))
84  return FALSE;
85 
86  /* Reset the queue state */
89 
90  return TRUE;
91 }
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
HANDLE StdInput
Definition: consup.c:36
static BOOLEAN WaitForInput
Definition: console.c:40
#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
static BOOLEAN InputQueueEmpty
Definition: console.c:39
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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 96 of file console.c.

98 {
99  return FALSE;
100 }

◆ FillConsoleOutputAttribute()

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

Definition at line 474 of file console.c.

480 {
484 
485  Buffer.wAttribute = wAttribute;
486  Buffer.nLength = nLength;
487  Buffer.dwCoord = dwWriteCoord;
488 
489  Status = NtDeviceIoControlFile(hConsoleOutput,
490  NULL,
491  NULL,
492  NULL,
493  &IoStatusBlock,
495  &Buffer,
496  sizeof(OUTPUT_ATTRIBUTE),
497  &Buffer,
498  sizeof(OUTPUT_ATTRIBUTE));
499  if (!NT_SUCCESS(Status))
500  return FALSE;
501 
502  *lpNumberOfAttrsWritten = Buffer.dwTransfered;
503  return TRUE;
504 }
#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:12
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_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 509 of file console.c.

515 {
519 
520  Buffer.cCharacter = cCharacter;
521  Buffer.nLength = nLength;
522  Buffer.dwCoord = dwWriteCoord;
523 
524  Status = NtDeviceIoControlFile(hConsoleOutput,
525  NULL,
526  NULL,
527  NULL,
528  &IoStatusBlock,
530  &Buffer,
531  sizeof(OUTPUT_CHARACTER),
532  &Buffer,
533  sizeof(OUTPUT_CHARACTER));
534  if (!NT_SUCCESS(Status))
535  return FALSE;
536 
537  *lpNumberOfCharsWritten = Buffer.dwTransfered;
538  return TRUE;
539 }
#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 169 of file console.c.

171 {
175  KEYBOARD_INPUT_DATA InputData;
176 
177  /* Cancel any pending read */
178  if (WaitForInput)
179  NtCancelIoFile(hConsoleInput, &IoStatusBlock);
180 
181  /* Reset the queue state */
184 
185  /* Flush the keyboard buffer */
186  do
187  {
188  Offset.QuadPart = 0;
189  Status = NtReadFile(hConsoleInput,
190  NULL,
191  NULL,
192  NULL,
193  &IoStatusBlock,
194  &InputData,
195  sizeof(InputData),
196  &Offset,
197  NULL);
198  if (Status == STATUS_PENDING)
199  {
200  Timeout.QuadPart = -100;
201  Status = NtWaitForSingleObject(hConsoleInput, FALSE, &Timeout);
202  if (Status == STATUS_TIMEOUT)
203  {
204  NtCancelIoFile(hConsoleInput, &IoStatusBlock);
205  return TRUE;
206  }
207  }
208  } while (NT_SUCCESS(Status));
209  return FALSE;
210 }
#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 105 of file console.c.

106 {
107  /* Reset the queue state */
110 
112  NtClose(StdInput);
113 
116 
117  return TRUE;
118 }
#define TRUE
Definition: types.h:120
HANDLE StdInput
Definition: consup.c:36
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
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 544 of file console.c.

547 {
550 
551  Status = NtDeviceIoControlFile(hConsoleOutput,
552  NULL,
553  NULL,
554  NULL,
555  &IoStatusBlock,
557  NULL,
558  0,
559  lpConsoleScreenBufferInfo,
561  return NT_SUCCESS(Status);
562 }
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:4

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 152 of file console.c.

154 {
155  switch (nStdHandle)
156  {
157  case STD_INPUT_HANDLE:
158  return StdInput;
159  case STD_OUTPUT_HANDLE:
160  return StdOutput;
161  default:
162  return INVALID_HANDLE_VALUE;
163  }
164 }
HANDLE StdInput
Definition: consup.c:36
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
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 215 of file console.c.

220 {
223  KEYBOARD_INPUT_DATA InputData;
224 
225  if (InputQueueEmpty)
226  {
227  /* Read the keyboard for an event, without waiting */
228  if (!WaitForInput)
229  {
230  Offset.QuadPart = 0;
231  Status = NtReadFile(hConsoleInput,
232  NULL,
233  NULL,
234  NULL,
235  &InputIosb,
237  sizeof(InputDataQueue),
238  &Offset,
239  NULL);
240  if (!NT_SUCCESS(Status))
241  return FALSE;
242  if (Status == STATUS_PENDING)
243  {
244  /* No input yet, we will have to wait next time */
246  WaitForInput = TRUE;
247  return TRUE;
248  }
249  }
250  else
251  {
252  /*
253  * We already tried to read from the keyboard and are
254  * waiting for data, check whether something showed up.
255  */
256  Timeout.QuadPart = -100; // Wait just a little bit.
257  Status = NtWaitForSingleObject(hConsoleInput, FALSE, &Timeout);
258  if (Status == STATUS_TIMEOUT)
259  {
260  /* Nothing yet, continue waiting next time */
262  WaitForInput = TRUE;
263  return TRUE;
264  }
266  if (!NT_SUCCESS(Status))
267  return FALSE;
268  }
269 
270  /* We got something in the queue */
273  }
274 
275  /* Fetch from the queue but keep it inside */
276  InputData = InputDataQueue;
277 
278  lpBuffer->EventType = KEY_EVENT;
279  Status = IntTranslateKey(hConsoleInput, &InputData, &lpBuffer->Event.KeyEvent);
280  if (!NT_SUCCESS(Status))
281  return FALSE;
282 
284  return TRUE;
285 }
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 290 of file console.c.

295 {
298  KEYBOARD_INPUT_DATA InputData;
299 
300  if (InputQueueEmpty)
301  {
302  /* Read the keyboard and wait for an event, skipping the queue */
303  if (!WaitForInput)
304  {
305  Offset.QuadPart = 0;
306  Status = NtReadFile(hConsoleInput,
307  NULL,
308  NULL,
309  NULL,
310  &InputIosb,
312  sizeof(InputDataQueue),
313  &Offset,
314  NULL);
315  if (Status == STATUS_PENDING)
316  {
317  /* Block and wait for input */
318  WaitForInput = TRUE;
319  Status = NtWaitForSingleObject(hConsoleInput, FALSE, NULL);
322  }
323  if (!NT_SUCCESS(Status))
324  return FALSE;
325  }
326  else
327  {
328  /*
329  * We already tried to read from the keyboard and are
330  * waiting for data, block and wait for input.
331  */
332  Status = NtWaitForSingleObject(hConsoleInput, FALSE, NULL);
335  if (!NT_SUCCESS(Status))
336  return FALSE;
337  }
338  }
339 
340  /* Fetch from the queue and empty it */
341  InputData = InputDataQueue;
343 
344  lpBuffer->EventType = KEY_EVENT;
345  Status = IntTranslateKey(hConsoleInput, &InputData, &lpBuffer->Event.KeyEvent);
346  if (!NT_SUCCESS(Status))
347  return FALSE;
348 
350  return TRUE;
351 }
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 567 of file console.c.

570 {
573 
574  Status = NtDeviceIoControlFile(hConsoleOutput,
575  NULL,
576  NULL,
577  NULL,
578  &IoStatusBlock,
580  (PCONSOLE_CURSOR_INFO)lpConsoleCursorInfo,
581  sizeof(CONSOLE_CURSOR_INFO),
582  NULL,
583  0);
584  return NT_SUCCESS(Status);
585 }
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:7
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 590 of file console.c.

593 {
594  CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo;
597 
598  Status = GetConsoleScreenBufferInfo(hConsoleOutput, &ConsoleScreenBufferInfo);
599  if (!NT_SUCCESS(Status))
600  return FALSE;
601 
602  ConsoleScreenBufferInfo.dwCursorPosition.X = dwCursorPosition.X;
603  ConsoleScreenBufferInfo.dwCursorPosition.Y = dwCursorPosition.Y;
604 
605  Status = NtDeviceIoControlFile(hConsoleOutput,
606  NULL,
607  NULL,
608  NULL,
609  &IoStatusBlock,
611  &ConsoleScreenBufferInfo,
613  NULL,
614  0);
615  return NT_SUCCESS(Status);
616 }
#define IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:5
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:544
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 644 of file console.c.

646 {
647  HANDLE hConsoleOutput;
650 
651  hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
652 
653  Status = NtDeviceIoControlFile(hConsoleOutput,
654  NULL,
655  NULL,
656  NULL,
657  &IoStatusBlock,
659  &wCodepage,
660  sizeof(ULONG),
661  NULL,
662  0);
663  return NT_SUCCESS(Status);
664 }
LONG NTSTATUS
Definition: precomp.h:26
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
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 621 of file console.c.

624 {
627 
628  Status = NtDeviceIoControlFile(hConsoleOutput,
629  NULL,
630  NULL,
631  NULL,
632  &IoStatusBlock,
634  &wAttributes,
635  sizeof(USHORT),
636  NULL,
637  0);
638  return NT_SUCCESS(Status);
639 }
#define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE
Definition: ntddblue.h:15
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 123 of file console.c.

129 {
132 
133  Status = NtWriteFile(hConsoleOutput,
134  NULL,
135  NULL,
136  NULL,
137  &IoStatusBlock,
138  (PVOID)lpBuffer,
139  nNumberOfCharsToWrite,
140  NULL,
141  NULL);
142  if (!NT_SUCCESS(Status))
143  return FALSE;
144 
145  *lpNumberOfCharsWritten = IoStatusBlock.Information;
146  return TRUE;
147 }
#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 356 of file console.c.

362 {
364  PCHAR Buffer;
365  COORD *pCoord;
366  PCHAR pText;
368 
370  0,
371  nLength + sizeof(COORD));
372  pCoord = (COORD *)Buffer;
373  pText = (PCHAR)(pCoord + 1);
374 
375  *pCoord = dwWriteCoord;
376  memcpy(pText, lpCharacter, nLength);
377 
378  Status = NtDeviceIoControlFile(hConsoleOutput,
379  NULL,
380  NULL,
381  NULL,
382  &IoStatusBlock,
384  NULL,
385  0,
386  Buffer,
387  nLength + sizeof(COORD));
388 
390  if (!NT_SUCCESS(Status))
391  return FALSE;
392 
393  *lpNumberOfCharsWritten = IoStatusBlock.Information;
394  return TRUE;
395 }
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:603
_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:585
#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 400 of file console.c.

406 {
408  PCHAR Buffer;
409  COORD *pCoord;
410  PCHAR pText;
412 // ULONG i;
413 
416  ULONG OemLength;
417 
418  UnicodeString.Length = nLength * sizeof(WCHAR);
419  UnicodeString.MaximumLength = nLength * sizeof(WCHAR);
420  UnicodeString.Buffer = (PWSTR)lpCharacter;
421 
423 
424 
426  0,
427  OemLength + sizeof(COORD));
428 // nLength + sizeof(COORD));
429  if (Buffer== NULL)
430  return FALSE;
431 
432  pCoord = (COORD *)Buffer;
433  pText = (PCHAR)(pCoord + 1);
434 
435  *pCoord = dwWriteCoord;
436 
437  OemString.Length = 0;
438  OemString.MaximumLength = OemLength;
439  OemString.Buffer = pText;
440 
442  &UnicodeString,
443  FALSE);
444  if (!NT_SUCCESS(Status))
445  goto done;
446 
447  /* FIXME: use real unicode->oem conversion */
448 // for (i = 0; i < nLength; i++)
449 // pText[i] = (CHAR)lpCharacter[i];
450 
451  Status = NtDeviceIoControlFile(hConsoleOutput,
452  NULL,
453  NULL,
454  NULL,
455  &IoStatusBlock,
457  NULL,
458  0,
459  Buffer,
460  nLength + sizeof(COORD));
461 
462 done:
464  if (!NT_SUCCESS(Status))
465  return FALSE;
466 
467  *lpNumberOfCharsWritten = IoStatusBlock.Information;
468  return TRUE;
469 }
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:603
_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:585
__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_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