ReactOS 0.4.16-dev-297-gc569aee
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)
 
BOOL HasInfoLine (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 260 of file prompt.c.

261{
262 INT retval = 0;
263
264 if (!_tcsncmp(param, _T("/?"), 2))
265 {
267#ifdef FEATURE_DIRECTORY_STACK
269#endif
271 return 0;
272 }
273
274 /*
275 * Set the PROMPT environment variable. If 'param' is NULL or is
276 * an empty string (the user entered "prompt" only), then remove
277 * the environment variable and therefore use the default prompt.
278 * Otherwise, use the new prompt.
279 */
280 if (!SetEnvironmentVariable(_T("PROMPT"),
281 (param && param[0] != _T('\0') ? param : NULL)))
282 {
283 retval = 1;
284 }
285
286 if (BatType != CMD_TYPE)
287 {
288 if (retval != 0)
289 nErrorLevel = retval;
290 }
291 else
292 {
293 nErrorLevel = retval;
294 }
295
296 return retval;
297}
BATCH_TYPE BatType
Definition: batch.c:66
INT nErrorLevel
Definition: cmd.c:158
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:178
#define STRING_PROMPT_HELP2
Definition: resource.h:158
#define STRING_PROMPT_HELP1
Definition: resource.h:157
#define STRING_PROMPT_HELP3
Definition: resource.h:159
@ 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:3933

◆ HasInfoLine()

BOOL HasInfoLine ( VOID  )

Definition at line 72 of file prompt.c.

73{
74 LPTSTR pr;
75 TCHAR szPrompt[256];
76
77 if (GetEnvironmentVariable(_T("PROMPT"), szPrompt, _countof(szPrompt)))
78 {
79 pr = szPrompt;
80 while (*pr)
81 {
82 if (*pr++ != _T('$'))
83 continue;
84 if (!*pr || _totupper(*pr++) != _T('I'))
85 continue;
86
87 return TRUE;
88 }
89 }
90
91 return FALSE;
92}
#define _totupper
Definition: tchar.h:1509
#define _countof(array)
Definition: sndvol32.h:70
#define GetEnvironmentVariable
Definition: winbase.h:3839
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by Initialize(), and PrintPrompt().

◆ 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

Referenced by Initialize().

◆ PrintInfoLine()

VOID PrintInfoLine ( VOID  )

Definition at line 97 of file prompt.c.

98{
99#define FOREGROUND_WHITE (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
100
103 COORD coPos;
104 DWORD dwWritten;
105
106 PTSTR pszInfoLine = NULL;
107 INT iInfoLineLen;
108
109 /* Return directly if the output handle is not a console handle */
110 if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
111 return;
112
113 iInfoLineLen = LoadString(CMD_ModuleHandle, STRING_CMD_INFOLINE, (PTSTR)&pszInfoLine, 0);
114 if (!pszInfoLine || iInfoLineLen == 0)
115 return;
116
117 /* Display the localized information line */
118 coPos.X = 0;
119 coPos.Y = 0;
121 csbi.dwSize.X,
122 coPos, &dwWritten);
123 FillConsoleOutputCharacter(hOutput, _T(' '),
124 csbi.dwSize.X,
125 coPos, &dwWritten);
126
127 WriteConsoleOutputCharacter(hOutput, pszInfoLine, iInfoLineLen,
128 coPos, &dwWritten);
129}
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:294
#define WriteConsoleOutputCharacter
Definition: wincon.h:789
#define FillConsoleOutputCharacter
Definition: wincon.h:788
#define LoadString
Definition: winuser.h:5831
CHAR * PTSTR
Definition: xmlstorage.h:191

Referenced by PrintPrompt().

◆ PrintPrompt()

VOID PrintPrompt ( VOID  )

Definition at line 134 of file prompt.c.

135{
136 LPTSTR pr, Prompt;
137 TCHAR szPrompt[256];
139
140 if (GetEnvironmentVariable(_T("PROMPT"), szPrompt, _countof(szPrompt)))
141 Prompt = szPrompt;
142 else
143 Prompt = DefaultPrompt;
144
145 /*
146 * Special pre-handling for $I: If the information line is displayed
147 * on top of the screen, ensure that the prompt won't be hidden below it.
148 */
149 if (HasInfoLine() && GetCursorY() == 0)
150 ConOutChar(_T('\n'));
151
152 /* Parse the prompt string */
153 for (pr = Prompt; *pr; ++pr)
154 {
155 if (*pr != _T('$'))
156 {
157 ConOutChar(*pr);
158 }
159 else
160 {
161 ++pr;
162 if (!*pr) break;
163 switch (_totupper(*pr))
164 {
165 case _T('A'):
166 ConOutChar(_T('&'));
167 break;
168
169 case _T('B'):
170 ConOutChar(_T('|'));
171 break;
172
173 case _T('C'):
174 ConOutChar(_T('('));
175 break;
176
177 case _T('D'):
178 ConOutPrintf(_T("%s"), GetDateString());
179 break;
180
181 case _T('E'):
182 ConOutChar(_T('\x1B'));
183 break;
184
185 case _T('F'):
186 ConOutChar(_T(')'));
187 break;
188
189 case _T('G'):
190 ConOutChar(_T('>'));
191 break;
192
193 case _T('H'):
194 ConOutPuts(_T("\x08 \x08"));
195 break;
196
197 case _T('I'):
199 break;
200
201 case _T('L'):
202 ConOutChar(_T('<'));
203 break;
204
205 case _T('N'):
206 {
208 ConOutChar(szPath[0]);
209 break;
210 }
211
212 case _T('P'):
213 {
215 ConOutPrintf(_T("%s"), szPath);
216 break;
217 }
218
219 case _T('Q'):
220 ConOutChar(_T('='));
221 break;
222
223 case _T('S'):
224 ConOutChar(_T(' '));
225 break;
226
227 case _T('T'):
228 ConOutPrintf(_T("%s"), GetTimeString());
229 break;
230
231 case _T('V'):
233 break;
234
235 case _T('_'):
236 ConOutChar(_T('\n'));
237 break;
238
239 case _T('$'):
240 ConOutChar(_T('$'));
241 break;
242
243#ifdef FEATURE_DIRECTORY_STACK
244 case _T('+'):
245 {
246 INT i;
247 for (i = 0; i < GetDirectoryStackDepth(); i++)
248 ConOutChar(_T('+'));
249 break;
250 }
251#endif
252 }
253 }
254 }
255}
LPTSTR GetTimeString(VOID)
Definition: locale.c:70
INT GetDirectoryStackDepth(VOID)
Definition: dirstack.c:98
LPTSTR GetDateString(VOID)
Definition: locale.c:58
SHORT GetCursorY(VOID)
Definition: console.c:214
#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
LPCWSTR szPath
Definition: env.c:37
VOID PrintInfoLine(VOID)
Definition: prompt.c:97
BOOL HasInfoLine(VOID)
Definition: prompt.c:72
VOID ConOutChar(TCHAR c)
Definition: util.c:233
static void PrintOSVersion(void)
Definition: rosperf.c:291
#define GetCurrentDirectory
Definition: winbase.h:3830

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().