forked from amdf/NativeShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.c
232 lines (202 loc) · 4.35 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*++
Copyright (c) Alex Ionescu. All rights reserved.
Copyright (c) 2011 amdf.
THIS CODE AND INFORMATION IS PROVIDED UNDER THE LESSER GNU PUBLIC LICENSE.
PLEASE READ THE FILE "COPYING" IN THE TOP LEVEL DIRECTORY.
Module Name:
display.c
Abstract:
The Native Command Line Interface (NCLI) is the command shell for the
TinyKRNL OS.
This module handles displaying output to screen.
Environment:
Native mode
Revision History:
Alex Ionescu - Started Implementation - 01-Mar-06
Alex Ionescu - Reworked architecture - 23-Mar-06
amdf - Display buffer extended (was too small) - 22-Feb-11
--*/
#include "precomp.h"
WCHAR DisplayBuffer[1024];
USHORT LinePos = 0;
WCHAR PutChar[2] = L" ";
UNICODE_STRING CharString = {2, 2, PutChar};
/*++
* @name RtlCliPrintString
*
* The RtlCliPrintString routine display a unicode string on the display device
*
* @param Message
* Pointer to a unicode string containing the message to print.
*
* @return STATUS_SUCCESS or failure code.
*
* @remarks None.
*
*--*/
NTSTATUS
RtlCliPrintString(IN PUNICODE_STRING Message)
{
ULONG i;
NTSTATUS Status;
//
// Loop every character
//
for (i = 0; i < (Message->Length / sizeof(WCHAR)); i++)
{
//
// Print the character
//
Status = RtlCliPutChar(Message->Buffer[i]);
}
//
// Return status
//
return Status;
}
/*++
* @name RtlCliPutChar
*
* The RtlCliPutChar routine displays a character.
*
* @param Char
* Character to print out.
*
* @return STATUS_SUCCESS or failure code.
*
* @remarks None.
*
*--*/
NTSTATUS
RtlCliPutChar(IN WCHAR Char)
{
//
// Initialize the string
//
CharString.Buffer[0] = Char;
//
// Check for overflow, or simply update.
//
#if 0
if (LinePos++ > 80)
{
//
// We'll be on a new line. Do the math and see how far.
//
MessageLength = NewPos - 80;
LinePos = sizeof(WCHAR);
}
#endif
//
// Make sure that this isn't backspace
//
if (Char != '\r')
{
//
// Check if it's a new line
//
if (Char == '\n')
{
//
// Reset the display buffer
//
LinePos = 0;
DisplayBuffer[LinePos] = UNICODE_NULL;
}
else
{
//
// Add the character in our buffer
//
DisplayBuffer[LinePos] = Char;
LinePos++;
}
}
//
// Print the character
//
return NtDisplayString(&CharString);
}
/*++
* @name RtlClipBackspace
*
* The RtlClipBackspace routine handles a backspace command.
*
* @param None.
*
* @return STATUS_SUCCESS or failure code if printing failed.
*
* @remarks Backspace is handled by printing the previous string minus the last
* two characters.
*
*--*/
NTSTATUS
RtlClipBackspace(VOID)
{
UNICODE_STRING BackString;
//
// Update the line position
//
LinePos--;
//
// Finalize this buffer and make it unicode
//
DisplayBuffer[LinePos] = ANSI_NULL;
RtlInitUnicodeString(&BackString, DisplayBuffer);
//
// Display the buffer
//
return NtDisplayString(&BackString);
}
/*++
* @name RtlCliDisplayString
*
* The RtlCliDisplayString routine FILLMEIN
*
* @param Message
* FILLMEIN
*
* @param ... (Ellipsis)
* There is no set number of parameters.
*
* @return NTSTATUS
*
* @remarks Documentation for this routine needs to be completed.
*
*--*/
NTSTATUS
__cdecl
RtlCliDisplayString(IN PCH Message, ...)
{
va_list MessageList;
PCHAR MessageBuffer;
UNICODE_STRING MessageString;
NTSTATUS Status;
//
// Allocate Memory for the String Buffer
//
MessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, 512);
//
// First, combine the message
//
va_start(MessageList, Message);
_vsnprintf(MessageBuffer, 512, Message, MessageList);
va_end(MessageList);
//
// Now make it a unicode string
//
RtlCreateUnicodeStringFromAsciiz(&MessageString, MessageBuffer);
//
// Display it on screen
//
Status = RtlCliPrintString(&MessageString);
//
// Free Memory
//
RtlFreeHeap(RtlGetProcessHeap(), 0, MessageBuffer);
RtlFreeUnicodeString(&MessageString);
//
// Return to the caller
//
return Status;
}