ReactOS 0.4.15-dev-8052-gc0e3179
prompt.c File Reference
#include "precomp.h"
Include dependency graph for prompt.c:

Go to the source code of this file.

Macros

#define FOREGROUND_WHITE   (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
 

Functions

VOID InitPrompt (VOID)
 
VOID PrintInfoLine (VOID)
 
VOID PrintPrompt (VOID)
 
INT cmd_prompt (LPTSTR param)
 

Variables

static TCHAR DefaultPrompt [] = _T("$P$G")
 

Macro Definition Documentation

◆ FOREGROUND_WHITE

Function Documentation

◆ cmd_prompt()

INT cmd_prompt ( LPTSTR  param)

Definition at line 244 of file prompt.c.

245{
246 INT retval = 0;
247
248 if (!_tcsncmp(param, _T("/?"), 2))
249 {
251#ifdef FEATURE_DIRECTORY_STACK
253#endif
255 return 0;
256 }
257
258 /*
259 * Set the PROMPT environment variable. If 'param' is NULL or is
260 * an empty string (the user entered "prompt" only), then remove
261 * the environment variable and therefore use the default prompt.
262 * Otherwise, use the new prompt.
263 */
264 if (!SetEnvironmentVariable(_T("PROMPT"),
265 (param && param[0] != _T('\0') ? param : NULL)))
266 {
267 retval = 1;
268 }
269
270 if (BatType != CMD_TYPE)
271 {
272 if (retval != 0)
273 nErrorLevel = retval;
274 }
275 else
276 {
277 nErrorLevel = retval;
278 }
279
280 return retval;
281}
BATCH_TYPE BatType
Definition: batch.c:66
INT nErrorLevel
Definition: cmd.c:158
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_PROMPT_HELP2
Definition: resource.h:156
#define STRING_PROMPT_HELP1
Definition: resource.h:155
#define STRING_PROMPT_HELP3
Definition: resource.h:157
@ CMD_TYPE
Definition: batch.h:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLfloat param
Definition: glext.h:5796
#define _tcsncmp
Definition: tchar.h:1428
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define SetEnvironmentVariable
Definition: winbase.h:3908

◆ InitPrompt()

VOID InitPrompt ( VOID  )

Definition at line 57 of file prompt.c.

58{
59 TCHAR Buffer[2];
60
61 /*
62 * Set the PROMPT environment variable if it doesn't exist already.
63 * You can change the PROMPT environment variable before cmd starts.
64 */
65 if (GetEnvironmentVariable(_T("PROMPT"), Buffer, _countof(Buffer)) == 0)
67}
Definition: bufpool.h:45
static TCHAR DefaultPrompt[]
Definition: prompt.c:52
#define _countof(array)
Definition: sndvol32.h:68
#define GetEnvironmentVariable
Definition: winbase.h:3814
char TCHAR
Definition: xmlstorage.h:189

Referenced by Initialize().

◆ PrintInfoLine()

VOID PrintInfoLine ( VOID  )

Definition at line 72 of file prompt.c.

73{
74#define FOREGROUND_WHITE (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
75
78 COORD coPos;
79 DWORD dwWritten;
80
81 PTSTR pszInfoLine = NULL;
82 INT iInfoLineLen;
83
84 /* Return directly if the output handle is not a console handle */
85 if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
86 return;
87
88 iInfoLineLen = LoadString(CMD_ModuleHandle, STRING_CMD_INFOLINE, (PTSTR)&pszInfoLine, 0);
89 if (!pszInfoLine || iInfoLineLen == 0)
90 return;
91
92 /* Display the localized information line */
93 coPos.X = 0;
94 coPos.Y = 0;
96 csbi.dwSize.X,
97 coPos, &dwWritten);
98 FillConsoleOutputCharacter(hOutput, _T(' '),
99 csbi.dwSize.X,
100 coPos, &dwWritten);
101
102 WriteConsoleOutputCharacter(hOutput, pszInfoLine, iInfoLineLen,
103 coPos, &dwWritten);
104}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:525
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
HANDLE CMD_ModuleHandle
Definition: cmd.c:165
#define STRING_CMD_INFOLINE
Definition: resource.h:88
#define BACKGROUND_BLUE
Definition: blue.h:65
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FOREGROUND_WHITE
Definition: bl.h:1338
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
SHORT X
Definition: blue.h:26
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define WriteConsoleOutputCharacter
Definition: wincon.h:789
#define FillConsoleOutputCharacter
Definition: wincon.h:788
#define LoadString
Definition: winuser.h:5819
CHAR * PTSTR
Definition: xmlstorage.h:191

