https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a3ea0a39f18ff5ddf7ce1…
commit a3ea0a39f18ff5ddf7ce1f739c58cb5026d00962
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Fri Apr 10 20:38:47 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Apr 11 15:37:27 2020 +0200
[WIN32SS] Get rid of "consrv_new".
Any new features/architectural changes to the console will either be
done in separate branches, or incrementally in master within the
existing console module.
---
win32ss/user/winsrv/consrv_new.cmake | 50 -
win32ss/user/winsrv/consrv_new/alias.c | 593 ----
win32ss/user/winsrv/consrv_new/alias.h | 14 -
win32ss/user/winsrv/consrv_new/api.h | 84 -
win32ss/user/winsrv/consrv_new/condrv/coninput.c | 514 ----
win32ss/user/winsrv/consrv_new/condrv/conoutput.c | 287 --
win32ss/user/winsrv/consrv_new/condrv/console.c | 1106 --------
.../user/winsrv/consrv_new/condrv/dummyfrontend.c | 185 --
win32ss/user/winsrv/consrv_new/condrv/graphics.c | 274 --
win32ss/user/winsrv/consrv_new/condrv/text.c | 1346 ---------
win32ss/user/winsrv/consrv_new/coninput.c | 482 ----
win32ss/user/winsrv/consrv_new/coninput.h | 23 -
win32ss/user/winsrv/consrv_new/conoutput.c | 810 ------
win32ss/user/winsrv/consrv_new/conoutput.h | 46 -
win32ss/user/winsrv/consrv_new/console.c | 663 -----
win32ss/user/winsrv/consrv_new/console.h | 27 -
win32ss/user/winsrv/consrv_new/consrv.h | 79 -
win32ss/user/winsrv/consrv_new/consrv.rc | 79 -
win32ss/user/winsrv/consrv_new/frontendctl.c | 343 ---
.../user/winsrv/consrv_new/frontends/frontends.rc | 1 -
.../winsrv/consrv_new/frontends/gui/consolecpl.h | 14 -
.../winsrv/consrv_new/frontends/gui/graphics.c | 81 -
.../winsrv/consrv_new/frontends/gui/guisettings.c | 541 ----
.../winsrv/consrv_new/frontends/gui/guisettings.h | 94 -
.../user/winsrv/consrv_new/frontends/gui/guiterm.c | 2960 --------------------
.../user/winsrv/consrv_new/frontends/gui/guiterm.h | 28 -
.../winsrv/consrv_new/frontends/gui/guiterm.rc | 88 -
.../winsrv/consrv_new/frontends/gui/lang/bg-BG.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/cs-CZ.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/de-DE.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/el-GR.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/en-US.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/es-ES.rc | 32 -
.../winsrv/consrv_new/frontends/gui/lang/fr-FR.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/he-IL.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/id-ID.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/it-IT.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/ja-JP.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/no-NO.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/pl-PL.rc | 32 -
.../winsrv/consrv_new/frontends/gui/lang/pt-BR.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/ro-RO.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/ru-RU.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/sk-SK.rc | 29 -
.../winsrv/consrv_new/frontends/gui/lang/sv-SE.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/tr-TR.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/uk-UA.rc | 26 -
.../winsrv/consrv_new/frontends/gui/lang/zh-CN.rc | 24 -
.../winsrv/consrv_new/frontends/gui/lang/zh-TW.rc | 24 -
.../consrv_new/frontends/gui/res/terminal.ico | Bin 236566 -> 0 bytes
.../winsrv/consrv_new/frontends/gui/resource.h | 43 -
.../user/winsrv/consrv_new/frontends/gui/text.c | 300 --
win32ss/user/winsrv/consrv_new/frontends/input.c | 146 -
.../user/winsrv/consrv_new/frontends/tui/tuiterm.c | 856 ------
.../user/winsrv/consrv_new/frontends/tui/tuiterm.h | 19 -
win32ss/user/winsrv/consrv_new/handle.c | 870 ------
win32ss/user/winsrv/consrv_new/handle.h | 34 -
win32ss/user/winsrv/consrv_new/heap.h | 17 -
win32ss/user/winsrv/consrv_new/include/conio.h | 377 ---
win32ss/user/winsrv/consrv_new/include/conio2.h | 50 -
win32ss/user/winsrv/consrv_new/include/console.h | 54 -
win32ss/user/winsrv/consrv_new/include/settings.h | 93 -
win32ss/user/winsrv/consrv_new/init.c | 531 ----
win32ss/user/winsrv/consrv_new/lang/bg-BG.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/cs-CZ.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/de-DE.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/el-GR.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/en-US.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/es-ES.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/fr-FR.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/he-IL.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/id-ID.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/it-IT.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/ja-JP.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/no-NO.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/pl-PL.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/pt-BR.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/pt-PT.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/ro-RO.rc | 8 -
win32ss/user/winsrv/consrv_new/lang/ru-RU.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/sk-SK.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/sv-SE.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/tr-TR.rc | 8 -
win32ss/user/winsrv/consrv_new/lang/uk-UA.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/zh-CN.rc | 6 -
win32ss/user/winsrv/consrv_new/lang/zh-TW.rc | 6 -
win32ss/user/winsrv/consrv_new/lineinput.c | 650 -----
win32ss/user/winsrv/consrv_new/lineinput.h | 14 -
win32ss/user/winsrv/consrv_new/procinit.h | 24 -
win32ss/user/winsrv/consrv_new/resource.h | 12 -
win32ss/user/winsrv/consrv_new/settings.c | 576 ----
91 files changed, 16185 deletions(-)
diff --git a/win32ss/user/winsrv/consrv_new.cmake b/win32ss/user/winsrv/consrv_new.cmake
deleted file mode 100644
index 7d841ba3fde..00000000000
--- a/win32ss/user/winsrv/consrv_new.cmake
+++ /dev/null
@@ -1,50 +0,0 @@
-
-remove_definitions(-D_WIN32_WINNT=0x502)
-add_definitions(-D_WIN32_WINNT=0x600)
-
-include_directories(consrv_new)
-
-list(APPEND CONSRV_SOURCE
- consrv_new/alias.c
- consrv_new/coninput.c
- consrv_new/conoutput.c
- consrv_new/console.c
- consrv_new/frontendctl.c
- consrv_new/handle.c
- consrv_new/init.c
- consrv_new/lineinput.c
- consrv_new/settings.c
- consrv_new/condrv/coninput.c
- consrv_new/condrv/conoutput.c
- consrv_new/condrv/console.c
- consrv_new/condrv/dummyfrontend.c
- consrv_new/condrv/graphics.c
- consrv_new/condrv/text.c
- consrv_new/frontends/input.c
- consrv_new/frontends/gui/guiterm.c
- consrv_new/frontends/gui/guisettings.c
- consrv_new/frontends/gui/graphics.c
- consrv_new/frontends/gui/text.c
- consrv_new/frontends/tui/tuiterm.c
- # consrv_new/consrv.rc
- )
-
-#
-# Explicitely enable MS extensions to be able to use unnamed (anonymous) nested structs.
-#
-# FIXME:
http://www.cmake.org/Bug/view.php?id=12998
-if(MSVC)
- ## NOTE: No need to specify it as we use MSVC :)
- ##add_target_compile_flags(consrv_new "/Ze")
- #set_source_files_properties(${CONSRV_SOURCE} PROPERTIES COMPILE_FLAGS
"/Ze")
-else()
- #add_target_compile_flags(consrv_new "-fms-extensions")
- set_source_files_properties(${CONSRV_SOURCE} PROPERTIES COMPILE_FLAGS
"-fms-extensions")
-endif()
-
-add_library(consrv_new ${CONSRV_SOURCE})
-#add_object_library(consrv_new ${CONSRV_SOURCE})
-add_delay_importlibs(consrv_new ole32) # And the default ones from winsrv
-add_importlibs(consrv_new psapi) # And the default ones from winsrv
-target_link_libraries(consrv_new uuid) # And the default ones from winsrv
-set_module_type(consrv_new module UNICODE)
diff --git a/win32ss/user/winsrv/consrv_new/alias.c
b/win32ss/user/winsrv/consrv_new/alias.c
deleted file mode 100644
index d435bcce50f..00000000000
--- a/win32ss/user/winsrv/consrv_new/alias.c
+++ /dev/null
@@ -1,593 +0,0 @@
-/*
- * LICENSE: GPL - See COPYING in the top level directory
- * PROJECT: ReactOS Console Server DLL
- * FILE: win32ss/user/winsrv/consrv_new/alias.c
- * PURPOSE: Alias support functions
- * PROGRAMMERS: Christoph Wittich
- * Johannes Anderwald
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "console.h"
-#include "include/conio.h"
-
-#define NDEBUG
-#include <debug.h>
-
-
-/* TYPES **********************************************************************/
-
-typedef struct _ALIAS_ENTRY
-{
- LPCWSTR lpSource;
- LPCWSTR lpTarget;
- struct _ALIAS_ENTRY* Next;
-} ALIAS_ENTRY, *PALIAS_ENTRY;
-
-typedef struct _ALIAS_HEADER
-{
- LPCWSTR lpExeName;
- PALIAS_ENTRY Data;
- struct _ALIAS_HEADER* Next;
-} ALIAS_HEADER, *PALIAS_HEADER;
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-static
-PALIAS_HEADER
-IntFindAliasHeader(PALIAS_HEADER RootHeader, LPCWSTR lpExeName)
-{
- while (RootHeader)
- {
- INT diff = _wcsicmp(RootHeader->lpExeName, lpExeName);
- if (!diff) return RootHeader;
- if (diff > 0) break;
-
- RootHeader = RootHeader->Next;
- }
- return NULL;
-}
-
-PALIAS_HEADER
-IntCreateAliasHeader(LPCWSTR lpExeName)
-{
- PALIAS_HEADER Entry;
- UINT dwLength = wcslen(lpExeName) + 1;
-
- Entry = ConsoleAllocHeap(0, sizeof(ALIAS_HEADER) + sizeof(WCHAR) * dwLength);
- if (!Entry) return Entry;
-
- Entry->lpExeName = (LPCWSTR)(Entry + 1);
- wcscpy((PWCHAR)Entry->lpExeName, lpExeName);
- Entry->Data = NULL;
- Entry->Next = NULL;
- return Entry;
-}
-
-VOID
-IntInsertAliasHeader(PALIAS_HEADER * RootHeader, PALIAS_HEADER NewHeader)
-{
- PALIAS_HEADER CurrentHeader;
- PALIAS_HEADER *LastLink = RootHeader;
-
- while ((CurrentHeader = *LastLink) != NULL)
- {
- INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName);
- if (Diff < 0) break;
-
- LastLink = &CurrentHeader->Next;
- }
-
- *LastLink = NewHeader;
- NewHeader->Next = CurrentHeader;
-}
-
-PALIAS_ENTRY
-IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName)
-{
- PALIAS_ENTRY RootHeader;
-
- if (Header == NULL) return NULL;
-
- RootHeader = Header->Data;
- while (RootHeader)
- {
- INT diff;
- DPRINT("IntGetAliasEntry->lpSource %S\n", RootHeader->lpSource);
- diff = _wcsicmp(RootHeader->lpSource, lpSrcName);
- if (!diff) return RootHeader;
- if (diff > 0) break;
-
- RootHeader = RootHeader->Next;
- }
- return NULL;
-}
-
-VOID
-IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry)
-{
- PALIAS_ENTRY CurrentEntry;
- PALIAS_ENTRY *LastLink = &Header->Data;
-
- while ((CurrentEntry = *LastLink) != NULL)
- {
- INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource);
- if (Diff < 0) break;
-
- LastLink = &CurrentEntry->Next;
- }
-
- *LastLink = NewEntry;
- NewEntry->Next = CurrentEntry;
-}
-
-PALIAS_ENTRY
-IntCreateAliasEntry(LPCWSTR lpSource, LPCWSTR lpTarget)
-{
- UINT dwSource;
- UINT dwTarget;
- PALIAS_ENTRY Entry;
-
- dwSource = wcslen(lpSource) + 1;
- dwTarget = wcslen(lpTarget) + 1;
-
- Entry = ConsoleAllocHeap(0, sizeof(ALIAS_ENTRY) + sizeof(WCHAR) * (dwSource +
dwTarget));
- if (!Entry) return Entry;
-
- Entry->lpSource = (LPCWSTR)(Entry + 1);
- wcscpy((LPWSTR)Entry->lpSource, lpSource);
- Entry->lpTarget = Entry->lpSource + dwSource;
- wcscpy((LPWSTR)Entry->lpTarget, lpTarget);
- Entry->Next = NULL;
-
- return Entry;
-}
-
-UINT
-IntGetConsoleAliasesExesLength(PALIAS_HEADER RootHeader)
-{
- UINT length = 0;
-
- while (RootHeader)
- {
- length += (wcslen(RootHeader->lpExeName) + 1) * sizeof(WCHAR);
- RootHeader = RootHeader->Next;
- }
- if (length)
- length += sizeof(WCHAR); // last entry entry is terminated with 2 zero bytes
-
- return length;
-}
-
-UINT
-IntGetConsoleAliasesExes(PALIAS_HEADER RootHeader, LPWSTR TargetBuffer, UINT
TargetBufferSize)
-{
- UINT Offset = 0;
- UINT Length;
-
- TargetBufferSize /= sizeof(WCHAR);
- while (RootHeader)
- {
- Length = wcslen(RootHeader->lpExeName) + 1;
- if (TargetBufferSize > Offset + Length)
- {
- wcscpy(&TargetBuffer[Offset], RootHeader->lpExeName);
- Offset += Length;
- }
- else
- {
- break;
- }
- RootHeader = RootHeader->Next;
- }
- Length = min(Offset+1, TargetBufferSize);
- TargetBuffer[Length] = L'\0';
- return Length * sizeof(WCHAR);
-}
-
-UINT
-IntGetAllConsoleAliasesLength(PALIAS_HEADER Header)
-{
- UINT Length = 0;
- PALIAS_ENTRY CurEntry = Header->Data;
-
- while (CurEntry)
- {
- Length += wcslen(CurEntry->lpSource);
- Length += wcslen(CurEntry->lpTarget);
- Length += 2; // zero byte and '='
- CurEntry = CurEntry->Next;
- }
-
- if (Length)
- {
- return (Length+1) * sizeof(WCHAR);
- }
- return 0;
-}
-
-UINT
-IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT
TargetBufferLength)
-{
- PALIAS_ENTRY CurEntry = Header->Data;
- UINT Offset = 0;
- UINT SrcLength, TargetLength;
-
- TargetBufferLength /= sizeof(WCHAR);
- while (CurEntry)
- {
- SrcLength = wcslen(CurEntry->lpSource) + 1;
- TargetLength = wcslen(CurEntry->lpTarget) + 1;
- if (Offset + TargetLength + SrcLength >= TargetBufferLength)
- break;
-
- wcscpy(&TargetBuffer[Offset], CurEntry->lpSource);
- Offset += SrcLength;
- TargetBuffer[Offset] = L'=';
- wcscpy(&TargetBuffer[Offset], CurEntry->lpTarget);
- Offset += TargetLength;
-
- CurEntry = CurEntry->Next;
- }
- TargetBuffer[Offset] = L'\0';
- return Offset * sizeof(WCHAR);
-}
-
-VOID
-IntDeleteAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY Entry)
-{
- PALIAS_ENTRY *LastLink = &Header->Data;
- PALIAS_ENTRY CurEntry;
-
- while ((CurEntry = *LastLink) != NULL)
- {
- if (CurEntry == Entry)
- {
- *LastLink = Entry->Next;
- ConsoleFreeHeap(Entry);
- return;
- }
- LastLink = &CurEntry->Next;
- }
-}
-
-VOID
-IntDeleteAllAliases(PCONSOLE Console)
-{
- PALIAS_HEADER Header, NextHeader;
- PALIAS_ENTRY Entry, NextEntry;
-
- for (Header = Console->Aliases; Header; Header = NextHeader)
- {
- NextHeader = Header->Next;
- for (Entry = Header->Data; Entry; Entry = NextEntry)
- {
- NextEntry = Entry->Next;
- ConsoleFreeHeap(Entry);
- }
- ConsoleFreeHeap(Header);
- }
-}
-
-
-/* PUBLIC SERVER APIS *********************************************************/
-
-/* API_NUMBER: ConsolepAddAlias */
-CSR_API(SrvAddConsoleAlias)
-{
- PCONSOLE_ADDGETALIAS ConsoleAliasRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
- PCONSOLE Console;
- PALIAS_HEADER Header;
- PALIAS_ENTRY Entry;
- LPWSTR lpSource, lpTarget, lpExeName;
-
- DPRINT("SrvAddConsoleAlias entered ApiMessage %p\n", ApiMessage);
-
- if ( !CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&ConsoleAliasRequest->Source,
- ConsoleAliasRequest->SourceLength,
- sizeof(BYTE)) ||
- !CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&ConsoleAliasRequest->Target,
- ConsoleAliasRequest->TargetLength,
- sizeof(BYTE)) ||
- !CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&ConsoleAliasRequest->Exe,
- ConsoleAliasRequest->ExeLength,
- sizeof(BYTE)) )
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- lpSource = ConsoleAliasRequest->Source;
- lpTarget = (ConsoleAliasRequest->TargetLength != 0 ?
ConsoleAliasRequest->Target : NULL);
- lpExeName = ConsoleAliasRequest->Exe;
-
- DPRINT("SrvAddConsoleAlias lpSource %p lpExeName %p lpTarget %p\n",
lpSource, lpExeName, lpTarget);
-
- if (lpExeName == NULL || lpSource == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status =
ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console,
TRUE);
- if (!NT_SUCCESS(ApiMessage->Status))
- {
- return ApiMessage->Status;
- }
-
- Header = IntFindAliasHeader(Console->Aliases, lpExeName);
- if (!Header && lpTarget != NULL)
- {
- Header = IntCreateAliasHeader(lpExeName);
- if (!Header)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
- IntInsertAliasHeader(&Console->Aliases, Header);
- }
-
- if (lpTarget == NULL) // Delete the entry
- {
- Entry = IntGetAliasEntry(Header, lpSource);
- if (Entry)
- {
- IntDeleteAliasEntry(Header, Entry);
- ApiMessage->Status = STATUS_SUCCESS;
- }
- else
- {
- ApiMessage->Status = STATUS_INVALID_PARAMETER;
- }
- ConSrvReleaseConsole(Console, TRUE);
- return ApiMessage->Status;
- }
-
- Entry = IntCreateAliasEntry(lpSource, lpTarget);
-
- if (!Entry)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- IntInsertAliasEntry(Header, Entry);
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_SUCCESS;
-}
-
-/* API_NUMBER: ConsolepGetAlias */
-CSR_API(SrvGetConsoleAlias)
-{
- PCONSOLE_ADDGETALIAS ConsoleAliasRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
- PCONSOLE Console;
- PALIAS_HEADER Header;
- PALIAS_ENTRY Entry;
- UINT Length;
- LPWSTR lpSource, lpTarget, lpExeName;
-
- DPRINT("SrvGetConsoleAlias entered ApiMessage %p\n", ApiMessage);
-
- if ( !CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&ConsoleAliasRequest->Source,
- ConsoleAliasRequest->SourceLength,
- sizeof(BYTE)) ||
- !CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&ConsoleAliasRequest->Target,
- ConsoleAliasRequest->TargetLength,
- sizeof(BYTE)) ||
- !CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&ConsoleAliasRequest->Exe,
- ConsoleAliasRequest->ExeLength,
- sizeof(BYTE)) )
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- lpSource = ConsoleAliasRequest->Source;
- lpTarget = ConsoleAliasRequest->Target;
- lpExeName = ConsoleAliasRequest->Exe;
-
- DPRINT("SrvGetConsoleAlias lpExeName %p lpSource %p TargetBuffer %p TargetLength
%u\n",
- lpExeName, lpSource, lpTarget, ConsoleAliasRequest->TargetLength);
-
- if (ConsoleAliasRequest->ExeLength == 0 || lpTarget == NULL ||
- ConsoleAliasRequest->TargetLength == 0 ||
ConsoleAliasRequest->SourceLength == 0)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status =
ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console,
TRUE);
- if (!NT_SUCCESS(ApiMessage->Status))
- {
- return ApiMessage->Status;
- }
-
- Header = IntFindAliasHeader(Console->Aliases, lpExeName);
- if (!Header)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_INVALID_PARAMETER;
- }
-
- Entry = IntGetAliasEntry(Header, lpSource);
- if (!Entry)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_INVALID_PARAMETER;
- }
-
- Length = (wcslen(Entry->lpTarget) + 1) * sizeof(WCHAR);
- if (Length > ConsoleAliasRequest->TargetLength)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_BUFFER_TOO_SMALL;
- }
-
- wcscpy(lpTarget, Entry->lpTarget);
- ConsoleAliasRequest->TargetLength = Length;
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_SUCCESS;
-}
-
-/* API_NUMBER: ConsolepGetAliases */
-CSR_API(SrvGetConsoleAliases)
-{
- PCONSOLE_GETALLALIASES GetAllAliasesRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesRequest;
- PCONSOLE Console;
- ULONG BytesWritten;
- PALIAS_HEADER Header;
-
- if ( !CsrValidateMessageBuffer(ApiMessage,
- (PVOID)&GetAllAliasesRequest->ExeName,
- GetAllAliasesRequest->ExeLength,
- sizeof(BYTE)) ||
- !CsrValidateMessageBuffer(ApiMessage,
- (PVOID)&GetAllAliasesRequest->AliasesBuffer,
- GetAllAliasesRequest->AliasesBufferLength,
- sizeof(BYTE)) )
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- if (GetAllAliasesRequest->ExeName == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status =
ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console,
TRUE);
- if (!NT_SUCCESS(ApiMessage->Status))
- {
- return ApiMessage->Status;
- }
-
- Header = IntFindAliasHeader(Console->Aliases, GetAllAliasesRequest->ExeName);
- if (!Header)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_INVALID_PARAMETER;
- }
-
- if (IntGetAllConsoleAliasesLength(Header) >
GetAllAliasesRequest->AliasesBufferLength)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_BUFFER_OVERFLOW;
- }
-
- BytesWritten = IntGetAllConsoleAliases(Header,
- GetAllAliasesRequest->AliasesBuffer,
-
GetAllAliasesRequest->AliasesBufferLength);
-
- GetAllAliasesRequest->AliasesBufferLength = BytesWritten;
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_SUCCESS;
-}
-
-/* API_NUMBER: ConsolepGetAliasesLength */
-CSR_API(SrvGetConsoleAliasesLength)
-{
- PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesLengthRequest;
- PCONSOLE Console;
- PALIAS_HEADER Header;
- UINT Length;
-
- if (!CsrValidateMessageBuffer(ApiMessage,
- (PVOID)&GetAllAliasesLengthRequest->ExeName,
- GetAllAliasesLengthRequest->ExeLength,
- sizeof(BYTE)))
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- if (GetAllAliasesLengthRequest->ExeName == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status =
ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console,
TRUE);
- if (!NT_SUCCESS(ApiMessage->Status))
- {
- return ApiMessage->Status;
- }
-
- Header = IntFindAliasHeader(Console->Aliases,
GetAllAliasesLengthRequest->ExeName);
- if (!Header)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_INVALID_PARAMETER;
- }
-
- Length = IntGetAllConsoleAliasesLength(Header);
- GetAllAliasesLengthRequest->Length = Length;
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_SUCCESS;
-}
-
-/* API_NUMBER: ConsolepGetAliasExes */
-CSR_API(SrvGetConsoleAliasExes)
-{
- PCONSOLE_GETALIASESEXES GetAliasesExesRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesRequest;
- PCONSOLE Console;
- UINT BytesWritten;
- UINT ExesLength;
-
- DPRINT("SrvGetConsoleAliasExes entered\n");
-
- if (!CsrValidateMessageBuffer(ApiMessage,
- (PVOID)&GetAliasesExesRequest->ExeNames,
- GetAliasesExesRequest->Length,
- sizeof(BYTE)))
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status =
ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console,
TRUE);
- if (!NT_SUCCESS(ApiMessage->Status))
- {
- return ApiMessage->Status;
- }
-
- ExesLength = IntGetConsoleAliasesExesLength(Console->Aliases);
-
- if (ExesLength > GetAliasesExesRequest->Length)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_BUFFER_OVERFLOW;
- }
-
- if (GetAliasesExesRequest->ExeNames == NULL)
- {
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_INVALID_PARAMETER;
- }
-
- BytesWritten = IntGetConsoleAliasesExes(Console->Aliases,
- GetAliasesExesRequest->ExeNames,
- GetAliasesExesRequest->Length);
-
- GetAliasesExesRequest->Length = BytesWritten;
- ConSrvReleaseConsole(Console, TRUE);
- return STATUS_SUCCESS;
-}
-
-/* API_NUMBER: ConsolepGetAliasExesLength */
-CSR_API(SrvGetConsoleAliasExesLength)
-{
- PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesLengthRequest;
- PCONSOLE Console;
- DPRINT("SrvGetConsoleAliasExesLength entered\n");
-
- ApiMessage->Status =
ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console,
TRUE);
- if (NT_SUCCESS(ApiMessage->Status))
- {
- GetAliasesExesLengthRequest->Length =
IntGetConsoleAliasesExesLength(Console->Aliases);
- ConSrvReleaseConsole(Console, TRUE);
- }
- return ApiMessage->Status;
-}
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/alias.h
b/win32ss/user/winsrv/consrv_new/alias.h
deleted file mode 100644
index 1a3909cbf33..00000000000
--- a/win32ss/user/winsrv/consrv_new/alias.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * LICENSE: GPL - See COPYING in the top level directory
- * PROJECT: ReactOS Console Server DLL
- * FILE: win32ss/user/winsrv/consrv_new/alias.h
- * PURPOSE: Alias support functions
- * PROGRAMMERS: Christoph Wittich
- * Johannes Anderwald
- */
-
-#pragma once
-
-VOID IntDeleteAllAliases(PCONSOLE Console);
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/api.h b/win32ss/user/winsrv/consrv_new/api.h
deleted file mode 100644
index f5357f72ae7..00000000000
--- a/win32ss/user/winsrv/consrv_new/api.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Server DLL
- * FILE: win32ss/user/winsrv/consrv_new/api.h
- * PURPOSE: Public server APIs definitions
- * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- */
-
-#pragma once
-
-/* alias.c */
-CSR_API(SrvAddConsoleAlias);
-CSR_API(SrvGetConsoleAlias);
-CSR_API(SrvGetConsoleAliases);
-CSR_API(SrvGetConsoleAliasesLength);
-CSR_API(SrvGetConsoleAliasExes);
-CSR_API(SrvGetConsoleAliasExesLength);
-
-/* coninput.c */
-CSR_API(SrvReadConsole);
-CSR_API(SrvGetConsoleInput);
-CSR_API(SrvWriteConsoleInput);
-CSR_API(SrvFlushConsoleInputBuffer);
-CSR_API(SrvGetConsoleNumberOfInputEvents);
-
-/* conoutput.c */
-CSR_API(SrvInvalidateBitMapRect);
-CSR_API(SrvReadConsoleOutput);
-CSR_API(SrvWriteConsole);
-CSR_API(SrvWriteConsoleOutput);
-CSR_API(SrvReadConsoleOutputString);
-CSR_API(SrvWriteConsoleOutputString);
-CSR_API(SrvFillConsoleOutput);
-CSR_API(SrvGetConsoleCursorInfo);
-CSR_API(SrvSetConsoleCursorInfo);
-CSR_API(SrvSetConsoleCursorPosition);
-CSR_API(SrvSetConsoleTextAttribute);
-CSR_API(SrvCreateConsoleScreenBuffer);
-CSR_API(SrvGetConsoleScreenBufferInfo);
-CSR_API(SrvSetConsoleActiveScreenBuffer);
-CSR_API(SrvScrollConsoleScreenBuffer);
-CSR_API(SrvSetConsoleScreenBufferSize);
-
-/* console.c */
-CSR_API(SrvAllocConsole);
-CSR_API(SrvAttachConsole);
-CSR_API(SrvFreeConsole);
-CSR_API(SrvGetConsoleMode);
-CSR_API(SrvSetConsoleMode);
-CSR_API(SrvGetConsoleTitle);
-CSR_API(SrvSetConsoleTitle);
-CSR_API(SrvGetConsoleHardwareState);
-CSR_API(SrvSetConsoleHardwareState);
-CSR_API(SrvGetConsoleDisplayMode);
-CSR_API(SrvSetConsoleDisplayMode);
-CSR_API(SrvGetLargestConsoleWindowSize);
-CSR_API(SrvShowConsoleCursor);
-CSR_API(SrvSetConsoleCursor);
-CSR_API(SrvConsoleMenuControl);
-CSR_API(SrvSetConsoleMenuClose);
-CSR_API(SrvSetConsoleWindowInfo);
-CSR_API(SrvGetConsoleWindow);
-CSR_API(SrvSetConsoleIcon);
-CSR_API(SrvGetConsoleCP);
-CSR_API(SrvSetConsoleCP);
-CSR_API(SrvGetConsoleProcessList);
-CSR_API(SrvGenerateConsoleCtrlEvent);
-CSR_API(SrvGetConsoleSelectionInfo);
-
-/* handle.c */
-CSR_API(SrvOpenConsole);
-CSR_API(SrvCloseHandle);
-CSR_API(SrvVerifyConsoleIoHandle);
-CSR_API(SrvDuplicateHandle);
-
-/* lineinput.c */
-CSR_API(SrvGetConsoleCommandHistory);
-CSR_API(SrvGetConsoleCommandHistoryLength);
-CSR_API(SrvExpungeConsoleCommandHistory);
-CSR_API(SrvSetConsoleNumberOfCommands);
-CSR_API(SrvGetConsoleHistory);
-CSR_API(SrvSetConsoleHistory);
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/condrv/coninput.c
b/win32ss/user/winsrv/consrv_new/condrv/coninput.c
deleted file mode 100644
index 96541e3ed33..00000000000
--- a/win32ss/user/winsrv/consrv_new/condrv/coninput.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Driver DLL
- * FILE: win32ss/user/winsrv/consrv_new/condrv/coninput.c
- * PURPOSE: Console Input functions
- * PROGRAMMERS: Jeffrey Morlan
- * Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "include/conio.h"
-#include "include/conio2.h"
-#include "handle.h"
-#include "lineinput.h"
-
-#define NDEBUG
-#include <debug.h>
-
-
-/* GLOBALS ********************************************************************/
-
-#define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
- ConSrvGetObject((ProcessData), (Handle), (PCONSOLE_IO_OBJECT*)(Ptr), NULL, \
- (Access), (LockConsole), INPUT_BUFFER)
-#define ConSrvGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access,
LockConsole) \
- ConSrvGetObject((ProcessData), (Handle), (PCONSOLE_IO_OBJECT*)(Ptr), (Entry),
\
- (Access), (LockConsole), INPUT_BUFFER)
-#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked) \
- ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))
-
-
-#define ConsoleInputUnicodeCharToAnsiChar(Console, dChar, sWChar) \
- WideCharToMultiByte((Console)->CodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
-
-#define ConsoleInputAnsiCharToUnicodeChar(Console, dWChar, sChar) \
- MultiByteToWideChar((Console)->CodePage, 0, (sChar), 1, (dWChar), 1)
-
-typedef struct ConsoleInput_t
-{
- LIST_ENTRY ListEntry;
- INPUT_RECORD InputEvent;
-} ConsoleInput;
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-static VOID FASTCALL
-ConioInputEventToAnsi(PCONSOLE Console, PINPUT_RECORD InputEvent)
-{
- if (InputEvent->EventType == KEY_EVENT)
- {
- WCHAR UnicodeChar = InputEvent->Event.KeyEvent.uChar.UnicodeChar;
- InputEvent->Event.KeyEvent.uChar.UnicodeChar = 0;
- ConsoleInputUnicodeCharToAnsiChar(Console,
-
&InputEvent->Event.KeyEvent.uChar.AsciiChar,
- &UnicodeChar);
- }
-}
-
-NTSTATUS FASTCALL
-ConioProcessInputEvent(PCONSOLE Console,
- PINPUT_RECORD InputEvent)
-{
- ConsoleInput *ConInRec;
-
- /* Check for pause or unpause */
- if (InputEvent->EventType == KEY_EVENT &&
InputEvent->Event.KeyEvent.bKeyDown)
- {
- WORD vk = InputEvent->Event.KeyEvent.wVirtualKeyCode;
- if (!(Console->PauseFlags & PAUSED_FROM_KEYBOARD))
- {
- DWORD cks = InputEvent->Event.KeyEvent.dwControlKeyState;
- if (Console->InputBuffer.Mode & ENABLE_LINE_INPUT &&
- (vk == VK_PAUSE || (vk == 'S' &&
- (cks & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
&&
- !(cks & (LEFT_ALT_PRESSED |
RIGHT_ALT_PRESSED)))))
- {
- ConioPause(Console, PAUSED_FROM_KEYBOARD);
- return STATUS_SUCCESS;
- }
- }
- else
- {
- if ((vk < VK_SHIFT || vk > VK_CAPITAL) && vk != VK_LWIN
&&
- vk != VK_RWIN && vk != VK_NUMLOCK && vk != VK_SCROLL)
- {
- ConioUnpause(Console, PAUSED_FROM_KEYBOARD);
- return STATUS_SUCCESS;
- }
- }
- }
-
- /* Add event to the queue */
- ConInRec = ConsoleAllocHeap(0, sizeof(ConsoleInput));
- if (ConInRec == NULL) return STATUS_INSUFFICIENT_RESOURCES;
-
- ConInRec->InputEvent = *InputEvent;
- InsertTailList(&Console->InputBuffer.InputEvents,
&ConInRec->ListEntry);
-
- SetEvent(Console->InputBuffer.ActiveEvent);
- CsrNotifyWait(&Console->InputBuffer.ReadWaitQueue,
- WaitAny,
- NULL,
- NULL);
- if (!IsListEmpty(&Console->InputBuffer.ReadWaitQueue))
- {
- CsrDereferenceWait(&Console->InputBuffer.ReadWaitQueue);
- }
-
- return STATUS_SUCCESS;
-}
-
-VOID FASTCALL
-PurgeInputBuffer(PCONSOLE Console)
-{
- PLIST_ENTRY CurrentEntry;
- ConsoleInput* Event;
-
- while (!IsListEmpty(&Console->InputBuffer.InputEvents))
- {
- CurrentEntry = RemoveHeadList(&Console->InputBuffer.InputEvents);
- Event = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
- ConsoleFreeHeap(Event);
- }
-
- CloseHandle(Console->InputBuffer.ActiveEvent);
-}
-
-VOID NTAPI
-ConDrvProcessKey(IN PCONSOLE Console,
- IN BOOLEAN Down,
- IN UINT VirtualKeyCode,
- IN UINT VirtualScanCode,
- IN WCHAR UnicodeChar,
- IN ULONG ShiftState,
- IN BYTE KeyStateCtrl)
-{
- INPUT_RECORD er;
-
- /* process Ctrl-C and Ctrl-Break */
- if ( Console->InputBuffer.Mode & ENABLE_PROCESSED_INPUT &&
- Down && (VirtualKeyCode == VK_PAUSE || VirtualKeyCode == 'C')
&&
- (ShiftState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) || KeyStateCtrl &
0x80) )
- {
- DPRINT1("Console_Api Ctrl-C\n");
- ConDrvConsoleProcessCtrlEvent(Console, 0, CTRL_C_EVENT);
-
- if (Console->LineBuffer && !Console->LineComplete)
- {
- /* Line input is in progress; end it */
- Console->LinePos = Console->LineSize = 0;
- Console->LineComplete = TRUE;
- }
- return;
- }
-
- if ( (ShiftState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) != 0 &&
- (VK_UP == VirtualKeyCode || VK_DOWN == VirtualKeyCode) )
- {
- if (!Down) return;
-
- /* scroll up or down */
- if (VK_UP == VirtualKeyCode)
- {
- /* only scroll up if there is room to scroll up into */
- if (Console->ActiveBuffer->CursorPosition.Y !=
Console->ActiveBuffer->ScreenBufferSize.Y - 1)
- {
- Console->ActiveBuffer->VirtualY =
(Console->ActiveBuffer->VirtualY +
-
Console->ActiveBuffer->ScreenBufferSize.Y - 1) %
-
Console->ActiveBuffer->ScreenBufferSize.Y;
- Console->ActiveBuffer->CursorPosition.Y++;
- }
- }
- else
- {
- /* only scroll down if there is room to scroll down into */
- if (Console->ActiveBuffer->CursorPosition.Y != 0)
- {
- Console->ActiveBuffer->VirtualY =
(Console->ActiveBuffer->VirtualY + 1) %
-
Console->ActiveBuffer->ScreenBufferSize.Y;
- Console->ActiveBuffer->CursorPosition.Y--;
- }
- }
-
- ConioDrawConsole(Console);
- return;
- }
-
- er.EventType = KEY_EVENT;
- er.Event.KeyEvent.bKeyDown = Down;
- er.Event.KeyEvent.wRepeatCount = 1;
- er.Event.KeyEvent.wVirtualKeyCode = VirtualKeyCode;
- er.Event.KeyEvent.wVirtualScanCode = VirtualScanCode;
- er.Event.KeyEvent.uChar.UnicodeChar = UnicodeChar;
- er.Event.KeyEvent.dwControlKeyState = ShiftState;
-
- ConioProcessInputEvent(Console, &er);
-}
-
-
-/* PUBLIC DRIVER APIS *********************************************************/
-
-NTSTATUS NTAPI
-ConDrvReadConsole(IN PCONSOLE Console,
- IN PCONSOLE_INPUT_BUFFER InputBuffer,
- IN BOOLEAN Unicode,
- OUT PVOID Buffer,
- IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl,
- IN ULONG NumCharsToRead,
- OUT PULONG NumCharsRead OPTIONAL)
-{
- // STATUS_PENDING : Wait if more to read ; STATUS_SUCCESS : Don't wait.
- NTSTATUS Status = STATUS_PENDING;
- PLIST_ENTRY CurrentEntry;
- ConsoleInput *Input;
- ULONG i = ReadControl->nInitialChars;
-
- if (Console == NULL || InputBuffer == NULL || /* Buffer == NULL || */
- ReadControl == NULL || ReadControl->nLength !=
sizeof(CONSOLE_READCONSOLE_CONTROL))
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Validity checks */
- ASSERT(Console == InputBuffer->Header.Console);
- ASSERT( (Buffer != NULL && NumCharsToRead >= 0) ||
- (Buffer == NULL && NumCharsToRead == 0) );
-
- /* We haven't read anything (yet) */
-
- if (InputBuffer->Mode & ENABLE_LINE_INPUT)
- {
- if (Console->LineBuffer == NULL)
- {
- /* Starting a new line */
- Console->LineMaxSize = (WORD)max(256, NumCharsToRead);
-
- Console->LineBuffer = ConsoleAllocHeap(0, Console->LineMaxSize *
sizeof(WCHAR));
- if (Console->LineBuffer == NULL) return STATUS_NO_MEMORY;
-
- Console->LineComplete = FALSE;
- Console->LineUpPressed = FALSE;
- Console->LineInsertToggle = 0;
- Console->LineWakeupMask = ReadControl->dwCtrlWakeupMask;
- Console->LineSize = ReadControl->nInitialChars;
- Console->LinePos = Console->LineSize;
-
- /*
- * Pre-filling the buffer is only allowed in the Unicode API,
- * so we don't need to worry about ANSI <-> Unicode conversion.
- */
- memcpy(Console->LineBuffer, Buffer, Console->LineSize *
sizeof(WCHAR));
- if (Console->LineSize == Console->LineMaxSize)
- {
- Console->LineComplete = TRUE;
- Console->LinePos = 0;
- }
- }
-
- /* If we don't have a complete line yet, process the pending input */
- while (!Console->LineComplete &&
!IsListEmpty(&InputBuffer->InputEvents))
- {
- /* Remove input event from queue */
- CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
- if (IsListEmpty(&InputBuffer->InputEvents))
- {
- ResetEvent(InputBuffer->ActiveEvent);
- }
- Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
-
- /* Only pay attention to key down */
- if (Input->InputEvent.EventType == KEY_EVENT &&
- Input->InputEvent.Event.KeyEvent.bKeyDown)
- {
- LineInputKeyDown(Console, &Input->InputEvent.Event.KeyEvent);
- ReadControl->dwControlKeyState =
Input->InputEvent.Event.KeyEvent.dwControlKeyState;
- }
- ConsoleFreeHeap(Input);
- }
-
- /* Check if we have a complete line to read from */
- if (Console->LineComplete)
- {
- while (i < NumCharsToRead && Console->LinePos !=
Console->LineSize)
- {
- WCHAR Char = Console->LineBuffer[Console->LinePos++];
-
- if (Unicode)
- {
- ((PWCHAR)Buffer)[i] = Char;
- }
- else
- {
- ConsoleInputUnicodeCharToAnsiChar(Console, &((PCHAR)Buffer)[i],
&Char);
- }
- ++i;
- }
-
- if (Console->LinePos == Console->LineSize)
- {
- /* Entire line has been read */
- ConsoleFreeHeap(Console->LineBuffer);
- Console->LineBuffer = NULL;
- }
-
- Status = STATUS_SUCCESS;
- }
- }
- else
- {
- /* Character input */
- while (i < NumCharsToRead &&
!IsListEmpty(&InputBuffer->InputEvents))
- {
- /* Remove input event from queue */
- CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
- if (IsListEmpty(&InputBuffer->InputEvents))
- {
- ResetEvent(InputBuffer->ActiveEvent);
- }
- Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
-
- /* Only pay attention to valid ASCII chars, on key down */
- if (Input->InputEvent.EventType == KEY_EVENT &&
- Input->InputEvent.Event.KeyEvent.bKeyDown &&
- Input->InputEvent.Event.KeyEvent.uChar.UnicodeChar != L'\0')
- {
- WCHAR Char = Input->InputEvent.Event.KeyEvent.uChar.UnicodeChar;
-
- if (Unicode)
- {
- ((PWCHAR)Buffer)[i] = Char;
- }
- else
- {
- ConsoleInputUnicodeCharToAnsiChar(Console, &((PCHAR)Buffer)[i],
&Char);
- }
- ++i;
-
- /* Did read something */
- Status = STATUS_SUCCESS;
- }
- ConsoleFreeHeap(Input);
- }
- }
-
- if (NumCharsRead) *NumCharsRead = i;
-
- return Status;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleInput(IN PCONSOLE Console,
- IN PCONSOLE_INPUT_BUFFER InputBuffer,
- IN BOOLEAN WaitForMoreEvents,
- IN BOOLEAN Unicode,
- OUT PINPUT_RECORD InputRecord,
- IN ULONG NumEventsToRead,
- OUT PULONG NumEventsRead OPTIONAL)
-{
- PLIST_ENTRY CurrentInput;
- ConsoleInput* Input;
- ULONG i = 0;
-
- if (Console == NULL || InputBuffer == NULL /* || InputRecord == NULL */)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity checks */
- ASSERT(Console == InputBuffer->Header.Console);
- ASSERT( (InputRecord != NULL && NumEventsToRead >= 0) ||
- (InputRecord == NULL && NumEventsToRead == 0) );
-
- // Do NOT do that !! Use the existing number of events already read, if any...
- // if (NumEventsRead) *NumEventsRead = 0;
-
- if (IsListEmpty(&InputBuffer->InputEvents))
- {
- /*
- * No input is available. Wait for more input if requested,
- * otherwise, we don't wait, so we return success.
- */
- return (WaitForMoreEvents ? STATUS_PENDING : STATUS_SUCCESS);
- }
-
- /* Only get input if there is any */
- CurrentInput = InputBuffer->InputEvents.Flink;
- if (NumEventsRead) i = *NumEventsRead; // We will read the remaining events...
-
- while ((CurrentInput != &InputBuffer->InputEvents) && (i <
NumEventsToRead))
- {
- Input = CONTAINING_RECORD(CurrentInput, ConsoleInput, ListEntry);
-
- *InputRecord = Input->InputEvent;
-
- if (!Unicode)
- {
- ConioInputEventToAnsi(InputBuffer->Header.Console, InputRecord);
- }
-
- ++InputRecord;
- ++i;
- CurrentInput = CurrentInput->Flink;
-
- if (WaitForMoreEvents) // TRUE --> Read, we remove inputs from the buffer ;
FALSE --> Peek, we keep inputs.
- {
- RemoveEntryList(&Input->ListEntry);
- ConsoleFreeHeap(Input);
- }
- }
-
- if (NumEventsRead) *NumEventsRead = i;
-
- if (IsListEmpty(&InputBuffer->InputEvents))
- {
- ResetEvent(InputBuffer->ActiveEvent);
- }
-
- /* We read all the inputs available, we return success */
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvWriteConsoleInput(IN PCONSOLE Console,
- IN PCONSOLE_INPUT_BUFFER InputBuffer,
- IN BOOLEAN Unicode,
- IN PINPUT_RECORD InputRecord,
- IN ULONG NumEventsToWrite,
- OUT PULONG NumEventsWritten OPTIONAL)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG i;
-
- if (Console == NULL || InputBuffer == NULL /* || InputRecord == NULL */)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity checks */
- ASSERT(Console == InputBuffer->Header.Console);
- ASSERT( (InputRecord != NULL && NumEventsToWrite >= 0) ||
- (InputRecord == NULL && NumEventsToWrite == 0) );
-
- // Do NOT do that !! Use the existing number of events already written, if any...
- // if (NumEventsWritten) *NumEventsWritten = 0;
-
- for (i = (NumEventsWritten ? *NumEventsWritten : 0); i < NumEventsToWrite
&& NT_SUCCESS(Status); ++i)
- {
- if (InputRecord->EventType == KEY_EVENT && !Unicode)
- {
- CHAR AsciiChar = InputRecord->Event.KeyEvent.uChar.AsciiChar;
- ConsoleInputAnsiCharToUnicodeChar(Console,
-
&InputRecord->Event.KeyEvent.uChar.UnicodeChar,
- &AsciiChar);
- }
-
- Status = ConioProcessInputEvent(Console, InputRecord++);
- }
-
- if (NumEventsWritten) *NumEventsWritten = i;
-
- return Status;
-}
-
-NTSTATUS NTAPI
-ConDrvFlushConsoleInputBuffer(IN PCONSOLE Console,
- IN PCONSOLE_INPUT_BUFFER InputBuffer)
-{
- PLIST_ENTRY CurrentEntry;
- ConsoleInput* Event;
-
- if (Console == NULL || InputBuffer == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == InputBuffer->Header.Console);
-
- /* Discard all entries in the input event queue */
- while (!IsListEmpty(&InputBuffer->InputEvents))
- {
- CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
- Event = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
- ConsoleFreeHeap(Event);
- }
- ResetEvent(InputBuffer->ActiveEvent);
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleNumberOfInputEvents(IN PCONSOLE Console,
- IN PCONSOLE_INPUT_BUFFER InputBuffer,
- OUT PULONG NumEvents)
-{
- PLIST_ENTRY CurrentInput;
-
- if (Console == NULL || InputBuffer == NULL || NumEvents == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == InputBuffer->Header.Console);
-
- *NumEvents = 0;
-
- /* If there are any events ... */
- CurrentInput = InputBuffer->InputEvents.Flink;
- while (CurrentInput != &InputBuffer->InputEvents)
- {
- CurrentInput = CurrentInput->Flink;
- (*NumEvents)++;
- }
-
- return STATUS_SUCCESS;
-}
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/condrv/conoutput.c
b/win32ss/user/winsrv/consrv_new/condrv/conoutput.c
deleted file mode 100644
index fef4900d30d..00000000000
--- a/win32ss/user/winsrv/consrv_new/condrv/conoutput.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Driver DLL
- * FILE: win32ss/user/winsrv/consrv_new/condrv/conoutput.c
- * PURPOSE: General Console Output Functions
- * PROGRAMMERS: Jeffrey Morlan
- * Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "console.h"
-#include "include/conio.h"
-#include "include/conio2.h"
-#include "conoutput.h"
-#include "handle.h"
-
-#define NDEBUG
-#include <debug.h>
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-NTSTATUS
-TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN PTEXTMODE_BUFFER_INFO TextModeInfo);
-NTSTATUS
-GRAPHICS_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN PGRAPHICS_BUFFER_INFO GraphicsInfo);
-
-VOID
-TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer);
-VOID
-GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer);
-
-
-NTSTATUS
-CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN SIZE_T Size)
-{
- if (Buffer == NULL || Console == NULL)
- return STATUS_INVALID_PARAMETER;
-
- *Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, max(sizeof(CONSOLE_SCREEN_BUFFER),
Size));
- if (*Buffer == NULL) return STATUS_INSUFFICIENT_RESOURCES;
-
- /* Initialize the header with the default type */
- ConSrvInitObject(&(*Buffer)->Header, SCREEN_BUFFER, Console);
- (*Buffer)->Vtbl = NULL;
- return STATUS_SUCCESS;
-}
-
-VOID
-CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
-{
- if (Buffer->Header.Type == TEXTMODE_BUFFER)
- TEXTMODE_BUFFER_Destroy(Buffer);
- else if (Buffer->Header.Type == GRAPHICS_BUFFER)
- GRAPHICS_BUFFER_Destroy(Buffer);
- else if (Buffer->Header.Type == SCREEN_BUFFER)
- ConsoleFreeHeap(Buffer);
- // else
- // do_nothing;
-}
-
-// ConDrvCreateConsoleScreenBuffer
-NTSTATUS FASTCALL
-ConDrvCreateScreenBuffer(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN ULONG BufferType,
- IN PVOID ScreenBufferInfo)
-{
- NTSTATUS Status = STATUS_SUCCESS;
-
- if ( Console == NULL || Buffer == NULL ||
- (BufferType != CONSOLE_TEXTMODE_BUFFER && BufferType !=
CONSOLE_GRAPHICS_BUFFER) )
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- if (BufferType == CONSOLE_TEXTMODE_BUFFER)
- {
- Status = TEXTMODE_BUFFER_Initialize(Buffer,
- Console,
- (PTEXTMODE_BUFFER_INFO)ScreenBufferInfo);
- }
- else if (BufferType == CONSOLE_GRAPHICS_BUFFER)
- {
- Status = GRAPHICS_BUFFER_Initialize(Buffer,
- Console,
- (PGRAPHICS_BUFFER_INFO)ScreenBufferInfo);
- }
- else
- {
- /* Never ever go there!! */
- ASSERT(FALSE);
- }
-
- /* Insert the newly created screen buffer into the list, if succeeded */
- if (NT_SUCCESS(Status)) InsertHeadList(&Console->BufferList,
&(*Buffer)->ListEntry);
-
- return Status;
-}
-
-static VOID
-ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer);
-
-VOID WINAPI
-ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
-{
- PCONSOLE Console = Buffer->Header.Console;
- PCONSOLE_SCREEN_BUFFER NewBuffer;
-
- RemoveEntryList(&Buffer->ListEntry);
- if (Buffer == Console->ActiveBuffer)
- {
- /* Delete active buffer; switch to most recently created */
- Console->ActiveBuffer = NULL;
- if (!IsListEmpty(&Console->BufferList))
- {
- NewBuffer = CONTAINING_RECORD(Console->BufferList.Flink,
- CONSOLE_SCREEN_BUFFER,
- ListEntry);
- ConioSetActiveScreenBuffer(NewBuffer);
- }
- }
-
- CONSOLE_SCREEN_BUFFER_Destroy(Buffer);
-}
-
-VOID FASTCALL
-ConioDrawConsole(PCONSOLE Console)
-{
- SMALL_RECT Region;
- PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer;
-
- if (ActiveBuffer)
- {
- ConioInitRect(&Region, 0, 0, ActiveBuffer->ViewSize.Y - 1,
ActiveBuffer->ViewSize.X - 1);
- ConioDrawRegion(Console, &Region);
- }
-}
-
-static VOID
-ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
-{
- PCONSOLE Console = Buffer->Header.Console;
- Console->ActiveBuffer = Buffer;
- ConioResizeTerminal(Console);
- // ConioDrawConsole(Console);
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleActiveScreenBuffer(IN PCONSOLE Console,
- IN PCONSOLE_SCREEN_BUFFER Buffer)
-{
- if (Console == NULL || Buffer == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- if (Buffer == Console->ActiveBuffer) return STATUS_SUCCESS;
-
- /* If old buffer has no handles, it's now unreferenced */
- if (Console->ActiveBuffer->Header.HandleCount == 0)
- {
- ConioDeleteScreenBuffer(Console->ActiveBuffer);
- }
-
- /* Tie console to new buffer */
- ConioSetActiveScreenBuffer(Buffer);
-
- return STATUS_SUCCESS;
-}
-
-PCONSOLE_SCREEN_BUFFER
-ConDrvGetActiveScreenBuffer(IN PCONSOLE Console)
-{
- return (Console ? Console->ActiveBuffer : NULL);
-}
-
-/* PUBLIC DRIVER APIS *********************************************************/
-
-NTSTATUS NTAPI
-ConDrvInvalidateBitMapRect(IN PCONSOLE Console,
- IN PCONSOLE_SCREEN_BUFFER Buffer,
- IN PSMALL_RECT Region)
-{
- if (Console == NULL || Buffer == NULL || Region == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- /* If the output buffer is the current one, redraw the correct portion of the screen
*/
- if (Buffer == Console->ActiveBuffer) ConioDrawRegion(Console, Region);
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleCursorInfo(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- OUT PCONSOLE_CURSOR_INFO CursorInfo)
-{
- if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- *CursorInfo = Buffer->CursorInfo;
- // CursorInfo->bVisible = Buffer->CursorInfo.bVisible;
- // CursorInfo->dwSize = Buffer->CursorInfo.dwSize;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleCursorInfo(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN PCONSOLE_CURSOR_INFO CursorInfo)
-{
- ULONG Size;
- BOOLEAN Visible, Success = TRUE;
-
- if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- Size = min(max(CursorInfo->dwSize, 1), 100);
- Visible = CursorInfo->bVisible;
-
- if ( (Size != Buffer->CursorInfo.dwSize) ||
- (Visible && !Buffer->CursorInfo.bVisible) ||
- (!Visible && Buffer->CursorInfo.bVisible) )
- {
- Buffer->CursorInfo.dwSize = Size;
- Buffer->CursorInfo.bVisible = Visible;
-
- Success = ConioSetCursorInfo(Console, (PCONSOLE_SCREEN_BUFFER)Buffer);
- }
-
- return (Success ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleCursorPosition(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN PCOORD Position)
-{
- SHORT OldCursorX, OldCursorY;
-
- if (Console == NULL || Buffer == NULL || Position == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- if ( Position->X < 0 || Position->X >= Buffer->ScreenBufferSize.X ||
- Position->Y < 0 || Position->Y >= Buffer->ScreenBufferSize.Y )
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- OldCursorX = Buffer->CursorPosition.X;
- OldCursorY = Buffer->CursorPosition.Y;
- Buffer->CursorPosition = *Position;
- // Buffer->CursorPosition.X = Position->X;
- // Buffer->CursorPosition.Y = Position->Y;
- if ( ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer) &&
- (!ConioSetScreenInfo(Console, (PCONSOLE_SCREEN_BUFFER)Buffer, OldCursorX,
OldCursorY)) )
- {
- return STATUS_UNSUCCESSFUL;
- }
-
- return STATUS_SUCCESS;
-}
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/condrv/console.c
b/win32ss/user/winsrv/consrv_new/condrv/console.c
deleted file mode 100644
index e5ffef4f4a7..00000000000
--- a/win32ss/user/winsrv/consrv_new/condrv/console.c
+++ /dev/null
@@ -1,1106 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Driver DLL
- * FILE: win32ss/user/winsrv/consrv_new/condrv/console.c
- * PURPOSE: Console Management Functions
- * PROGRAMMERS: G� van Geldorp
- * Jeffrey Morlan
- * Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "include/conio.h"
-#include "include/conio2.h"
-#include "handle.h"
-#include "procinit.h"
-#include "alias.h"
-#include "coninput.h"
-#include "conoutput.h"
-#include "lineinput.h"
-#include "include/settings.h"
-
-#include "include/console.h"
-#include "console.h"
-#include "resource.h"
-
-#define NDEBUG
-#include <debug.h>
-
-// FIXME: Add this prototype to winternl.h / rtlfuncs.h / ...
-NTSTATUS NTAPI RtlGetLastNtStatus(VOID);
-
-
-/* GLOBALS ********************************************************************/
-
-static ULONG ConsoleListSize;
-static PCONSOLE* ConsoleList; /* The list of all the allocated consoles */
-static RTL_RESOURCE ListLock;
-
-#define ConDrvLockConsoleListExclusive() \
- RtlAcquireResourceExclusive(&ListLock, TRUE)
-
-#define ConDrvLockConsoleListShared() \
- RtlAcquireResourceShared(&ListLock, TRUE)
-
-#define ConDrvUnlockConsoleList() \
- RtlReleaseResource(&ListLock)
-
-// Adapted from reactos/lib/rtl/unicode.c, RtlCreateUnicodeString line 2180
-static BOOLEAN
-ConsoleCreateUnicodeString(IN OUT PUNICODE_STRING UniDest,
- IN PCWSTR Source)
-{
- SIZE_T Size = (wcslen(Source) + 1) * sizeof(WCHAR);
- if (Size > MAXUSHORT) return FALSE;
-
- UniDest->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Size);
- if (UniDest->Buffer == NULL) return FALSE;
-
- RtlCopyMemory(UniDest->Buffer, Source, Size);
- UniDest->MaximumLength = (USHORT)Size;
- UniDest->Length = (USHORT)Size - sizeof(WCHAR);
-
- return TRUE;
-}
-
-// Adapted from reactos/lib/rtl/unicode.c, RtlFreeUnicodeString line 431
-static VOID
-ConsoleFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
-{
- if (UnicodeString->Buffer)
- {
- ConsoleFreeHeap(UnicodeString->Buffer);
- RtlZeroMemory(UnicodeString, sizeof(UNICODE_STRING));
- }
-}
-
-
-static NTSTATUS
-InsertConsole(OUT PHANDLE Handle,
- IN PCONSOLE Console)
-{
-#define CONSOLE_HANDLES_INCREMENT 2 * 3
-
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG i = 0;
- PCONSOLE* Block;
-
- ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
- (ConsoleList != NULL && ConsoleListSize != 0) );
-
- /* All went right, so add the console to the list */
- ConDrvLockConsoleListExclusive();
- DPRINT1("Insert in the list\n");
-
- if (ConsoleList)
- {
- for (i = 0; i < ConsoleListSize; i++)
- {
- if (ConsoleList[i] == NULL) break;
- }
- }
-
- if (i >= ConsoleListSize)
- {
- DPRINT1("Creation of a new handles table\n");
- /* Allocate a new handles table */
- Block = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
- (ConsoleListSize +
- CONSOLE_HANDLES_INCREMENT) * sizeof(PCONSOLE));
- if (Block == NULL)
- {
- Status = STATUS_UNSUCCESSFUL;
- goto Quit;
- }
-
- /* If we previously had a handles table, free it and use the new one */
- if (ConsoleList)
- {
- /* Copy the handles from the old table to the new one */
- RtlCopyMemory(Block,
- ConsoleList,
- ConsoleListSize * sizeof(PCONSOLE));
- ConsoleFreeHeap(ConsoleList);
- }
- ConsoleList = Block;
- ConsoleListSize += CONSOLE_HANDLES_INCREMENT;
- }
-
- ConsoleList[i] = Console;
- *Handle = ULongToHandle((i << 2) | 0x3);
-
-Quit:
- /* Unlock the console list and return status */
- ConDrvUnlockConsoleList();
- return Status;
-}
-
-/* Unused */
-#if 0
-static NTSTATUS
-RemoveConsoleByHandle(IN HANDLE Handle)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG Index = HandleToULong(Handle) >> 2;
- PCONSOLE Console;
-
- ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
- (ConsoleList != NULL && ConsoleListSize != 0) );
-
- /* Remove the console from the list */
- ConDrvLockConsoleListExclusive();
-
- if (Index >= ConsoleListSize ||
- (Console = ConsoleList[Index]) == NULL)
- {
- Status = STATUS_INVALID_HANDLE;
- goto Quit;
- }
-
- ConsoleList[Index] = NULL;
-
-Quit:
- /* Unlock the console list and return status */
- ConDrvUnlockConsoleList();
- return Status;
-}
-#endif
-
-static NTSTATUS
-RemoveConsoleByPointer(IN PCONSOLE Console)
-{
- ULONG i = 0;
-
- if (!Console) return STATUS_INVALID_PARAMETER;
-
- ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
- (ConsoleList != NULL && ConsoleListSize != 0) );
-
- /* Remove the console from the list */
- ConDrvLockConsoleListExclusive();
-
- if (ConsoleList)
- {
- for (i = 0; i < ConsoleListSize; i++)
- {
- if (ConsoleList[i] == Console) ConsoleList[i] = NULL;
- }
- }
-
- /* Unlock the console list */
- ConDrvUnlockConsoleList();
-
- return STATUS_SUCCESS;
-}
-
-
-/* For resetting the frontend - defined in dummyfrontend.c */
-VOID ResetFrontEnd(IN PCONSOLE Console);
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-static NTSTATUS
-ConDrvConsoleCtrlEventTimeout(IN ULONG Event,
- IN PCONSOLE_PROCESS_DATA ProcessData,
- IN ULONG Timeout)
-{
- NTSTATUS Status = STATUS_SUCCESS;
-
- DPRINT("ConDrvConsoleCtrlEventTimeout Parent ProcessId = %x\n",
ProcessData->Process->ClientId.UniqueProcess);
-
- if (ProcessData->CtrlDispatcher)
- {
- _SEH2_TRY
- {
- HANDLE Thread = NULL;
-
- _SEH2_TRY
- {
- Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle,
NULL, 0,
- ProcessData->CtrlDispatcher,
- UlongToPtr(Event), 0, NULL);
- if (NULL == Thread)
- {
- Status = RtlGetLastNtStatus();
- DPRINT1("Failed thread creation, Status = 0x%08lx\n",
Status);
- }
- else
- {
- DPRINT("ProcessData->CtrlDispatcher remote thread creation
succeeded, ProcessId = %x, Process = 0x%p\n",
ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
- WaitForSingleObject(Thread, Timeout);
- }
- }
- _SEH2_FINALLY
- {
- CloseHandle(Thread);
- }
- _SEH2_END;
- }
- _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
- {
- Status = _SEH2_GetExceptionCode();
- DPRINT1("ConDrvConsoleCtrlEventTimeout - Caught an exception, Status =
0x%08lx\n", Status);
- }
- _SEH2_END;
- }
-
- return Status;
-}
-
-static NTSTATUS
-ConDrvConsoleCtrlEvent(IN ULONG Event,
- IN PCONSOLE_PROCESS_DATA ProcessData)
-{
- return ConDrvConsoleCtrlEventTimeout(Event, ProcessData, 0);
-}
-
-VOID FASTCALL
-ConioPause(PCONSOLE Console, UINT Flags)
-{
- Console->PauseFlags |= Flags;
- if (!Console->UnpauseEvent)
- Console->UnpauseEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
-}
-
-VOID FASTCALL
-ConioUnpause(PCONSOLE Console, UINT Flags)
-{
- Console->PauseFlags &= ~Flags;
-
- // if ((Console->PauseFlags & (PAUSED_FROM_KEYBOARD | PAUSED_FROM_SCROLLBAR |
PAUSED_FROM_SELECTION)) == 0)
- if (Console->PauseFlags == 0 && Console->UnpauseEvent)
- {
- SetEvent(Console->UnpauseEvent);
- CloseHandle(Console->UnpauseEvent);
- Console->UnpauseEvent = NULL;
-
- CsrNotifyWait(&Console->WriteWaitQueue,
- WaitAll,
- NULL,
- NULL);
- if (!IsListEmpty(&Console->WriteWaitQueue))
- {
- CsrDereferenceWait(&Console->WriteWaitQueue);
- }
- }
-}
-
-
-/*
- * Console accessibility check helpers
- */
-
-BOOLEAN NTAPI
-ConDrvValidateConsoleState(IN PCONSOLE Console,
- IN CONSOLE_STATE ExpectedState)
-{
- // if (!Console) return FALSE;
-
- /* The console must be locked */
- // ASSERT(Console_locked);
-
- return (Console->State == ExpectedState);
-}
-
-BOOLEAN NTAPI
-ConDrvValidateConsoleUnsafe(IN PCONSOLE Console,
- IN CONSOLE_STATE ExpectedState,
- IN BOOLEAN LockConsole)
-{
- if (!Console) return FALSE;
-
- /*
- * Lock the console to forbid possible console's state changes
- * (which must be done when the console is already locked).
- * If we don't want to lock it, it's because the lock is already
- * held. So there must be no problems.
- */
- if (LockConsole) EnterCriticalSection(&Console->Lock);
-
- // ASSERT(Console_locked);
-
- /* Check whether the console's state is what we expect */
- if (!ConDrvValidateConsoleState(Console, ExpectedState))
- {
- if (LockConsole) LeaveCriticalSection(&Console->Lock);
- return FALSE;
- }
-
- return TRUE;
-}
-
-BOOLEAN NTAPI
-ConDrvValidateConsole(OUT PCONSOLE* Console,
- IN HANDLE ConsoleHandle,
- IN CONSOLE_STATE ExpectedState,
- IN BOOLEAN LockConsole)
-{
- BOOLEAN RetVal = FALSE;
-
- ULONG Index = HandleToULong(ConsoleHandle) >> 2;
- PCONSOLE ValidatedConsole;
-
- if (!Console) return FALSE;
- *Console = NULL;
-
- /*
- * Forbid creation or deletion of consoles when
- * checking for the existence of a console.
- */
- ConDrvLockConsoleListShared();
-
- if (Index >= ConsoleListSize ||
- (ValidatedConsole = ConsoleList[Index]) == NULL)
- {
- /* Unlock the console list */
- ConDrvUnlockConsoleList();
-
- return FALSE;
- }
-
- ValidatedConsole = ConsoleList[Index];
-
- /* Unlock the console list and return */
- ConDrvUnlockConsoleList();
-
- RetVal = ConDrvValidateConsoleUnsafe(ValidatedConsole,
- ExpectedState,
- LockConsole);
- if (RetVal) *Console = ValidatedConsole;
-
- return RetVal;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsole(OUT PCONSOLE* Console,
- IN HANDLE ConsoleHandle,
- IN BOOLEAN LockConsole)
-{
- NTSTATUS Status = STATUS_INVALID_HANDLE;
- PCONSOLE GrabConsole;
-
- if (Console == NULL) return STATUS_INVALID_PARAMETER;
- *Console = NULL;
-
- if (ConDrvValidateConsole(&GrabConsole,
- ConsoleHandle,
- CONSOLE_RUNNING,
- LockConsole))
- {
- InterlockedIncrement(&GrabConsole->ReferenceCount);
- *Console = GrabConsole;
- Status = STATUS_SUCCESS;
- }
-
- return Status;
-}
-
-VOID NTAPI
-ConDrvReleaseConsole(IN PCONSOLE Console,
- IN BOOLEAN WasConsoleLocked)
-{
- LONG RefCount = 0;
-
- if (!Console) return;
- // if (Console->ReferenceCount == 0) return; // This shouldn't happen
- ASSERT(Console->ReferenceCount > 0);
-
- /* The console must be locked */
- // ASSERT(Console_locked);
-
- /*
- * Decrement the reference count. Save the new value too,
- * because Console->ReferenceCount might be modified after
- * the console gets unlocked but before we check whether we
- * can destroy it.
- */
- RefCount = _InterlockedDecrement(&Console->ReferenceCount);
-
- /* Unlock the console if needed */
- if (WasConsoleLocked) LeaveCriticalSection(&Console->Lock);
-
- /* Delete the console if needed */
- if (RefCount <= 0) ConDrvDeleteConsole(Console);
-}
-
-
-/* CONSOLE INITIALIZATION FUNCTIONS *******************************************/
-
-VOID NTAPI
-ConDrvInitConsoleSupport(VOID)
-{
- DPRINT("CONSRV: ConDrvInitConsoleSupport()\n");
-
- /* Initialize the console list and its lock */
- ConsoleListSize = 0;
- ConsoleList = NULL;
- RtlInitializeResource(&ListLock);
-
- /* Should call LoadKeyboardLayout */
-}
-
-NTSTATUS NTAPI
-ConDrvInitConsole(OUT PHANDLE NewConsoleHandle,
- OUT PCONSOLE* NewConsole,
- IN PCONSOLE_INFO ConsoleInfo,
- IN ULONG ConsoleLeaderProcessId)
-{
- NTSTATUS Status;
- SECURITY_ATTRIBUTES SecurityAttributes;
- // CONSOLE_INFO CapturedConsoleInfo;
- TEXTMODE_BUFFER_INFO ScreenBufferInfo;
- HANDLE ConsoleHandle;
- PCONSOLE Console;
- PCONSOLE_SCREEN_BUFFER NewBuffer;
- // WCHAR DefaultTitle[128];
-
- if (NewConsoleHandle == NULL || NewConsole == NULL || ConsoleInfo == NULL)
- return STATUS_INVALID_PARAMETER;
-
- *NewConsoleHandle = NULL;
- *NewConsole = NULL;
-
- /*
- * Allocate a console structure
- */
- Console = ConsoleAllocHeap(HEAP_ZERO_MEMORY, sizeof(CONSOLE));
- if (NULL == Console)
- {
- DPRINT1("Not enough memory for console creation.\n");
- return STATUS_NO_MEMORY;
- }
-
- /*
- * Load the console settings
- */
-
- /* 1. Load the default settings */
- // ConSrvGetDefaultSettings(ConsoleInfo, ProcessId);
-
- // /* 2. Get the title of the console (initialize ConsoleInfo.ConsoleTitle) */
- // Length = min(wcslen(ConsoleStartInfo->ConsoleTitle),
- // sizeof(ConsoleInfo.ConsoleTitle) /
sizeof(ConsoleInfo.ConsoleTitle[0]) - 1);
- // wcsncpy(ConsoleInfo.ConsoleTitle, ConsoleStartInfo->ConsoleTitle, Length);
- // ConsoleInfo.ConsoleTitle[Length] = L'\0';
-
- /*
- * 4. Load the remaining console settings via the registry.
- */
-#if 0
- if ((ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) == 0)
- {
- /*
- * Either we weren't created by an app launched via a shell-link,
- * or we failed to load shell-link console properties.
- * Therefore, load the console infos for the application from the registry.
- */
- ConSrvReadUserSettings(ConsoleInfo, ProcessId);
-
- /*
- * Now, update them with the properties the user might gave to us
- * via the STARTUPINFO structure before calling CreateProcess
- * (and which was transmitted via the ConsoleStartInfo structure).
- * We therefore overwrite the values read in the registry.
- */
- if (ConsoleStartInfo->dwStartupFlags & STARTF_USEFILLATTRIBUTE)
- {
- ConsoleInfo->ScreenAttrib = (USHORT)ConsoleStartInfo->FillAttribute;
- }
- if (ConsoleStartInfo->dwStartupFlags & STARTF_USECOUNTCHARS)
- {
- ConsoleInfo->ScreenBufferSize = ConsoleStartInfo->ScreenBufferSize;
- }
- if (ConsoleStartInfo->dwStartupFlags & STARTF_USESIZE)
- {
- // ConsoleInfo->ConsoleSize = ConsoleStartInfo->ConsoleWindowSize;
- ConsoleInfo->ConsoleSize.X =
(SHORT)ConsoleStartInfo->ConsoleWindowSize.cx;
- ConsoleInfo->ConsoleSize.Y =
(SHORT)ConsoleStartInfo->ConsoleWindowSize.cy;
- }
- }
-#endif
-
- /*
- * Fix the screen buffer size if needed. The rule is:
- * ScreenBufferSize >= ConsoleSize
- */
- if (ConsoleInfo->ScreenBufferSize.X < ConsoleInfo->ConsoleSize.X)
- ConsoleInfo->ScreenBufferSize.X = ConsoleInfo->ConsoleSize.X;
- if (ConsoleInfo->ScreenBufferSize.Y < ConsoleInfo->ConsoleSize.Y)
- ConsoleInfo->ScreenBufferSize.Y = ConsoleInfo->ConsoleSize.Y;
-
- /*
- * Initialize the console
- */
- Console->State = CONSOLE_INITIALIZING;
- Console->ReferenceCount = 0;
- InitializeCriticalSection(&Console->Lock);
- InitializeListHead(&Console->ProcessList);
-
- /* Initialize the frontend interface */
- ResetFrontEnd(Console);
-
- memcpy(Console->Colors, ConsoleInfo->Colors, sizeof(ConsoleInfo->Colors));
- Console->ConsoleSize = ConsoleInfo->ConsoleSize;
- Console->FixedSize = FALSE; // Value by default; is reseted by the front-ends if
needed.
-
- /*
- * Initialize the input buffer
- */
- ConSrvInitObject(&Console->InputBuffer.Header, INPUT_BUFFER, Console);
-
- SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
- SecurityAttributes.lpSecurityDescriptor = NULL;
- SecurityAttributes.bInheritHandle = TRUE;
- Console->InputBuffer.ActiveEvent = CreateEventW(&SecurityAttributes, TRUE,
FALSE, NULL);
- if (NULL == Console->InputBuffer.ActiveEvent)
- {
- DeleteCriticalSection(&Console->Lock);
- ConsoleFreeHeap(Console);
- return STATUS_UNSUCCESSFUL;
- }
-
- Console->InputBuffer.InputBufferSize = 0; // FIXME!
- InitializeListHead(&Console->InputBuffer.InputEvents);
- InitializeListHead(&Console->InputBuffer.ReadWaitQueue);
- Console->InputBuffer.Mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
- ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
-
- Console->QuickEdit = ConsoleInfo->QuickEdit;
- Console->InsertMode = ConsoleInfo->InsertMode;
- Console->LineBuffer = NULL;
- Console->LineMaxSize = Console->LineSize = Console->LinePos = 0;
- Console->LineComplete = Console->LineUpPressed = Console->LineInsertToggle =
FALSE;
- // LineWakeupMask
-
- // FIXME: This is terminal-specific !! VV
- RtlZeroMemory(&Console->Selection, sizeof(CONSOLE_SELECTION_INFO));
- Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
- // dwSelectionCursor
-
- /* Set-up the code page */
- Console->CodePage = Console->OutputCodePage = ConsoleInfo->CodePage;
-
- /* Initialize a new text-mode screen buffer with default settings */
- ScreenBufferInfo.ScreenBufferSize = ConsoleInfo->ScreenBufferSize;
- ScreenBufferInfo.ScreenAttrib = ConsoleInfo->ScreenAttrib;
- ScreenBufferInfo.PopupAttrib = ConsoleInfo->PopupAttrib;
- ScreenBufferInfo.IsCursorVisible = TRUE;
- ScreenBufferInfo.CursorSize = ConsoleInfo->CursorSize;
-
- InitializeListHead(&Console->BufferList);
- Status = ConDrvCreateScreenBuffer(&NewBuffer,
- Console,
- CONSOLE_TEXTMODE_BUFFER,
- &ScreenBufferInfo);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ConDrvCreateScreenBuffer: failed, Status = 0x%08lx\n",
Status);
- CloseHandle(Console->InputBuffer.ActiveEvent);
- DeleteCriticalSection(&Console->Lock);
- ConsoleFreeHeap(Console);
- return Status;
- }
- /* Make the new screen buffer active */
- Console->ActiveBuffer = NewBuffer;
- InitializeListHead(&Console->WriteWaitQueue);
- Console->PauseFlags = 0;
- Console->UnpauseEvent = NULL;
-
- /*
- * Initialize the alias and history buffers
- */
- Console->Aliases = NULL;
- InitializeListHead(&Console->HistoryBuffers);
- Console->HistoryBufferSize = ConsoleInfo->HistoryBufferSize;
- Console->NumberOfHistoryBuffers = ConsoleInfo->NumberOfHistoryBuffers;
- Console->HistoryNoDup = ConsoleInfo->HistoryNoDup;
-
- /* Initialize the console title */
- ConsoleCreateUnicodeString(&Console->OriginalTitle,
ConsoleInfo->ConsoleTitle);
- // if (ConsoleInfo.ConsoleTitle[0] == L'\0')
- // {
- // if (LoadStringW(ConSrvDllInstance, IDS_CONSOLE_TITLE, DefaultTitle,
sizeof(DefaultTitle) / sizeof(DefaultTitle[0])))
- // {
- // ConsoleCreateUnicodeString(&Console->Title, DefaultTitle);
- // }
- // else
- // {
- // ConsoleCreateUnicodeString(&Console->Title, L"ReactOS
Console");
- // }
- // }
- // else
- // {
- ConsoleCreateUnicodeString(&Console->Title,
ConsoleInfo->ConsoleTitle);
- // }
-
- /* Lock the console until its initialization is finished */
- // EnterCriticalSection(&Console->Lock);
-
- DPRINT("Console initialized\n");
-
- /* All went right, so add the console to the list */
- Status = InsertConsole(&ConsoleHandle, Console);
- if (!NT_SUCCESS(Status))
- {
- /* Fail */
- ConDrvDeleteConsole(Console);
- return Status;
- }
-
- /* The initialization is finished */
- DPRINT("Change state\n");
- Console->State = CONSOLE_RUNNING;
-
- /* Unlock the console */
- // LeaveCriticalSection(&Console->Lock);
-
- /* Return the newly created console to the caller and a success code too */
- *NewConsoleHandle = ConsoleHandle;
- *NewConsole = Console;
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvRegisterFrontEnd(IN PCONSOLE Console,
- IN PFRONTEND FrontEnd)
-{
- NTSTATUS Status;
-
- if (Console == NULL || FrontEnd == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* FIXME: Lock the console before ?? */
-
- /*
- * Attach the frontend to the console. Use now the TermIFace of the console,
- * and not the user-defined temporary FrontEnd pointer.
- */
- Console->TermIFace = *FrontEnd;
- Console->TermIFace.Console = Console;
-
- /* Initialize the frontend AFTER having attached it to the console */
- DPRINT("Finish initialization of frontend\n");
- Status = Console->TermIFace.Vtbl->InitFrontEnd(&Console->TermIFace,
Console);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("FrontEnd initialization failed, Status = 0x%08lx\n", Status);
-
- /* We failed, detach the frontend from the console */
- FrontEnd->Console = NULL; // For the caller
- ResetFrontEnd(Console);
-
- return Status;
- }
-
- /* Copy buffer contents to screen */
- // FrontEnd.Draw();
- // ConioDrawConsole(Console);
- DPRINT("Console drawn\n");
-
- DPRINT("Terminal FrontEnd initialization done\n");
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvDeregisterFrontEnd(IN PCONSOLE Console)
-{
- if (Console == NULL) return STATUS_INVALID_PARAMETER;
-
- /* FIXME: Lock the console before ?? */
-
- /* Deinitialize the frontend BEFORE detaching it from the console */
- Console->TermIFace.Vtbl->DeinitFrontEnd(&Console->TermIFace/*,
Console*/);
-
- /*
- * Detach the frontend from the console:
- * reinitialize the frontend interface.
- */
- ResetFrontEnd(Console);
-
- DPRINT("Terminal FrontEnd unregistered\n");
- return STATUS_SUCCESS;
-}
-
-VOID NTAPI
-ConDrvDeleteConsole(IN PCONSOLE Console)
-{
- DPRINT("ConDrvDeleteConsole(0x%p)\n", Console);
-
- /*
- * Forbid validation of any console by other threads
- * during the deletion of this console.
- */
- ConDrvLockConsoleListExclusive();
-
- /*
- * If the console is already being destroyed, i.e. not running
- * or finishing to be initialized, just return.
- */
- if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE) &&
- !ConDrvValidateConsoleUnsafe(Console, CONSOLE_INITIALIZING, TRUE))
- {
- /* Unlock the console list and return */
- ConDrvUnlockConsoleList();
- return;
- }
-
- /*
- * We are about to be destroyed. Signal it to other people
- * so that they can terminate what they are doing, and that
- * they cannot longer validate the console.
- */
- Console->State = CONSOLE_TERMINATING;
-
- /*
- * Allow other threads to finish their job: basically, unlock
- * all other calls to EnterCriticalSection(&Console->Lock); by
- * ConDrvValidateConsole(Unsafe) functions so that they just see
- * that we are not in CONSOLE_RUNNING state anymore, or unlock
- * other concurrent calls to ConDrvDeleteConsole so that they
- * can see that we are in fact already deleting the console.
- */
- LeaveCriticalSection(&Console->Lock);
- ConDrvUnlockConsoleList();
-
- /* FIXME: Send a terminate message to all the processes owning this console */
-
- /* Cleanup the UI-oriented part */
- DPRINT("Deregister console\n");
- ConDrvDeregisterFrontEnd(Console);
- DPRINT("Console deregistered\n");
-
- /***
- * Check that the console is in terminating state before continuing
- * (the cleanup code must not change the state of the console...
- * ...unless to cancel console deletion ?).
- ***/
-
- ConDrvLockConsoleListExclusive();
-
- if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_TERMINATING, TRUE))
- {
- ConDrvUnlockConsoleList();
- return;
- }
-
- /* We are now in destruction */
- Console->State = CONSOLE_IN_DESTRUCTION;
-
- /* We really delete the console. Reset the count to be sure. */
- Console->ReferenceCount = 0;
-
- /* Remove the console from the list */
- RemoveConsoleByPointer(Console);
-
- /* Discard all entries in the input event queue */
- PurgeInputBuffer(Console);
-
- if (Console->LineBuffer) ConsoleFreeHeap(Console->LineBuffer);
-
- IntDeleteAllAliases(Console);
- HistoryDeleteBuffers(Console);
-
- ConioDeleteScreenBuffer(Console->ActiveBuffer);
- Console->ActiveBuffer = NULL;
- if (!IsListEmpty(&Console->BufferList))
- {
- DPRINT1("BUG: screen buffer list not empty\n");
- ASSERT(FALSE);
- }
-
- /**/ CloseHandle(Console->InputBuffer.ActiveEvent); /**/
- if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent);
-
- ConsoleFreeUnicodeString(&Console->OriginalTitle);
- ConsoleFreeUnicodeString(&Console->Title);
-
- DPRINT("ConDrvDeleteConsole - Unlocking\n");
- LeaveCriticalSection(&Console->Lock);
- DPRINT("ConDrvDeleteConsole - Destroying lock\n");
- DeleteCriticalSection(&Console->Lock);
- DPRINT("ConDrvDeleteConsole - Lock destroyed ; freeing console\n");
-
- ConsoleFreeHeap(Console);
- DPRINT("ConDrvDeleteConsole - Console destroyed\n");
-
- /* Unlock the console list and return */
- ConDrvUnlockConsoleList();
-}
-
-
-/* PUBLIC DRIVER APIS *********************************************************/
-
-NTSTATUS NTAPI
-ConDrvGetConsoleMode(IN PCONSOLE Console,
- IN PCONSOLE_IO_OBJECT Object,
- OUT PULONG ConsoleMode)
-{
- NTSTATUS Status = STATUS_SUCCESS;
-
- if (Console == NULL || Object == NULL || ConsoleMode == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Object->Console);
-
- /*** FIXME: */ *ConsoleMode = 0; /***/
-
- if (INPUT_BUFFER == Object->Type)
- {
- PCONSOLE_INPUT_BUFFER InputBuffer = (PCONSOLE_INPUT_BUFFER)Object;
-
- *ConsoleMode = InputBuffer->Mode;
-
- if (Console->QuickEdit || Console->InsertMode)
- {
- // Windows does this, even if it's not documented on MSDN
- *ConsoleMode |= ENABLE_EXTENDED_FLAGS;
-
- if (Console->QuickEdit ) *ConsoleMode |= ENABLE_QUICK_EDIT_MODE;
- if (Console->InsertMode) *ConsoleMode |= ENABLE_INSERT_MODE;
- }
- }
- else if (TEXTMODE_BUFFER == Object->Type || GRAPHICS_BUFFER == Object->Type)
- {
- PCONSOLE_SCREEN_BUFFER Buffer = (PCONSOLE_SCREEN_BUFFER)Object;
- *ConsoleMode = Buffer->Mode;
- }
- else
- {
- Status = STATUS_INVALID_HANDLE;
- }
-
- return Status;
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleMode(IN PCONSOLE Console,
- IN PCONSOLE_IO_OBJECT Object,
- IN ULONG ConsoleMode)
-{
-#define CONSOLE_VALID_CONTROL_MODES ( ENABLE_EXTENDED_FLAGS | ENABLE_INSERT_MODE |
ENABLE_QUICK_EDIT_MODE )
-#define CONSOLE_VALID_INPUT_MODES ( ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | \
- ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT | \
- ENABLE_MOUSE_INPUT )
-#define CONSOLE_VALID_OUTPUT_MODES ( ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT
)
-
- NTSTATUS Status = STATUS_SUCCESS;
-
- if (Console == NULL || Object == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Object->Console);
-
- if (INPUT_BUFFER == Object->Type)
- {
- PCONSOLE_INPUT_BUFFER InputBuffer = (PCONSOLE_INPUT_BUFFER)Object;
-
- DPRINT("SetConsoleMode(Input, %d)\n", ConsoleMode);
-
- /*
- * 1. Only the presence of valid mode flags is allowed.
- */
- if (ConsoleMode & ~(CONSOLE_VALID_INPUT_MODES |
CONSOLE_VALID_CONTROL_MODES))
- {
- Status = STATUS_INVALID_PARAMETER;
- goto Quit;
- }
-
- /*
- * 2. If we use control mode flags without ENABLE_EXTENDED_FLAGS,
- * then consider the flags invalid.
- *
- if ( (ConsoleMode & CONSOLE_VALID_CONTROL_MODES) &&
- (ConsoleMode & ENABLE_EXTENDED_FLAGS) == 0 )
- {
- Status = STATUS_INVALID_PARAMETER;
- goto Quit;
- }
- */
-
- /*
- * 3. Now we can continue.
- */
- if (ConsoleMode & CONSOLE_VALID_CONTROL_MODES)
- {
- Console->QuickEdit = !!(ConsoleMode & ENABLE_QUICK_EDIT_MODE);
- Console->InsertMode = !!(ConsoleMode & ENABLE_INSERT_MODE);
- }
- InputBuffer->Mode = (ConsoleMode & CONSOLE_VALID_INPUT_MODES);
- }
- else if (TEXTMODE_BUFFER == Object->Type || GRAPHICS_BUFFER == Object->Type)
- {
- PCONSOLE_SCREEN_BUFFER Buffer = (PCONSOLE_SCREEN_BUFFER)Object;
-
- DPRINT("SetConsoleMode(Output, %d)\n", ConsoleMode);
-
- if (ConsoleMode & ~CONSOLE_VALID_OUTPUT_MODES)
- {
- Status = STATUS_INVALID_PARAMETER;
- }
- else
- {
- Buffer->Mode = (ConsoleMode & CONSOLE_VALID_OUTPUT_MODES);
- }
- }
- else
- {
- Status = STATUS_INVALID_HANDLE;
- }
-
-Quit:
- return Status;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleTitle(IN PCONSOLE Console,
- IN OUT PWCHAR Title,
- IN OUT PULONG BufLength)
-{
- ULONG Length;
-
- if (Console == NULL || Title == NULL || BufLength == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Copy title of the console to the user title buffer */
- if (*BufLength >= sizeof(WCHAR))
- {
- Length = min(*BufLength - sizeof(WCHAR), Console->Title.Length);
- RtlCopyMemory(Title, Console->Title.Buffer, Length);
- Title[Length / sizeof(WCHAR)] = L'\0';
- }
-
- *BufLength = Console->Title.Length;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleTitle(IN PCONSOLE Console,
- IN PWCHAR Title,
- IN ULONG BufLength)
-{
- PWCHAR Buffer;
-
- if (Console == NULL || Title == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Allocate a new buffer to hold the new title (NULL-terminated) */
- Buffer = ConsoleAllocHeap(0, BufLength + sizeof(WCHAR));
- if (!Buffer) return STATUS_NO_MEMORY;
-
- /* Free the old title */
- ConsoleFreeUnicodeString(&Console->Title);
-
- /* Copy title to console */
- Console->Title.Buffer = Buffer;
- Console->Title.Length = BufLength;
- Console->Title.MaximumLength = Console->Title.Length + sizeof(WCHAR);
- RtlCopyMemory(Console->Title.Buffer, Title, Console->Title.Length);
- Console->Title.Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0';
-
- // ConioChangeTitle(Console);
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleCP(IN PCONSOLE Console,
- OUT PUINT CodePage,
- IN BOOLEAN InputCP)
-{
- if (Console == NULL || CodePage == NULL)
- return STATUS_INVALID_PARAMETER;
-
- *CodePage = (InputCP ? Console->CodePage : Console->OutputCodePage);
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleCP(IN PCONSOLE Console,
- IN UINT CodePage,
- IN BOOLEAN InputCP)
-{
- if (Console == NULL || !IsValidCodePage(CodePage))
- return STATUS_INVALID_PARAMETER;
-
- if (InputCP)
- Console->CodePage = CodePage;
- else
- Console->OutputCodePage = CodePage;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleProcessList(IN PCONSOLE Console,
- IN OUT PULONG ProcessIdsList,
- IN ULONG MaxIdListItems,
- OUT PULONG ProcessIdsTotal)
-{
- PCONSOLE_PROCESS_DATA current;
- PLIST_ENTRY current_entry;
-
- if (Console == NULL || ProcessIdsList == NULL || ProcessIdsTotal == NULL)
- return STATUS_INVALID_PARAMETER;
-
- *ProcessIdsTotal = 0;
-
- for (current_entry = Console->ProcessList.Flink;
- current_entry != &Console->ProcessList;
- current_entry = current_entry->Flink)
- {
- current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
- if (++(*ProcessIdsTotal) <= MaxIdListItems)
- {
- *ProcessIdsList++ =
HandleToUlong(current->Process->ClientId.UniqueProcess);
- }
- }
-
- return STATUS_SUCCESS;
-}
-
-// ConDrvGenerateConsoleCtrlEvent
-NTSTATUS NTAPI
-ConDrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
- IN ULONG ProcessGroupId,
- IN ULONG Event)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- PLIST_ENTRY current_entry;
- PCONSOLE_PROCESS_DATA current;
-
- /* If the console is already being destroyed, just return */
- if (!ConDrvValidateConsoleState(Console, CONSOLE_RUNNING))
- return STATUS_UNSUCCESSFUL;
-
- /*
- * Loop through the process list, from the most recent process
- * (the active one) to the oldest one (the first created, i.e.
- * the console leader process), and for each, send an event
- * (new processes are inserted at the head of the console process list).
- */
- current_entry = Console->ProcessList.Flink;
- while (current_entry != &Console->ProcessList)
- {
- current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
- current_entry = current_entry->Flink;
-
- /*
- * Only processes belonging to the same process group are signaled.
- * If the process group ID is zero, then all the processes are signaled.
- */
- if (ProcessGroupId == 0 || current->Process->ProcessGroupId ==
ProcessGroupId)
- {
- Status = ConDrvConsoleCtrlEvent(Event, current);
- }
- }
-
- return Status;
-}
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/condrv/dummyfrontend.c
b/win32ss/user/winsrv/consrv_new/condrv/dummyfrontend.c
deleted file mode 100644
index 6389da461f2..00000000000
--- a/win32ss/user/winsrv/consrv_new/condrv/dummyfrontend.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Server DLL
- * FILE: win32ss/user/winsrv/consrv_new/condrv/dummyfrontend.c
- * PURPOSE: Dummy Terminal Front-End used when no frontend
- * is attached to the specified console.
- * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "include/conio.h"
-
-
-/* DUMMY FRONTEND INTERFACE ***************************************************/
-
-static NTSTATUS NTAPI
-DummyInitFrontEnd(IN OUT PFRONTEND This,
- IN PCONSOLE Console)
-{
- /* Load some settings ?? */
- return STATUS_SUCCESS;
-}
-
-static VOID NTAPI
-DummyDeinitFrontEnd(IN OUT PFRONTEND This)
-{
- /* Free some settings ?? */
-}
-
-static VOID NTAPI
-DummyDrawRegion(IN OUT PFRONTEND This,
- SMALL_RECT* Region)
-{
-}
-
-static VOID NTAPI
-DummyWriteStream(IN OUT PFRONTEND This,
- SMALL_RECT* Region,
- SHORT CursorStartX,
- SHORT CursorStartY,
- UINT ScrolledLines,
- PWCHAR Buffer,
- UINT Length)
-{
-}
-
-static BOOL NTAPI
-DummySetCursorInfo(IN OUT PFRONTEND This,
- PCONSOLE_SCREEN_BUFFER Buff)
-{
- return TRUE;
-}
-
-static BOOL NTAPI
-DummySetScreenInfo(IN OUT PFRONTEND This,
- PCONSOLE_SCREEN_BUFFER Buff,
- SHORT OldCursorX,
- SHORT OldCursorY)
-{
- return TRUE;
-}
-
-static VOID NTAPI
-DummyResizeTerminal(IN OUT PFRONTEND This)
-{
-}
-
-static BOOL NTAPI
-DummyProcessKeyCallback(IN OUT PFRONTEND This,
- MSG* msg,
- BYTE KeyStateMenu,
- DWORD ShiftState,
- UINT VirtualKeyCode,
- BOOL Down)
-{
- return FALSE;
-}
-
-static VOID NTAPI
-DummyRefreshInternalInfo(IN OUT PFRONTEND This)
-{
-}
-
-static VOID NTAPI
-DummyChangeTitle(IN OUT PFRONTEND This)
-{
-}
-
-static BOOL NTAPI
-DummyChangeIcon(IN OUT PFRONTEND This,
- HICON hWindowIcon)
-{
- return TRUE;
-}
-
-static HWND NTAPI
-DummyGetConsoleWindowHandle(IN OUT PFRONTEND This)
-{
- return NULL;
-}
-
-static VOID NTAPI
-DummyGetLargestConsoleWindowSize(IN OUT PFRONTEND This,
- PCOORD pSize)
-{
-}
-
-static ULONG NTAPI
-DummyGetDisplayMode(IN OUT PFRONTEND This)
-{
- return 0;
-}
-
-static BOOL NTAPI
-DummySetDisplayMode(IN OUT PFRONTEND This,
- ULONG NewMode)
-{
- return TRUE;
-}
-
-static INT NTAPI
-DummyShowMouseCursor(IN OUT PFRONTEND This,
- BOOL Show)
-{
- return 0;
-}
-
-static BOOL NTAPI
-DummySetMouseCursor(IN OUT PFRONTEND This,
- HCURSOR hCursor)
-{
- return TRUE;
-}
-
-static HMENU NTAPI
-DummyMenuControl(IN OUT PFRONTEND This,
- UINT cmdIdLow,
- UINT cmdIdHigh)
-{
- return NULL;
-}
-
-static BOOL NTAPI
-DummySetMenuClose(IN OUT PFRONTEND This,
- BOOL Enable)
-{
- return TRUE;
-}
-
-static FRONTEND_VTBL DummyVtbl =
-{
- DummyInitFrontEnd,
- DummyDeinitFrontEnd,
- DummyDrawRegion,
- DummyWriteStream,
- DummySetCursorInfo,
- DummySetScreenInfo,
- DummyResizeTerminal,
- DummyProcessKeyCallback,
- DummyRefreshInternalInfo,
- DummyChangeTitle,
- DummyChangeIcon,
- DummyGetConsoleWindowHandle,
- DummyGetLargestConsoleWindowSize,
- DummyGetDisplayMode,
- DummySetDisplayMode,
- DummyShowMouseCursor,
- DummySetMouseCursor,
- DummyMenuControl,
- DummySetMenuClose,
-};
-
-VOID
-ResetFrontEnd(IN PCONSOLE Console)
-{
- if (!Console) return;
-
- /* Reinitialize the frontend interface */
- RtlZeroMemory(&Console->TermIFace, sizeof(Console->TermIFace));
- Console->TermIFace.Vtbl = &DummyVtbl;
-}
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/condrv/graphics.c
b/win32ss/user/winsrv/consrv_new/condrv/graphics.c
deleted file mode 100644
index ffd1d3363d2..00000000000
--- a/win32ss/user/winsrv/consrv_new/condrv/graphics.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Driver DLL
- * FILE: win32ss/user/winsrv/consrv_new/condrv/graphics.c
- * PURPOSE: Console Output Functions for graphics-mode screen-buffers
- * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- *
- * NOTE: See
http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you…
- * for more information.
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "include/conio.h"
-#include "include/conio2.h"
-#include "conoutput.h"
-#include "handle.h"
-
-#define NDEBUG
-#include <debug.h>
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-CONSOLE_IO_OBJECT_TYPE
-GRAPHICS_BUFFER_GetType(PCONSOLE_SCREEN_BUFFER This)
-{
- // return This->Header.Type;
- return GRAPHICS_BUFFER;
-}
-
-static CONSOLE_SCREEN_BUFFER_VTBL GraphicsVtbl =
-{
- GRAPHICS_BUFFER_GetType,
-};
-
-
-NTSTATUS
-CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN SIZE_T Size);
-VOID
-CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer);
-
-
-NTSTATUS
-GRAPHICS_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- PGRAPHICS_SCREEN_BUFFER NewBuffer = NULL;
-
- LARGE_INTEGER SectionSize;
- ULONG ViewSize = 0;
- HANDLE ProcessHandle;
-
- if (Buffer == NULL || Console == NULL || GraphicsInfo == NULL)
- return STATUS_INVALID_PARAMETER;
-
- *Buffer = NULL;
-
- Status = CONSOLE_SCREEN_BUFFER_Initialize((PCONSOLE_SCREEN_BUFFER*)&NewBuffer,
- Console,
- sizeof(GRAPHICS_SCREEN_BUFFER));
- if (!NT_SUCCESS(Status)) return Status;
- NewBuffer->Header.Type = GRAPHICS_BUFFER;
- NewBuffer->Vtbl = &GraphicsVtbl;
-
- /*
- * Remember the handle to the process so that we can close or unmap
- * correctly the allocated resources when the client releases the
- * screen buffer.
- */
- ProcessHandle = CsrGetClientThread()->Process->ProcessHandle;
- NewBuffer->ClientProcess = ProcessHandle;
-
- /* Get infos from the graphics buffer information structure */
- NewBuffer->BitMapInfoLength = GraphicsInfo->Info.dwBitMapInfoLength;
-
- NewBuffer->BitMapInfo = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
NewBuffer->BitMapInfoLength);
- if (NewBuffer->BitMapInfo == NULL)
- {
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- /* Adjust the bitmap height if needed (bottom-top vs. top-bottom). Use always
bottom-up. */
- if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight > 0)
- GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight =
-GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
-
- /* We do not use anything else than uncompressed bitmaps */
- if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression != BI_RGB)
- {
- DPRINT1("biCompression == %d != BI_RGB, correct that!\n",
GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression);
- GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression = BI_RGB;
- }
-
- RtlCopyMemory(NewBuffer->BitMapInfo,
- GraphicsInfo->Info.lpBitMapInfo,
- GraphicsInfo->Info.dwBitMapInfoLength);
-
- NewBuffer->BitMapUsage = GraphicsInfo->Info.dwUsage;
-
- /* Set the screen buffer size. Fight against overflows. */
- if ( GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth <= 0xFFFF
&&
- -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight <= 0xFFFF )
- {
- /* Be careful about the sign of biHeight */
- NewBuffer->ScreenBufferSize.X =
(SHORT)GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth ;
- NewBuffer->ScreenBufferSize.Y =
(SHORT)-GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
-
- NewBuffer->OldViewSize = NewBuffer->ViewSize =
- NewBuffer->OldScreenBufferSize = NewBuffer->ScreenBufferSize;
- }
- else
- {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- ConsoleFreeHeap(NewBuffer->BitMapInfo);
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- goto Quit;
- }
-
- /*
- * Create a mutex to synchronize bitmap memory access
- * between ourselves and the client.
- */
- Status = NtCreateMutant(&NewBuffer->Mutex, MUTANT_ALL_ACCESS, NULL, FALSE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("NtCreateMutant() failed: %lu\n", Status);
- ConsoleFreeHeap(NewBuffer->BitMapInfo);
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- goto Quit;
- }
-
- /*
- * Duplicate the Mutex for the client. We must keep a trace of it
- * so that we can close it when the client releases the screen buffer.
- */
- Status = NtDuplicateObject(NtCurrentProcess(),
- NewBuffer->Mutex,
- ProcessHandle,
- &NewBuffer->ClientMutex,
- 0, 0, DUPLICATE_SAME_ACCESS);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("NtDuplicateObject() failed: %lu\n", Status);
- NtClose(NewBuffer->Mutex);
- ConsoleFreeHeap(NewBuffer->BitMapInfo);
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- goto Quit;
- }
-
- /*
- * Create a memory section for the bitmap area, to share with the client.
- */
- SectionSize.QuadPart = NewBuffer->BitMapInfo->bmiHeader.biSizeImage;
- Status = NtCreateSection(&NewBuffer->hSection,
- SECTION_ALL_ACCESS,
- NULL,
- &SectionSize,
- PAGE_READWRITE,
- SEC_COMMIT,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("Error: Impossible to create a shared section ; Status =
%lu\n", Status);
- NtClose(NewBuffer->ClientMutex);
- NtClose(NewBuffer->Mutex);
- ConsoleFreeHeap(NewBuffer->BitMapInfo);
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- goto Quit;
- }
-
- /*
- * Create a view for our needs.
- */
- ViewSize = 0;
- NewBuffer->BitMap = NULL;
- Status = NtMapViewOfSection(NewBuffer->hSection,
- NtCurrentProcess(),
- (PVOID*)&NewBuffer->BitMap,
- 0,
- 0,
- NULL,
- &ViewSize,
- ViewUnmap,
- 0,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n",
Status);
- NtClose(NewBuffer->hSection);
- NtClose(NewBuffer->ClientMutex);
- NtClose(NewBuffer->Mutex);
- ConsoleFreeHeap(NewBuffer->BitMapInfo);
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- goto Quit;
- }
-
- /*
- * Create a view for the client. We must keep a trace of it so that
- * we can unmap it when the client releases the screen buffer.
- */
- ViewSize = 0;
- NewBuffer->ClientBitMap = NULL;
- Status = NtMapViewOfSection(NewBuffer->hSection,
- ProcessHandle,
- (PVOID*)&NewBuffer->ClientBitMap,
- 0,
- 0,
- NULL,
- &ViewSize,
- ViewUnmap,
- 0,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n",
Status);
- NtUnmapViewOfSection(NtCurrentProcess(), NewBuffer->BitMap);
- NtClose(NewBuffer->hSection);
- NtClose(NewBuffer->ClientMutex);
- NtClose(NewBuffer->Mutex);
- ConsoleFreeHeap(NewBuffer->BitMapInfo);
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- goto Quit;
- }
-
- NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
- NewBuffer->VirtualY = 0;
-
- NewBuffer->CursorBlinkOn = FALSE;
- NewBuffer->ForceCursorOff = TRUE;
- NewBuffer->CursorInfo.bVisible = FALSE;
- NewBuffer->CursorInfo.dwSize = 0;
- NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
-
- NewBuffer->Mode = 0;
-
- *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
- Status = STATUS_SUCCESS;
-
-Quit:
- return Status;
-}
-
-VOID
-GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
-{
- PGRAPHICS_SCREEN_BUFFER Buff = (PGRAPHICS_SCREEN_BUFFER)Buffer;
-
- /*
- * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
- * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
- */
- Buffer->Header.Type = SCREEN_BUFFER;
-
- /*
- * Uninitialize the graphics screen buffer
- * in the reverse way we initialized it.
- */
- NtUnmapViewOfSection(Buff->ClientProcess, Buff->ClientBitMap);
- NtUnmapViewOfSection(NtCurrentProcess(), Buff->BitMap);
- NtClose(Buff->hSection);
- NtClose(Buff->ClientMutex);
- NtClose(Buff->Mutex);
- ConsoleFreeHeap(Buff->BitMapInfo);
-
- CONSOLE_SCREEN_BUFFER_Destroy(Buffer);
-}
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/condrv/text.c
b/win32ss/user/winsrv/consrv_new/condrv/text.c
deleted file mode 100644
index 7ae234b1b71..00000000000
--- a/win32ss/user/winsrv/consrv_new/condrv/text.c
+++ /dev/null
@@ -1,1346 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Driver DLL
- * FILE: win32ss/user/winsrv/consrv_new/condrv/text.c
- * PURPOSE: Console Output Functions for text-mode screen-buffers
- * PROGRAMMERS: Jeffrey Morlan
- * Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "include/conio.h"
-#include "include/conio2.h"
-#include "conoutput.h"
-#include "handle.h"
-
-#define NDEBUG
-#include <debug.h>
-
-
-/* GLOBALS ********************************************************************/
-
-#define TAB_WIDTH 8
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-CONSOLE_IO_OBJECT_TYPE
-TEXTMODE_BUFFER_GetType(PCONSOLE_SCREEN_BUFFER This)
-{
- // return This->Header.Type;
- return TEXTMODE_BUFFER;
-}
-
-static CONSOLE_SCREEN_BUFFER_VTBL TextVtbl =
-{
- TEXTMODE_BUFFER_GetType,
-};
-
-
-static VOID FASTCALL
-ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff);
-
-
-NTSTATUS
-CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN SIZE_T Size);
-VOID
-CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer);
-
-
-NTSTATUS
-TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
- IN OUT PCONSOLE Console,
- IN PTEXTMODE_BUFFER_INFO TextModeInfo)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- PTEXTMODE_SCREEN_BUFFER NewBuffer = NULL;
-
- if (Console == NULL || Buffer == NULL || TextModeInfo == NULL)
- return STATUS_INVALID_PARAMETER;
-
- *Buffer = NULL;
-
- Status = CONSOLE_SCREEN_BUFFER_Initialize((PCONSOLE_SCREEN_BUFFER*)&NewBuffer,
- Console,
- sizeof(TEXTMODE_SCREEN_BUFFER));
- if (!NT_SUCCESS(Status)) return Status;
- NewBuffer->Header.Type = TEXTMODE_BUFFER;
- NewBuffer->Vtbl = &TextVtbl;
-
- NewBuffer->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
- TextModeInfo->ScreenBufferSize.X *
- TextModeInfo->ScreenBufferSize.Y *
- sizeof(CHAR_INFO));
- if (NewBuffer->Buffer == NULL)
- {
- CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- NewBuffer->ScreenBufferSize = NewBuffer->OldScreenBufferSize
- = TextModeInfo->ScreenBufferSize;
- NewBuffer->ViewSize = NewBuffer->OldViewSize
- = Console->ConsoleSize;
-
- NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
- NewBuffer->VirtualY = 0;
-
- NewBuffer->CursorBlinkOn = NewBuffer->ForceCursorOff = FALSE;
- NewBuffer->CursorInfo.bVisible = (TextModeInfo->IsCursorVisible &&
(TextModeInfo->CursorSize != 0));
- NewBuffer->CursorInfo.dwSize = min(max(TextModeInfo->CursorSize, 0), 100);
-
- NewBuffer->ScreenDefaultAttrib = TextModeInfo->ScreenAttrib;
- NewBuffer->PopupDefaultAttrib = TextModeInfo->PopupAttrib;
-
- /* Initialize buffer to be empty with default attributes */
- for (NewBuffer->CursorPosition.Y = 0 ; NewBuffer->CursorPosition.Y <
NewBuffer->ScreenBufferSize.Y; NewBuffer->CursorPosition.Y++)
- {
- ClearLineBuffer(NewBuffer);
- }
- NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
-
- NewBuffer->Mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
-
- *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
- return STATUS_SUCCESS;
-}
-
-VOID
-TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
-{
- PTEXTMODE_SCREEN_BUFFER Buff = (PTEXTMODE_SCREEN_BUFFER)Buffer;
-
- /*
- * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
- * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
- */
- Buffer->Header.Type = SCREEN_BUFFER;
-
- ConsoleFreeHeap(Buff->Buffer);
-
- CONSOLE_SCREEN_BUFFER_Destroy(Buffer);
-}
-
-
-PCHAR_INFO
-ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
-{
- return &Buff->Buffer[((Y + Buff->VirtualY) % Buff->ScreenBufferSize.Y) *
Buff->ScreenBufferSize.X + X];
-}
-
-static VOID FASTCALL
-ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff)
-{
- PCHAR_INFO Ptr = ConioCoordToPointer(Buff, 0, Buff->CursorPosition.Y);
- SHORT Pos;
-
- for (Pos = 0; Pos < Buff->ScreenBufferSize.X; Pos++, Ptr++)
- {
- /* Fill the cell */
- Ptr->Char.UnicodeChar = L' ';
- Ptr->Attributes = Buff->ScreenDefaultAttrib;
- }
-}
-
-static __inline BOOLEAN
-ConioGetIntersection(OUT PSMALL_RECT Intersection,
- IN PSMALL_RECT Rect1,
- IN PSMALL_RECT Rect2)
-{
- if ( ConioIsRectEmpty(Rect1) ||
- ConioIsRectEmpty(Rect2) ||
- (Rect1->Top > Rect2->Bottom) ||
- (Rect1->Left > Rect2->Right) ||
- (Rect1->Bottom < Rect2->Top) ||
- (Rect1->Right < Rect2->Left) )
- {
- /* The rectangles do not intersect */
- ConioInitRect(Intersection, 0, -1, 0, -1);
- return FALSE;
- }
-
- ConioInitRect(Intersection,
- max(Rect1->Top , Rect2->Top ),
- max(Rect1->Left , Rect2->Left ),
- min(Rect1->Bottom, Rect2->Bottom),
- min(Rect1->Right , Rect2->Right ));
-
- return TRUE;
-}
-
-static __inline BOOLEAN
-ConioGetUnion(OUT PSMALL_RECT Union,
- IN PSMALL_RECT Rect1,
- IN PSMALL_RECT Rect2)
-{
- if (ConioIsRectEmpty(Rect1))
- {
- if (ConioIsRectEmpty(Rect2))
- {
- ConioInitRect(Union, 0, -1, 0, -1);
- return FALSE;
- }
- else
- {
- *Union = *Rect2;
- }
- }
- else if (ConioIsRectEmpty(Rect2))
- {
- *Union = *Rect1;
- }
- else
- {
- ConioInitRect(Union,
- min(Rect1->Top , Rect2->Top ),
- min(Rect1->Left , Rect2->Left ),
- max(Rect1->Bottom, Rect2->Bottom),
- max(Rect1->Right , Rect2->Right ));
- }
-
- return TRUE;
-}
-
-static VOID FASTCALL
-ConioComputeUpdateRect(IN PTEXTMODE_SCREEN_BUFFER Buff,
- IN OUT PSMALL_RECT UpdateRect,
- IN PCOORD Start,
- IN UINT Length)
-{
- if (Buff->ScreenBufferSize.X <= Start->X + Length)
- {
- UpdateRect->Left = 0;
- }
- else
- {
- UpdateRect->Left = Start->X;
- }
- if (Buff->ScreenBufferSize.X <= Start->X + Length)
- {
- UpdateRect->Right = Buff->ScreenBufferSize.X - 1;
- }
- else
- {
- UpdateRect->Right = Start->X + Length - 1;
- }
- UpdateRect->Top = Start->Y;
- UpdateRect->Bottom = Start->Y + (Start->X + Length - 1) /
Buff->ScreenBufferSize.X;
- if (Buff->ScreenBufferSize.Y <= UpdateRect->Bottom)
- {
- UpdateRect->Bottom = Buff->ScreenBufferSize.Y - 1;
- }
-}
-
-/*
- * Move from one rectangle to another. We must be careful about the order that
- * this is done, to avoid overwriting parts of the source before they are moved.
- */
-static VOID FASTCALL
-ConioMoveRegion(PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
- PSMALL_RECT SrcRegion,
- PSMALL_RECT DstRegion,
- PSMALL_RECT ClipRegion,
- CHAR_INFO FillChar)
-{
- int Width = ConioRectWidth(SrcRegion);
- int Height = ConioRectHeight(SrcRegion);
- int SX, SY;
- int DX, DY;
- int XDelta, YDelta;
- int i, j;
-
- SY = SrcRegion->Top;
- DY = DstRegion->Top;
- YDelta = 1;
- if (SY < DY)
- {
- /* Moving down: work from bottom up */
- SY = SrcRegion->Bottom;
- DY = DstRegion->Bottom;
- YDelta = -1;
- }
- for (i = 0; i < Height; i++)
- {
- PCHAR_INFO SRow = ConioCoordToPointer(ScreenBuffer, 0, SY);
- PCHAR_INFO DRow = ConioCoordToPointer(ScreenBuffer, 0, DY);
-
- SX = SrcRegion->Left;
- DX = DstRegion->Left;
- XDelta = 1;
- if (SX < DX)
- {
- /* Moving right: work from right to left */
- SX = SrcRegion->Right;
- DX = DstRegion->Right;
- XDelta = -1;
- }
- for (j = 0; j < Width; j++)
- {
- CHAR_INFO Cell = SRow[SX];
- if (SX >= ClipRegion->Left && SX <= ClipRegion->Right
&&
- SY >= ClipRegion->Top && SY <= ClipRegion->Bottom)
- {
- SRow[SX] = FillChar;
- }
- if (DX >= ClipRegion->Left && DX <= ClipRegion->Right
&&
- DY >= ClipRegion->Top && DY <= ClipRegion->Bottom)
- {
- DRow[DX] = Cell;
- }
- SX += XDelta;
- DX += XDelta;
- }
- SY += YDelta;
- DY += YDelta;
- }
-}
-
-DWORD FASTCALL
-ConioEffectiveCursorSize(PCONSOLE Console, DWORD Scale)
-{
- DWORD Size = (Console->ActiveBuffer->CursorInfo.dwSize * Scale + 99) / 100;
- /* If line input in progress, perhaps adjust for insert toggle */
- if (Console->LineBuffer && !Console->LineComplete &&
Console->LineInsertToggle)
- return (Size * 2 <= Scale) ? (Size * 2) : (Size / 2);
- return Size;
-}
-
-NTSTATUS
-ConioResizeBuffer(PCONSOLE Console,
- PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
- COORD Size)
-{
- PCHAR_INFO Buffer;
- DWORD Offset = 0;
- PCHAR_INFO ptr;
- WORD CurrentAttribute;
- USHORT CurrentY;
- PCHAR_INFO OldBuffer;
- DWORD i;
- DWORD diff;
-
- /* Buffer size is not allowed to be smaller than the view size */
- if (Size.X < ScreenBuffer->ViewSize.X || Size.Y <
ScreenBuffer->ViewSize.Y)
- return STATUS_INVALID_PARAMETER;
-
- if (Size.X == ScreenBuffer->ScreenBufferSize.X && Size.Y ==
ScreenBuffer->ScreenBufferSize.Y)
- {
- // FIXME: Trigger a buffer resize event ??
- return STATUS_SUCCESS;
- }
-
- if (Console->FixedSize)
- {
- /*
- * The console is in fixed-size mode, so we cannot resize anything
- * at the moment. However, keep those settings somewhere so that
- * we can try to set them up when we will be allowed to do so.
- */
- ScreenBuffer->OldScreenBufferSize = Size;
- return STATUS_NOT_SUPPORTED; // STATUS_SUCCESS
- }
-
- Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Size.X * Size.Y * sizeof(CHAR_INFO));
- if (!Buffer) return STATUS_NO_MEMORY;
-
- DPRINT1("Resizing (%d,%d) to (%d,%d)\n",
ScreenBuffer->ScreenBufferSize.X, ScreenBuffer->ScreenBufferSize.Y, Size.X,
Size.Y);
- OldBuffer = ScreenBuffer->Buffer;
-
- for (CurrentY = 0; CurrentY < ScreenBuffer->ScreenBufferSize.Y &&
CurrentY < Size.Y; CurrentY++)
- {
- ptr = ConioCoordToPointer(ScreenBuffer, 0, CurrentY);
- if (Size.X <= ScreenBuffer->ScreenBufferSize.X)
- {
- /* Reduce size */
- RtlCopyMemory(Buffer + Offset, ptr, Size.X * sizeof(CHAR_INFO));
- Offset += Size.X;
- }
- else
- {
- /* Enlarge size */
- RtlCopyMemory(Buffer + Offset, ptr, ScreenBuffer->ScreenBufferSize.X *
sizeof(CHAR_INFO));
- Offset += ScreenBuffer->ScreenBufferSize.X;
-
- /* The attribute to be used is the one of the last cell of the current line
*/
- CurrentAttribute = ConioCoordToPointer(ScreenBuffer,
- ScreenBuffer->ScreenBufferSize.X -
1,
- CurrentY)->Attributes;
-
- diff = Size.X - ScreenBuffer->ScreenBufferSize.X;
-
- /* Zero-out the new part of the buffer */
- for (i = 0; i < diff; i++)
- {
- ptr = Buffer + Offset;
- ptr->Char.UnicodeChar = L' ';
- ptr->Attributes = CurrentAttribute;
- ++Offset;
- }
- }
- }
-
- if (Size.Y > ScreenBuffer->ScreenBufferSize.Y)
- {
- diff = Size.X * (Size.Y - ScreenBuffer->ScreenBufferSize.Y);
-
- /* Zero-out the new part of the buffer */
- for (i = 0; i < diff; i++)
- {
- ptr = Buffer + Offset;
- ptr->Char.UnicodeChar = L' ';
- ptr->Attributes = ScreenBuffer->ScreenDefaultAttrib;
- ++Offset;
- }
- }
-
- (void)InterlockedExchangePointer((PVOID volatile*)&ScreenBuffer->Buffer,
Buffer);
- ConsoleFreeHeap(OldBuffer);
- ScreenBuffer->ScreenBufferSize = ScreenBuffer->OldScreenBufferSize = Size;
- ScreenBuffer->VirtualY = 0;
-
- /* Ensure cursor and window are within buffer */
- if (ScreenBuffer->CursorPosition.X >= Size.X)
- ScreenBuffer->CursorPosition.X = Size.X - 1;
- if (ScreenBuffer->CursorPosition.Y >= Size.Y)
- ScreenBuffer->CursorPosition.Y = Size.Y - 1;
- if (ScreenBuffer->ViewOrigin.X > Size.X - ScreenBuffer->ViewSize.X)
- ScreenBuffer->ViewOrigin.X = Size.X - ScreenBuffer->ViewSize.X;
- if (ScreenBuffer->ViewOrigin.Y > Size.Y - ScreenBuffer->ViewSize.Y)
- ScreenBuffer->ViewOrigin.Y = Size.Y - ScreenBuffer->ViewSize.Y;
-
- /*
- * Trigger a buffer resize event
- */
- if (Console->InputBuffer.Mode & ENABLE_WINDOW_INPUT)
- {
- INPUT_RECORD er;
-
- er.EventType = WINDOW_BUFFER_SIZE_EVENT;
- er.Event.WindowBufferSizeEvent.dwSize = ScreenBuffer->ScreenBufferSize;
-
- ConioProcessInputEvent(Console, &er);
- }
-
- return STATUS_SUCCESS;
-}
-
-static VOID FASTCALL
-ConioNextLine(PTEXTMODE_SCREEN_BUFFER Buff, PSMALL_RECT UpdateRect, PUINT ScrolledLines)
-{
- /* If we hit bottom, slide the viewable screen */
- if (++Buff->CursorPosition.Y == Buff->ScreenBufferSize.Y)
- {
- Buff->CursorPosition.Y--;
- if (++Buff->VirtualY == Buff->ScreenBufferSize.Y)
- {
- Buff->VirtualY = 0;
- }
- (*ScrolledLines)++;
- ClearLineBuffer(Buff);
- if (UpdateRect->Top != 0)
- {
- UpdateRect->Top--;
- }
- }
- UpdateRect->Left = 0;
- UpdateRect->Right = Buff->ScreenBufferSize.X - 1;
- UpdateRect->Bottom = Buff->CursorPosition.Y;
-}
-
-NTSTATUS
-ConioWriteConsole(PCONSOLE Console,
- PTEXTMODE_SCREEN_BUFFER Buff,
- PWCHAR Buffer,
- DWORD Length,
- BOOL Attrib)
-{
- UINT i;
- PCHAR_INFO Ptr;
- SMALL_RECT UpdateRect;
- SHORT CursorStartX, CursorStartY;
- UINT ScrolledLines;
-
- CursorStartX = Buff->CursorPosition.X;
- CursorStartY = Buff->CursorPosition.Y;
- UpdateRect.Left = Buff->ScreenBufferSize.X;
- UpdateRect.Top = Buff->CursorPosition.Y;
- UpdateRect.Right = -1;
- UpdateRect.Bottom = Buff->CursorPosition.Y;
- ScrolledLines = 0;
-
- for (i = 0; i < Length; i++)
- {
- /*
- * If we are in processed mode, interpret special characters and
- * display them correctly. Otherwise, just put them into the buffer.
- */
- if (Buff->Mode & ENABLE_PROCESSED_OUTPUT)
- {
- /* --- CR --- */
- if (Buffer[i] == L'\r')
- {
- Buff->CursorPosition.X = 0;
- UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
- UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X);
- continue;
- }
- /* --- LF --- */
- else if (Buffer[i] == L'\n')
- {
- Buff->CursorPosition.X = 0;
- ConioNextLine(Buff, &UpdateRect, &ScrolledLines);
- continue;
- }
- /* --- BS --- */
- else if (Buffer[i] == L'\b')
- {
- /* Only handle BS if we're not on the first pos of the first line */
- if (0 != Buff->CursorPosition.X || 0 != Buff->CursorPosition.Y)
- {
- if (0 == Buff->CursorPosition.X)
- {
- /* slide virtual position up */
- Buff->CursorPosition.X = Buff->ScreenBufferSize.X - 1;
- Buff->CursorPosition.Y--;
- UpdateRect.Top = min(UpdateRect.Top, Buff->CursorPosition.Y);
- }
- else
- {
- Buff->CursorPosition.X--;
- }
- Ptr = ConioCoordToPointer(Buff, Buff->CursorPosition.X,
Buff->CursorPosition.Y);
- Ptr->Char.UnicodeChar = L' ';
- Ptr->Attributes = Buff->ScreenDefaultAttrib;
- UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
- UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X);
- }
- continue;
- }
- /* --- TAB --- */
- else if (Buffer[i] == L'\t')
- {
- UINT EndX;
-
- UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
- EndX = (Buff->CursorPosition.X + TAB_WIDTH) & ~(TAB_WIDTH - 1);
- EndX = min(EndX, (UINT)Buff->ScreenBufferSize.X);
- Ptr = ConioCoordToPointer(Buff, Buff->CursorPosition.X,
Buff->CursorPosition.Y);
- while (Buff->CursorPosition.X < EndX)
- {
- Ptr->Char.UnicodeChar = L' ';
- Ptr->Attributes = Buff->ScreenDefaultAttrib;
- ++Ptr;
- Buff->CursorPosition.X++;
- }
- UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X - 1);
- if (Buff->CursorPosition.X == Buff->ScreenBufferSize.X)
- {
- if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT)
- {
- Buff->CursorPosition.X = 0;
- ConioNextLine(Buff, &UpdateRect, &ScrolledLines);
- }
- else
- {
- Buff->CursorPosition.X--;
- }
- }
- continue;
- }
- // /* --- BEL ---*/
- // else if (Buffer[i] == L'\a')
- // {
- // // FIXME: This MUST BE moved to the terminal emulator frontend!!
- // DPRINT1("Bell\n");
- // // SendNotifyMessage(Console->hWindow, PM_CONSOLE_BEEP, 0, 0);
- // continue;
- // }
- }
- UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
- UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X);
-
- Ptr = ConioCoordToPointer(Buff, Buff->CursorPosition.X,
Buff->CursorPosition.Y);
- Ptr->Char.UnicodeChar = Buffer[i];
- if (Attrib) Ptr->Attributes = Buff->ScreenDefaultAttrib;
-
- Buff->CursorPosition.X++;
- if (Buff->CursorPosition.X == Buff->ScreenBufferSize.X)
- {
- if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT)
- {
- Buff->CursorPosition.X = 0;
- ConioNextLine(Buff, &UpdateRect, &ScrolledLines);
- }
- else
- {
- Buff->CursorPosition.X = CursorStartX;
- }
- }
- }
-
- if (!ConioIsRectEmpty(&UpdateRect) && (PCONSOLE_SCREEN_BUFFER)Buff ==
Console->ActiveBuffer)
- {
- ConioWriteStream(Console, &UpdateRect, CursorStartX, CursorStartY,
- ScrolledLines, Buffer, Length);
- }
-
- return STATUS_SUCCESS;
-}
-
-
-/* PUBLIC DRIVER APIS *********************************************************/
-
-NTSTATUS NTAPI
-ConDrvReadConsoleOutput(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN BOOLEAN Unicode,
- OUT PCHAR_INFO CharInfo/*Buffer*/,
- IN PCOORD BufferSize,
- IN PCOORD BufferCoord,
- IN OUT PSMALL_RECT ReadRegion)
-{
- PCHAR_INFO CurCharInfo;
- SHORT SizeX, SizeY;
- SMALL_RECT CapturedReadRegion;
- SMALL_RECT ScreenRect;
- DWORD i;
- PCHAR_INFO Ptr;
- LONG X, Y;
- UINT CodePage;
-
- if (Console == NULL || Buffer == NULL || CharInfo == NULL ||
- BufferSize == NULL || BufferCoord == NULL || ReadRegion == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- CapturedReadRegion = *ReadRegion;
-
- /* FIXME: Is this correct? */
- CodePage = Console->OutputCodePage;
-
- SizeX = min(BufferSize->X - BufferCoord->X,
ConioRectWidth(&CapturedReadRegion));
- SizeY = min(BufferSize->Y - BufferCoord->Y,
ConioRectHeight(&CapturedReadRegion));
- CapturedReadRegion.Right = CapturedReadRegion.Left + SizeX;
- CapturedReadRegion.Bottom = CapturedReadRegion.Top + SizeY;
-
- ConioInitRect(&ScreenRect, 0, 0, Buffer->ScreenBufferSize.Y,
Buffer->ScreenBufferSize.X);
- if (!ConioGetIntersection(&CapturedReadRegion, &ScreenRect,
&CapturedReadRegion))
- {
- return STATUS_SUCCESS;
- }
-
- for (i = 0, Y = CapturedReadRegion.Top; Y < CapturedReadRegion.Bottom; ++i, ++Y)
- {
- CurCharInfo = CharInfo + (i * BufferSize->X);
-
- Ptr = ConioCoordToPointer(Buffer, CapturedReadRegion.Left, Y);
- for (X = CapturedReadRegion.Left; X < CapturedReadRegion.Right; ++X)
- {
- if (Unicode)
- {
- CurCharInfo->Char.UnicodeChar = Ptr->Char.UnicodeChar;
- }
- else
- {
- // ConsoleUnicodeCharToAnsiChar(Console,
&CurCharInfo->Char.AsciiChar, &Ptr->Char.UnicodeChar);
- WideCharToMultiByte(CodePage, 0, &Ptr->Char.UnicodeChar, 1,
- &CurCharInfo->Char.AsciiChar, 1, NULL, NULL);
- }
- CurCharInfo->Attributes = Ptr->Attributes;
- ++Ptr;
- ++CurCharInfo;
- }
- }
-
- ReadRegion->Left = CapturedReadRegion.Left;
- ReadRegion->Top = CapturedReadRegion.Top ;
- ReadRegion->Right = CapturedReadRegion.Left + SizeX - 1;
- ReadRegion->Bottom = CapturedReadRegion.Top + SizeY - 1;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvWriteConsoleOutput(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN BOOLEAN Unicode,
- IN PCHAR_INFO CharInfo/*Buffer*/,
- IN PCOORD BufferSize,
- IN PCOORD BufferCoord,
- IN OUT PSMALL_RECT WriteRegion)
-{
- SHORT i, X, Y, SizeX, SizeY;
- SMALL_RECT ScreenBuffer;
- PCHAR_INFO CurCharInfo;
- SMALL_RECT CapturedWriteRegion;
- PCHAR_INFO Ptr;
-
- if (Console == NULL || Buffer == NULL || CharInfo == NULL ||
- BufferSize == NULL || BufferCoord == NULL || WriteRegion == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- CapturedWriteRegion = *WriteRegion;
-
- SizeX = min(BufferSize->X - BufferCoord->X,
ConioRectWidth(&CapturedWriteRegion));
- SizeY = min(BufferSize->Y - BufferCoord->Y,
ConioRectHeight(&CapturedWriteRegion));
- CapturedWriteRegion.Right = CapturedWriteRegion.Left + SizeX - 1;
- CapturedWriteRegion.Bottom = CapturedWriteRegion.Top + SizeY - 1;
-
- /* Make sure WriteRegion is inside the screen buffer */
- ConioInitRect(&ScreenBuffer, 0, 0, Buffer->ScreenBufferSize.Y - 1,
Buffer->ScreenBufferSize.X - 1);
- if (!ConioGetIntersection(&CapturedWriteRegion, &ScreenBuffer,
&CapturedWriteRegion))
- {
- /*
- * It is okay to have a WriteRegion completely outside
- * the screen buffer. No data is written then.
- */
- return STATUS_SUCCESS;
- }
-
- for (i = 0, Y = CapturedWriteRegion.Top; Y <= CapturedWriteRegion.Bottom; i++,
Y++)
- {
- CurCharInfo = CharInfo + (i + BufferCoord->Y) * BufferSize->X +
BufferCoord->X;
-
- Ptr = ConioCoordToPointer(Buffer, CapturedWriteRegion.Left, Y);
- for (X = CapturedWriteRegion.Left; X <= CapturedWriteRegion.Right; X++)
- {
- if (Unicode)
- {
- Ptr->Char.UnicodeChar = CurCharInfo->Char.UnicodeChar;
- }
- else
- {
- ConsoleAnsiCharToUnicodeChar(Console, &Ptr->Char.UnicodeChar,
&CurCharInfo->Char.AsciiChar);
- }
- Ptr->Attributes = CurCharInfo->Attributes;
- ++Ptr;
- ++CurCharInfo;
- }
- }
-
- ConioDrawRegion(Console, &CapturedWriteRegion);
-
- WriteRegion->Left = CapturedWriteRegion.Left;
- WriteRegion->Top = CapturedWriteRegion.Top ;
- WriteRegion->Right = CapturedWriteRegion.Left + SizeX - 1;
- WriteRegion->Bottom = CapturedWriteRegion.Top + SizeY - 1;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvWriteConsole(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
- IN BOOLEAN Unicode,
- IN PVOID StringBuffer,
- IN ULONG NumCharsToWrite,
- OUT PULONG NumCharsWritten OPTIONAL)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- PWCHAR Buffer = NULL;
- ULONG Written = 0;
- ULONG Length;
-
- if (Console == NULL || ScreenBuffer == NULL /* || StringBuffer == NULL */)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity checks */
- ASSERT(Console == ScreenBuffer->Header.Console);
- ASSERT( (StringBuffer != NULL && NumCharsToWrite >= 0) ||
- (StringBuffer == NULL && NumCharsToWrite == 0) );
-
- // if (Console->PauseFlags & (PAUSED_FROM_KEYBOARD | PAUSED_FROM_SCROLLBAR |
PAUSED_FROM_SELECTION))
- if (Console->PauseFlags && Console->UnpauseEvent != NULL)
- {
- return STATUS_PENDING;
- }
-
- if (Unicode)
- {
- Buffer = StringBuffer;
- }
- else
- {
- Length = MultiByteToWideChar(Console->OutputCodePage, 0,
- (PCHAR)StringBuffer,
- NumCharsToWrite,
- NULL, 0);
- Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length * sizeof(WCHAR));
- if (Buffer)
- {
- MultiByteToWideChar(Console->OutputCodePage, 0,
- (PCHAR)StringBuffer,
- NumCharsToWrite,
- (PWCHAR)Buffer, Length);
- }
- else
- {
- Status = STATUS_NO_MEMORY;
- }
- }
-
- if (Buffer)
- {
- if (NT_SUCCESS(Status))
- {
- Status = ConioWriteConsole(Console,
- ScreenBuffer,
- Buffer,
- NumCharsToWrite,
- TRUE);
- if (NT_SUCCESS(Status))
- {
- Written = NumCharsToWrite;
- }
- }
-
- if (!Unicode) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
- }
-
- if (NumCharsWritten) *NumCharsWritten = Written;
-
- return Status;
-}
-
-NTSTATUS NTAPI
-ConDrvReadConsoleOutputString(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN CODE_TYPE CodeType,
- OUT PVOID StringBuffer,
- IN ULONG NumCodesToRead,
- IN PCOORD ReadCoord,
- OUT PCOORD EndCoord,
- OUT PULONG CodesRead)
-{
- SHORT Xpos, Ypos;
- PVOID ReadBuffer;
- ULONG i;
- ULONG CodeSize;
- PCHAR_INFO Ptr;
-
- if (Console == NULL || Buffer == NULL ||
- ReadCoord == NULL || EndCoord == NULL || CodesRead == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Validity checks */
- ASSERT(Console == Buffer->Header.Console);
- ASSERT( (StringBuffer != NULL && NumCodesToRead >= 0) ||
- (StringBuffer == NULL && NumCodesToRead == 0) );
-
- switch (CodeType)
- {
- case CODE_ASCII:
- CodeSize = sizeof(CHAR);
- break;
-
- case CODE_UNICODE:
- CodeSize = sizeof(WCHAR);
- break;
-
- case CODE_ATTRIBUTE:
- CodeSize = sizeof(WORD);
- break;
-
- default:
- return STATUS_INVALID_PARAMETER;
- }
-
- ReadBuffer = StringBuffer;
- Xpos = ReadCoord->X;
- Ypos = (ReadCoord->Y + Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
-
- /*
- * MSDN (ReadConsoleOutputAttribute and ReadConsoleOutputCharacter) :
- *
- * If the number of attributes (resp. characters) to be read from extends
- * beyond the end of the specified screen buffer row, attributes (resp.
- * characters) are read from the next row. If the number of attributes
- * (resp. characters) to be read from extends beyond the end of the console
- * screen buffer, attributes (resp. characters) up to the end of the console
- * screen buffer are read.
- *
- * TODO: Do NOT loop up to NumCodesToRead, but stop before
- * if we are going to overflow...
- */
- // Ptr = ConioCoordToPointer(Buffer, Xpos, Ypos); // Doesn't work
- for (i = 0; i < min(NumCodesToRead, Buffer->ScreenBufferSize.X *
Buffer->ScreenBufferSize.Y); ++i)
- {
- // Ptr = ConioCoordToPointer(Buffer, Xpos, Ypos); // Doesn't work either
- Ptr = &Buffer->Buffer[Xpos + Ypos * Buffer->ScreenBufferSize.X];
-
- switch (CodeType)
- {
- case CODE_ASCII:
- ConsoleUnicodeCharToAnsiChar(Console, (PCHAR)ReadBuffer,
&Ptr->Char.UnicodeChar);
- break;
-
- case CODE_UNICODE:
- *(PWCHAR)ReadBuffer = Ptr->Char.UnicodeChar;
- break;
-
- case CODE_ATTRIBUTE:
- *(PWORD)ReadBuffer = Ptr->Attributes;
- break;
- }
- ReadBuffer = (PVOID)((ULONG_PTR)ReadBuffer + CodeSize);
- // ++Ptr;
-
- Xpos++;
-
- if (Xpos == Buffer->ScreenBufferSize.X)
- {
- Xpos = 0;
- Ypos++;
-
- if (Ypos == Buffer->ScreenBufferSize.Y)
- {
- Ypos = 0;
- }
- }
- }
-
- // switch (CodeType)
- // {
- // case CODE_UNICODE:
- // *(PWCHAR)ReadBuffer = 0;
- // break;
-
- // case CODE_ASCII:
- // *(PCHAR)ReadBuffer = 0;
- // break;
-
- // case CODE_ATTRIBUTE:
- // *(PWORD)ReadBuffer = 0;
- // break;
- // }
-
- EndCoord->X = Xpos;
- EndCoord->Y = (Ypos - Buffer->VirtualY + Buffer->ScreenBufferSize.Y) %
Buffer->ScreenBufferSize.Y;
-
- *CodesRead = (ULONG)((ULONG_PTR)ReadBuffer - (ULONG_PTR)StringBuffer) / CodeSize;
- // <= NumCodesToRead
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvWriteConsoleOutputString(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN CODE_TYPE CodeType,
- IN PVOID StringBuffer,
- IN ULONG NumCodesToWrite,
- IN PCOORD WriteCoord /*,
- OUT PCOORD EndCoord,
- OUT PULONG CodesWritten */)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- PVOID WriteBuffer = NULL;
- PWCHAR tmpString = NULL;
- DWORD X, Y, Length; // , Written = 0;
- ULONG CodeSize;
- SMALL_RECT UpdateRect;
- PCHAR_INFO Ptr;
-
- if (Console == NULL || Buffer == NULL ||
- WriteCoord == NULL /* || EndCoord == NULL || CodesWritten == NULL */)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Validity checks */
- ASSERT(Console == Buffer->Header.Console);
- ASSERT( (StringBuffer != NULL && NumCodesToWrite >= 0) ||
- (StringBuffer == NULL && NumCodesToWrite == 0) );
-
- switch (CodeType)
- {
- case CODE_ASCII:
- CodeSize = sizeof(CHAR);
- break;
-
- case CODE_UNICODE:
- CodeSize = sizeof(WCHAR);
- break;
-
- case CODE_ATTRIBUTE:
- CodeSize = sizeof(WORD);
- break;
-
- default:
- return STATUS_INVALID_PARAMETER;
- }
-
- if (CodeType == CODE_ASCII)
- {
- /* Convert the ASCII string into Unicode before writing it to the console */
- Length = MultiByteToWideChar(Console->OutputCodePage, 0,
- (PCHAR)StringBuffer,
- NumCodesToWrite,
- NULL, 0);
- tmpString = WriteBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length *
sizeof(WCHAR));
- if (WriteBuffer)
- {
- MultiByteToWideChar(Console->OutputCodePage, 0,
- (PCHAR)StringBuffer,
- NumCodesToWrite,
- (PWCHAR)WriteBuffer, Length);
- }
- else
- {
- Status = STATUS_NO_MEMORY;
- }
- }
- else
- {
- /* For CODE_UNICODE or CODE_ATTRIBUTE, we are already OK */
- WriteBuffer = StringBuffer;
- }
-
- if (WriteBuffer == NULL || !NT_SUCCESS(Status)) goto Cleanup;
-
- X = WriteCoord->X;
- Y = (WriteCoord->Y + Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
- Length = NumCodesToWrite;
- // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work
- // Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X]; // May work
-
- while (Length--)
- {
- // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work either
- Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X];
-
- switch (CodeType)
- {
- case CODE_ASCII:
- case CODE_UNICODE:
- Ptr->Char.UnicodeChar = *(PWCHAR)WriteBuffer;
- break;
-
- case CODE_ATTRIBUTE:
- Ptr->Attributes = *(PWORD)WriteBuffer;
- break;
- }
- WriteBuffer = (PVOID)((ULONG_PTR)WriteBuffer + CodeSize);
- // ++Ptr;
-
- // Written++;
- if (++X == Buffer->ScreenBufferSize.X)
- {
- X = 0;
-
- if (++Y == Buffer->ScreenBufferSize.Y)
- {
- Y = 0;
- }
- }
- }
-
- if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
- {
- ConioComputeUpdateRect(Buffer, &UpdateRect, WriteCoord, NumCodesToWrite);
- ConioDrawRegion(Console, &UpdateRect);
- }
-
- // EndCoord->X = X;
- // EndCoord->Y = (Y + Buffer->ScreenBufferSize.Y - Buffer->VirtualY) %
Buffer->ScreenBufferSize.Y;
-
-Cleanup:
- if (tmpString) RtlFreeHeap(RtlGetProcessHeap(), 0, tmpString);
-
- // CodesWritten = Written;
- return Status;
-}
-
-NTSTATUS NTAPI
-ConDrvFillConsoleOutput(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN CODE_TYPE CodeType,
- IN PVOID Code,
- IN ULONG NumCodesToWrite,
- IN PCOORD WriteCoord /*,
- OUT PULONG CodesWritten */)
-{
- DWORD X, Y, Length; // , Written = 0;
- PCHAR_INFO Ptr;
- SMALL_RECT UpdateRect;
-
- if (Console == NULL || Buffer == NULL || Code == NULL ||
- WriteCoord == NULL /* || CodesWritten == NULL */)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
-#if 0
- switch (CodeType)
- {
- case CODE_ASCII:
- /* On-place conversion from the ASCII char to the UNICODE char */
- ConsoleAnsiCharToUnicodeChar(Console, &Code->UnicodeChar,
&Code->AsciiChar);
- /* Fall through */
- case CODE_UNICODE:
- Code = &Code->UnicodeChar;
- break;
-
- case CODE_ATTRIBUTE:
- Code = &Code->Attribute;
- break;
- }
-#else
- if (CodeType == CODE_ASCII)
- {
- /* On-place conversion from the ASCII char to the UNICODE char */
- // FIXME: What if Code points to an invalid memory zone ??
- ConsoleAnsiCharToUnicodeChar(Console, (PWCHAR)Code, (PCHAR)Code);
- }
-#endif
-
- X = WriteCoord->X;
- Y = (WriteCoord->Y + Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
- Length = NumCodesToWrite;
- // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work
- // Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X]; // May work
-
- while (Length--)
- {
- // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work either
- Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X];
-
- switch (CodeType)
- {
- case CODE_ASCII:
- case CODE_UNICODE:
- Ptr->Char.UnicodeChar = *(PWCHAR)Code;
- break;
-
- case CODE_ATTRIBUTE:
- Ptr->Attributes = *(PWORD)Code;
- break;
- }
- // ++Ptr;
-
- // Written++;
- if (++X == Buffer->ScreenBufferSize.X)
- {
- X = 0;
-
- if (++Y == Buffer->ScreenBufferSize.Y)
- {
- Y = 0;
- }
- }
- }
-
- if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
- {
- ConioComputeUpdateRect(Buffer, &UpdateRect, WriteCoord, NumCodesToWrite);
- ConioDrawRegion(Console, &UpdateRect);
- }
-
- // CodesWritten = Written; // NumCodesToWrite;
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleScreenBufferInfo(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- OUT PCONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo)
-{
- if (Console == NULL || Buffer == NULL || ScreenBufferInfo == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- ScreenBufferInfo->dwSize = Buffer->ScreenBufferSize;
- ScreenBufferInfo->dwCursorPosition = Buffer->CursorPosition;
- ScreenBufferInfo->wAttributes = Buffer->ScreenDefaultAttrib;
- ScreenBufferInfo->srWindow.Left = Buffer->ViewOrigin.X;
- ScreenBufferInfo->srWindow.Top = Buffer->ViewOrigin.Y;
- ScreenBufferInfo->srWindow.Right = Buffer->ViewOrigin.X +
Buffer->ViewSize.X - 1;
- ScreenBufferInfo->srWindow.Bottom = Buffer->ViewOrigin.Y +
Buffer->ViewSize.Y - 1;
-
- // FIXME: Refine the computation
- ScreenBufferInfo->dwMaximumWindowSize = Buffer->ScreenBufferSize;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleTextAttribute(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN WORD Attribute)
-{
- if (Console == NULL || Buffer == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- Buffer->ScreenDefaultAttrib = Attribute;
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleScreenBufferSize(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN PCOORD Size)
-{
- NTSTATUS Status;
-
- if (Console == NULL || Buffer == NULL || Size == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- Status = ConioResizeBuffer(Console, Buffer, *Size);
- if (NT_SUCCESS(Status)) ConioResizeTerminal(Console);
-
- return Status;
-}
-
-NTSTATUS NTAPI
-ConDrvScrollConsoleScreenBuffer(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN BOOLEAN Unicode,
- IN PSMALL_RECT ScrollRectangle,
- IN BOOLEAN UseClipRectangle,
- IN PSMALL_RECT ClipRectangle OPTIONAL,
- IN PCOORD DestinationOrigin,
- IN CHAR_INFO FillChar)
-{
- COORD CapturedDestinationOrigin;
- SMALL_RECT ScreenBuffer;
- SMALL_RECT SrcRegion;
- SMALL_RECT DstRegion;
- SMALL_RECT UpdateRegion;
- SMALL_RECT CapturedClipRectangle;
-
- if (Console == NULL || Buffer == NULL || ScrollRectangle == NULL ||
- (UseClipRectangle ? ClipRectangle == NULL : FALSE) || DestinationOrigin == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- CapturedDestinationOrigin = *DestinationOrigin;
-
- /* Make sure the source rectangle is inside the screen buffer */
- ConioInitRect(&ScreenBuffer, 0, 0, Buffer->ScreenBufferSize.Y - 1,
Buffer->ScreenBufferSize.X - 1);
- if (!ConioGetIntersection(&SrcRegion, &ScreenBuffer, ScrollRectangle))
- {
- return STATUS_SUCCESS;
- }
-
- /* If the source was clipped on the left or top, adjust the destination accordingly
*/
- if (ScrollRectangle->Left < 0)
- {
- CapturedDestinationOrigin.X -= ScrollRectangle->Left;
- }
- if (ScrollRectangle->Top < 0)
- {
- CapturedDestinationOrigin.Y -= ScrollRectangle->Top;
- }
-
- if (UseClipRectangle)
- {
- CapturedClipRectangle = *ClipRectangle;
- if (!ConioGetIntersection(&CapturedClipRectangle, &CapturedClipRectangle,
&ScreenBuffer))
- {
- return STATUS_SUCCESS;
- }
- }
- else
- {
- CapturedClipRectangle = ScreenBuffer;
- }
-
- ConioInitRect(&DstRegion,
- CapturedDestinationOrigin.Y,
- CapturedDestinationOrigin.X,
- CapturedDestinationOrigin.Y + ConioRectHeight(&SrcRegion) - 1,
- CapturedDestinationOrigin.X + ConioRectWidth(&SrcRegion ) - 1);
-
- if (!Unicode)
- ConsoleAnsiCharToUnicodeChar(Console, &FillChar.Char.UnicodeChar,
&FillChar.Char.AsciiChar);
-
- ConioMoveRegion(Buffer, &SrcRegion, &DstRegion, &CapturedClipRectangle,
FillChar);
-
- if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
- {
- ConioGetUnion(&UpdateRegion, &SrcRegion, &DstRegion);
- if (ConioGetIntersection(&UpdateRegion, &UpdateRegion,
&CapturedClipRectangle))
- {
- /* Draw update region */
- ConioDrawRegion(Console, &UpdateRegion);
- }
- }
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS NTAPI
-ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
- IN PTEXTMODE_SCREEN_BUFFER Buffer,
- IN BOOLEAN Absolute,
- IN PSMALL_RECT WindowRect)
-{
- SMALL_RECT CapturedWindowRect;
-
- if (Console == NULL || Buffer == NULL || WindowRect == NULL)
- return STATUS_INVALID_PARAMETER;
-
- /* Validity check */
- ASSERT(Console == Buffer->Header.Console);
-
- CapturedWindowRect = *WindowRect;
-
- if (Absolute == FALSE)
- {
- /* Relative positions given. Transform them to absolute ones */
- CapturedWindowRect.Left += Buffer->ViewOrigin.X;
- CapturedWindowRect.Top += Buffer->ViewOrigin.Y;
- CapturedWindowRect.Right += Buffer->ViewOrigin.X + Buffer->ViewSize.X -
1;
- CapturedWindowRect.Bottom += Buffer->ViewOrigin.Y + Buffer->ViewSize.Y -
1;
- }
-
- /* See MSDN documentation on SetConsoleWindowInfo about the performed checks */
- if ( (CapturedWindowRect.Left < 0) || (CapturedWindowRect.Top < 0) ||
- (CapturedWindowRect.Right >= Buffer->ScreenBufferSize.X) ||
- (CapturedWindowRect.Bottom >= Buffer->ScreenBufferSize.Y) ||
- (CapturedWindowRect.Right <= CapturedWindowRect.Left) ||
- (CapturedWindowRect.Bottom <= CapturedWindowRect.Top) )
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- Buffer->ViewOrigin.X = CapturedWindowRect.Left;
- Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
-
- Buffer->ViewSize.X = CapturedWindowRect.Right - CapturedWindowRect.Left + 1;
- Buffer->ViewSize.Y = CapturedWindowRect.Bottom - CapturedWindowRect.Top + 1;
-
- return STATUS_SUCCESS;
-}
-
-/* EOF */
diff --git a/win32ss/user/winsrv/consrv_new/coninput.c
b/win32ss/user/winsrv/consrv_new/coninput.c
deleted file mode 100644
index 2516df2e047..00000000000
--- a/win32ss/user/winsrv/consrv_new/coninput.c
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS Console Server DLL
- * FILE: win32ss/user/winsrv/consrv_new/coninput.c
- * PURPOSE: Console Input functions
- * PROGRAMMERS: Jeffrey Morlan
- * Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
- */
-
-/* INCLUDES *******************************************************************/
-
-#include "consrv.h"
-#include "include/conio.h"
-#include "include/conio2.h"
-#include "handle.h"
-#include "lineinput.h"
-
-#define NDEBUG
-#include <debug.h>
-
-
-/* GLOBALS ********************************************************************/
-
-#define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
- ConSrvGetObject((ProcessData), (Handle), (PCONSOLE_IO_OBJECT*)(Ptr), NULL, \
- (Access), (LockConsole), INPUT_BUFFER)
-#define ConSrvGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access,
LockConsole) \
- ConSrvGetObject((ProcessData), (Handle), (PCONSOLE_IO_OBJECT*)(Ptr), (Entry),
\
- (Access), (LockConsole), INPUT_BUFFER)
-#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked) \
- ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))
-
-
-typedef struct _GET_INPUT_INFO
-{
- PCSR_THREAD CallingThread; // The thread which called the input API.
- PVOID HandleEntry; // The handle data associated with the wait
thread.
- PCONSOLE_INPUT_BUFFER InputBuffer; // The input buffer corresponding to the
handle.
-} GET_INPUT_INFO, *PGET_INPUT_INFO;
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-static NTSTATUS
-WaitBeforeReading(IN PGET_INPUT_INFO InputInfo,
- IN PCSR_API_MESSAGE ApiMessage,
- IN CSR_WAIT_FUNCTION WaitFunction OPTIONAL,
- IN BOOL CreateWaitBlock OPTIONAL)
-{
- if (CreateWaitBlock)
- {
- PGET_INPUT_INFO CapturedInputInfo;
-
- CapturedInputInfo = ConsoleAllocHeap(0, sizeof(GET_INPUT_INFO));
- if (!CapturedInputInfo) return STATUS_NO_MEMORY;
-
- RtlMoveMemory(CapturedInputInfo, InputInfo, sizeof(GET_INPUT_INFO));
-
- if (!CsrCreateWait(&InputInfo->InputBuffer->ReadWaitQueue,
- WaitFunction,
- InputInfo->CallingThread,
- ApiMessage,
- CapturedInputInfo,
- NULL))
- {
- ConsoleFreeHeap(CapturedInputInfo);
- return STATUS_NO_MEMORY;
- }
- }
-
- /* Wait for input */
- return STATUS_PENDING;
-}
-
-static NTSTATUS
-ReadChars(IN PGET_INPUT_INFO InputInfo,
- IN PCSR_API_MESSAGE ApiMessage,
- IN BOOL CreateWaitBlock OPTIONAL);
-
-// Wait function CSR_WAIT_FUNCTION
-static BOOLEAN
-ReadCharsThread(IN PLIST_ENTRY WaitList,
- IN PCSR_THREAD WaitThread,
- IN PCSR_API_MESSAGE WaitApiMessage,
- IN PVOID WaitContext,
- IN PVOID WaitArgument1,
- IN PVOID WaitArgument2,
- IN ULONG WaitFlags)
-{
- NTSTATUS Status;
- PGET_INPUT_INFO InputInfo = (PGET_INPUT_INFO)WaitContext;
-
- PVOID InputHandle = WaitArgument2;
-
- DPRINT("ReadCharsThread - WaitContext = 0x%p, WaitArgument1 = 0x%p,
WaitArgument2 = 0x%p, WaitFlags = %lu\n", WaitContext, WaitArgument1, WaitArgument2,
WaitFlags);
-
- /*
- * If we are notified of the process termination via a call
- * to CsrNotifyWaitBlock triggered by CsrDestroyProcess or
- * CsrDestroyThread, just return.
- */
- if (WaitFlags & CsrProcessTerminating)
- {
- Status = STATUS_THREAD_IS_TERMINATING;
- goto Quit;
- }
-
- /*
- * Somebody is closing a handle to this input buffer,
- * by calling ConSrvCloseHandleEntry.
- * See whether we are linked to that handle (ie. we
- * are a waiter for this handle), and if so, return.
- * Otherwise, ignore the call and continue waiting.
- */
- if (InputHandle != NULL)
- {
- Status = (InputHandle == InputInfo->HandleEntry ? STATUS_ALERTED
- : STATUS_PENDING);
- goto Quit;
- }
-
- /*
- * If we go there, that means we are notified for some new input.
- * The console is therefore already locked.
- */
- Status = ReadChars(InputInfo,
- WaitApiMessage,
- FALSE);
-
-Quit:
- if (Status != STATUS_PENDING)
- {
- WaitApiMessage->Status = Status;
- ConsoleFreeHeap(InputInfo);
- }
-
- return (Status == STATUS_PENDING ? FALSE : TRUE);
-}
-
-NTSTATUS NTAPI
-ConDrvReadConsole(IN PCONSOLE Console,
- IN PCONSOLE_INPUT_BUFFER InputBuffer,
- IN BOOLEAN Unicode,
- OUT PVOID Buffer,
- IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl,
- IN ULONG NumCharsToRead,
- OUT PULONG NumCharsRead OPTIONAL);
-static NTSTATUS
-ReadChars(IN PGET_INPUT_INFO InputInfo,
- IN PCSR_API_MESSAGE ApiMessage,
- IN BOOL CreateWaitBlock OPTIONAL)
-{
- NTSTATUS Status;
- PCONSOLE_READCONSOLE ReadConsoleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadConsoleRequest;
- PCONSOLE_INPUT_BUFFER InputBuffer = InputInfo->InputBuffer;
- CONSOLE_READCONSOLE_CONTROL ReadControl;
-
- ReadControl.nLength = sizeof(CONSOLE_READCONSOLE_CONTROL);
- ReadControl.nInitialChars = ReadConsoleRequest->NrCharactersRead;
- ReadControl.dwCtrlWakeupMask = ReadConsoleRequest->CtrlWakeupMask;
- ReadControl.dwControlKeyState = ReadConsoleRequest->ControlKeyState;
-
- Status = ConDrvReadConsole(InputBuffer->Header.Console,
- InputBuffer,
- ReadConsoleRequest->Unicode,
- ReadConsoleRequest->Buffer,
- &ReadControl,
- ReadConsoleRequest->NrCharactersToRead,
- &ReadConsoleRequest->NrCharactersRead);
-
- ReadConsoleRequest->ControlKeyState = ReadControl.dwControlKeyState;
-
- if (Status == STATUS_PENDING)
- {
- /* We haven't completed a read, so start a wait */
- return WaitBeforeReading(InputInfo,
- ApiMessage,
- ReadCharsThread,
- CreateWaitBlock);
- }
- else
- {
- /* We read all what we wanted, we return the error code we were given */
- return Status;
- // return STATUS_SUCCESS;
- }
-}
-
-static NTSTATUS
-ReadInputBuffer(IN PGET_INPUT_INFO InputInfo,
- IN BOOL Wait,
- IN PCSR_API_MESSAGE ApiMessage,
- IN BOOL CreateWaitBlock OPTIONAL);
-
-// Wait function CSR_WAIT_FUNCTION
-static BOOLEAN
-ReadInputBufferThread(IN PLIST_ENTRY WaitList,
- IN PCSR_THREAD WaitThread,
- IN PCSR_API_MESSAGE WaitApiMessage,
- IN PVOID WaitContext,
- IN PVOID WaitArgument1,
- IN PVOID WaitArgument2,
- IN ULONG WaitFlags)
-{
- NTSTATUS Status;
- PCONSOLE_GETINPUT GetInputRequest =
&((PCONSOLE_API_MESSAGE)WaitApiMessage)->Data.GetInputRequest;
- PGET_INPUT_INFO InputInfo = (PGET_INPUT_INFO)WaitContext;
-
- PVOID InputHandle = WaitArgument2;
-
- DPRINT("ReadInputBufferThread - WaitContext = 0x%p, WaitArgument1 = 0x%p,
WaitArgument2 = 0x%p, WaitFlags = %lu\n", WaitContext, WaitArgument1, WaitArgument2,
WaitFlags);
-
- /*
- * If we are notified of the process termination via a call
- * to CsrNotifyWaitBlock triggered by CsrDestroyProcess or
- * CsrDestroyThread, just return.
- */
- if (WaitFlags & CsrProcessTerminating)
- {
- Status = STATUS_THREAD_IS_TERMINATING;
- goto Quit;
- }
-
- /*
- * Somebody is closing a handle to this input buffer,
- * by calling ConSrvCloseHandleEntry.
- * See whether we are linked to that handle (ie. we
- * are a waiter for this handle), and if so, return.
- * Otherwise, ignore the call and continue waiting.
- */
- if (InputHandle != NULL)
- {
- Status = (InputHandle == InputInfo->HandleEntry ? STATUS_ALERTED
- : STATUS_PENDING);
- goto Quit;
- }
-
- /*
- * If we go there, that means we are notified for some new input.
- * The console is therefore already locked.
- */
- Status = ReadInputBuffer(InputInfo,
- GetInputRequest->bRead,
- WaitApiMessage,
- FALSE);
-
-Quit:
- if (Status != STATUS_PENDING)
- {
- WaitApiMessage->Status = Status;
- ConsoleFreeHeap(InputInfo);
- }
-
- return (Status == STATUS_PENDING ? FALSE : TRUE);
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsoleInput(IN PCONSOLE Console,
- IN PCONSOLE_INPUT_BUFFER InputBuffer,
- IN BOOLEAN WaitForMoreEvents,
- IN BOOLEAN Unicode,
- OUT PINPUT_RECORD InputRecord,
- IN ULONG NumEventsToRead,
- OUT PULONG NumEventsRead);
-static NTSTATUS
-ReadInputBuffer(IN PGET_INPUT_INFO InputInfo,
- IN BOOL Wait, // TRUE --> Read ; FALSE --> Peek
- IN PCSR_API_MESSAGE ApiMessage,
- IN BOOL CreateWaitBlock OPTIONAL)
-{
- NTSTATUS Status;
- PCONSOLE_GETINPUT GetInputRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetInputRequest;
- PCONSOLE_INPUT_BUFFER InputBuffer = InputInfo->InputBuffer;
-
- // GetInputRequest->InputsRead = 0;
-
- Status = ConDrvGetConsoleInput(InputBuffer->Header.Console,
- InputBuffer,
- Wait,
- GetInputRequest->Unicode,
- GetInputRequest->InputRecord,
- GetInputRequest->Length,
- &GetInputRequest->InputsRead);
-
- if (Status == STATUS_PENDING)
- {
- /* We haven't completed a read, so start a wait */
- return WaitBeforeReading(InputInfo,
- ApiMessage,
- ReadInputBufferThread,
- CreateWaitBlock);
- }
- else
- {
- /* We read all what we wanted, we return the error code we were given */
- return Status;
- // return STATUS_SUCCESS;
- }
-}
-
-
-/* PUBLIC SERVER APIS *********************************************************/
-
-/* API_NUMBER: ConsolepReadConsole */
-CSR_API(SrvReadConsole)
-{
- NTSTATUS Status;
- PCONSOLE_READCONSOLE ReadConsoleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadConsoleRequest;
- PCONSOLE_PROCESS_DATA ProcessData =
ConsoleGetPerProcessData(CsrGetClientThread()->Process);
- PVOID HandleEntry;
- PCONSOLE_INPUT_BUFFER InputBuffer;
- GET_INPUT_INFO InputInfo;
-
- DPRINT("SrvReadConsole\n");
-
- if (!CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&ReadConsoleRequest->Buffer,
- ReadConsoleRequest->BufferSize,
- sizeof(BYTE)))
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- if (ReadConsoleRequest->NrCharactersRead >
ReadConsoleRequest->NrCharactersToRead)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- Status = ConSrvGetInputBufferAndHandleEntry(ProcessData,
ReadConsoleRequest->InputHandle, &InputBuffer, &HandleEntry, GENERIC_READ,
TRUE);
- if (!NT_SUCCESS(Status)) return Status;
-
- // This member is set by the caller (IntReadConsole in kernel32)
- // ReadConsoleRequest->NrCharactersRead = 0;
-
- InputInfo.CallingThread = CsrGetClientThread();
- InputInfo.HandleEntry = HandleEntry;
- InputInfo.InputBuffer = InputBuffer;
-
- Status = ReadChars(&InputInfo,
- ApiMessage,
- TRUE);
-
- ConSrvReleaseInputBuffer(InputBuffer, TRUE);
-
- if (Status == STATUS_PENDING) *ReplyCode = CsrReplyPending;
-
- return Status;
-}
-
-CSR_API(SrvGetConsoleInput)
-{
- NTSTATUS Status;
- PCONSOLE_GETINPUT GetInputRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetInputRequest;
- PCONSOLE_PROCESS_DATA ProcessData =
ConsoleGetPerProcessData(CsrGetClientThread()->Process);
- PVOID HandleEntry;
- PCONSOLE_INPUT_BUFFER InputBuffer;
- GET_INPUT_INFO InputInfo;
-
- DPRINT("SrvGetConsoleInput\n");
-
- if (!CsrValidateMessageBuffer(ApiMessage,
- (PVOID*)&GetInputRequest->InputRecord,
- GetInputRequest->Length,
- sizeof(INPUT_RECORD)))
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- Status = ConSrvGetInputBufferAndHandleEntry(ProcessData,
GetInputRequest->InputHandle, &InputBuffer, &HandleEntry, GENERIC_READ, TRUE);
- if (!NT_SUCCESS(Status)) return Status;
-
- GetInputRequest->InputsRead = 0;
-
- InputInfo.CallingThread = CsrGetClientThread();
- InputInfo.HandleEntry = HandleEntry;
- InputInfo.InputBuffer = InputBuffer;
... 11834 lines suppressed ...