[CMD]: Continue refactoring to lay out the way to using the CONUTILS library in CMD...
[reactos.git] / reactos / base / shell / cmd / error.c
1 /*
2 * ERROR.C - error reporting functions.
3 *
4 *
5 * History:
6 *
7 * 07/12/98 (Rob Lake)
8 * started
9 *
10 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
11 * added config.h include
12 *
13 * 24-Jan-1999 (Eric Kohl)
14 * Redirection safe!
15 *
16 * 02-Feb-1999 (Eric Kohl)
17 * Use FormatMessage() for error reports.
18 *
19 * 28-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
20 * Remove all hardcoded strings in En.rc
21 */
22
23 #include "precomp.h"
24
25
26 VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...)
27 {
28 TCHAR szMsg[RC_STRING_MAX_SIZE];
29 TCHAR szMessage[1024];
30 LPTSTR szError;
31 va_list arg_ptr;
32
33 if (dwErrorCode == ERROR_SUCCESS)
34 return;
35
36 nErrorLevel = 1;
37
38 if (szFormat)
39 {
40 va_start(arg_ptr, szFormat);
41 _vstprintf(szMessage, szFormat, arg_ptr);
42 va_end(arg_ptr);
43 }
44
45 if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
46 NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
47 (LPTSTR)&szError, 0, NULL))
48 {
49 ConErrPrintf(_T("%s %s\n"), szError, szMessage);
50 if (szError)
51 LocalFree (szError);
52 return;
53 }
54
55 /* Fall back just in case the error is not defined */
56 LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, ARRAYSIZE(szMsg));
57 if (szFormat)
58 ConErrPrintf(_T("%s -- %s\n"), szMsg, szMessage);
59 else
60 ConErrPrintf(_T("%s\n"), szMsg);
61 }
62
63 VOID error_parameter_format(TCHAR ch)
64 {
65 ConErrResPrintf(STRING_ERROR_PARAMETERF_ERROR, ch);
66 nErrorLevel = 1;
67 }
68
69
70 VOID error_invalid_switch (TCHAR ch)
71 {
72 ConErrResPrintf(STRING_ERROR_INVALID_SWITCH, ch);
73 nErrorLevel = 1;
74 }
75
76
77 VOID error_too_many_parameters (LPTSTR s)
78 {
79 ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS, s);
80 nErrorLevel = 1;
81 }
82
83
84 VOID error_path_not_found (VOID)
85 {
86 ConErrResPuts(STRING_ERROR_PATH_NOT_FOUND);
87 nErrorLevel = 1;
88 }
89
90
91 VOID error_file_not_found (VOID)
92 {
93 ConErrResPuts(STRING_ERROR_FILE_NOT_FOUND);
94 nErrorLevel = 1;
95 }
96
97
98 VOID error_sfile_not_found (LPTSTR f)
99 {
100 TCHAR szMsg[RC_STRING_MAX_SIZE];
101
102 LoadString(CMD_ModuleHandle, STRING_ERROR_FILE_NOT_FOUND, szMsg, ARRAYSIZE(szMsg));
103 ConErrPrintf(_T("%s - %s\n"), szMsg, f);
104 nErrorLevel = 1;
105 }
106
107
108 VOID error_req_param_missing (VOID)
109 {
110 ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
111 nErrorLevel = 1;
112 }
113
114
115 VOID error_invalid_drive (VOID)
116 {
117 ConErrResPuts(STRING_ERROR_INVALID_DRIVE);
118 nErrorLevel = 1;
119 }
120
121
122 VOID error_bad_command (LPTSTR s)
123 {
124 ConErrResPrintf(STRING_ERROR_BADCOMMAND, s);
125 nErrorLevel = 9009;
126 }
127
128
129 VOID error_no_pipe (VOID)
130 {
131 ConErrResPuts(STRING_ERROR_CANNOTPIPE);
132 nErrorLevel = 1;
133 }
134
135
136 VOID error_out_of_memory (VOID)
137 {
138 ConErrResPuts(STRING_ERROR_OUT_OF_MEMORY);
139 nErrorLevel = 1;
140 }
141
142
143 VOID error_invalid_parameter_format (LPTSTR s)
144 {
145 ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, s);
146 nErrorLevel = 1;
147 }
148
149
150 VOID error_syntax (LPTSTR s)
151 {
152 TCHAR szMsg[RC_STRING_MAX_SIZE];
153
154 LoadString(CMD_ModuleHandle, STRING_ERROR_ERROR2, szMsg, ARRAYSIZE(szMsg));
155
156 if (s)
157 ConErrPrintf(_T("%s - %s\n"), szMsg, s);
158 else
159 ConErrPrintf(_T("%s.\n"), szMsg);
160
161 nErrorLevel = 1;
162 }
163
164
165 VOID msg_pause (VOID)
166 {
167 ConOutResPuts(STRING_ERROR_D_PAUSEMSG);
168 }
169
170 /* EOF */