ReactOS 0.4.15-dev-8002-gbbb3b00
kdprompt.c File Reference
#include <ntoskrnl.h>
#include "kd.h"
#include "kdterminal.h"
Include dependency graph for kdprompt.c:

Go to the source code of this file.

Functions

PCSTR KdbGetHistoryEntry (_Inout_ PLONG NextIndex, _In_ BOOLEAN Next)
 
SIZE_T KdIoReadLine (_Out_ PCHAR Buffer, _In_ SIZE_T Size)
 Reads a line of user input from the terminal.
 

Function Documentation

◆ KdbGetHistoryEntry()

PCSTR KdbGetHistoryEntry ( _Inout_ PLONG  NextIndex,
_In_ BOOLEAN  Next 
)

Definition at line 24 of file kdprompt.c.

27{
28 /* Dummy function */
29 return NULL;
30}
#define NULL
Definition: types.h:112

Referenced by KdIoReadLine().

◆ KdIoReadLine()

SIZE_T KdIoReadLine ( _Out_ PCHAR  Buffer,
_In_ SIZE_T  Size 
)

Reads a line of user input from the terminal.

Parameters
[out]BufferBuffer where to store the input. Trailing newlines are removed.
[in]SizeSize of Buffer.
Returns
Returns the number of characters stored, not counting the NULL terminator.
Note
Accepts only
newlines, \r is ignored.

Definition at line 51 of file kdprompt.c.

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}
unsigned char BOOLEAN
UINT ScanCode
Definition: VirtualKey.c:24
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: bufpool.h:45
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
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 ANSI_NULL
long LONG
Definition: pedump.c:60
ULONG_PTR SIZE_T
Definition: typedefs.h:80
const char * PCSTR
Definition: typedefs.h:52
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

Referenced by KdReceivePacket().