xref: /reactos/base/shell/cmd/echo.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  *  ECHO.C - internal echo commands.
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  *
5*c2c66affSColin Finck  *  History:
6*c2c66affSColin Finck  *
7*c2c66affSColin Finck  *    16 Jul 1998 (Hans B Pufal)
8*c2c66affSColin Finck  *        Started.
9*c2c66affSColin Finck  *
10*c2c66affSColin Finck  *    16 Jul 1998 (John P Price)
11*c2c66affSColin Finck  *        Separated commands into individual files.
12*c2c66affSColin Finck  *
13*c2c66affSColin Finck  *    27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
14*c2c66affSColin Finck  *        Added config.h include
15*c2c66affSColin Finck  *
16*c2c66affSColin Finck  *    08-Dec-1998 (Eric Kohl)
17*c2c66affSColin Finck  *        Added help text ("/?").
18*c2c66affSColin Finck  *
19*c2c66affSColin Finck  *    19-Jan-1999 (Eric Kohl)
20*c2c66affSColin Finck  *        Unicode and redirection ready!
21*c2c66affSColin Finck  *
22*c2c66affSColin Finck  *    13-Jul-2000 (Eric Kohl)
23*c2c66affSColin Finck  *        Implemented 'echo.' and 'echoerr.'.
24*c2c66affSColin Finck  *
25*c2c66affSColin Finck  *    28-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
26*c2c66affSColin Finck  *        Remove all hardcoded strings in En.rc
27*c2c66affSColin Finck  */
28*c2c66affSColin Finck 
29*c2c66affSColin Finck #include "precomp.h"
30*c2c66affSColin Finck 
31*c2c66affSColin Finck BOOL
OnOffCommand(LPTSTR param,LPBOOL flag,INT message)32*c2c66affSColin Finck OnOffCommand(LPTSTR param, LPBOOL flag, INT message)
33*c2c66affSColin Finck {
34*c2c66affSColin Finck     TCHAR *p2;
35*c2c66affSColin Finck     if (_tcsnicmp(param, D_OFF, sizeof(D_OFF)/sizeof(TCHAR) - 1) == 0)
36*c2c66affSColin Finck     {
37*c2c66affSColin Finck         p2 = param + sizeof(D_OFF)/sizeof(TCHAR) - 1;
38*c2c66affSColin Finck         while (_istspace(*p2))
39*c2c66affSColin Finck             p2++;
40*c2c66affSColin Finck         if (*p2 == _T('\0'))
41*c2c66affSColin Finck         {
42*c2c66affSColin Finck             *flag = FALSE;
43*c2c66affSColin Finck             return TRUE;
44*c2c66affSColin Finck         }
45*c2c66affSColin Finck     }
46*c2c66affSColin Finck     else if (_tcsnicmp(param, D_ON, sizeof(D_ON)/sizeof(TCHAR) - 1) == 0)
47*c2c66affSColin Finck     {
48*c2c66affSColin Finck         p2 = param + sizeof(D_ON)/sizeof(TCHAR) - 1;
49*c2c66affSColin Finck         while (_istspace(*p2))
50*c2c66affSColin Finck             p2++;
51*c2c66affSColin Finck         if (*p2 == _T('\0'))
52*c2c66affSColin Finck         {
53*c2c66affSColin Finck             *flag = TRUE;
54*c2c66affSColin Finck             return TRUE;
55*c2c66affSColin Finck         }
56*c2c66affSColin Finck     }
57*c2c66affSColin Finck     else if (*param == _T('\0'))
58*c2c66affSColin Finck     {
59*c2c66affSColin Finck         ConOutResPrintf(message, *flag ? D_ON : D_OFF);
60*c2c66affSColin Finck         return TRUE;
61*c2c66affSColin Finck     }
62*c2c66affSColin Finck     return FALSE;
63*c2c66affSColin Finck }
64*c2c66affSColin Finck 
CommandEcho(LPTSTR param)65*c2c66affSColin Finck INT CommandEcho (LPTSTR param)
66*c2c66affSColin Finck {
67*c2c66affSColin Finck     LPTSTR p1;
68*c2c66affSColin Finck 
69*c2c66affSColin Finck     TRACE ("CommandEcho: '%s'\n", debugstr_aw(param));
70*c2c66affSColin Finck 
71*c2c66affSColin Finck     /* skip all spaces for the check of '/?', 'ON' and 'OFF' */
72*c2c66affSColin Finck     p1 = param;
73*c2c66affSColin Finck     while(_istspace(*p1))
74*c2c66affSColin Finck             p1++;
75*c2c66affSColin Finck 
76*c2c66affSColin Finck     if (!_tcsncmp (p1, _T("/?"), 2))
77*c2c66affSColin Finck     {
78*c2c66affSColin Finck         ConOutResPaging(TRUE,STRING_ECHO_HELP4);
79*c2c66affSColin Finck         return 0;
80*c2c66affSColin Finck     }
81*c2c66affSColin Finck 
82*c2c66affSColin Finck     if (!OnOffCommand(p1, &bEcho, STRING_ECHO_HELP5))
83*c2c66affSColin Finck     {
84*c2c66affSColin Finck         /* skip the first character */
85*c2c66affSColin Finck         ConOutPuts(param + 1);
86*c2c66affSColin Finck         ConOutChar(_T('\n'));
87*c2c66affSColin Finck     }
88*c2c66affSColin Finck     return 0;
89*c2c66affSColin Finck }
90*c2c66affSColin Finck 
CommandEchos(LPTSTR param)91*c2c66affSColin Finck INT CommandEchos (LPTSTR param)
92*c2c66affSColin Finck {
93*c2c66affSColin Finck     TRACE ("CommandEchos: '%s'\n", debugstr_aw(param));
94*c2c66affSColin Finck 
95*c2c66affSColin Finck     if (!_tcsncmp (param, _T("/?"), 2))
96*c2c66affSColin Finck     {
97*c2c66affSColin Finck         ConOutResPuts(STRING_ECHO_HELP1);
98*c2c66affSColin Finck         return 0;
99*c2c66affSColin Finck     }
100*c2c66affSColin Finck 
101*c2c66affSColin Finck     ConOutPrintf (_T("%s"), param);
102*c2c66affSColin Finck     return 0;
103*c2c66affSColin Finck }
104*c2c66affSColin Finck 
105*c2c66affSColin Finck 
CommandEchoerr(LPTSTR param)106*c2c66affSColin Finck INT CommandEchoerr (LPTSTR param)
107*c2c66affSColin Finck {
108*c2c66affSColin Finck     TRACE ("CommandEchoerr: '%s'\n", debugstr_aw(param));
109*c2c66affSColin Finck 
110*c2c66affSColin Finck     if (!_tcsncmp (param, _T("/?"), 2))
111*c2c66affSColin Finck     {
112*c2c66affSColin Finck         ConOutResPuts(STRING_ECHO_HELP2);
113*c2c66affSColin Finck         return 0;
114*c2c66affSColin Finck     }
115*c2c66affSColin Finck 
116*c2c66affSColin Finck     ConErrPuts (param);
117*c2c66affSColin Finck     return 0;
118*c2c66affSColin Finck }
119*c2c66affSColin Finck 
120*c2c66affSColin Finck 
CommandEchoserr(LPTSTR param)121*c2c66affSColin Finck INT CommandEchoserr (LPTSTR param)
122*c2c66affSColin Finck {
123*c2c66affSColin Finck     TRACE ("CommandEchoserr: '%s'\n", debugstr_aw(param));
124*c2c66affSColin Finck 
125*c2c66affSColin Finck     if (!_tcsncmp (param, _T("/?"), 2))
126*c2c66affSColin Finck     {
127*c2c66affSColin Finck         ConOutResPuts(STRING_ECHO_HELP3);
128*c2c66affSColin Finck         return 0;
129*c2c66affSColin Finck     }
130*c2c66affSColin Finck 
131*c2c66affSColin Finck     ConErrPrintf (_T("%s"), param);
132*c2c66affSColin Finck     return 0;
133*c2c66affSColin Finck }
134*c2c66affSColin Finck 
135*c2c66affSColin Finck /* EOF */
136