34cad00a3c7fbe4f00a5dfdf9c305f54686e096e
[reactos.git] / reactos / subsys / system / 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 <ekohl@abo.rhein-zeitung.de>)
30 * Added help text ("/?").
31 *
32 * 14-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
33 * Added "$+" option.
34 *
35 * 09-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
36 * Added "$A", "$C" and "$F" option.
37 * Added locale support.
38 * Fixed "$V" option.
39 *
40 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
41 * Unicode and redirection safe!
42 *
43 * 24-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
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 #include "resource.h"
51
52 /*
53 * print the command-line prompt
54 */
55 VOID PrintPrompt(VOID)
56 {
57 static TCHAR default_pr[] = _T("$P$G");
58 TCHAR szPrompt[256];
59 LPTSTR pr;
60
61 if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
62 pr = szPrompt;
63 else
64 pr = default_pr;
65
66 while (*pr)
67 {
68 if (*pr != _T('$'))
69 {
70 ConOutChar (*pr);
71 }
72 else
73 {
74 pr++;
75
76 switch (_totupper (*pr))
77 {
78 case _T('A'):
79 ConOutChar (_T('&'));
80 break;
81
82 case _T('B'):
83 ConOutChar (_T('|'));
84 break;
85
86 case _T('C'):
87 ConOutChar (_T('('));
88 break;
89
90 case _T('D'):
91 PrintDate ();
92 break;
93
94 case _T('E'):
95 ConOutChar (_T('\x1B'));
96 break;
97
98 case _T('F'):
99 ConOutChar (_T(')'));
100 break;
101
102 case _T('G'):
103 ConOutChar (_T('>'));
104 break;
105
106 case _T('H'):
107 ConOutChar (_T('\x08'));
108 ConOutChar (_T(' '));
109 ConOutChar (_T('\x08'));
110 break;
111
112 case _T('L'):
113 ConOutChar (_T('<'));
114 break;
115
116 case _T('N'):
117 {
118 TCHAR szPath[MAX_PATH];
119 GetCurrentDirectory (MAX_PATH, szPath);
120 ConOutChar (szPath[0]);
121 }
122 break;
123
124 case _T('P'):
125 {
126 TCHAR szPath[MAX_PATH];
127 GetCurrentDirectory (MAX_PATH, szPath);
128 ConOutPrintf (_T("%s"), szPath);
129 }
130 break;
131
132 case _T('Q'):
133 ConOutChar (_T('='));
134 break;
135
136 case _T('S'):
137 ConOutChar (_T(' '));
138 break;
139
140 case _T('T'):
141 {
142 SYSTEMTIME t;
143 GetSystemTime(&t);
144 ConOutPrintf(_T("%02d%c%02d%c%02d%c%02d\n"),t.wHour, cTimeSeparator,t.wMinute , cTimeSeparator,
145 t.wSecond , cDecimalSeparator, t.wMilliseconds );
146 }
147 break;
148
149 case _T('V'):
150 switch (osvi.dwPlatformId)
151 {
152 case VER_PLATFORM_WIN32_WINDOWS:
153 if (osvi.dwMajorVersion == 4 &&
154 osvi.dwMinorVersion == 1)
155 ConOutPrintf (_T("Windows 98"));
156 else
157 ConOutPrintf (_T("Windows 95"));
158 break;
159
160
161 case VER_PLATFORM_WIN32_NT:
162 ConOutPrintf (_T("Windows NT Version %lu.%lu"),
163 osvi.dwMajorVersion, osvi.dwMinorVersion);
164 break;
165 }
166 break;
167
168 case _T('_'):
169 ConOutChar (_T('\n'));
170 break;
171
172 case '$':
173 ConOutChar (_T('$'));
174 break;
175
176 #ifdef FEATURE_DIRECTORY_STACK
177 case '+':
178 {
179 INT i;
180 for (i = 0; i < GetDirectoryStackDepth (); i++)
181 ConOutChar (_T('+'));
182 }
183 break;
184 #endif
185 }
186 }
187 pr++;
188 }
189 }
190
191
192 #ifdef INCLUDE_CMD_PROMPT
193
194 INT cmd_prompt (LPTSTR cmd, LPTSTR param)
195 {
196 TCHAR szParam[512];
197 if (!_tcsncmp (param, _T("/?"), 2))
198 {
199 ConOutResPaging(TRUE,STRING_PROMPT_HELP1);
200
201 #ifdef FEATURE_DIRECTORY_STACK
202 ConOutResPaging(FALSE,STRING_PROMPT_HELP2);
203 #endif
204 ConOutResPaging(FALSE,STRING_PROMPT_HELP3);
205 return 0;
206 }
207 if (param[0] != _T('\0'))
208 _tcscpy(szParam,param);
209 else
210 _tcscpy(szParam,_T("$P$G"));
211
212 /* set PROMPT environment variable */
213 if (!SetEnvironmentVariable (_T("PROMPT"), szParam))
214 return 1;
215
216 return 0;
217 }
218 #endif
219
220 /* EOF */