ReactOS 0.4.15-dev-8058-ga7cbb60
kdb_cmdhist.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS KDBG Kernel Debugger
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Command History helpers
5 * COPYRIGHT: Copyright 2005 Gregor Anich <blight@blight.eu.org>
6 * Copyright 2023 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ntoskrnl.h>
12
13/* GLOBALS *******************************************************************/
14
21/* Command history string ring buffer */
23/* Command history ring buffer */
27
28/* FUNCTIONS *****************************************************************/
29
36VOID
39{
41 SIZE_T Length2 = 0;
42 LONG i;
44
46
47 /*
48 * Do not append the string if:
49 * - it is empty (just the NULL terminator);
50 * - or the last command is the same.
51 */
52 if (Length1 <= 1 ||
55 {
56 return;
57 }
58
59 /* Calculate Length1 and Length2 */
63 {
67 }
68
69 /* Remove previous commands until there is enough space to append the new command */
71 {
72 if ((Length2 > 0 &&
75 (Length2 <= 0 &&
78 {
80 }
81
82 i--;
83 if (i < 0)
85
87 break;
88 }
89
90 /* Make sure the new command history entry is free */
94 {
96 }
97
98 /* Append command */
102 if (Length2 > 0)
103 {
105 }
106}
107
108static PCSTR
110 _Inout_ PLONG NextIndex)
111{
112 if (*NextIndex < 0)
113 {
114 /* Start at the end of the history */
115 *NextIndex = KdbCommandHistoryIndex;
116 }
117 else
118 {
119 LONG i = *NextIndex - 1;
120 if (i < 0)
121 *NextIndex = RTL_NUMBER_OF(KdbCommandHistory) - 1;
122
124 *NextIndex = i;
125 else
126 return NULL;
127 }
128
129 return KdbCommandHistory[*NextIndex];
130}
131
132static PCSTR
134 _Inout_ PLONG NextIndex)
135{
136 LONG i;
137
138 if (!(*NextIndex > 0 && *NextIndex != KdbCommandHistoryIndex))
139 return NULL;
140
141 i = *NextIndex + 1;
143 i = 0;
144
145 if (KdbCommandHistory[i])
146 *NextIndex = i;
147
148 return KdbCommandHistory[i];
149}
150
151PCSTR
153 _Inout_ PLONG NextIndex,
154 _In_ BOOLEAN Next)
155{
156 if (Next)
157 return KdbpGetNextHistoryEntry(NextIndex);
158 else
159 return KdbpGetPrevHistoryEntry(NextIndex);
160}
161
162/* EOF */
INT Length2
Definition: FsRtlDissect.c:16
INT Length1
Definition: FsRtlDissect.c:15
unsigned char BOOLEAN
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
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
PCSTR KdbGetHistoryEntry(_Inout_ PLONG NextIndex, _In_ BOOLEAN Next)
Definition: kdb_cmdhist.c:152
static LONG KdbCommandHistoryBufferIndex
Definition: kdb_cmdhist.c:25
static LONG KdbCommandHistoryIndex
Definition: kdb_cmdhist.c:26
VOID KdbpCommandHistoryAppend(_In_ PCSTR Command)
Appends a command to the command history.
Definition: kdb_cmdhist.c:37
static PCSTR KdbpGetPrevHistoryEntry(_Inout_ PLONG NextIndex)
Definition: kdb_cmdhist.c:109
static CHAR KdbCommandHistoryBuffer[2048]
Definition: kdb_cmdhist.c:22
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cmdhist.c:24
static PCSTR KdbpGetNextHistoryEntry(_Inout_ PLONG NextIndex)
Definition: kdb_cmdhist.c:133
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ASSERT(a)
Definition: mode.c:44
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
long LONG
Definition: pedump.c:60
Definition: shell.h:41
ULONG_PTR SIZE_T
Definition: typedefs.h:80
const char * PCSTR
Definition: typedefs.h:52
int32_t * PLONG
Definition: typedefs.h:58
char * PCHAR
Definition: typedefs.h:51
char CHAR
Definition: xmlstorage.h:175