remove whitespace from end of lines
[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 break;
109
110 case _T('L'):
111 ConOutChar (_T('<'));
112 break;
113
114 case _T('N'):
115 {
116 TCHAR szPath[MAX_PATH];
117 GetCurrentDirectory (MAX_PATH, szPath);
118 ConOutChar (szPath[0]);
119 }
120 break;
121
122 case _T('P'):
123 {
124 TCHAR szPath[MAX_PATH];
125 GetCurrentDirectory (MAX_PATH, szPath);
126 ConOutPrintf (_T("%s"), szPath);
127 }
128 break;
129
130 case _T('Q'):
131 ConOutChar (_T('='));
132 break;
133
134 case _T('T'):
135 PrintTime ();
136 break;
137
138 case _T('V'):
139 switch (osvi.dwPlatformId)
140 {
141 case VER_PLATFORM_WIN32_WINDOWS:
142 if (osvi.dwMajorVersion == 4 &&
143 osvi.dwMinorVersion == 1)
144 ConOutPrintf (_T("Windows 98"));
145 else
146 ConOutPrintf (_T("Windows 95"));
147 break;
148
149 case VER_PLATFORM_WIN32_NT:
150 ConOutPrintf (_T("Windows NT Version %lu.%lu"),
151 osvi.dwMajorVersion, osvi.dwMinorVersion);
152 break;
153 }
154 break;
155
156 case _T('_'):
157 ConOutChar (_T('\n'));
158 break;
159
160 case '$':
161 ConOutChar (_T('$'));
162 break;
163
164 #ifdef FEATURE_DIRECTORY_STACK
165 case '+':
166 {
167 INT i;
168 for (i = 0; i < GetDirectoryStackDepth (); i++)
169 ConOutChar (_T('+'));
170 }
171 break;
172 #endif
173 }
174 }
175 pr++;
176 }
177 }
178
179
180 #ifdef INCLUDE_CMD_PROMPT
181
182 INT cmd_prompt (LPTSTR cmd, LPTSTR param)
183 {
184
185 if (!_tcsncmp (param, _T("/?"), 2))
186 {
187 ConOutResPuts(STRING_PROMPT_HELP1);
188
189 #ifdef FEATURE_DIRECTORY_STACK
190 ConOutResPuts(STRING_PROMPT_HELP2);
191 #endif
192 ConOutResPuts(STRING_PROMPT_HELP3);
193 return 0;
194 }
195
196 /* set PROMPT environment variable */
197 if (!SetEnvironmentVariable (_T("PROMPT"), param))
198 return 1;
199
200 return 0;
201 }
202 #endif
203
204 /* EOF */