Implement escape char in console. "^"
[reactos.git] / reactos / subsys / system / cmd / echo.c
1 /*
2 * ECHO.C - internal echo commands.
3 *
4 *
5 * History:
6 *
7 * 16 Jul 1998 (Hans B Pufal)
8 * Started.
9 *
10 * 16 Jul 1998 (John P Price)
11 * Separated commands into individual files.
12 *
13 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
14 * Added config.h include
15 *
16 * 08-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
17 * Added help text ("/?").
18 *
19 * 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
20 * Unicode and redirection ready!
21 *
22 * 13-Jul-2000 (Eric Kohl <ekohl@rz-online.de>)
23 * Implemented 'echo.' and 'echoerr.'.
24 *
25 * 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
26 * Remove all hardcode string to En.rc
27 */
28
29 #include <precomp.h>
30 #include "resource.h"
31
32
33 INT CommandEcho (LPTSTR cmd, LPTSTR param)
34 {
35 TCHAR szMsg[RC_STRING_MAX_SIZE];
36 INT i = 0;
37
38 #ifdef _DEBUG
39 DebugPrintf (_T("CommandEcho '%s' : '%s'\n"), cmd, param);
40 #endif
41
42 if (!_tcsncmp (param, _T("/?"), 2))
43 {
44 ConOutResPaging(TRUE,STRING_ECHO_HELP4);
45 return 0;
46 }
47
48 if (_tcsicmp (cmd, _T("echo.")) == 0)
49 {
50 if (param[0] == 0)
51 ConOutChar (_T('\n'));
52 else
53 ConOutPuts (param);
54 }
55 else
56 {
57 if (_tcsicmp (param, D_OFF) == 0)
58 bEcho = FALSE;
59 else if (_tcsicmp (param, D_ON) == 0)
60 bEcho = TRUE;
61 else if (*param)
62 {
63 while(i < _tcslen(param))
64 {
65 if(param[i] == _T('^'))
66 {
67 memmove(&param[i],&param[i + 1], _tcslen(&param[i]) * sizeof(TCHAR));
68 //skip past the char being escaped
69 i++;
70 }
71 else
72 i++;
73 }
74 ConOutPuts (param);
75 }
76 else
77 {
78 LoadString(CMD_ModuleHandle, STRING_ECHO_HELP5, szMsg, RC_STRING_MAX_SIZE);
79 ConOutPrintf(szMsg, bEcho ? D_ON : D_OFF);
80 }
81 }
82
83 return 0;
84 }
85
86
87 INT CommandEchos (LPTSTR cmd, LPTSTR param)
88 {
89
90 #ifdef _DEBUG
91 DebugPrintf (_T("CommandEchos '%s' : '%s'\n"), cmd, param);
92 #endif
93
94 if (!_tcsncmp (param, _T("/?"), 2))
95 {
96 ConOutResPuts(STRING_ECHO_HELP1);
97 return 0;
98 }
99
100 if (*param)
101 ConOutPrintf (_T("%s"), param);
102
103 return 0;
104 }
105
106
107 INT CommandEchoerr (LPTSTR cmd, LPTSTR param)
108 {
109
110 #ifdef _DEBUG
111 DebugPrintf (_T("CommandEchoerr '%s' : '%s'\n"), cmd, param);
112 #endif
113
114 if (!_tcsncmp (param, _T("/?"), 2))
115 {
116 ConOutResPuts(STRING_ECHO_HELP2);
117 return 0;
118 }
119
120 if (_tcsicmp (cmd, _T("echoerr.")) == 0)
121 {
122 if (param[0] == 0)
123 ConErrChar (_T('\n'));
124 else
125 ConErrPuts (param);
126 }
127 else if (*param)
128 {
129 ConErrPuts (param);
130 }
131
132 return 0;
133 }
134
135
136 INT CommandEchoserr (LPTSTR cmd, LPTSTR param)
137 {
138
139 #ifdef _DEBUG
140 DebugPrintf (_T("CommandEchoserr '%s' : '%s'\n"), cmd, param);
141 #endif
142
143 if (!_tcsncmp (param, _T("/?"), 2))
144 {
145 ConOutResPuts(STRING_ECHO_HELP3);
146 return 0;
147 }
148
149 if (*param)
150 ConOutPrintf (_T("%s"), param);
151
152 return 0;
153 }
154
155 /* EOF */