Reactos
at listview 179 lines 3.6 kB view raw
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 25VOID 26ErrorMessage( 27 IN DWORD dwErrorCode, 28 IN PCWSTR szFormat OPTIONAL, 29 ...) 30{ 31 va_list arg_ptr; 32 PWSTR szError; 33 TCHAR szMsg[RC_STRING_MAX_SIZE]; 34 TCHAR szMessage[1024]; 35 36 if (dwErrorCode == ERROR_SUCCESS) 37 return; 38 39 *szMessage = 0; 40 if (szFormat) 41 { 42 va_start(arg_ptr, szFormat); 43 vswprintf(szMessage, szFormat, arg_ptr); 44 va_end(arg_ptr); 45 } 46 47 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, 48 NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 49 (PTSTR)&szError, 0, NULL)) 50 { 51 ConErrPrintf(_T("%s%s%s"), szError, szMessage, (*szMessage ? _T("\n") : _T(""))); 52 if (szError) 53 LocalFree(szError); 54 return; 55 } 56 57 /* Fall back just in case the error is not defined */ 58 LoadString(CMD_ModuleHandle, STRING_CONSOLE_ERROR, szMsg, ARRAYSIZE(szMsg)); 59 if (szFormat) 60 ConErrPrintf(_T("%s -- %s\n"), szMsg, szMessage); 61 else 62 ConErrPrintf(_T("%s\n"), szMsg); 63} 64 65VOID error_parameter_format(WCHAR ch) 66{ 67 ConErrResPrintf(STRING_ERROR_PARAMETERF_ERROR, ch); 68 nErrorLevel = 1; 69} 70 71 72VOID error_invalid_switch(WCHAR ch) 73{ 74 ConErrResPrintf(STRING_ERROR_INVALID_SWITCH, ch); 75 nErrorLevel = 1; 76} 77 78 79VOID error_too_many_parameters(PCWSTR s) 80{ 81 ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS, s); 82 nErrorLevel = 1; 83} 84 85 86VOID error_path_not_found(VOID) 87{ 88 ConErrResPuts(STRING_ERROR_PATH_NOT_FOUND); 89 nErrorLevel = 1; 90} 91 92 93VOID error_file_not_found(VOID) 94{ 95 ConErrResPuts(STRING_ERROR_FILE_NOT_FOUND); 96 nErrorLevel = 1; 97} 98 99 100VOID error_sfile_not_found(PCWSTR s) 101{ 102 TCHAR szMsg[RC_STRING_MAX_SIZE]; 103 104 LoadString(CMD_ModuleHandle, STRING_ERROR_FILE_NOT_FOUND, szMsg, ARRAYSIZE(szMsg)); 105 ConErrPrintf(_T("%s - %s\n"), szMsg, s); 106 nErrorLevel = 1; 107} 108 109 110VOID error_req_param_missing(VOID) 111{ 112 ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING); 113 nErrorLevel = 1; 114} 115 116 117VOID error_invalid_drive(VOID) 118{ 119 ConErrResPuts(STRING_ERROR_INVALID_DRIVE); 120 nErrorLevel = 1; 121} 122 123 124VOID error_bad_command(PCWSTR s) 125{ 126 ConErrResPrintf(STRING_ERROR_BADCOMMAND, s); 127 nErrorLevel = 9009; 128} 129 130 131VOID error_no_pipe(VOID) 132{ 133 ConErrResPuts(STRING_ERROR_CANNOTPIPE); 134 nErrorLevel = 1; 135} 136 137 138VOID error_out_of_memory(VOID) 139{ 140 ConErrResPuts(STRING_ERROR_OUT_OF_MEMORY); 141 nErrorLevel = 1; 142} 143 144VOID error_cant_exec_program(VOID) 145{ 146 /* TODO: Windows uses the custom string "The system cannot execute the specified program" here */ 147 ErrorMessage(ERROR_NO_ASSOCIATION, NULL); 148 nErrorLevel = 1; 149} 150 151 152VOID error_invalid_parameter_format(PCWSTR s) 153{ 154 ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, s); 155 nErrorLevel = 1; 156} 157 158 159VOID error_syntax(PCWSTR s) 160{ 161 WCHAR szMsg[RC_STRING_MAX_SIZE]; 162 163 LoadString(CMD_ModuleHandle, STRING_ERROR_ERROR2, szMsg, ARRAYSIZE(szMsg)); 164 165 if (s) 166 ConErrPrintf(_T("%s - %s\n"), szMsg, s); 167 else 168 ConErrPrintf(_T("%s.\n"), szMsg); 169 170 nErrorLevel = 1; 171} 172 173 174VOID msg_pause(VOID) 175{ 176 ConOutResPuts(STRING_ERROR_D_PAUSEMSG); 177} 178 179/* EOF */