ReactOS  0.4.14-dev-52-g6116262
lineinput.c File Reference
#include "consrv.h"
#include "popup.h"
#include <debug.h>
Include dependency graph for lineinput.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN ConvertInputAnsiToUnicode (PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PWCHAR *Target, PUSHORT TargetLength)
 
BOOLEAN ConvertInputUnicodeToAnsi (PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PCHAR Target, USHORT TargetLength)
 
VOID HistoryAddEntry (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
 
BOOL HistoryRecallHistory (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, INT Offset, PUNICODE_STRING Entry)
 
VOID HistoryGetCurrentEntry (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
 
VOID HistoryDeleteCurrentBuffer (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
 
BOOL HistoryFindEntryByPrefix (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Prefix, PUNICODE_STRING Entry)
 
static VOID LineInputSetPos (PCONSRV_CONSOLE Console, UINT Pos)
 
static VOID LineInputEdit (PCONSRV_CONSOLE Console, UINT NumToDelete, UINT NumToInsert, PWCHAR Insertion)
 
static VOID LineInputRecallHistory (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, INT Offset)
 
PPOPUP_WINDOW HistoryDisplayCurrentHistory (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
 
VOID LineInputKeyDown (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, KEY_EVENT_RECORD *KeyEvent)
 

Variables

PPOPUP_WINDOW Popup = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file lineinput.c.

Function Documentation

◆ ConvertInputAnsiToUnicode()

BOOLEAN ConvertInputAnsiToUnicode ( PCONSRV_CONSOLE  Console,
PVOID  Source,
USHORT  SourceLength,
PWCHAR Target,
PUSHORT  TargetLength 
)

Definition at line 37 of file alias.c.

43 {
44  ASSERT(Source && Target && TargetLength);
45 
46  /* Use the console input CP for the conversion */
47  *TargetLength = MultiByteToWideChar(Console->InputCodePage, 0,
48  Source, SourceLength,
49  NULL, 0);
50  *Target = ConsoleAllocHeap(0, *TargetLength * sizeof(WCHAR));
51  if (*Target == NULL) return FALSE;
52 
53  MultiByteToWideChar(Console->InputCodePage, 0,
54  Source, SourceLength,
55  *Target, *TargetLength);
56 
57  /* The returned Length was in number of WCHARs, convert it in bytes */
58  *TargetLength *= sizeof(WCHAR);
59 
60  return TRUE;
61 }
#define TRUE
Definition: types.h:120
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define MultiByteToWideChar
Definition: compat.h:100
CConsole Console
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by IntCreateAliasEntry(), IntCreateAliasHeader(), IntFindAliasHeader(), and IntGetAliasEntry().

◆ ConvertInputUnicodeToAnsi()

BOOLEAN ConvertInputUnicodeToAnsi ( PCONSRV_CONSOLE  Console,
PVOID  Source,
USHORT  SourceLength,
PCHAR  Target,
USHORT  TargetLength 
)

Definition at line 64 of file alias.c.

70 {
71  ASSERT(Source && Target && TargetLength);
72 
73  /*
74  * From MSDN:
75  * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
76  * If they are the same, the function fails, and GetLastError returns
77  * ERROR_INVALID_PARAMETER."
78  */
80 
81  /* Use the console input CP for the conversion */
82  // *TargetLength = WideCharToMultiByte(Console->InputCodePage, 0,
83  // Source, SourceLength,
84  // NULL, 0, NULL, NULL);
85  // *Target = ConsoleAllocHeap(0, *TargetLength * sizeof(WCHAR));
86  // if (*Target == NULL) return FALSE;
87 
88  WideCharToMultiByte(Console->InputCodePage, 0,
89  Source, SourceLength,
90  /* * */Target, /* * */TargetLength,
91  NULL, NULL);
92 
93  // /* The returned Length was in number of WCHARs, convert it in bytes */
94  // *TargetLength *= sizeof(WCHAR);
95 
96  return TRUE;
97 }
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by CSR_API().

◆ HistoryAddEntry()

VOID HistoryAddEntry ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
PUNICODE_STRING  Entry 
)

Definition at line 141 of file history.c.

144 {
145  // UNICODE_STRING NewEntry;
147 
148  if (!Hist) return;
149 
150  // NewEntry.Length = NewEntry.MaximumLength = Console->LineSize * sizeof(WCHAR);
151  // NewEntry.Buffer = Console->LineBuffer;
152 
153  /* Don't add blank or duplicate entries */
154  if (Entry->Length == 0 || Hist->MaxEntries == 0 ||
155  (Hist->NumEntries > 0 &&
156  RtlEqualUnicodeString(&Hist->Entries[Hist->NumEntries - 1], Entry, FALSE)))
157  {
158  return;
159  }
160 
161  if (Console->HistoryNoDup)
162  {
163  INT i;
164 
165  /* Check if this line has been entered before */
166  for (i = Hist->NumEntries - 1; i >= 0; i--)
167  {
168  if (RtlEqualUnicodeString(&Hist->Entries[i], Entry, FALSE))
169  {
170  UNICODE_STRING NewEntry;
171 
172  /* Just rotate the list to bring this entry to the end */
173  NewEntry = Hist->Entries[i];
174  memmove(&Hist->Entries[i], &Hist->Entries[i + 1],
175  (Hist->NumEntries - (i + 1)) * sizeof(UNICODE_STRING));
176  Hist->Entries[Hist->NumEntries - 1] = NewEntry;
177  Hist->Position = Hist->NumEntries - 1;
178  return;
179  }
180  }
181  }
182 
183  if (Hist->NumEntries == Hist->MaxEntries)
184  {
185  /* List is full, remove oldest entry */
186  RtlFreeUnicodeString(&Hist->Entries[0]);
187  memmove(&Hist->Entries[0], &Hist->Entries[1],
188  --Hist->NumEntries * sizeof(UNICODE_STRING));
189  }
190 
192  Hist->NumEntries++;
193  Hist->Position = Hist->NumEntries - 1;
194 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
ULONG NumEntries
Definition: history.c:22
int32_t INT
Definition: typedefs.h:56
ULONG MaxEntries
Definition: history.c:21
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PUNICODE_STRING Entries
Definition: history.c:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG Position
Definition: history.c:20
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
CConsole Console
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ HistoryDeleteCurrentBuffer()

VOID HistoryDeleteCurrentBuffer ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)

Definition at line 306 of file history.c.

308 {
310 }
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:128
CConsole Console
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47

Referenced by LineInputKeyDown().

◆ HistoryDisplayCurrentHistory()

PPOPUP_WINDOW HistoryDisplayCurrentHistory ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)

Definition at line 271 of file history.c.

273 {
274  PCONSOLE_SCREEN_BUFFER ActiveBuffer;
276 
277  SHORT xLeft, yTop;
278  SHORT Width, Height;
279 
281 
282  if (!Hist) return NULL;
283  if (Hist->NumEntries == 0) return NULL;
284 
285  if (GetType(Console->ActiveBuffer) != TEXTMODE_BUFFER) return NULL;
286  ActiveBuffer = Console->ActiveBuffer;
287 
288  Width = 40;
289  Height = 10;
290 
291  /* Center the popup window on the screen */
292  xLeft = ActiveBuffer->ViewOrigin.X + (ActiveBuffer->ViewSize.X - Width ) / 2;
293  yTop = ActiveBuffer->ViewOrigin.Y + (ActiveBuffer->ViewSize.Y - Height) / 2;
294 
295  /* Create the popup */
296  Popup = CreatePopupWindow(Console, ActiveBuffer,
297  xLeft, yTop, Width, Height);
298  if (Popup == NULL) return NULL;
299 
300  Popup->PopupInputRoutine = NULL;
301 
302  return Popup;
303 }
ULONG NumEntries
Definition: history.c:22
#define TEXTMODE_BUFFER
Definition: pccons.c:21
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
ULONG X
Definition: bl.h:1340
INT GetType(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:129
Definition: console.h:35
CConsole Console
ULONG Y
Definition: bl.h:1341
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47

Referenced by LineInputKeyDown().

◆ HistoryFindEntryByPrefix()

BOOL HistoryFindEntryByPrefix ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
PUNICODE_STRING  Prefix,
PUNICODE_STRING  Entry 
)

Definition at line 229 of file history.c.

233 {
234  INT HistPos;
235 
236  /* Search for history entries starting with input. */
238  if (!Hist || Hist->NumEntries == 0) return FALSE;
239 
240  /*
241  * Like Up/F5, on first time start from current (usually last) entry,
242  * but on subsequent times start at previous entry.
243  */
244  if (Console->LineUpPressed)
245  Hist->Position = (Hist->Position ? Hist->Position : Hist->NumEntries) - 1;
246  Console->LineUpPressed = TRUE;
247 
248  // Entry.Length = Console->LinePos * sizeof(WCHAR); // == Pos * sizeof(WCHAR)
249  // Entry.Buffer = Console->LineBuffer;
250 
251  /*
252  * Keep going backwards, even wrapping around to the end,
253  * until we get back to starting point.
254  */
255  HistPos = Hist->Position;
256  do
257  {
258  if (RtlPrefixUnicodeString(Prefix, &Hist->Entries[HistPos], FALSE))
259  {
260  Hist->Position = HistPos;
261  *Entry = Hist->Entries[HistPos];
262  return TRUE;
263  }
264  if (--HistPos < 0) HistPos += Hist->NumEntries;
265  } while (HistPos != Hist->Position);
266 
267  return FALSE;
268 }
#define TRUE
Definition: types.h:120
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
ULONG NumEntries
Definition: history.c:22
int32_t INT
Definition: typedefs.h:56
PUNICODE_STRING Entries
Definition: history.c:24
ULONG Position
Definition: history.c:20
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
CConsole Console
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ HistoryGetCurrentEntry()

VOID HistoryGetCurrentEntry ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
PUNICODE_STRING  Entry 
)

Definition at line 197 of file history.c.

200 {
202 
203  if (!Hist || Hist->NumEntries == 0)
204  Entry->Length = 0;
205  else
206  *Entry = Hist->Entries[Hist->Position];
207 }
ULONG NumEntries
Definition: history.c:22
PUNICODE_STRING Entries
Definition: history.c:24
ULONG Position
Definition: history.c:20
CConsole Console
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ HistoryRecallHistory()

BOOL HistoryRecallHistory ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
INT  Offset,
PUNICODE_STRING  Entry 
)

