ReactOS 0.4.15-dev-7953-g1f49173
kdprompt.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS KDBG Kernel Debugger Terminal Driver
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Terminal line-editing (Prompt) interface
5 * COPYRIGHT: Copyright 2001-2004 David Welch <welch@cwcom.net>
6 * Copyright 2004-2005 Gregor Anich <blight@blight.eu.org>
7 * Copyright 2022-2023 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
8 */
9
10/* INCLUDES ******************************************************************/
11
12#include <ntoskrnl.h>
13#include "kd.h"
14#include "kdterminal.h"
15
16/* In kdb.h only when KDBG defined */
17#ifdef KDBG
18extern PCSTR
20 _Inout_ PLONG NextIndex,
21 _In_ BOOLEAN Next);
22#else
25 _Inout_ PLONG NextIndex,
26 _In_ BOOLEAN Next)
27{
28 /* Dummy function */
29 return NULL;
30}
31#endif
32
33
34/* FUNCTIONS *****************************************************************/
35
54{
55 PCHAR Orig = Buffer;
56 ULONG ScanCode = 0;
57 CHAR Key;
59 LONG CmdHistIndex = -1; // Start at end of history.
60
61 /* Flush the input buffer */
63
64 /* Bail out if the buffer is zero-sized */
65 if (Size == 0)
66 return 0;
67
68 for (;;)
69 {
71
72 /* Check for return or newline */
73 if ((Key == '\r') || (Key == '\n'))
74 {
76 KdIoPuts("\n");
77 return (SIZE_T)(Buffer - Orig);
78 }
79 else if (Key == KEY_BS || Key == KEY_DEL)
80 {
81 /* Erase the last character */
82 if (Buffer > Orig)
83 {
84 Buffer--;
86
87 if (EchoOn)
88 KdIoPrintf("%c %c", KEY_BS, KEY_BS);
89 else
90 KdIoPrintf(" %c", KEY_BS);
91 }
92 }
94 {
95 PCSTR CmdHistory = KdbGetHistoryEntry(&CmdHistIndex,
97 if (CmdHistory)
98 {
99 SIZE_T i;
100
101 /* Erase the whole line */
102 while (Buffer > Orig)
103 {
104 Buffer--;
105 *Buffer = ANSI_NULL;
106
107 if (EchoOn)
108 KdIoPrintf("%c %c", KEY_BS, KEY_BS);
109 else
110 KdIoPrintf(" %c", KEY_BS);
111 }
112
113 /* Copy and display the history entry */
114 i = min(strlen(CmdHistory), Size - 1);
115 memcpy(Orig, CmdHistory, i);
116 Orig[i] = ANSI_NULL;
117 Buffer = Orig + i;
118 KdIoPuts(Orig);
119 }
120 }
121 else
122 {
123 /* Do not accept characters anymore if the buffer is full */
124 if ((SIZE_T)(Buffer - Orig) >= (Size - 1))
125 continue;
126
127 if (EchoOn)
128 KdIoPrintf("%c", Key);
129
130 *Buffer = Key;
131 Buffer++;
132 }
133 }
134}
135
136/* EOF */
unsigned char BOOLEAN
UINT ScanCode
Definition: VirtualKey.c:24
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
VOID __cdecl KdIoPrintf(_In_ PCSTR Format,...)
Definition: kdio.c:576
VOID KdIoPuts(_In_ PCSTR String)
Definition: kdio.c:568
PCSTR KdbGetHistoryEntry(_Inout_ PLONG NextIndex, _In_ BOOLEAN Next)
Definition: kdprompt.c:24
SIZE_T KdIoReadLine(_Out_ PCHAR Buffer, _In_ SIZE_T Size)
Reads a line of user input from the terminal.
Definition: kdprompt.c:51
VOID KdpFlushTerminalInput(VOID)
Flushes terminal input (either serial or PS/2).
Definition: kdterminal.c:197
ULONG KdbDebugState
Definition: kdterminal.c:32
CHAR KdpReadTermKey(_Out_ PULONG ScanCode)
Reads one character from the terminal. This function returns a scan code even when reading is done fr...
Definition: kdterminal.c:217
@ KD_DEBUG_KDNOECHO
Definition: kdterminal.h:37
#define KEY_SCAN_DOWN
Definition: kdterminal.h:15
#define KEY_BS
Definition: kdterminal.h:10
#define KEY_SCAN_UP
Definition: kdterminal.h:14
#define KEY_DEL
Definition: kdterminal.h:12
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
#define _Inout_
Definition: ms_sal.h:378
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define ANSI_NULL
long LONG
Definition: pedump.c:60
ULONG_PTR SIZE_T
Definition: typedefs.h:80
const char * PCSTR
Definition: typedefs.h:52
int32_t * PLONG
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
char CHAR
Definition: xmlstorage.h:175