Referenced by PrintPrompt().

◆ PrintPrompt()

VOID PrintPrompt ( VOID  )

Definition at line 109 of file prompt.c.

110{
111 LPTSTR pr, Prompt;
112 TCHAR szPrompt[256];
114
115 if (GetEnvironmentVariable(_T("PROMPT"), szPrompt, _countof(szPrompt)))
116 Prompt = szPrompt;
117 else
118 Prompt = DefaultPrompt;
119
120 /*
121 * Special pre-handling for $I: If the information line is displayed
122 * on top of the screen, ensure that the prompt won't be hidden below it.
123 */
124 for (pr = Prompt; *pr;)
125 {
126 if (*pr++ != _T('$'))
127 continue;
128 if (!*pr || _totupper(*pr++) != _T('I'))
129 continue;
130
131 if (GetCursorY() == 0)
132 ConOutChar(_T('\n'));
133 break;
134 }
135
136 /* Parse the prompt string */
137 for (pr = Prompt; *pr; ++pr)
138 {
139 if (*pr != _T('$'))
140 {
141 ConOutChar(*pr);
142 }
143 else
144 {
145 ++pr;
146 if (!*pr) break;
147 switch (_totupper(*pr))
148 {
149 case _T('A'):
150 ConOutChar(_T('&'));
151 break;
152
153 case _T('B'):
154 ConOutChar(_T('|'));
155 break;
156
157 case _T('C'):
158 ConOutChar(_T('('));
159 break;
160
161 case _T('D'):
162 ConOutPrintf(_T("%s"), GetDateString());
163 break;
164
165 case _T('E'):
166 ConOutChar(_T('\x1B'));
167 break;
168
169 case _T('F'):
170 ConOutChar(_T(')'));
171 break;
172
173 case _T('G'):
174 ConOutChar(_T('>'));
175 break;
176
177 case _T('H'):
178 ConOutPuts(_T("\x08 \x08"));
179 break;
180
181 case _T('I'):
183 break;
184
185 case _T('L'):
186 ConOutChar(_T('<'));
187 break;
188
189 case _T('N'):
190 {
192 ConOutChar(szPath[0]);
193 break;
194 }
195
196 case _T('P'):
197 {
199 ConOutPrintf(_T("%s"), szPath);
200 break;
201 }
202
203 case _T('Q'):
204 ConOutChar(_T('='));
205 break;
206
207 case _T('S'):
208 ConOutChar(_T(' '));
209 break;
210
211 case _T('T'):
212 ConOutPrintf(_T("%s"), GetTimeString());
213 break;
214
215 case _T('V'):
217 break;
218
219 case _T('_'):
220 ConOutChar(_T('\n'));
221 break;
222
223 case _T('$'):
224 ConOutChar(_T('$'));
225 break;
226
227#ifdef FEATURE_DIRECTORY_STACK
228 case _T('+'):
229 {
230 INT i;
231 for (i = 0; i < GetDirectoryStackDepth(); i++)
232 ConOutChar(_T('+'));
233 break;
234 }
235#endif
236 }
237 }
238 }
239}
LPTSTR GetTimeString(VOID)
Definition: locale.c:73
INT GetDirectoryStackDepth(VOID)
Definition: dirstack.c:98
LPTSTR GetDateString(VOID)
Definition: locale.c:58
VOID ConOutChar(TCHAR c)
Definition: console.c:123
SHORT GetCursorY(VOID)
Definition: console.c:218
#define ConOutPrintf(szStr,...)
Definition: console.h:41
#define ConOutPuts(szStr)
Definition: console.h:29
#define MAX_PATH
Definition: compat.h:34
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
#define _totupper
Definition: tchar.h:1509
LPCWSTR szPath
Definition: env.c:37
VOID PrintInfoLine(VOID)
Definition: prompt.c:72
static void PrintOSVersion(void)
Definition: rosperf.c:291
#define GetCurrentDirectory
Definition: winbase.h:3805
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by Batch(), ExecuteCommandWithEcho(), ReadCommand(), and ReadLine().

Variable Documentation

◆ DefaultPrompt

TCHAR DefaultPrompt[] = _T("$P$G")
static

Definition at line 52 of file prompt.c.

Referenced by InitPrompt(), and PrintPrompt().