- Remove hard-coded reference to cmdstart.bat and load it from registry (Software...
[reactos.git] / reactos / base / shell / cmd / prompt.c
1 /*
2 * PROMPT.C - prompt handling.
3 *
4 *
5 * History:
6 *
7 * 14/01/95 (Tim Normal)
8 * started.
9 *
10 * 08/08/95 (Matt Rains)
11 * i have cleaned up the source code. changes now bring this source
12 * into guidelines for recommended programming practice.
13 *
14 * 01/06/96 (Tim Norman)
15 * added day of the week printing (oops, forgot about that!)
16 *
17 * 08/07/96 (Steffan Kaiser)
18 * small changes for speed
19 *
20 * 20-Jul-1998 (John P Price <linux-guru@gcfl.net>)
21 * removed redundant day strings. Use ones defined in date.c.
22 *
23 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
24 * added config.h include
25 *
26 * 28-Jul-1998 (John P Price <linux-guru@gcfl.net>)
27 * moved cmd_prompt from internal.c to here
28 *
29 * 09-Dec-1998 (Eric Kohl)
30 * Added help text ("/?").
31 *
32 * 14-Dec-1998 (Eric Kohl)
33 * Added "$+" option.
34 *
35 * 09-Jan-1999 (Eric Kohl)
36 * Added "$A", "$C" and "$F" option.
37 * Added locale support.
38 * Fixed "$V" option.
39 *
40 * 20-Jan-1999 (Eric Kohl)
41 * Unicode and redirection safe!
42 *
43 * 24-Jan-1999 (Eric Kohl)
44 * Fixed Win32 environment handling.
45 *
46 * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
47 * Remove all hardcode string to En.rc
48 */
49 #include <precomp.h>
50
51 /*
52 * print the command-line prompt
53 */
54 VOID PrintPrompt(VOID)
55 {
56 static TCHAR default_pr[] = _T("$P$G");
57 TCHAR szPrompt[256];
58 LPTSTR pr;
59
60 if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
61 pr = szPrompt;
62 else
63 pr = default_pr;
64
65 while (*pr)
66 {
67 if (*pr != _T('$'))
68 {
69 ConOutChar (*pr);
70 }
71 else
72 {
73 pr++;
74
75 switch (_totupper (*pr))
76 {
77 case _T('A'):
78 ConOutChar (_T('&'));
79 break;
80
81 case _T('B'):
82 ConOutChar (_T('|'));
83 break;
84
85 case _T('C'):
86 ConOutChar (_T('('));
87 break;
88
89 case _T('D'):
90 PrintDate ();
91 break;
92
93 case _T('E'):
94 ConOutChar (_T('\x1B'));
95 break;
96
97 case _T('F'):
98 ConOutChar (_T(')'));
99 break;
100
101 case _T('G'):
102 ConOutChar (_T('>'));
103 break;
104
105 case _T('H'):
106 ConOutChar (_T('\x08'));
107 ConOutChar (_T(' '));
108 ConOutChar (_T('\x08'));
109 break;
110
111 case _T('L'):
112 ConOutChar (_T('<'));
113 break;
114
115 case _T('N'):
116 {
117 TCHAR szPath[MAX_PATH];
118 GetCurrentDirectory (MAX_PATH, szPath);
119 ConOutChar (szPath[0]);
120 }
121 break;
122
123 case _T('P'):
124 {
125 TCHAR szPath[MAX_PATH];
126 GetCurrentDirectory (MAX_PATH, szPath);
127 ConOutPrintf (_T("%s"), szPath);
128 }
129 break;
130
131 case _T('Q'):
132 ConOutChar (_T('='));
133 break;
134
135 case _T('S'):
136 ConOutChar (_T(' '));
137 break;
138
139 case _T('T'):
140 {
141 SYSTEMTIME t;
142 GetSystemTime(&t);
143 ConOutPrintf(_T("%02d%c%02d%c%02d%c%02d\n"),t.wHour, cTimeSeparator,t.wMinute , cTimeSeparator,
144 t.wSecond , cDecimalSeparator, t.wMilliseconds );
145 }
146 break;
147
148 case _T('V'):
149 switch (osvi.dwPlatformId)
150 {
151 case VER_PLATFORM_WIN32_WINDOWS:
152 if (osvi.dwMajorVersion == 4 &&
153 osvi.dwMinorVersion == 1)
154 ConOutPrintf (_T("Windows 98"));
155 else
156 ConOutPrintf (_T("Windows 95"));
157 break;
158
159
160 case VER_PLATFORM_WIN32_NT:
161 ConOutPrintf (_T("Windows NT Version %lu.%lu"),
162 osvi.dwMajorVersion, osvi.dwMinorVersion);
163 break;
164 }
165 break;
166
167 case _T('_'):
168 ConOutChar (_T('\n'));
169 break;
170
171 case '$':
172 ConOutChar (_T('$'));
173 break;
174
175 #ifdef FEATURE_DIRECTORY_STACK
176 case '+':
177 {
178 INT i;
179 for (i = 0; i < GetDirectoryStackDepth (); i++)
180 ConOutChar (_T('+'));
181 }
182 break;
183 #endif
184 }
185 }
186 pr++;
187 }
188 }
189
190
191 #ifdef INCLUDE_CMD_PROMPT
192
193 INT cmd_prompt (LPTSTR cmd, LPTSTR param)
194 {
195 if (!_tcsncmp (param, _T("/?"), 2))
196 {
197 ConOutResPaging(TRUE,STRING_PROMPT_HELP1);
198
199 #ifdef FEATURE_DIRECTORY_STACK
200 ConOutResPaging(FALSE,STRING_PROMPT_HELP2);
201 #endif
202 ConOutResPaging(FALSE,STRING_PROMPT_HELP3);
203 return 0;
204 }
205
206 /* if it is null, then it needs to set to default,
207 because that means the user entered "prompt" only.
208 so even if param is null you _must_ still set prompt
209 to the default. There seems to be some kinda difference
210 between winxp and 2k in this matter and this way will
211 cover both. Do not use fixed size of szParam for param the buffer are 8192bytes
212 and will later change to dymatic buffer */
213
214 /* set PROMPT environment variable */
215 if (param[0] != _T('\0'))
216 {
217 if (!SetEnvironmentVariable (_T("PROMPT"), param))
218 return 1;
219 }
220 else
221 {
222 TCHAR szParam[5];
223 _tcscpy(szParam,_T("$P$G"));
224 if (!SetEnvironmentVariable (_T("PROMPT"),szParam))
225 return 1;
226 }
227
228
229
230 return 0;
231 }
232 #endif
233
234 /* EOF */