Author: hbelusca
Date: Tue Mar 19 22:05:38 2013
New Revision: 58555
URL:
http://svn.reactos.org/svn/reactos?rev=58555&view=rev
Log:
[CONSRV]
Code beautification, no changes.
Modified:
branches/ros-csrss/win32ss/user/consrv/coninput.c
branches/ros-csrss/win32ss/user/consrv/conoutput.c
branches/ros-csrss/win32ss/user/consrv/console.c
branches/ros-csrss/win32ss/user/consrv/consrv.h
branches/ros-csrss/win32ss/user/consrv/handle.c
branches/ros-csrss/win32ss/user/consrv/lineinput.c
Modified: branches/ros-csrss/win32ss/user/consrv/coninput.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/coninput.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/coninput.c [iso-8859-1] Tue Mar 19 22:05:38
2013
@@ -673,7 +673,7 @@
}
-/* PUBLIC APIS ****************************************************************/
+/* PUBLIC SERVER APIS *********************************************************/
CSR_API(SrvReadConsole)
{
Modified: branches/ros-csrss/win32ss/user/consrv/conoutput.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] Tue Mar 19 22:05:38
2013
@@ -593,7 +593,7 @@
}
-/* PUBLIC APIS ****************************************************************/
+/* PUBLIC SERVER APIS *********************************************************/
CSR_API(SrvReadConsoleOutput)
{
Modified: branches/ros-csrss/win32ss/user/consrv/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/console.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/console.c [iso-8859-1] Tue Mar 19 22:05:38
2013
@@ -6,7 +6,7 @@
* PROGRAMMERS:
*/
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
#define COBJMACROS
#define NONAMELESSUNION
@@ -26,7 +26,7 @@
#include <debug.h>
-/* FUNCTIONS *****************************************************************/
+/* PRIVATE FUNCTIONS **********************************************************/
BOOL FASTCALL
DtbgIsDesktopVisible(VOID)
@@ -507,6 +507,9 @@
RtlFreeHeap(ConSrvHeap, 0, Console);
}
+
+/* PUBLIC SERVER APIS *********************************************************/
+
CSR_API(SrvOpenConsole)
{
NTSTATUS Status = STATUS_SUCCESS;
@@ -598,7 +601,6 @@
* and recreate a new one later on.
*/
ConSrvRemoveConsole(ProcessData);
- // ConSrvFreeHandlesTable(ProcessData);
/* Initialize a new Console owned by the Console Leader Process */
Status = ConSrvAllocateConsole(ProcessData,
@@ -689,7 +691,6 @@
* and recreate a new one later on.
*/
ConSrvRemoveConsole(TargetProcessData);
- // ConSrvFreeHandlesTable(TargetProcessData);
/*
* Inherit the console from the parent,
Modified: branches/ros-csrss/win32ss/user/consrv/consrv.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/consrv.h [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/consrv.h [iso-8859-1] Tue Mar 19 22:05:38 2013
@@ -149,13 +149,6 @@
CSR_API(SrvVerifyConsoleIoHandle);
CSR_API(SrvDuplicateHandle);
-NTSTATUS FASTCALL ConSrvInitHandlesTable(IN OUT PCONSOLE_PROCESS_DATA ProcessData,
- OUT PHANDLE pInputHandle,
- OUT PHANDLE pOutputHandle,
- OUT PHANDLE pErrorHandle);
-NTSTATUS FASTCALL ConSrvInheritHandlesTable(IN PCONSOLE_PROCESS_DATA SourceProcessData,
- IN PCONSOLE_PROCESS_DATA TargetProcessData);
-VOID FASTCALL ConSrvFreeHandlesTable(PCONSOLE_PROCESS_DATA ProcessData);
NTSTATUS FASTCALL ConSrvInsertObject(PCONSOLE_PROCESS_DATA ProcessData,
PHANDLE Handle,
Object_t *Object,
Modified: branches/ros-csrss/win32ss/user/consrv/handle.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/h…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/handle.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/handle.c [iso-8859-1] Tue Mar 19 22:05:38 2013
@@ -6,7 +6,7 @@
* PROGRAMMERS:
*/
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
#include "consrv.h"
#include "conio.h"
@@ -15,7 +15,7 @@
#include <debug.h>
-/* PRIVATE FUNCTIONS *********************************************************/
+/* PRIVATE FUNCTIONS **********************************************************/
static INT
AdjustHandleCounts(PCONSOLE_IO_HANDLE Entry, INT Change)
@@ -103,10 +103,10 @@
}
-/* FUNCTIONS *****************************************************************/
-
-/* static */ NTSTATUS
-FASTCALL
+/* Forward declaration, used in ConSrvInitHandlesTable */
+static VOID ConSrvFreeHandlesTable(PCONSOLE_PROCESS_DATA ProcessData);
+
+static NTSTATUS
ConSrvInitHandlesTable(IN OUT PCONSOLE_PROCESS_DATA ProcessData,
OUT PHANDLE pInputHandle,
OUT PHANDLE pOutputHandle,
@@ -181,8 +181,7 @@
return STATUS_SUCCESS;
}
-NTSTATUS
-FASTCALL
+static NTSTATUS
ConSrvInheritHandlesTable(IN PCONSOLE_PROCESS_DATA SourceProcessData,
IN PCONSOLE_PROCESS_DATA TargetProcessData)
{
@@ -234,8 +233,7 @@
return Status;
}
-VOID
-FASTCALL
+static VOID
ConSrvFreeHandlesTable(PCONSOLE_PROCESS_DATA ProcessData)
{
DPRINT1("ConSrvFreeHandlesTable\n");
@@ -756,6 +754,7 @@
}
+/* PUBLIC SERVER APIS *********************************************************/
CSR_API(SrvCloseHandle)
{
Modified: branches/ros-csrss/win32ss/user/consrv/lineinput.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/l…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/lineinput.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/lineinput.c [iso-8859-1] Tue Mar 19 22:05:38
2013
@@ -6,7 +6,7 @@
* PROGRAMMERS: Jeffrey Morlan
*/
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
#include "consrv.h"
#include "conio.h"
@@ -24,7 +24,8 @@
UNICODE_STRING ExeName;
} HISTORY_BUFFER, *PHISTORY_BUFFER;
-/* FUNCTIONS *****************************************************************/
+
+/* PRIVATE FUNCTIONS **********************************************************/
static PHISTORY_BUFFER
HistoryCurrentBuffer(PCONSOLE Console)
@@ -140,14 +141,294 @@
VOID FASTCALL
HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
{
- if (!Hist)
- return;
+ if (!Hist) return;
+
while (Hist->NumEntries != 0)
RtlFreeUnicodeString(&Hist->Entries[--Hist->NumEntries]);
+
RtlFreeHeap(ConSrvHeap, 0, Hist->Entries);
RemoveEntryList(&Hist->ListEntry);
RtlFreeHeap(ConSrvHeap, 0, Hist);
}
+
+static VOID
+LineInputSetPos(PCONSOLE Console, UINT Pos)
+{
+ if (Pos != Console->LinePos && Console->InputBuffer.Mode &
ENABLE_ECHO_INPUT)
+ {
+ PCONSOLE_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
+ UINT OldCursorX = Buffer->CursorPosition.X;
+ UINT OldCursorY = Buffer->CursorPosition.Y;
+ INT XY = OldCursorY * Buffer->ScreenBufferSize.X + OldCursorX;
+
+ XY += (Pos - Console->LinePos);
+ if (XY < 0)
+ XY = 0;
+ else if (XY >= Buffer->ScreenBufferSize.Y * Buffer->ScreenBufferSize.X)
+ XY = Buffer->ScreenBufferSize.Y * Buffer->ScreenBufferSize.X - 1;
+
+ Buffer->CursorPosition.X = XY % Buffer->ScreenBufferSize.X;
+ Buffer->CursorPosition.Y = XY / Buffer->ScreenBufferSize.X;
+ ConioSetScreenInfo(Console, Buffer, OldCursorX, OldCursorY);
+ }
+
+ Console->LinePos = Pos;
+}
+
+static VOID
+LineInputEdit(PCONSOLE Console, UINT NumToDelete, UINT NumToInsert, WCHAR *Insertion)
+{
+ UINT Pos = Console->LinePos;
+ UINT NewSize = Console->LineSize - NumToDelete + NumToInsert;
+ INT i;
+
+ /* Make sure there's always enough room for ending \r\n */
+ if (NewSize + 2 > Console->LineMaxSize)
+ return;
+
+ memmove(&Console->LineBuffer[Pos + NumToInsert],
+ &Console->LineBuffer[Pos + NumToDelete],
+ (Console->LineSize - (Pos + NumToDelete)) * sizeof(WCHAR));
+ memcpy(&Console->LineBuffer[Pos], Insertion, NumToInsert * sizeof(WCHAR));
+
+ if (Console->InputBuffer.Mode & ENABLE_ECHO_INPUT)
+ {
+ for (i = Pos; i < NewSize; i++)
+ {
+ CHAR AsciiChar;
+ WideCharToMultiByte(Console->OutputCodePage, 0,
+ &Console->LineBuffer[i], 1,
+ &AsciiChar, 1, NULL, NULL);
+ ConioWriteConsole(Console, Console->ActiveBuffer, &AsciiChar, 1,
TRUE);
+ }
+ for (; i < Console->LineSize; i++)
+ {
+ ConioWriteConsole(Console, Console->ActiveBuffer, " ", 1,
TRUE);
+ }
+ Console->LinePos = i;
+ }
+
+ Console->LineSize = NewSize;
+ LineInputSetPos(Console, Pos + NumToInsert);
+}
+
+static VOID
+LineInputRecallHistory(PCONSOLE Console, INT Offset)
+{
+ PHISTORY_BUFFER Hist;
+
+ if (!(Hist = HistoryCurrentBuffer(Console)) || Hist->NumEntries == 0)
+ return;
+
+ Offset += Hist->Position;
+ Offset = max(Offset, 0);
+ Offset = min(Offset, Hist->NumEntries - 1);
+ Hist->Position = Offset;
+
+ LineInputSetPos(Console, 0);
+ LineInputEdit(Console, Console->LineSize,
+ Hist->Entries[Offset].Length / sizeof(WCHAR),
+ Hist->Entries[Offset].Buffer);
+}
+
+VOID FASTCALL
+LineInputKeyDown(PCONSOLE Console, KEY_EVENT_RECORD *KeyEvent)
+{
+ UINT Pos = Console->LinePos;
+ PHISTORY_BUFFER Hist;
+ UNICODE_STRING Entry;
+ INT HistPos;
+
+ switch (KeyEvent->wVirtualKeyCode)
+ {
+ case VK_ESCAPE:
+ /* Clear entire line */
+ LineInputSetPos(Console, 0);
+ LineInputEdit(Console, Console->LineSize, 0, NULL);
+ return;
+ case VK_HOME:
+ /* Move to start of line. With ctrl, erase everything left of cursor */
+ LineInputSetPos(Console, 0);
+ if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
+ LineInputEdit(Console, Pos, 0, NULL);
+ return;
+ case VK_END:
+ /* Move to end of line. With ctrl, erase everything right of cursor */
+ if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
+ LineInputEdit(Console, Console->LineSize - Pos, 0, NULL);
+ else
+ LineInputSetPos(Console, Console->LineSize);
+ return;
+ case VK_LEFT:
+ /* Move left. With ctrl, move to beginning of previous word */
+ if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
+ {
+ while (Pos > 0 && Console->LineBuffer[Pos - 1] == L' ')
Pos--;
+ while (Pos > 0 && Console->LineBuffer[Pos - 1] != L' ')
Pos--;
+ }
+ else
+ {
+ Pos -= (Pos > 0);
+ }
+ LineInputSetPos(Console, Pos);
+ return;
+ case VK_RIGHT:
+ case VK_F1:
+ /* Move right. With ctrl, move to beginning of next word */
+ if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
+ {
+ while (Pos < Console->LineSize && Console->LineBuffer[Pos]
!= L' ') Pos++;
+ while (Pos < Console->LineSize && Console->LineBuffer[Pos]
== L' ') Pos++;
+ LineInputSetPos(Console, Pos);
+ return;
+ }
+ else
+ {
+ /* Recall one character (but don't overwrite current line) */
+ HistoryGetCurrentEntry(Console, &Entry);
+ if (Pos < Console->LineSize)
+ LineInputSetPos(Console, Pos + 1);
+ else if (Pos * sizeof(WCHAR) < Entry.Length)
+ LineInputEdit(Console, 0, 1, &Entry.Buffer[Pos]);
+ }
+ return;
+ case VK_INSERT:
+ /* Toggle between insert and overstrike */
+ Console->LineInsertToggle = !Console->LineInsertToggle;
+ ConioSetCursorInfo(Console, Console->ActiveBuffer);
+ return;
+ case VK_DELETE:
+ /* Remove character to right of cursor */
+ if (Pos != Console->LineSize)
+ LineInputEdit(Console, 1, 0, NULL);
+ return;
+ case VK_PRIOR:
+ /* Recall first history entry */
+ LineInputRecallHistory(Console, -((WORD)-1));
+ return;
+ case VK_NEXT:
+ /* Recall last history entry */
+ LineInputRecallHistory(Console, +((WORD)-1));
+ return;
+ case VK_UP:
+ case VK_F5:
+ /* Recall previous history entry. On first time, actually recall the
+ * current (usually last) entry; on subsequent times go back. */
+ LineInputRecallHistory(Console, Console->LineUpPressed ? -1 : 0);
+ Console->LineUpPressed = TRUE;
+ return;
+ case VK_DOWN:
+ /* Recall next history entry */
+ LineInputRecallHistory(Console, +1);
+ return;
+ case VK_F3:
+ /* Recall remainder of current history entry */
+ HistoryGetCurrentEntry(Console, &Entry);
+ if (Pos * sizeof(WCHAR) < Entry.Length)
+ {
+ UINT InsertSize = (Entry.Length / sizeof(WCHAR) - Pos);
+ UINT DeleteSize = min(Console->LineSize - Pos, InsertSize);
+ LineInputEdit(Console, DeleteSize, InsertSize, &Entry.Buffer[Pos]);
+ }
+ return;
+ case VK_F6:
+ /* Insert a ^Z character */
+ KeyEvent->uChar.UnicodeChar = 26;
+ break;
+ case VK_F7:
+ if (KeyEvent->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
+ HistoryDeleteBuffer(HistoryCurrentBuffer(Console));
+ return;
+ case VK_F8:
+ /* Search for history entries starting with input. */
+ if (!(Hist = HistoryCurrentBuffer(Console)) || Hist->NumEntries == 0)
+ return;
+
+ /* Like Up/F5, on first time start from current (usually last) entry,
+ * but on subsequent times start at previous entry. */
+ if (Console->LineUpPressed)
+ Hist->Position = (Hist->Position ? Hist->Position :
Hist->NumEntries) - 1;
+ Console->LineUpPressed = TRUE;
+
+ Entry.Length = Console->LinePos * sizeof(WCHAR);
+ Entry.Buffer = Console->LineBuffer;
+
+ /* Keep going backwards, even wrapping around to the end,
+ * until we get back to starting point */
+ HistPos = Hist->Position;
+ do
+ {
+ if (RtlPrefixUnicodeString(&Entry, &Hist->Entries[HistPos],
FALSE))
+ {
+ Hist->Position = HistPos;
+ LineInputEdit(Console, Console->LineSize - Pos,
+ Hist->Entries[HistPos].Length / sizeof(WCHAR) - Pos,
+ &Hist->Entries[HistPos].Buffer[Pos]);
+ /* Cursor stays where it was */
+ LineInputSetPos(Console, Pos);
+ return;
+ }
+ if (--HistPos < 0) HistPos += Hist->NumEntries;
+ } while (HistPos != Hist->Position);
+ return;
+ }
+
+ if (KeyEvent->uChar.UnicodeChar == L'\b' &&
Console->InputBuffer.Mode & ENABLE_PROCESSED_INPUT)
+ {
+ /* backspace handling - if processed input enabled then we handle it here
+ * otherwise we treat it like a normal char. */
+ if (Pos > 0)
+ {
+ LineInputSetPos(Console, Pos - 1);
+ LineInputEdit(Console, 1, 0, NULL);
+ }
+ }
+ else if (KeyEvent->uChar.UnicodeChar == L'\r')
+ {
+ HistoryAddEntry(Console);
+
+ /* TODO: Expand aliases */
+
+ LineInputSetPos(Console, Console->LineSize);
+ Console->LineBuffer[Console->LineSize++] = L'\r';
+ if (Console->InputBuffer.Mode & ENABLE_ECHO_INPUT)
+ ConioWriteConsole(Console, Console->ActiveBuffer, "\r", 1,
TRUE);
+
+ /* Add \n if processed input. There should usually be room for it,
+ * but an exception to the rule exists: the buffer could have been
+ * pre-filled with LineMaxSize - 1 characters. */
+ if (Console->InputBuffer.Mode & ENABLE_PROCESSED_INPUT &&
+ Console->LineSize < Console->LineMaxSize)
+ {
+ Console->LineBuffer[Console->LineSize++] = L'\n';
+ if (Console->InputBuffer.Mode & ENABLE_ECHO_INPUT)
+ ConioWriteConsole(Console, Console->ActiveBuffer, "\n", 1,
TRUE);
+ }
+ Console->LineComplete = TRUE;
+ Console->LinePos = 0;
+ }
+ else if (KeyEvent->uChar.UnicodeChar != L'\0')
+ {
+ if (KeyEvent->uChar.UnicodeChar < 0x20 &&
+ Console->LineWakeupMask & (1 <<
KeyEvent->uChar.UnicodeChar))
+ {
+ /* Control key client wants to handle itself (e.g. for tab completion) */
+ Console->LineBuffer[Console->LineSize++] = L' ';
+ Console->LineBuffer[Console->LinePos] =
KeyEvent->uChar.UnicodeChar;
+ Console->LineComplete = TRUE;
+ Console->LinePos = 0;
+ }
+ else
+ {
+ /* Normal character */
+ BOOL Overstrike = Console->LineInsertToggle && Console->LinePos
!= Console->LineSize;
+ LineInputEdit(Console, Overstrike, 1, &KeyEvent->uChar.UnicodeChar);
+ }
+ }
+}
+
+
+/* PUBLIC SERVER APIS *********************************************************/
CSR_API(SrvGetConsoleCommandHistoryLength)
{
@@ -337,280 +618,4 @@
return Status;
}
-static VOID
-LineInputSetPos(PCONSOLE Console, UINT Pos)
-{
- if (Pos != Console->LinePos && Console->InputBuffer.Mode &
ENABLE_ECHO_INPUT)
- {
- PCONSOLE_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
- UINT OldCursorX = Buffer->CursorPosition.X;
- UINT OldCursorY = Buffer->CursorPosition.Y;
- INT XY = OldCursorY * Buffer->ScreenBufferSize.X + OldCursorX;
-
- XY += (Pos - Console->LinePos);
- if (XY < 0)
- XY = 0;
- else if (XY >= Buffer->ScreenBufferSize.Y * Buffer->ScreenBufferSize.X)
- XY = Buffer->ScreenBufferSize.Y * Buffer->ScreenBufferSize.X - 1;
-
- Buffer->CursorPosition.X = XY % Buffer->ScreenBufferSize.X;
- Buffer->CursorPosition.Y = XY / Buffer->ScreenBufferSize.X;
- ConioSetScreenInfo(Console, Buffer, OldCursorX, OldCursorY);
- }
-
- Console->LinePos = Pos;
-}
-
-static VOID
-LineInputEdit(PCONSOLE Console, UINT NumToDelete, UINT NumToInsert, WCHAR *Insertion)
-{
- UINT Pos = Console->LinePos;
- UINT NewSize = Console->LineSize - NumToDelete + NumToInsert;
- INT i;
-
- /* Make sure there's always enough room for ending \r\n */
- if (NewSize + 2 > Console->LineMaxSize)
- return;
-
- memmove(&Console->LineBuffer[Pos + NumToInsert],
- &Console->LineBuffer[Pos + NumToDelete],
- (Console->LineSize - (Pos + NumToDelete)) * sizeof(WCHAR));
- memcpy(&Console->LineBuffer[Pos], Insertion, NumToInsert * sizeof(WCHAR));
-
- if (Console->InputBuffer.Mode & ENABLE_ECHO_INPUT)
- {
- for (i = Pos; i < NewSize; i++)
- {
- CHAR AsciiChar;
- WideCharToMultiByte(Console->OutputCodePage, 0,
- &Console->LineBuffer[i], 1,
- &AsciiChar, 1, NULL, NULL);
- ConioWriteConsole(Console, Console->ActiveBuffer, &AsciiChar, 1,
TRUE);
- }
- for (; i < Console->LineSize; i++)
- {
- ConioWriteConsole(Console, Console->ActiveBuffer, " ", 1,
TRUE);
- }
- Console->LinePos = i;
- }
-
- Console->LineSize = NewSize;
- LineInputSetPos(Console, Pos + NumToInsert);
-}
-
-static VOID
-LineInputRecallHistory(PCONSOLE Console, INT Offset)
-{
- PHISTORY_BUFFER Hist;
-
- if (!(Hist = HistoryCurrentBuffer(Console)) || Hist->NumEntries == 0)
- return;
-
- Offset += Hist->Position;
- Offset = max(Offset, 0);
- Offset = min(Offset, Hist->NumEntries - 1);
- Hist->Position = Offset;
-
- LineInputSetPos(Console, 0);
- LineInputEdit(Console, Console->LineSize,
- Hist->Entries[Offset].Length / sizeof(WCHAR),
- Hist->Entries[Offset].Buffer);
-}
-
-VOID FASTCALL
-LineInputKeyDown(PCONSOLE Console, KEY_EVENT_RECORD *KeyEvent)
-{
- UINT Pos = Console->LinePos;
- PHISTORY_BUFFER Hist;
- UNICODE_STRING Entry;
- INT HistPos;
-
- switch (KeyEvent->wVirtualKeyCode)
- {
- case VK_ESCAPE:
- /* Clear entire line */
- LineInputSetPos(Console, 0);
- LineInputEdit(Console, Console->LineSize, 0, NULL);
- return;
- case VK_HOME:
- /* Move to start of line. With ctrl, erase everything left of cursor */
- LineInputSetPos(Console, 0);
- if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
- LineInputEdit(Console, Pos, 0, NULL);
- return;
- case VK_END:
- /* Move to end of line. With ctrl, erase everything right of cursor */
- if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
- LineInputEdit(Console, Console->LineSize - Pos, 0, NULL);
- else
- LineInputSetPos(Console, Console->LineSize);
- return;
- case VK_LEFT:
- /* Move left. With ctrl, move to beginning of previous word */
- if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
- {
- while (Pos > 0 && Console->LineBuffer[Pos - 1] == L' ')
Pos--;
- while (Pos > 0 && Console->LineBuffer[Pos - 1] != L' ')
Pos--;
- }
- else
- {
- Pos -= (Pos > 0);
- }
- LineInputSetPos(Console, Pos);
- return;
- case VK_RIGHT:
- case VK_F1:
- /* Move right. With ctrl, move to beginning of next word */
- if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))
- {
- while (Pos < Console->LineSize && Console->LineBuffer[Pos]
!= L' ') Pos++;
- while (Pos < Console->LineSize && Console->LineBuffer[Pos]
== L' ') Pos++;
- LineInputSetPos(Console, Pos);
- return;
- }
- else
- {
- /* Recall one character (but don't overwrite current line) */
- HistoryGetCurrentEntry(Console, &Entry);
- if (Pos < Console->LineSize)
- LineInputSetPos(Console, Pos + 1);
- else if (Pos * sizeof(WCHAR) < Entry.Length)
- LineInputEdit(Console, 0, 1, &Entry.Buffer[Pos]);
- }
- return;
- case VK_INSERT:
- /* Toggle between insert and overstrike */
- Console->LineInsertToggle = !Console->LineInsertToggle;
- ConioSetCursorInfo(Console, Console->ActiveBuffer);
- return;
- case VK_DELETE:
- /* Remove character to right of cursor */
- if (Pos != Console->LineSize)
- LineInputEdit(Console, 1, 0, NULL);
- return;
- case VK_PRIOR:
- /* Recall first history entry */
- LineInputRecallHistory(Console, -((WORD)-1));
- return;
- case VK_NEXT:
- /* Recall last history entry */
- LineInputRecallHistory(Console, +((WORD)-1));
- return;
- case VK_UP:
- case VK_F5:
- /* Recall previous history entry. On first time, actually recall the
- * current (usually last) entry; on subsequent times go back. */
- LineInputRecallHistory(Console, Console->LineUpPressed ? -1 : 0);
- Console->LineUpPressed = TRUE;
- return;
- case VK_DOWN:
- /* Recall next history entry */
- LineInputRecallHistory(Console, +1);
- return;
- case VK_F3:
- /* Recall remainder of current history entry */
- HistoryGetCurrentEntry(Console, &Entry);
- if (Pos * sizeof(WCHAR) < Entry.Length)
- {
- UINT InsertSize = (Entry.Length / sizeof(WCHAR) - Pos);
- UINT DeleteSize = min(Console->LineSize - Pos, InsertSize);
- LineInputEdit(Console, DeleteSize, InsertSize, &Entry.Buffer[Pos]);
- }
- return;
- case VK_F6:
- /* Insert a ^Z character */
- KeyEvent->uChar.UnicodeChar = 26;
- break;
- case VK_F7:
- if (KeyEvent->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
- HistoryDeleteBuffer(HistoryCurrentBuffer(Console));
- return;
- case VK_F8:
- /* Search for history entries starting with input. */
- if (!(Hist = HistoryCurrentBuffer(Console)) || Hist->NumEntries == 0)
- return;
-
- /* Like Up/F5, on first time start from current (usually last) entry,
- * but on subsequent times start at previous entry. */
- if (Console->LineUpPressed)
- Hist->Position = (Hist->Position ? Hist->Position :
Hist->NumEntries) - 1;
- Console->LineUpPressed = TRUE;
-
- Entry.Length = Console->LinePos * sizeof(WCHAR);
- Entry.Buffer = Console->LineBuffer;
-
- /* Keep going backwards, even wrapping around to the end,
- * until we get back to starting point */
- HistPos = Hist->Position;
- do
- {
- if (RtlPrefixUnicodeString(&Entry, &Hist->Entries[HistPos],
FALSE))
- {
- Hist->Position = HistPos;
- LineInputEdit(Console, Console->LineSize - Pos,
- Hist->Entries[HistPos].Length / sizeof(WCHAR) - Pos,
- &Hist->Entries[HistPos].Buffer[Pos]);
- /* Cursor stays where it was */
- LineInputSetPos(Console, Pos);
- return;
- }
- if (--HistPos < 0) HistPos += Hist->NumEntries;
- } while (HistPos != Hist->Position);
- return;
- }
-
- if (KeyEvent->uChar.UnicodeChar == L'\b' &&
Console->InputBuffer.Mode & ENABLE_PROCESSED_INPUT)
- {
- /* backspace handling - if processed input enabled then we handle it here
- * otherwise we treat it like a normal char. */
- if (Pos > 0)
- {
- LineInputSetPos(Console, Pos - 1);
- LineInputEdit(Console, 1, 0, NULL);
- }
- }
- else if (KeyEvent->uChar.UnicodeChar == L'\r')
- {
- HistoryAddEntry(Console);
-
- /* TODO: Expand aliases */
-
- LineInputSetPos(Console, Console->LineSize);
- Console->LineBuffer[Console->LineSize++] = L'\r';
- if (Console->InputBuffer.Mode & ENABLE_ECHO_INPUT)
- ConioWriteConsole(Console, Console->ActiveBuffer, "\r", 1,
TRUE);
-
- /* Add \n if processed input. There should usually be room for it,
- * but an exception to the rule exists: the buffer could have been
- * pre-filled with LineMaxSize - 1 characters. */
- if (Console->InputBuffer.Mode & ENABLE_PROCESSED_INPUT &&
- Console->LineSize < Console->LineMaxSize)
- {
- Console->LineBuffer[Console->LineSize++] = L'\n';
- if (Console->InputBuffer.Mode & ENABLE_ECHO_INPUT)
- ConioWriteConsole(Console, Console->ActiveBuffer, "\n", 1,
TRUE);
- }
- Console->LineComplete = TRUE;
- Console->LinePos = 0;
- }
- else if (KeyEvent->uChar.UnicodeChar != L'\0')
- {
- if (KeyEvent->uChar.UnicodeChar < 0x20 &&
- Console->LineWakeupMask & (1 <<
KeyEvent->uChar.UnicodeChar))
- {
- /* Control key client wants to handle itself (e.g. for tab completion) */
- Console->LineBuffer[Console->LineSize++] = L' ';
- Console->LineBuffer[Console->LinePos] =
KeyEvent->uChar.UnicodeChar;
- Console->LineComplete = TRUE;
- Console->LinePos = 0;
- }
- else
- {
- /* Normal character */
- BOOL Overstrike = Console->LineInsertToggle && Console->LinePos
!= Console->LineSize;
- LineInputEdit(Console, Overstrike, 1, &KeyEvent->uChar.UnicodeChar);
- }
- }
-}
-
/* EOF */