ReactOS  0.4.15-dev-338-g3dad100
history.c File Reference
#include "consrv.h"
#include "popup.h"
#include <debug.h>
Include dependency graph for history.c:

Go to the source code of this file.

Classes

struct  _HISTORY_BUFFER
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _HISTORY_BUFFER HISTORY_BUFFER
 
typedef struct _HISTORY_BUFFERPHISTORY_BUFFER
 

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)
 
static PHISTORY_BUFFER HistoryCurrentBuffer (IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
 
static PHISTORY_BUFFER HistoryFindBuffer (PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
 
static VOID HistoryDeleteBuffer (PHISTORY_BUFFER Hist)
 
static NTSTATUS HistoryResizeBuffer (IN PHISTORY_BUFFER Hist, IN ULONG NumCommands)
 
VOID HistoryAddEntry (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
 
VOID HistoryGetCurrentEntry (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
 
BOOL HistoryRecallHistory (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, INT Offset, PUNICODE_STRING Entry)
 
BOOL HistoryFindEntryByPrefix (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Prefix, PUNICODE_STRING Entry)
 
PPOPUP_WINDOW HistoryDisplayCurrentHistory (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
 
VOID HistoryDeleteCurrentBuffer (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
 
VOID HistoryDeleteBuffers (PCONSRV_CONSOLE Console)
 
VOID HistoryReshapeAllBuffers (IN PCONSRV_CONSOLE Console, IN ULONG HistoryBufferSize, IN ULONG MaxNumberOfHistoryBuffers, IN BOOLEAN HistoryNoDup)
 
 CON_API (SrvGetConsoleCommandHistory, CONSOLE_GETCOMMANDHISTORY, GetCommandHistoryRequest)
 
 CON_API (SrvGetConsoleCommandHistoryLength, CONSOLE_GETCOMMANDHISTORYLENGTH, GetCommandHistoryLengthRequest)
 
 CON_API (SrvExpungeConsoleCommandHistory, CONSOLE_EXPUNGECOMMANDHISTORY, ExpungeCommandHistoryRequest)
 
 CON_API (SrvSetConsoleNumberOfCommands, CONSOLE_SETHISTORYNUMBERCOMMANDS, SetHistoryNumberCommandsRequest)
 
 CON_API_NOCONSOLE (SrvGetConsoleHistory, CONSOLE_GETSETHISTORYINFO, HistoryInfoRequest)
 
 CON_API_NOCONSOLE (SrvSetConsoleHistory, CONSOLE_GETSETHISTORYINFO, HistoryInfoRequest)
 
 CON_API (SrvSetConsoleCommandHistoryMode, CONSOLE_SETHISTORYMODE, SetHistoryModeRequest)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file history.c.

Typedef Documentation

◆ HISTORY_BUFFER

◆ PHISTORY_BUFFER

Function Documentation

◆ CON_API() [1/5]

CON_API ( SrvGetConsoleCommandHistory  ,
CONSOLE_GETCOMMANDHISTORY  ,
GetCommandHistoryRequest   
)

Definition at line 426 of file history.c.

428 {
430  ULONG BytesWritten = 0;
431  PHISTORY_BUFFER Hist;
432 
433  if ( !CsrValidateMessageBuffer(ApiMessage,
434  (PVOID*)&GetCommandHistoryRequest->History,
435  GetCommandHistoryRequest->HistoryLength,
436  sizeof(BYTE)) ||
437  !CsrValidateMessageBuffer(ApiMessage,
438  (PVOID*)&GetCommandHistoryRequest->ExeName,
439  GetCommandHistoryRequest->ExeLength,
440  sizeof(BYTE)) )
441  {
443  }
444 
445  Hist = HistoryFindBuffer(Console,
446  GetCommandHistoryRequest->ExeName,
447  GetCommandHistoryRequest->ExeLength,
448  GetCommandHistoryRequest->Unicode2);
449  if (Hist)
450  {
451  ULONG i;
452 
453  LPSTR TargetBufferA;
454  LPWSTR TargetBufferW;
455  ULONG BufferSize = GetCommandHistoryRequest->HistoryLength;
456 
457  ULONG Offset = 0;
458  ULONG SourceLength;
459 
460  if (GetCommandHistoryRequest->Unicode)
461  {
462  TargetBufferW = GetCommandHistoryRequest->History;
463  BufferSize /= sizeof(WCHAR);
464  }
465  else
466  {
467  TargetBufferA = GetCommandHistoryRequest->History;
468  }
469 
470  for (i = 0; i < Hist->NumEntries; i++)
471  {
472  SourceLength = Hist->Entries[i].Length / sizeof(WCHAR);
473  if (Offset + SourceLength + 1 > BufferSize)
474  {
476  break;
477  }
478 
479  if (GetCommandHistoryRequest->Unicode)
480  {
481  RtlCopyMemory(&TargetBufferW[Offset], Hist->Entries[i].Buffer, SourceLength * sizeof(WCHAR));
482  Offset += SourceLength;
483  TargetBufferW[Offset++] = L'\0';
484  }
485  else
486  {
488  Hist->Entries[i].Buffer, SourceLength * sizeof(WCHAR),
489  &TargetBufferA[Offset], SourceLength);
490  Offset += SourceLength;
491  TargetBufferA[Offset++] = '\0';
492  }
493  }
494 
495  if (GetCommandHistoryRequest->Unicode)
496  BytesWritten = Offset * sizeof(WCHAR);
497  else
499  }
500 
501  // GetCommandHistoryRequest->HistoryLength = TargetBuffer - (PBYTE)GetCommandHistoryRequest->History;
502  GetCommandHistoryRequest->HistoryLength = BytesWritten;
503 
504  return Status;
505 }
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:96
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG NumEntries
Definition: history.c:22
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
char * LPSTR
Definition: xmlstorage.h:182
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
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PUNICODE_STRING Entries
Definition: history.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define BufferSize
Definition: classpnp.h:419
static const WCHAR L[]
Definition: oid.c:1250
BOOLEAN ConvertInputUnicodeToAnsi(PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PCHAR Target, USHORT TargetLength)
Definition: alias.c:64
unsigned char BYTE
Definition: xxhash.c:193
Status
Definition: gdiplustypes.h:24
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [2/5]

CON_API ( SrvGetConsoleCommandHistoryLength  ,
CONSOLE_GETCOMMANDHISTORYLENGTH  ,
GetCommandHistoryLengthRequest   
)

Definition at line 508 of file history.c.

510 {
511  PHISTORY_BUFFER Hist;
512  ULONG Length = 0;
513 
514  if (!CsrValidateMessageBuffer(ApiMessage,
515  (PVOID*)&GetCommandHistoryLengthRequest->ExeName,
516  GetCommandHistoryLengthRequest->ExeLength,
517  sizeof(BYTE)))
518  {
520  }
521 
522  Hist = HistoryFindBuffer(Console,
523  GetCommandHistoryLengthRequest->ExeName,
524  GetCommandHistoryLengthRequest->ExeLength,
525  GetCommandHistoryLengthRequest->Unicode2);
526  if (Hist)
527  {
528  ULONG i;
529  for (i = 0; i < Hist->NumEntries; i++)
530  Length += Hist->Entries[i].Length + sizeof(WCHAR); // Each entry is returned NULL-terminated
531  }
532  /*
533  * Quick and dirty way of getting the number of bytes of the
534  * corresponding ANSI string from the one in UNICODE.
535  */
536  if (!GetCommandHistoryLengthRequest->Unicode)
537  Length /= sizeof(WCHAR);
538 
539  GetCommandHistoryLengthRequest->HistoryLength = Length;
540 
541  return STATUS_SUCCESS;
542 }
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:96
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG NumEntries
Definition: history.c:22
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char BYTE
Definition: xxhash.c:193
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [3/5]

CON_API ( SrvExpungeConsoleCommandHistory  ,
CONSOLE_EXPUNGECOMMANDHISTORY  ,
ExpungeCommandHistoryRequest   
)

Definition at line 545 of file history.c.

547 {
548  PHISTORY_BUFFER Hist;
549 
550  if (!CsrValidateMessageBuffer(ApiMessage,
551  (PVOID*)&ExpungeCommandHistoryRequest->ExeName,
552  ExpungeCommandHistoryRequest->ExeLength,
553  sizeof(BYTE)))
554  {
556  }
557 
558  Hist = HistoryFindBuffer(Console,
559  ExpungeCommandHistoryRequest->ExeName,
560  ExpungeCommandHistoryRequest->ExeLength,
561  ExpungeCommandHistoryRequest->Unicode2);
562  HistoryDeleteBuffer(Hist);
563 
564  return STATUS_SUCCESS;
565 }
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:96
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:144
unsigned char BYTE
Definition: xxhash.c:193
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [4/5]

CON_API ( SrvSetConsoleNumberOfCommands  ,
CONSOLE_SETHISTORYNUMBERCOMMANDS  ,
SetHistoryNumberCommandsRequest   
)

Definition at line 568 of file history.c.

570 {
572  PHISTORY_BUFFER Hist;
573 
574  if (!CsrValidateMessageBuffer(ApiMessage,
575  (PVOID*)&SetHistoryNumberCommandsRequest->ExeName,
576  SetHistoryNumberCommandsRequest->ExeLength,
577  sizeof(BYTE)))
578  {
580  }
581 
582  Hist = HistoryFindBuffer(Console,
583  SetHistoryNumberCommandsRequest->ExeName,
584  SetHistoryNumberCommandsRequest->ExeLength,
585  SetHistoryNumberCommandsRequest->Unicode2);
586  if (Hist)
587  {
588  Status = HistoryResizeBuffer(Hist, SetHistoryNumberCommandsRequest->NumCommands);
589  }
590 
591  return Status;
592 }
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:96
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
static NTSTATUS HistoryResizeBuffer(IN PHISTORY_BUFFER Hist, IN ULONG NumCommands)
Definition: history.c:157
unsigned char BYTE
Definition: xxhash.c:193
Status
Definition: gdiplustypes.h:24
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [5/5]

CON_API ( SrvSetConsoleCommandHistoryMode  ,
CONSOLE_SETHISTORYMODE  ,
SetHistoryModeRequest   
)

Definition at line 646 of file history.c.

648 {
649  DPRINT("SrvSetConsoleCommandHistoryMode(Mode = %d) is not yet implemented\n",
650  SetHistoryModeRequest->Mode);
651 
652  Console->InsertMode = !!(SetHistoryModeRequest->Mode & CONSOLE_OVERSTRIKE);
653  return STATUS_SUCCESS;
654 }
void DPRINT(...)
Definition: polytest.cpp:61
#define CONSOLE_OVERSTRIKE
Definition: wincon.h:115
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API_NOCONSOLE() [1/2]

CON_API_NOCONSOLE ( SrvGetConsoleHistory  ,
CONSOLE_GETSETHISTORYINFO  ,
HistoryInfoRequest   
)

Definition at line 595 of file history.c.

597 {
598 #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
601 
602  Status = ConSrvGetConsole(ProcessData,
603  &Console, TRUE);
604  if (!NT_SUCCESS(Status))
605  return Status;
606 
607  HistoryInfoRequest->HistoryBufferSize = Console->HistoryBufferSize;
608  HistoryInfoRequest->NumberOfHistoryBuffers = Console->MaxNumberOfHistoryBuffers;
609  HistoryInfoRequest->dwFlags = (Console->HistoryNoDup ? HISTORY_NO_DUP_FLAG : 0);
610 
612  return Status;
613 #else
614  DPRINT1("%s not yet implemented\n", __FUNCTION__);
615  return STATUS_NOT_IMPLEMENTED;
616 #endif
617 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:291
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:316
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define HISTORY_NO_DUP_FLAG
Definition: wincon.h:113
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CON_API_NOCONSOLE() [2/2]

CON_API_NOCONSOLE ( SrvSetConsoleHistory  ,
CONSOLE_GETSETHISTORYINFO  ,
HistoryInfoRequest   
)

Definition at line 620 of file history.c.

622 {
623 #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
626 
627  Status = ConSrvGetConsole(ProcessData,
628  &Console, TRUE);
629  if (!NT_SUCCESS(Status))
630  return Status;
631 
633  HistoryInfoRequest->HistoryBufferSize,
634  HistoryInfoRequest->NumberOfHistoryBuffers,
635  !!(HistoryInfoRequest->dwFlags & HISTORY_NO_DUP_FLAG));
636 
638  return STATUS_SUCCESS;
639 #else
640  DPRINT1("%s not yet implemented\n", __FUNCTION__);
641  return STATUS_NOT_IMPLEMENTED;
642 #endif
643 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:291
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:316
VOID HistoryReshapeAllBuffers(IN PCONSRV_CONSOLE Console, IN ULONG HistoryBufferSize, IN ULONG MaxNumberOfHistoryBuffers, IN BOOLEAN HistoryNoDup)
Definition: history.c:371
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define HISTORY_NO_DUP_FLAG
Definition: wincon.h:113
CConsole Console
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define __FUNCTION__
Definition: types.h:112

◆ 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 HistoryFindBuffer().

◆ 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:64
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 CON_API().

◆ HistoryAddEntry()

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

Definition at line 185 of file history.c.

188 {
189  // UNICODE_STRING NewEntry;
191 
192  if (!Hist) return;
193 
194  // NewEntry.Length = NewEntry.MaximumLength = Console->LineSize * sizeof(WCHAR);
195  // NewEntry.Buffer = Console->LineBuffer;
196 
197  /* Don't add blank or duplicate entries */
198  if (Entry->Length == 0 || Hist->MaxEntries == 0 ||
199  (Hist->NumEntries > 0 &&
200  RtlEqualUnicodeString(&Hist->Entries[Hist->NumEntries - 1], Entry, FALSE)))
201  {
202  return;
203  }
204 
205  if (Console->HistoryNoDup)
206  {
207  INT i;
208 
209  /* Check if this line has been entered before */
210  for (i = Hist->NumEntries - 1; i >= 0; i--)
211  {
212  if (RtlEqualUnicodeString(&Hist->Entries[i], Entry, FALSE))
213  {
214  UNICODE_STRING NewEntry;
215 
216  /* Just rotate the list to bring this entry to the end */
217  NewEntry = Hist->Entries[i];
218  RtlMoveMemory(&Hist->Entries[i], &Hist->Entries[i + 1],
219  (Hist->NumEntries - (i + 1)) * sizeof(UNICODE_STRING));
220  Hist->Entries[Hist->NumEntries - 1] = NewEntry;
221  Hist->Position = Hist->NumEntries - 1;
222  return;
223  }
224  }
225  }
226 
227  if (Hist->NumEntries == Hist->MaxEntries)
228  {
229  /* List is full, remove oldest entry */
230  RtlFreeUnicodeString(&Hist->Entries[0]);
231  RtlMoveMemory(&Hist->Entries[0], &Hist->Entries[1],
232  --Hist->NumEntries * sizeof(UNICODE_STRING));
233  }
234 
236  Hist->NumEntries++;
237  Hist->Position = Hist->NumEntries - 1;
238 }
ULONG NumEntries
Definition: history.c:22
static PHISTORY_BUFFER HistoryCurrentBuffer(IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
Definition: history.c:47
int32_t INT
Definition: typedefs.h:57
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
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
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
ULONG Position
Definition: history.c:20
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
CConsole Console
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ HistoryCurrentBuffer()

static PHISTORY_BUFFER HistoryCurrentBuffer ( IN PCONSRV_CONSOLE  Console,
IN PUNICODE_STRING  ExeName 
)
static

Definition at line 47 of file history.c.

50 {
52  PHISTORY_BUFFER Hist;
53 
54  for (Entry = Console->HistoryBuffers.Flink;
55  Entry != &Console->HistoryBuffers;
56  Entry = Entry->Flink)
57  {
58  Hist = CONTAINING_RECORD(Entry, HISTORY_BUFFER, ListEntry);
59  if (RtlEqualUnicodeString(ExeName, &Hist->ExeName, FALSE))
60  return Hist;
61  }
62 
63  /* Could not find the buffer, create a new one */
64 
65  if (Console->NumberOfHistoryBuffers < Console->MaxNumberOfHistoryBuffers)
66  {
67  Hist = ConsoleAllocHeap(0, sizeof(HISTORY_BUFFER) + ExeName->Length);
68  if (!Hist) return NULL;
69  Hist->MaxEntries = Console->HistoryBufferSize;
70  Hist->NumEntries = 0;
71  Hist->Entries = ConsoleAllocHeap(0, Hist->MaxEntries * sizeof(UNICODE_STRING));
72  if (!Hist->Entries)
73  {
74  ConsoleFreeHeap(Hist);
75  return NULL;
76  }
77  Hist->ExeName.Length = Hist->ExeName.MaximumLength = ExeName->Length;
78  Hist->ExeName.Buffer = (PWCHAR)(Hist + 1);
79  RtlCopyMemory(Hist->ExeName.Buffer, ExeName->Buffer, ExeName->Length);
80  InsertHeadList(&Console->HistoryBuffers, &Hist->ListEntry);
81  Console->NumberOfHistoryBuffers++;
82  return Hist;
83  }
84  else
85  {
86  // FIXME: TODO !!!!!!!
87  // Reuse an older history buffer, if possible with the same Exe name,
88  // otherwise take the oldest one and reset its contents.
89  // And move the history buffer back to the head of the list.
91  return NULL;
92  }
93 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
UNICODE_STRING ExeName
Definition: history.c:23
struct _Entry Entry
Definition: kefuncs.h:627
USHORT MaximumLength
Definition: env_spec_w32.h:370
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
ULONG NumEntries
Definition: history.c:22
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
uint16_t * PWCHAR
Definition: typedefs.h:55
ULONG MaxEntries
Definition: history.c:21
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY ListEntry
Definition: history.c:19
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PUNICODE_STRING Entries
Definition: history.c:24
Definition: typedefs.h:118
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
#define UNIMPLEMENTED
Definition: debug.h:115
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
base of all file and directory entries
Definition: entries.h:82

Referenced by HistoryAddEntry(), HistoryDeleteCurrentBuffer(), HistoryDisplayCurrentHistory(), HistoryFindEntryByPrefix(), HistoryGetCurrentEntry(), HistoryRecallHistory(), LineInputKeyDown(), and LineInputRecallHistory().

◆ HistoryDeleteBuffer()

static VOID HistoryDeleteBuffer ( PHISTORY_BUFFER  Hist)
static

Definition at line 144 of file history.c.

145 {
146  if (!Hist) return;
147 
148  while (Hist->NumEntries != 0)
149  RtlFreeUnicodeString(&Hist->Entries[--Hist->NumEntries]);
150 
151  ConsoleFreeHeap(Hist->Entries);
152  RemoveEntryList(&Hist->ListEntry);
153  ConsoleFreeHeap(Hist);
154 }
ULONG NumEntries
Definition: history.c:22
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
LIST_ENTRY ListEntry
Definition: history.c:19
PUNICODE_STRING Entries
Definition: history.c:24
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15

Referenced by CON_API(), HistoryDeleteBuffers(), HistoryDeleteCurrentBuffer(), and HistoryReshapeAllBuffers().

◆ HistoryDeleteBuffers()

VOID HistoryDeleteBuffers ( PCONSRV_CONSOLE  Console)

Definition at line 357 of file history.c.

358 {
359  PLIST_ENTRY CurrentEntry;
360  PHISTORY_BUFFER HistoryBuffer;
361 
362  while (!IsListEmpty(&Console->HistoryBuffers))
363  {
364  CurrentEntry = RemoveHeadList(&Console->HistoryBuffers);
365  HistoryBuffer = CONTAINING_RECORD(CurrentEntry, HISTORY_BUFFER, ListEntry);
366  HistoryDeleteBuffer(HistoryBuffer);
367  }
368 }
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:144
Definition: typedefs.h:118
CConsole Console

Referenced by ConSrvDeleteConsole().

◆ HistoryDeleteCurrentBuffer()

VOID HistoryDeleteCurrentBuffer ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)

Definition at line 350 of file history.c.

352 {
354 }
static PHISTORY_BUFFER HistoryCurrentBuffer(IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
Definition: history.c:47
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:144
CConsole Console

Referenced by LineInputKeyDown().

◆ HistoryDisplayCurrentHistory()

PPOPUP_WINDOW HistoryDisplayCurrentHistory ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)

Definition at line 315 of file history.c.

317 {
318  PCONSOLE_SCREEN_BUFFER ActiveBuffer;
320 
321  SHORT xLeft, yTop;
322  SHORT Width, Height;
323 
325 
326  if (!Hist) return NULL;
327  if (Hist->NumEntries == 0) return NULL;
328 
329  if (GetType(Console->ActiveBuffer) != TEXTMODE_BUFFER) return NULL;
330  ActiveBuffer = Console->ActiveBuffer;
331 
332  Width = 40;
333  Height = 10;
334 
335  /* Center the popup window on the screen */
336  xLeft = ActiveBuffer->ViewOrigin.X + (ActiveBuffer->ViewSize.X - Width ) / 2;
337  yTop = ActiveBuffer->ViewOrigin.Y + (ActiveBuffer->ViewSize.Y - Height) / 2;
338 
339  /* Create the popup */
340  Popup = CreatePopupWindow(Console, ActiveBuffer,
341  xLeft, yTop, Width, Height);
342  if (Popup == NULL) return NULL;
343 
344  Popup->PopupInputRoutine = NULL;
345 
346  return Popup;
347 }
ULONG NumEntries
Definition: history.c:22
static PHISTORY_BUFFER HistoryCurrentBuffer(IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
Definition: history.c:47
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

Referenced by LineInputKeyDown().

◆ HistoryFindBuffer()

static PHISTORY_BUFFER HistoryFindBuffer ( PCONSRV_CONSOLE  Console,
PVOID  ExeName,
USHORT  ExeLength,
BOOLEAN  UnicodeExe 
)
static

Definition at line 96 of file history.c.

100 {
101  UNICODE_STRING ExeNameU;
102 
104  PHISTORY_BUFFER Hist = NULL;
105 
106  if (ExeName == NULL) return NULL;
107 
108  if (UnicodeExe)
109  {
110  ExeNameU.Buffer = ExeName;
111  /* Length is in bytes */
112  ExeNameU.MaximumLength = ExeLength;
113  }
114  else
115  {
117  ExeName, ExeLength,
118  &ExeNameU.Buffer, &ExeNameU.MaximumLength))
119  {
120  return NULL;
121  }
122  }
123  ExeNameU.Length = ExeNameU.MaximumLength;
124 
125  for (Entry = Console->HistoryBuffers.Flink;
126  Entry != &Console->HistoryBuffers;
127  Entry = Entry->Flink)
128  {
129  Hist = CONTAINING_RECORD(Entry, HISTORY_BUFFER, ListEntry);
130 
131  /* For the history APIs, the caller is allowed to give only part of the name */
132  if (RtlPrefixUnicodeString(&ExeNameU, &Hist->ExeName, TRUE))
133  {
134  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
135  return Hist;
136  }
137  }
138 
139  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
140  return NULL;
141 }
#define TRUE
Definition: types.h:120
UNICODE_STRING ExeName
Definition: history.c:23
struct _Entry Entry
Definition: kefuncs.h:627
USHORT MaximumLength
Definition: env_spec_w32.h:370
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
BOOLEAN ConvertInputAnsiToUnicode(PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PWCHAR *Target, PUSHORT TargetLength)
Definition: alias.c:37
Definition: typedefs.h:118
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
base of all file and directory entries
Definition: entries.h:82

Referenced by CON_API().

◆ HistoryFindEntryByPrefix()

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

Definition at line 273 of file history.c.

277 {
278  INT HistPos;
279 
280  /* Search for history entries starting with input. */
282  if (!Hist || Hist->NumEntries == 0) return FALSE;
283 
284  /*
285  * Like Up/F5, on first time start from current (usually last) entry,
286  * but on subsequent times start at previous entry.
287  */
288  if (Console->LineUpPressed)
289  Hist->Position = (Hist->Position ? Hist->Position : Hist->NumEntries) - 1;
290  Console->LineUpPressed = TRUE;
291 
292  // Entry.Length = Console->LinePos * sizeof(WCHAR); // == Pos * sizeof(WCHAR)
293  // Entry.Buffer = Console->LineBuffer;
294 
295  /*
296  * Keep going backwards, even wrapping around to the end,
297  * until we get back to starting point.
298  */
299  HistPos = Hist->Position;
300  do
301  {
302  if (RtlPrefixUnicodeString(Prefix, &Hist->Entries[HistPos], FALSE))
303  {
304  Hist->Position = HistPos;
305  *Entry = Hist->Entries[HistPos];
306  return TRUE;
307  }
308  if (--HistPos < 0) HistPos += Hist->NumEntries;
309  } while (HistPos != Hist->Position);
310 
311  return FALSE;
312 }
#define TRUE
Definition: types.h:120
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
ULONG NumEntries
Definition: history.c:22
static PHISTORY_BUFFER HistoryCurrentBuffer(IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
Definition: history.c:47
int32_t INT
Definition: typedefs.h:57
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
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 241 of file history.c.

244 {
246 
247  if (!Hist || Hist->NumEntries == 0)
248  Entry->Length = 0;
249  else
250  *Entry = Hist->Entries[Hist->Position];
251 }
ULONG NumEntries
Definition: history.c:22
static PHISTORY_BUFFER HistoryCurrentBuffer(IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
Definition: history.c:47
PUNICODE_STRING Entries
Definition: history.c:24
ULONG Position
Definition: history.c:20
CConsole Console
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 254 of file history.c.

258 {
260  ULONG Position = 0;
261 
262  if (!Hist || Hist->NumEntries == 0) return FALSE;
263 
264  Position = Hist->Position + Offset;
265  Position = min(max(Position, 0), Hist->NumEntries - 1);
266  Hist->Position = Position;
267 
268  *Entry = Hist->Entries[Hist->Position];
269  return TRUE;
270 }
#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
static PHISTORY_BUFFER HistoryCurrentBuffer(IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
Definition: history.c:47
_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
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputRecallHistory().

◆ HistoryReshapeAllBuffers()

VOID HistoryReshapeAllBuffers ( IN PCONSRV_CONSOLE  Console,
IN ULONG  HistoryBufferSize,
IN ULONG  MaxNumberOfHistoryBuffers,
IN BOOLEAN  HistoryNoDup 
)

Definition at line 371 of file history.c.

376 {
378  PHISTORY_BUFFER Hist;
380 
381  // ASSERT(Console->NumberOfHistoryBuffers <= Console->MaxNumberOfHistoryBuffers);
382  if (MaxNumberOfHistoryBuffers < Console->NumberOfHistoryBuffers)
383  {
384  /*
385  * Trim the history buffers list and reduce it up to MaxNumberOfHistoryBuffers.
386  * We loop the history buffers list backwards so as to trim the oldest
387  * buffers first.
388  */
389  while (!IsListEmpty(&Console->HistoryBuffers) &&
390  (Console->NumberOfHistoryBuffers > MaxNumberOfHistoryBuffers))
391  {
392  Entry = RemoveTailList(&Console->HistoryBuffers);
393  Hist = CONTAINING_RECORD(Entry, HISTORY_BUFFER, ListEntry);
394  HistoryDeleteBuffer(Hist);
395  Console->NumberOfHistoryBuffers--;
396  }
397  ASSERT(Console->NumberOfHistoryBuffers == MaxNumberOfHistoryBuffers);
398  ASSERT(((Console->NumberOfHistoryBuffers == 0) && IsListEmpty(&Console->HistoryBuffers)) ||
399  ((Console->NumberOfHistoryBuffers > 0) && !IsListEmpty(&Console->HistoryBuffers)));
400  }
401  Console->MaxNumberOfHistoryBuffers = MaxNumberOfHistoryBuffers;
402 
403  /* Resize each history buffer */
404  for (Entry = Console->HistoryBuffers.Flink;
405  Entry != &Console->HistoryBuffers;
406  Entry = Entry->Flink)
407  {
408  Hist = CONTAINING_RECORD(Entry, HISTORY_BUFFER, ListEntry);
409  Status = HistoryResizeBuffer(Hist, HistoryBufferSize);
410  if (!NT_SUCCESS(Status))
411  {
412  DPRINT1("HistoryResizeBuffer(0x%p, %lu) failed, Status 0x%08lx\n",
413  Hist, HistoryBufferSize, Status);
414  }
415  }
416  Console->HistoryBufferSize = HistoryBufferSize;
417 
418  /* No duplicates */
419  Console->HistoryNoDup = !!HistoryNoDup;
420 }
struct _Entry Entry
Definition: kefuncs.h:627
FORCEINLINE PLIST_ENTRY RemoveTailList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:154
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
static NTSTATUS HistoryResizeBuffer(IN PHISTORY_BUFFER Hist, IN ULONG NumCommands)
Definition: history.c:157
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:144
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:118
Status
Definition: gdiplustypes.h:24
CConsole Console
#define DPRINT1
Definition: precomp.h:8
base of all file and directory entries
Definition: entries.h:82

Referenced by CON_API_NOCONSOLE(), and ConSrvApplyUserSettings().

◆ HistoryResizeBuffer()

static NTSTATUS HistoryResizeBuffer ( IN PHISTORY_BUFFER  Hist,
IN ULONG  NumCommands 
)
static

Definition at line 157 of file history.c.

160 {
161  PUNICODE_STRING OldEntryList = Hist->Entries;
162  PUNICODE_STRING NewEntryList;
163 
164  NewEntryList = ConsoleAllocHeap(0, NumCommands * sizeof(UNICODE_STRING));
165  if (!NewEntryList)
166  return STATUS_NO_MEMORY;
167 
168  /* If necessary, shrink by removing oldest entries */
169  for (; Hist->NumEntries > NumCommands; Hist->NumEntries--)
170  {
171  RtlFreeUnicodeString(Hist->Entries++);
172  Hist->Position += (Hist->Position == 0);
173  }
174 
175  Hist->MaxEntries = NumCommands;
176  RtlCopyMemory(NewEntryList, Hist->Entries,
177  Hist->NumEntries * sizeof(UNICODE_STRING));
178  Hist->Entries = NewEntryList;
179  ConsoleFreeHeap(OldEntryList);
180 
181  return STATUS_SUCCESS;
182 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API(), and HistoryReshapeAllBuffers().