ReactOS 0.4.15-dev-8119-g4fb2fdb
history.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

VOID HistoryAddEntry (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
 
BOOL HistoryFindEntryByPrefix (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Prefix, 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)
 
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)
 

Function Documentation

◆ 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 {
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}
CConsole Console
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
base of all file and directory entries
Definition: entries.h:83
PUNICODE_STRING Entries
Definition: history.c:24
ULONG NumEntries
Definition: history.c:22
ULONG MaxEntries
Definition: history.c:21
ULONG Position
Definition: history.c:20
int32_t INT
Definition: typedefs.h:58
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
static PHISTORY_BUFFER HistoryCurrentBuffer(IN PCONSRV_CONSOLE Console, IN PUNICODE_STRING ExeName)
Definition: history.c:47

Referenced by LineInputKeyDown().

◆ 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}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:144

Referenced by ConSrvDeleteConsole().

◆ HistoryDeleteCurrentBuffer()

VOID HistoryDeleteCurrentBuffer ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)

Definition at line 350 of file history.c.

Referenced by LineInputKeyDown().

◆ 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
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1630

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}

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 min(a, b)
Definition: monoChain.cc:55
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
static COORD Position
Definition: mouse.c:34
#define max(a, b)
Definition: svc.c:63
uint32_t ULONG
Definition: typedefs.h:59

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);
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}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define RemoveTailList(ListHead)
Definition: env_spec_w32.h:975
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
static NTSTATUS HistoryResizeBuffer(IN PHISTORY_BUFFER Hist, IN ULONG NumCommands)
Definition: history.c:157

Referenced by CON_API_NOCONSOLE(), and ConSrvApplyUserSettings().