update for HEAD-2003050101
[reactos.git] / subsys / system / cmd / echo.c
1 /* $Id$
2  *
3  *  ECHO.C - internal echo commands.
4  *
5  *
6  *  History:
7  *
8  *    16 Jul 1998 (Hans B Pufal)
9  *        Started.
10  *
11  *    16 Jul 1998 (John P Price)
12  *        Separated commands into individual files.
13  *
14  *    27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
15  *        Added config.h include
16  *
17  *    08-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
18  *        Added help text ("/?").
19  *
20  *    19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
21  *        Unicode and redirection ready!
22  *
23  *    13-Jul-2000 (Eric Kohl <ekohl@rz-online.de>)
24  *        Implemented 'echo.' and 'echoerr.'.
25  */
26
27 #include "config.h"
28
29 #include <windows.h>
30 #include <tchar.h>
31 #include <string.h>
32
33 #include "cmd.h"
34 #include "batch.h"
35
36
37 INT CommandEcho (LPTSTR cmd, LPTSTR param)
38 {
39 #ifdef _DEBUG
40         DebugPrintf ("CommandEcho '%s' : '%s'\n", cmd, param);
41 #endif
42
43         if (!_tcsncmp (param, _T("/?"), 2))
44         {
45                 ConOutPuts ("Displays a message or switches command echoing on or off.\n"
46                             "\n"
47                             "  ECHO [ON | OFF]\n"
48                             "  ECHO [message]\n"
49                             "  ECHO.             prints an empty line\n"
50                             "\n"
51                             "Type ECHO without a parameter to display the current ECHO setting.");
52                 return 0;
53         }
54
55         if (_tcsicmp (cmd, _T("echo.")) == 0)
56         {
57                 if (param[0] == 0)
58                         ConOutChar (_T('\n'));
59                 else
60                         ConOutPuts (param);
61         }
62         else
63         {
64                 if (_tcsicmp (param, D_OFF) == 0)
65                         bEcho = FALSE;
66                 else if (_tcsicmp (param, D_ON) == 0)
67                         bEcho = TRUE;
68                 else if (*param)
69                         ConOutPuts (param);
70                 else
71                         ConOutPrintf (_T("ECHO is %s\n"), bEcho ? D_ON : D_OFF);
72         }
73
74         return 0;
75 }
76
77 INT CommandEchos (LPTSTR cmd, LPTSTR param)
78 {
79 #ifdef _DEBUG
80         DebugPrintf ("CommandEchos '%s' : '%s'\n", cmd, param);
81 #endif
82
83         if (!_tcsncmp (param, _T("/?"), 2))
84         {
85                 ConOutPuts ("Display a messages without trailing carridge return and line feed.\n"
86                             "\n"
87                             "  ECHOS message");
88                 return 0;
89         }
90
91         if (*param)
92                 ConOutPrintf ("%s", param);
93
94         return 0;
95 }
96
97
98 INT CommandEchoerr (LPTSTR cmd, LPTSTR param)
99 {
100 #ifdef _DEBUG
101         DebugPrintf ("CommandEchoerr '%s' : '%s'\n", cmd, param);
102 #endif
103
104         if (!_tcsncmp (param, _T("/?"), 2))
105         {
106                 ConOutPuts ("Displays a message to the standard error.\n"
107                             "\n"
108                             "  ECHOERR message\n"
109                             "  ECHOERR.           prints an empty line");
110                 return 0;
111         }
112
113         if (_tcsicmp (cmd, _T("echoerr.")) == 0)
114         {
115                 if (param[0] == 0)
116                         ConErrChar (_T('\n'));
117                 else
118                         ConErrPuts (param);
119         }
120         else if (*param)
121         {
122                 ConErrPuts (param);
123         }
124
125         return 0;
126 }
127
128 INT CommandEchoserr (LPTSTR cmd, LPTSTR param)
129 {
130 #ifdef _DEBUG
131         DebugPrintf ("CommandEchoserr '%s' : '%s'\n", cmd, param);
132 #endif
133
134         if (!_tcsncmp (param, _T("/?"), 2))
135         {
136                 ConOutPuts ("Prints a messages to standard error output without trailing carridge return and line feed.\n"
137                             "\n"
138                             "  ECHOSERR message");
139                 return 0;
140         }
141
142         if (*param)
143                 ConOutPrintf (_T("%s"), param);
144
145         return 0;
146 }
147
148 /* EOF */