Fixed obvious typos.
[reactos.git] / rosapps / 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
47 #include "config.h"
48
49 #include <windows.h>
50 #include <tchar.h>
51 #include <string.h>
52 #include <ctype.h>
53
54 #include "cmd.h"
55
56
57 /*
58 * print the command-line prompt
59 *
60 */
61 VOID PrintPrompt(VOID)
62 {
63 static TCHAR default_pr[] = _T("$P$G");
64 TCHAR szPrompt[256];
65 LPTSTR pr;
66
67 if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
68 pr = szPrompt;
69 else
70 pr = default_pr;
71
72 while (*pr)
73 {
74 if (*pr != _T('$'))
75 {
76 ConOutChar (*pr);
77 }
78 else
79 {
80 pr++;
81
82 switch (_totupper (*pr))
83 {
84 case _T('A'):
85 ConOutChar (_T('&'));
86 break;
87
88 case _T('B'):
89 ConOutChar (_T('|'));
90 break;
91
92 case _T('C'):
93 ConOutChar (_T('('));
94 break;
95
96 case _T('D'):
97 PrintDate ();
98 break;
99
100 case _T('E'):
101 ConOutChar (_T('\x1B'));
102 break;
103
104 case _T('F'):
105 ConOutChar (_T(')'));
106 break;
107
108 case _T('G'):
109 ConOutChar (_T('>'));
110 break;
111
112 case _T('H'):
113 ConOutChar (_T('\x08'));
114 break;
115
116 case _T('L'):
117 ConOutChar (_T('<'));
118 break;
119
120 case _T('N'):
121 {
122 TCHAR szPath[MAX_PATH];
123 GetCurrentDirectory (MAX_PATH, szPath);
124 ConOutChar (szPath[0]);
125 }
126 break;
127
128 case _T('P'):
129 {
130 TCHAR szPath[MAX_PATH];
131 GetCurrentDirectory (MAX_PATH, szPath);
132 ConOutPrintf (_T("%s"), szPath);
133 }
134 break;
135
136 case _T('Q'):
137 ConOutChar (_T('='));
138 break;
139
140 case _T('T'):
141 PrintTime ();
142 break;
143
144 case _T('V'):
145 switch (osvi.dwPlatformId)
146 {
147 case VER_PLATFORM_WIN32_WINDOWS:
148 if (osvi.dwMajorVersion == 4 &&
149 osvi.dwMinorVersion == 1)
150 ConOutPrintf (_T("Windows 98"));
151 else
152 ConOutPrintf (_T("Windows 95"));
153 break;
154
155 case VER_PLATFORM_WIN32_NT:
156 ConOutPrintf (_T("Windows NT Version %lu.%lu"),
157 osvi.dwMajorVersion, osvi.dwMinorVersion);
158 break;
159 }
160 break;
161
162 case _T('_'):
163 ConOutChar (_T('\n'));
164 break;
165
166 case '$':
167 ConOutChar (_T('$'));
168 break;
169
170 #ifdef FEATURE_DIRECTORY_STACK
171 case '+':
172 {
173 INT i;
174 for (i = 0; i < GetDirectoryStackDepth (); i++)
175 ConOutChar (_T('+'));
176 }
177 break;
178 #endif
179 }
180 }
181 pr++;
182 }
183 }
184
185
186 #ifdef INCLUDE_CMD_PROMPT
187
188 INT cmd_prompt (LPTSTR cmd, LPTSTR param)
189 {
190 if (!_tcsncmp (param, _T("/?"), 2))
191 {
192 ConOutPuts (_T("Changes the command prompt.\n\n"
193 "PROMPT [text]\n\n"
194 " text Specifies a new command prompt.\n\n"
195 "Prompt can be made up of normal characters and the following special codes:\n\n"
196 " $A & (Ampersand)\n"
197 " $B | (pipe)\n"
198 " $C ( (Left parenthesis)\n"
199 " $D Current date\n"
200 " $E Escape code (ASCII code 27)\n"
201 " $F ) (Right parenthesis)\n"
202 " $G > (greater-than sign)\n"
203 " $H Backspace (erases previous character)\n"
204 " $L < (less-than sign)\n"
205 " $N Current drive\n"
206 " $P Current drive and path\n"
207 " $Q = (equal sign)\n"
208 " $T Current time\n"
209 " $V OS version number\n"
210 " $_ Carriage return and linefeed\n"
211 " $$ $ (dollar sign)"));
212 #ifdef FEATURE_DIRECTORY_STACK
213 ConOutPuts (_T(" $+ Displays the current depth of the directory stack"));
214 #endif
215 ConOutPuts (_T("\nType PROMPT without parameters to reset the prompt to the default setting."));
216 return 0;
217 }
218
219 /* set PROMPT environment variable */
220 if (!SetEnvironmentVariable (_T("PROMPT"), param))
221 return 1;
222
223 return 0;
224 }
225 #endif