ReactOS  0.4.13-dev-249-gcba1a2f
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 231 of file prompt.c.

232 {
233  if (!_tcsncmp(param, _T("/?"), 2))
234  {
236 
237 #ifdef FEATURE_DIRECTORY_STACK
239 #endif
241  return 0;
242  }
243 
244  /*
245  * Set the PROMPT environment variable. If 'param' is NULL or is
246  * an empty string (the user entered "prompt" only), then remove
247  * the environment variable and therefore use the default prompt.
248  * Otherwise, use the new prompt.
249  */
250  if (!SetEnvironmentVariable(_T("PROMPT"),
251  (param && param[0] != _T('\0') ? param : NULL)))
252  {
253  return 1;
254  }
255 
256  return 0;
257 }
#define TRUE
Definition: types.h:120
#define STRING_PROMPT_HELP1
Definition: resource.h:162
#define STRING_PROMPT_HELP2
Definition: resource.h:163
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_PROMPT_HELP3
Definition: resource.h:164
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define SetEnvironmentVariable
Definition: winbase.h:3722
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ 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, ARRAYSIZE(Buffer)) == 0)
67 }
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
Definition: bufpool.h:45
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static TCHAR DefaultPrompt[]
Definition: prompt.c:52
#define SetEnvironmentVariable
Definition: winbase.h:3722
#define GetEnvironmentVariable
Definition: winbase.h:3628

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 }
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:474
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define STRING_CMD_INFOLINE
Definition: resource.h:89
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
CHAR * PTSTR
Definition: xmlstorage.h:191
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
ULONG X
Definition: bl.h:1340
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FOREGROUND_WHITE
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
#define FillConsoleOutputCharacter
Definition: wincon.h:776
Definition: bl.h:1338
#define BACKGROUND_BLUE
Definition: wincon.h:43
HANDLE CMD_ModuleHandle
Definition: cmd.c:164
#define WriteConsoleOutputCharacter
Definition: wincon.h:777
ULONG Y
Definition: bl.h:1341
#define LoadString
Definition: winuser.h:5685

Referenced by PrintPrompt().

◆ PrintPrompt()

VOID PrintPrompt ( VOID  )

Definition at line 109 of file prompt.c.

110 {
111  TCHAR szPrompt[256];
112  LPTSTR pr;
113 
114  if (GetEnvironmentVariable(_T("PROMPT"), szPrompt, 256))
115  pr = szPrompt;
116  else
117  pr = DefaultPrompt;
118 
119  while (*pr)
120  {
121  if (*pr != _T('$'))
122  {
123  ConOutChar(*pr);
124  }
125  else
126  {
127  pr++;
128 
129  switch (_totupper(*pr))
130  {
131  case _T('A'):
132  ConOutChar(_T('&'));
133  break;
134 
135  case _T('B'):
136  ConOutChar(_T('|'));
137  break;
138 
139  case _T('C'):
140  ConOutChar(_T('('));
141  break;
142 
143  case _T('D'):
144  ConOutPrintf(_T("%s"), GetDateString());
145  break;
146 
147  case _T('E'):
148  ConOutChar(_T('\x1B'));
149  break;
150 
151  case _T('F'):
152  ConOutChar(_T(')'));
153  break;
154 
155  case _T('G'):
156  ConOutChar(_T('>'));
157  break;
158 
159  case _T('H'):
160  ConOutChar(_T('\x08'));
161  ConOutChar(_T(' '));
162  ConOutChar(_T('\x08'));
163  break;
164 
165  case _T('I'):
166  PrintInfoLine();
167  break;
168 
169  case _T('L'):
170  ConOutChar(_T('<'));
171  break;
172 
173  case _T('N'):
174  {
177  ConOutChar(szPath[0]);
178  }
179  break;
180 
181  case _T('P'):
182  {
185  ConOutPrintf(_T("%s"), szPath);
186  }
187  break;
188 
189  case _T('Q'):
190  ConOutChar(_T('='));
191  break;
192 
193  case _T('S'):
194  ConOutChar(_T(' '));
195  break;
196 
197  case _T('T'):
198  ConOutPrintf(_T("%s"), GetTimeString());
199  break;
200 
201  case _T('V'):
202  PrintOSVersion();
203  break;
204 
205  case _T('_'):
206  ConOutChar(_T('\n'));
207  break;
208 
209  case '$':
210  ConOutChar(_T('$'));
211  break;
212 
213 #ifdef FEATURE_DIRECTORY_STACK
214  case '+':
215  {
216  INT i;
217  for (i = 0; i < GetDirectoryStackDepth (); i++)
218  ConOutChar(_T('+'));
219  }
220  break;
221 #endif
222  }
223  }
224  pr++;
225  }
226 }
VOID ConOutChar(TCHAR c)
Definition: console.c:123
#define ConOutPrintf(szStr,...)
Definition: console.h:42
#define _totupper
Definition: tchar.h:1509
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID PrintInfoLine(VOID)
Definition: prompt.c:72
LPTSTR GetTimeString(VOID)
Definition: locale.c:73
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 GetCurrentDirectory
Definition: winbase.h:3619
INT GetDirectoryStackDepth(VOID)
Definition: dirstack.c:98
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static TCHAR DefaultPrompt[]
Definition: prompt.c:52
#define MAX_PATH
Definition: compat.h:26
VOID PrintOSVersion(VOID)
Definition: ver.c:114
LPTSTR GetDateString(VOID)
Definition: locale.c:58
LPCWSTR szPath
Definition: env.c:35
#define GetEnvironmentVariable
Definition: winbase.h:3628

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

Variable Documentation

◆ DefaultPrompt

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

Definition at line 52 of file prompt.c.

Referenced by InitPrompt(), and PrintPrompt().