Definition at line 210 of file history.c.

214 {
216  ULONG Position = 0;
217 
218  if (!Hist || Hist->NumEntries == 0) return FALSE;
219 
220  Position = Hist->Position + Offset;
221  Position = min(max(Position, 0), Hist->NumEntries - 1);
222  Hist->Position = Position;
223 
224  *Entry = Hist->Entries[Hist->Position];
225  return TRUE;
226 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
ULONG NumEntries
Definition: history.c:22
static COORD Position
Definition: mouse.c:34
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PUNICODE_STRING Entries
Definition: history.c:24
ULONG Position
Definition: history.c:20
#define min(a, b)
Definition: monoChain.cc:55
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputRecallHistory().

◆ LineInputEdit()

static VOID LineInputEdit ( PCONSRV_CONSOLE  Console,
UINT  NumToDelete,
UINT  NumToInsert,
PWCHAR  Insertion 
)
static

Definition at line 85 of file lineinput.c.

89 {
90  PTEXTMODE_SCREEN_BUFFER ActiveBuffer;
91  UINT Pos = Console->LinePos;
92  UINT NewSize = Console->LineSize - NumToDelete + NumToInsert;
93  UINT i;
94 
95  if (GetType(Console->ActiveBuffer) != TEXTMODE_BUFFER) return;
96  ActiveBuffer = (PTEXTMODE_SCREEN_BUFFER)Console->ActiveBuffer;
97 
98  /* Make sure there is always enough room for ending \r\n */
99  if (NewSize + 2 > Console->LineMaxSize)
100  return;
101 
102  memmove(&Console->LineBuffer[Pos + NumToInsert],
103  &Console->LineBuffer[Pos + NumToDelete],
104  (Console->LineSize - (Pos + NumToDelete)) * sizeof(WCHAR));
105  memcpy(&Console->LineBuffer[Pos], Insertion, NumToInsert * sizeof(WCHAR));
106 
108  {
109  for (i = Pos; i < NewSize; i++)
110  {
111  TermWriteStream(Console, ActiveBuffer, &Console->LineBuffer[i], 1, TRUE);
112  }
113  for (; i < Console->LineSize; i++)
114  {
115  TermWriteStream(Console, ActiveBuffer, L" ", 1, TRUE);
116  }
117  Console->LinePos = i;
118  }
119 
120  Console->LineSize = NewSize;
121  LineInputSetPos(Console, Pos + NumToInsert);
122 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define TRUE
Definition: types.h:120
ush Pos
Definition: deflate.h:92
#define TEXTMODE_BUFFER
Definition: pccons.c:21
#define ENABLE_ECHO_INPUT
Definition: wincon.h:77
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define GetConsoleInputBufferMode(Console)
Definition: conio.h:362
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
INT GetType(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:129
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
unsigned int UINT
Definition: ndis.h:50
static VOID LineInputSetPos(PCONSRV_CONSOLE Console, UINT Pos)
Definition: lineinput.c:60
CConsole Console
#define TermWriteStream(Console, ScreenBuffer, Buffer, Length, Attrib)
Definition: term.h:17
struct _TEXTMODE_SCREEN_BUFFER * PTEXTMODE_SCREEN_BUFFER

Referenced by LineInputKeyDown(), and LineInputRecallHistory().

◆ LineInputKeyDown()

VOID LineInputKeyDown ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
KEY_EVENT_RECORD KeyEvent 
)

Definition at line 166 of file lineinput.c.

169 {
170  UINT Pos = Console->LinePos;
172 
173  /*
174  * First, deal with control keys...
175  */
176 
177  switch (KeyEvent->wVirtualKeyCode)
178  {
179  case VK_ESCAPE:
180  {
181  /* Clear the entire line */
183  LineInputEdit(Console, Console->LineSize, 0, NULL);
184 
185  // TESTS!!
186  if (Popup)
187  {
189  Popup = NULL;
190  }
191  return;
192  }
193 
194  case VK_HOME:
195  {
196  /* Move to start of line. With CTRL, erase everything left of cursor. */
200  return;
201  }
202 
203  case VK_END:
204  {
205  /* Move to end of line. With CTRL, erase everything right of cursor. */
207  LineInputEdit(Console, Console->LineSize - Pos, 0, NULL);
208  else
209  LineInputSetPos(Console, Console->LineSize);
210  return;
211  }
212 
213  case VK_LEFT:
214  {
215  /* Move to the left. With CTRL, move to beginning of previous word. */
217  {
218  while (Pos > 0 && Console->LineBuffer[Pos - 1] == L' ') Pos--;
219  while (Pos > 0 && Console->LineBuffer[Pos - 1] != L' ') Pos--;
220  }
221  else
222  {
223  Pos -= (Pos > 0);
224  }
226  return;
227  }
228 
229  case VK_RIGHT:
230  case VK_F1:
231  {
232  /* Move to the right. With CTRL, move to beginning of next word. */
234  {
235  while (Pos < Console->LineSize && Console->LineBuffer[Pos] != L' ') Pos++;
236  while (Pos < Console->LineSize && Console->LineBuffer[Pos] == L' ') Pos++;
238  }
239  else
240  {
241  /* Recall one character (but don't overwrite current line) */
243  if (Pos < Console->LineSize)
245  else if (Pos * sizeof(WCHAR) < Entry.Length)
246  LineInputEdit(Console, 0, 1, &Entry.Buffer[Pos]);
247  }
248  return;
249  }
250 
251  case VK_INSERT:
252  {
253  /* Toggle between insert and overstrike */
254  Console->LineInsertToggle = !Console->LineInsertToggle;
255  TermSetCursorInfo(Console, Console->ActiveBuffer);
256  return;
257  }
258 
259  case VK_DELETE:
260  {
261  /* Remove one character to right of cursor */
262  if (Pos != Console->LineSize)
263  LineInputEdit(Console, 1, 0, NULL);
264  return;
265  }
266 
267  case VK_PRIOR:
268  {
269  /* Recall the first history entry */
270  LineInputRecallHistory(Console, ExeName, -((WORD)-1));
271  return;
272  }
273 
274  case VK_NEXT:
275  {
276  /* Recall the last history entry */
277  LineInputRecallHistory(Console, ExeName, +((WORD)-1));
278  return;
279  }
280 
281  case VK_UP:
282  case VK_F5:
283  {
284  /*
285  * Recall the previous history entry. On first time, actually recall
286  * the current (usually last) entry; on subsequent times go back.
287  */
288  LineInputRecallHistory(Console, ExeName, Console->LineUpPressed ? -1 : 0);
289  Console->LineUpPressed = TRUE;
290  return;
291  }
292 
293  case VK_DOWN:
294  {
295  /* Recall the next history entry */
296  LineInputRecallHistory(Console, ExeName, +1);
297  return;
298  }
299 
300  case VK_F3:
301  {
302  /* Recall the remainder of the current history entry */
304  if (Pos * sizeof(WCHAR) < Entry.Length)
305  {
306  UINT InsertSize = (Entry.Length / sizeof(WCHAR) - Pos);
307  UINT DeleteSize = min(Console->LineSize - Pos, InsertSize);
308  LineInputEdit(Console, DeleteSize, InsertSize, &Entry.Buffer[Pos]);
309  }
310  return;
311  }
312 
313  case VK_F6:
314  {
315  /* Insert a ^Z character */
316  KeyEvent->uChar.UnicodeChar = 26;
317  break;
318  }
319 
320  case VK_F7:
321  {
324  else
325  {
328  }
329  return;
330  }
331 
332  case VK_F8:
333  {
334  UNICODE_STRING EntryFound;
335 
336  Entry.Length = Console->LinePos * sizeof(WCHAR); // == Pos * sizeof(WCHAR)
337  Entry.Buffer = Console->LineBuffer;
338 
339  if (HistoryFindEntryByPrefix(Console, ExeName, &Entry, &EntryFound))
340  {
341  LineInputEdit(Console, Console->LineSize - Pos,
342  EntryFound.Length / sizeof(WCHAR) - Pos,
343  &EntryFound.Buffer[Pos]);
344  /* Cursor stays where it was */
346  }
347 
348  return;
349  }
350 #if 0
351  {
352  PHISTORY_BUFFER Hist;
353  INT HistPos;
354 
355  /* Search for history entries starting with input */
356  Hist = HistoryCurrentBuffer(Console, ExeName);
357  if (!Hist || Hist->NumEntries == 0) return;
358 
359  /*
360  * Like Up/F5, on first time start from current (usually last) entry,
361  * but on subsequent times start at previous entry.
362  */
363  if (Console->LineUpPressed)
364  Hist->Position = (Hist->Position ? Hist->Position : Hist->NumEntries) - 1;
365  Console->LineUpPressed = TRUE;
366 
367  Entry.Length = Console->LinePos * sizeof(WCHAR); // == Pos * sizeof(WCHAR)
368  Entry.Buffer = Console->LineBuffer;
369 
370  /*
371  * Keep going backwards, even wrapping around to the end,
372  * until we get back to starting point.
373  */
374  HistPos = Hist->Position;
375  do
376  {
377  if (RtlPrefixUnicodeString(&Entry, &Hist->Entries[HistPos], FALSE))
378  {
379  Hist->Position = HistPos;
380  LineInputEdit(Console, Console->LineSize - Pos,
381  Hist->Entries[HistPos].Length / sizeof(WCHAR) - Pos,
382  &Hist->Entries[HistPos].Buffer[Pos]);
383  /* Cursor stays where it was */
385  return;
386  }
387  if (--HistPos < 0) HistPos += Hist->NumEntries;
388  } while (HistPos != Hist->Position);
389 
390  return;
391  }
392 #endif
393 
394  return;
395  }
396 
397 
398  /*
399  * OK, we deal with normal keys, we can continue...
400  */
401 
403  {
404  /*
405  * Backspace handling - if processed input enabled then we handle it
406  * here, otherwise we treat it like a normal character.
407  */
408  if (Pos > 0)
409  {
411  LineInputEdit(Console, 1, 0, NULL);
412  }
413  }
414  else if (KeyEvent->uChar.UnicodeChar == L'\r')
415  {
416  /*
417  * Only add a history entry if console echo is enabled. This ensures
418  * that anything sent to the console when echo is disabled (e.g.
419  * binary data, or secrets like passwords...) does not remain stored
420  * in memory.
421  */
423  {
424  Entry.Length = Entry.MaximumLength = Console->LineSize * sizeof(WCHAR);
425  Entry.Buffer = Console->LineBuffer;
426  HistoryAddEntry(Console, ExeName, &Entry);
427  }
428 
429  /* TODO: Expand aliases */
430  DPRINT1("TODO: Expand aliases\n");
431 
432  LineInputSetPos(Console, Console->LineSize);
433  Console->LineBuffer[Console->LineSize++] = L'\r';
435  {
436  if (GetType(Console->ActiveBuffer) == TEXTMODE_BUFFER)
437  {
438  TermWriteStream(Console, (PTEXTMODE_SCREEN_BUFFER)(Console->ActiveBuffer), L"\r", 1, TRUE);
439  }
440  }
441 
442  /*
443  * Add \n if processed input. There should usually be room for it,
444  * but an exception to the rule exists: the buffer could have been
445  * pre-filled with LineMaxSize - 1 characters.
446  */
448  Console->LineSize < Console->LineMaxSize)
449  {
450  Console->LineBuffer[Console->LineSize++] = L'\n';
452  {
453  if (GetType(Console->ActiveBuffer) == TEXTMODE_BUFFER)
454  {
455  TermWriteStream(Console, (PTEXTMODE_SCREEN_BUFFER)(Console->ActiveBuffer), L"\n", 1, TRUE);
456  }
457  }
458  }
459  Console->LineComplete = TRUE;
460  Console->LinePos = 0;
461  }
462  else if (KeyEvent->uChar.UnicodeChar != L'\0')
463  {
464  if (KeyEvent->uChar.UnicodeChar < 0x20 &&
465  Console->LineWakeupMask & (1 << KeyEvent->uChar.UnicodeChar))
466  {
467  /* Control key client wants to handle itself (e.g. for tab completion) */
468  Console->LineBuffer[Console->LineSize++] = L' ';
469  Console->LineBuffer[Console->LinePos] = KeyEvent->uChar.UnicodeChar;
470  Console->LineComplete = TRUE;
471  Console->LinePos = 0;
472  }
473  else
474  {
475  /* Normal character */
476  BOOL Overstrike = !Console->LineInsertToggle && (Console->LinePos != Console->LineSize);
477  DPRINT("Overstrike = %s\n", Overstrike ? "true" : "false");
478  LineInputEdit(Console, (Overstrike ? 1 : 0), 1, &KeyEvent->uChar.UnicodeChar);
479  }
480  }
481 }
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSOLE Console)
Definition: lineinput.c:33
#define VK_F5
Definition: winuser.h:2234
#define VK_F6
Definition: winuser.h:2235
struct _Entry Entry
Definition: kefuncs.h:640
ULONG NumEntries
Definition: history.c:22
ush Pos
Definition: deflate.h:92
DWORD dwControlKeyState
Definition: wincon.h:233
#define VK_LEFT
Definition: winuser.h:2199
#define VK_DOWN
Definition: winuser.h:2202
#define VK_INSERT
Definition: winuser.h:2207
#define VK_PRIOR
Definition: winuser.h:2195
#define TEXTMODE_BUFFER
Definition: pccons.c:21
#define VK_ESCAPE
Definition: winuser.h:2189
int32_t INT
Definition: typedefs.h:56
#define VK_NEXT
Definition: winuser.h:2196
VOID HistoryDeleteCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:306
WORD wVirtualKeyCode
Definition: wincon.h:227
#define ENABLE_ECHO_INPUT
Definition: wincon.h:77
#define VK_HOME
Definition: winuser.h:2198
#define VK_UP
Definition: winuser.h:2200
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define GetConsoleInputBufferMode(Console)
Definition: conio.h:362
void DPRINT(...)
Definition: polytest.cpp:61
#define VK_DELETE
Definition: winuser.h:2208
#define LEFT_ALT_PRESSED
Definition: wincon.h:132
VOID HistoryGetCurrentEntry(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
Definition: history.c:197
PPOPUP_WINDOW Popup
Definition: lineinput.c:159
union _KEY_EVENT_RECORD::@3153 uChar
PUNICODE_STRING Entries
Definition: history.c:24
PPOPUP_WINDOW HistoryDisplayCurrentHistory(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:271
#define VK_F7
Definition: winuser.h:2236
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned short WORD
Definition: ntddk_ex.h:93
ULONG Position
Definition: history.c:20
#define VK_F3
Definition: winuser.h:2232
#define VK_F8
Definition: winuser.h:2237
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
INT GetType(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:129
static const WCHAR L[]
Definition: oid.c:1250
VOID HistoryAddEntry(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
Definition: history.c:141
#define VK_RIGHT
Definition: winuser.h:2201
#define ENABLE_PROCESSED_INPUT
Definition: wincon.h:75
#define TermSetCursorInfo(Console, ScreenBuffer)
Definition: term.h:24
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
static VOID LineInputSetPos(PCONSRV_CONSOLE Console, UINT Pos)
Definition: lineinput.c:60
#define VK_F1
Definition: winuser.h:2230
CConsole Console
#define DPRINT1
Definition: precomp.h:8
BOOL HistoryFindEntryByPrefix(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Prefix, PUNICODE_STRING Entry)
Definition: history.c:229
#define TermWriteStream(Console, ScreenBuffer, Buffer, Length, Attrib)
Definition: term.h:17
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
static VOID LineInputEdit(PCONSRV_CONSOLE Console, UINT NumToDelete, UINT NumToInsert, PWCHAR Insertion)
Definition: lineinput.c:85
static VOID LineInputRecallHistory(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, INT Offset)
Definition: lineinput.c:125
#define VK_END
Definition: winuser.h:2197
base of all file and directory entries
Definition: entries.h:82
#define RIGHT_ALT_PRESSED
Definition: wincon.h:131

Referenced by ConDrvReadConsole(), and ConSrvTermReadStream().

◆ LineInputRecallHistory()

static VOID LineInputRecallHistory ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
INT  Offset 
)
static

Definition at line 125 of file lineinput.c.

128 {
129 #if 0
131  UINT Position = 0;
132 
133  if (!Hist || Hist->NumEntries == 0) return;
134 
135  Position = Hist->Position + Offset;
136  Position = min(max(Position, 0), Hist->NumEntries - 1);
137  Hist->Position = Position;
138 
140  LineInputEdit(Console, Console->LineSize,
141  Hist->Entries[Hist->Position].Length / sizeof(WCHAR),
142  Hist->Entries[Hist->Position].Buffer);
143 
144 #else
145 
147 
148  if (!HistoryRecallHistory(Console, ExeName, Offset, &Entry)) return;
149 
151  LineInputEdit(Console, Console->LineSize,
152  Entry.Length / sizeof(WCHAR),
153  Entry.Buffer);
154 #endif
155 }
#define max(a, b)
Definition: svc.c:63
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSOLE Console)
Definition: lineinput.c:33
struct _Entry Entry
Definition: kefuncs.h:640
ULONG NumEntries
Definition: history.c:22
static COORD Position
Definition: mouse.c:34
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PUNICODE_STRING Entries
Definition: history.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG Position
Definition: history.c:20
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
static VOID LineInputSetPos(PCONSRV_CONSOLE Console, UINT Pos)
Definition: lineinput.c:60
CConsole Console
BOOL HistoryRecallHistory(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, INT Offset, PUNICODE_STRING Entry)
Definition: history.c:210
static VOID LineInputEdit(PCONSRV_CONSOLE Console, UINT NumToDelete, UINT NumToInsert, PWCHAR Insertion)
Definition: lineinput.c:85
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ LineInputSetPos()

static VOID LineInputSetPos ( PCONSRV_CONSOLE  Console,
UINT  Pos 
)
static

Definition at line 60 of file lineinput.c.

62 {
64  {
65  PCONSOLE_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
66  SHORT OldCursorX = Buffer->CursorPosition.X;
67  SHORT OldCursorY = Buffer->CursorPosition.Y;
68  INT XY = OldCursorY * Buffer->ScreenBufferSize.X + OldCursorX;
69 
70  XY += (Pos - Console->LinePos);
71  if (XY < 0)
72  XY = 0;
73  else if (XY >= Buffer->ScreenBufferSize.Y * Buffer->ScreenBufferSize.X)
74  XY = Buffer->ScreenBufferSize.Y * Buffer->ScreenBufferSize.X - 1;
75 
76  Buffer->CursorPosition.X = XY % Buffer->ScreenBufferSize.X;
77  Buffer->CursorPosition.Y = XY / Buffer->ScreenBufferSize.X;
78  TermSetScreenInfo(Console, Buffer, OldCursorX, OldCursorY);
79  }
80 
81  Console->LinePos = Pos;
82 }
ush Pos
Definition: deflate.h:92
int32_t INT
Definition: typedefs.h:56
#define ENABLE_ECHO_INPUT
Definition: wincon.h:77
#define TermSetScreenInfo(Console, ScreenBuffer, OldCursorX, OldCursorY)
Definition: term.h:26
short SHORT
Definition: pedump.c:59
#define GetConsoleInputBufferMode(Console)
Definition: conio.h:362
Definition: bufpool.h:45
CConsole Console

Referenced by LineInputEdit(), LineInputKeyDown(), and LineInputRecallHistory().

Variable Documentation

◆ Popup

Definition at line 159 of file lineinput.c.

Referenced by LineInputKeyDown().