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