Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
7.0 KiB

  1. /*****************************************************************************
  2. * Copyright (c) 1993-1999 Microsoft Corporation
  3. *
  4. * RPC compiler: error handler
  5. *
  6. * Author : Vibhas Chandorkar
  7. * Created : 22nd Aug 1990
  8. *
  9. ****************************************************************************/
  10. #pragma warning ( disable : 4514 ) // Unreferenced inline function
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "nulldefs.h"
  15. extern "C"
  16. {
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. }
  21. #include "common.hxx"
  22. #include "errors.hxx"
  23. #include "cmdana.hxx"
  24. #include "control.hxx"
  25. #include "pragma.hxx"
  26. extern CMessageNumberList GlobalMainMessageNumberList;
  27. #define ERROR_PREFIX "MIDL"
  28. /****************************************************************************
  29. * local definitions and macros
  30. ***************************************************************************/
  31. #include "errdb.h"
  32. const ERRDB UnknownError =
  33. {
  34. 0, CHECK_ERR(I_ERR_UNKNOWN_ERROR)
  35. MAKE_E_MASK(ERR_ALWAYS, C_MSG, CLASS_ERROR, NOWARN )
  36. ,"unknown internal error"
  37. };
  38. extern CMD_ARG * pCommand;
  39. /*** IsErrorRelevant ******************************************************
  40. * Purpose : To decide whether the error is going to be ignored anyhow, and
  41. * : cut out further processing
  42. * Input : error value
  43. * Output : nothing
  44. * Notes : The error number itself is an indicator of the location of
  45. * : the error, (user/compile-time,run-time) , and severity.
  46. ****************************************************************************/
  47. ErrorInfo::ErrorInfo( STATUS_T ErrValue )
  48. {
  49. ErrVal = ErrValue;
  50. // cast away the constness
  51. pErrorRecord = (ERRDB *) ErrorDataBase;
  52. if( ErrVal < D_ERR_MAX )
  53. {
  54. pErrorRecord += ( ErrVal - D_ERR_START ) + INDEX_D_ERROR();
  55. }
  56. else if( ErrVal < C_ERR_MAX )
  57. {
  58. pErrorRecord += ( ErrVal - C_ERR_START ) + INDEX_C_ERROR();
  59. }
  60. else if( ErrVal < A_ERR_MAX )
  61. {
  62. pErrorRecord += ( ErrVal - A_ERR_START ) + INDEX_A_ERROR();
  63. }
  64. else
  65. {
  66. pErrorRecord = NULL;
  67. }
  68. }
  69. int
  70. ErrorInfo::IsRelevant()
  71. {
  72. unsigned short ErrorClass = GET_ECLASS( pErrorRecord->ErrMask );
  73. unsigned short ErrorWL = GET_WL( pErrorRecord->ErrMask );
  74. unsigned short ModeSwitchConfigI = pCommand->GetModeSwitchConfigMask();
  75. unsigned short CurWL = pCommand->GetWarningLevel();
  76. if ( pCommand->GetEnv() & pErrorRecord->inApplicableEnviron )
  77. {
  78. return FALSE;
  79. }
  80. // if this is not relevant to this mode, return FALSE
  81. if( GET_SC(pErrorRecord->ErrMask) & ModeSwitchConfigI )
  82. return FALSE;
  83. // does this qualify to be a warning in this mode ? If not return.
  84. if ( ErrorClass == CLASS_WARN )
  85. {
  86. if( CurWL < ErrorWL )
  87. return FALSE;
  88. if ( !GlobalMainMessageNumberList.GetMessageFlag( ErrVal ) )
  89. return FALSE;
  90. }
  91. return TRUE;
  92. }
  93. /*** RpcError ***************************************************************
  94. * Purpose : To report an error in a formatted fashion
  95. * Input : filename where the error occured, line number, error value
  96. * : error mesage suffix string if any
  97. * : input filename ptr could be NULL if no filename
  98. * : suffix string ptr could be null if no suffix string
  99. * Output : nothing
  100. * Notes : The error number itself is an indicator of the location of
  101. * : the error, (user/compile-time,run-time) , and severity.
  102. * : Filename and line number depend upon where the error occurs. If
  103. * : the error is a user-error(command line), file and line number
  104. * : does not make sense. The input can be a NULL for filename, and
  105. * : 0 for line number in case of the command line errors
  106. ****************************************************************************/
  107. void
  108. RpcError(
  109. char * pFile, // filename where error occured
  110. short Line, // line number
  111. STATUS_T ErrVal, // error value
  112. char * pSuffix) // error message suffix string
  113. {
  114. ErrorInfo ErrDescription( ErrVal );
  115. // does this qualify to be an error in this mode ? If not return.
  116. if ( !ErrDescription.IsRelevant() )
  117. return;
  118. // report the error
  119. ErrDescription.ReportError( pFile, Line, pSuffix );
  120. }
  121. /*** RpcReportError ***************************************************************
  122. * Purpose : To report an error in a formatted fashion
  123. * Input : filename where the error occured, line number, error value
  124. * : error mesage suffix string if any
  125. * : input filename ptr could be NULL if no filename
  126. * : suffix string ptr could be null if no suffix string
  127. * Output : nothing
  128. * Notes : The error number itself is an indicator of the location of
  129. * : the error, (user/compile-time,run-time) , and severity.
  130. * : Filename and line number depend upon where the error occurs. If
  131. * : the error is a user-error(command line), file and line number
  132. * : does not make sense. The input can be a NULL for filename, and
  133. * : 0 for line number in case of the command line errors
  134. ****************************************************************************/
  135. void
  136. ErrorInfo::ReportError(
  137. char * pFile, // filename where error occured
  138. short Line, // line number
  139. char * pSuffix) // error message suffix string
  140. {
  141. char * pSeverity = "error";
  142. char * pPrefix;
  143. unsigned short ErrorClass = GET_ECLASS( pErrorRecord->ErrMask );
  144. if (!pErrorRecord)
  145. {
  146. fprintf( stdout
  147. , "%s %c%.4d\n"
  148. , "internal error"
  149. , 'I'
  150. , ErrVal
  151. );
  152. return;
  153. }
  154. switch( ErrorClass )
  155. {
  156. case CLASS_WARN:
  157. // check if all warnings emitted are to be treated as error
  158. if( !pCommand->IsSwitchDefined( SWITCH_WX ) )
  159. {
  160. pSeverity = "warning";
  161. }
  162. else
  163. {
  164. // treat as error.
  165. ErrorClass = CLASS_ERROR;
  166. }
  167. break;
  168. case CLASS_ADVICE:
  169. // we report these as warnings, because we want tools like VC++ to understand
  170. // our error messages for "jump to line" actions.
  171. pSeverity = "warning";
  172. break;
  173. case CLASS_ERROR:
  174. default:
  175. break;
  176. }
  177. // now report the error
  178. if ( !pSuffix )
  179. pSuffix = "";
  180. // mark command line errors specially
  181. if( GET_MT(pErrorRecord->ErrMask) == 'D' )
  182. pPrefix = "command line ";
  183. else
  184. pPrefix = "";
  185. // if it a warning , dont increment error count
  186. if( ErrorClass == CLASS_ERROR )
  187. IncrementErrorCount();
  188. // Print the file and line number ...
  189. // If no file, print something anyway - this is required for automatic
  190. // build tools to be able to parse and log error lines correctly.
  191. if( pFile )
  192. {
  193. if ( Line )
  194. fprintf( stdout, "%s(%d) : ", pFile, Line );
  195. else
  196. fprintf( stdout, "%s : ", pFile );
  197. }
  198. else
  199. fprintf( stdout, "midl : " );
  200. // print the error message
  201. fprintf( stdout
  202. , "%s%s " ERROR_PREFIX "%.4d : %s %s\n"
  203. , pPrefix
  204. , pSeverity
  205. , ErrVal
  206. , pErrorRecord->pError
  207. , pSuffix );
  208. }