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