[BOOTDATA]
[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 if (szFormat)
57 ConErrPrintf(_T("%s -- %s\n"), szMsg, szMessage);
58 else
59 ConErrPrintf(_T("%s\n"), szMsg);
60 }
61
62 VOID error_parameter_format(TCHAR ch)
63 {
64 ConErrResPrintf(STRING_ERROR_PARAMETERF_ERROR, ch);
65 nErrorLevel = 1;
66 }
67
68
69 VOID error_invalid_switch (TCHAR ch)
70 {
71 ConErrResPrintf(STRING_ERROR_INVALID_SWITCH, ch);
72 nErrorLevel = 1;
73 }
74
75
76 VOID error_too_many_parameters (LPTSTR s)
77 {
78 ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS, s);
79 nErrorLevel = 1;
80 }
81
82
83 VOID error_path_not_found (VOID)
84 {
85 ConErrResPuts(STRING_ERROR_PATH_NOT_FOUND);
86 nErrorLevel = 1;
87 }
88
89
90 VOID error_file_not_found (VOID)
91 {
92 ConErrResPuts(STRING_ERROR_FILE_NOT_FOUND);
93 nErrorLevel = 1;
94 }
95
96
97 VOID error_sfile_not_found (LPTSTR f)
98 {
99 TCHAR szMsg[RC_STRING_MAX_SIZE];
100
101 LoadString(CMD_ModuleHandle, STRING_ERROR_FILE_NOT_FOUND, szMsg, ARRAYSIZE(szMsg));
102 ConErrPrintf(_T("%s - %s\n"), szMsg, f);
103 nErrorLevel = 1;
104 }
105
106
107 VOID error_req_param_missing (VOID)
108 {
109 ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
110 nErrorLevel = 1;
111 }
112
113
114 VOID error_invalid_drive (VOID)
115 {
116 ConErrResPuts(STRING_ERROR_INVALID_DRIVE);
117 nErrorLevel = 1;
118 }
119
120
121 VOID error_bad_command (LPTSTR s)
122 {
123 ConErrResPrintf(STRING_ERROR_BADCOMMAND, s);
124 nErrorLevel = 9009;
125 }
126
127
128 VOID error_no_pipe (VOID)
129 {
130 ConErrResPuts(STRING_ERROR_CANNOTPIPE);
131 nErrorLevel = 1;
132 }
133
134
135 VOID error_out_of_memory (VOID)
136 {
137 ConErrResPuts(STRING_ERROR_OUT_OF_MEMORY);
138 nErrorLevel = 1;
139 }
140
141
142 VOID error_invalid_parameter_format (LPTSTR s)
143 {
144 ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, s);
145 nErrorLevel = 1;
146 }
147
148
149 VOID error_syntax (LPTSTR s)
150 {
151 TCHAR szMsg[RC_STRING_MAX_SIZE];
152
153 LoadString(CMD_ModuleHandle, STRING_ERROR_ERROR2, szMsg, ARRAYSIZE(szMsg));
154
155 if (s)
156 ConErrPrintf(_T("%s - %s\n"), szMsg, s);
157 else
158 ConErrPrintf(_T("%s.\n"), szMsg);
159
160 nErrorLevel = 1;
161 }
162
163
164 VOID msg_pause (VOID)
165 {
166 ConOutResPuts(STRING_ERROR_D_PAUSEMSG);
167 }
168
169 /* EOF */