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