Source code of Windows XP (NT5)
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.

140 lines
4.0 KiB

  1. /************************************************************************/
  2. /* */
  3. /* RCPP - Resource Compiler Pre-Processor for NT system */
  4. /* */
  5. /* ERROR.C - Error Handler Routines */
  6. /* */
  7. /* 04-Dec-90 w-BrianM Update for NT from PM SDK RCPP */
  8. /* */
  9. /************************************************************************/
  10. #include "rc.h"
  11. #include "rcmsgs.h"
  12. /* defines for message types */
  13. #define W_MSG 4000
  14. #define E_MSG 2000
  15. #define F_MSG 1000
  16. static CHAR Errbuff[128] = {0};
  17. /************************************************************************/
  18. /* Local Function Prototypes */
  19. /************************************************************************/
  20. void message (int, int, PCHAR);
  21. /************************************************************************/
  22. /* ERROR - Print an error message to STDOUT. */
  23. /************************************************************************/
  24. #define MAX_ERRORS 100
  25. void
  26. error (
  27. int msgnum
  28. )
  29. {
  30. message(E_MSG, msgnum, Msg_Text);
  31. if (++Nerrors > MAX_ERRORS) {
  32. Msg_Temp = GET_MSG (1003);
  33. SET_MSG (Msg_Text, sizeof(Msg_Text), Msg_Temp, MAX_ERRORS);
  34. fatal(1003); /* die - too many errors */
  35. }
  36. return;
  37. }
  38. /************************************************************************/
  39. /* FATAL - Print an error message to STDOUT and exit. */
  40. /************************************************************************/
  41. void
  42. fatal (
  43. int msgnum
  44. )
  45. {
  46. message(F_MSG, msgnum, Msg_Text);
  47. quit(NULL);
  48. }
  49. /************************************************************************/
  50. /* WARNING - Print an error message to STDOUT. */
  51. /************************************************************************/
  52. void
  53. warning (
  54. int msgnum
  55. )
  56. {
  57. message(W_MSG, msgnum, Msg_Text);
  58. }
  59. /************************************************************************/
  60. /* MESSAGE - format and print the message to STDERR. */
  61. /* The msg goes out in the form : */
  62. /* <file>(<line>) : <msgtype> <errnum> <expanded msg> */
  63. /************************************************************************/
  64. void
  65. message(
  66. int msgtype,
  67. int msgnum,
  68. PCHAR msg
  69. )
  70. {
  71. static CHAR mbuff[512];
  72. static CHAR mbuffT[512];
  73. PCHAR p = mbuff;
  74. PCHAR pT;
  75. PCHAR msgname;
  76. CHAR msgnumstr[32];
  77. if (Linenumber > 0 && Filename) {
  78. wsprintfA(p, "%ws(%d) : ", Filename, Linenumber);
  79. p += strlen(p);
  80. }
  81. if (msgtype) {
  82. switch (msgtype) {
  83. case W_MSG:
  84. msgname = GET_MSG(MSG_WARN);
  85. break;
  86. case E_MSG:
  87. msgname = GET_MSG(MSG_ERROR);
  88. break;
  89. case F_MSG:
  90. msgname = GET_MSG(MSG_FATAL);
  91. break;
  92. }
  93. /* remove CR and LF from message */
  94. for (pT = msgname ; *pT && *pT != '\n' && *pT != '\r' ; pT++)
  95. ;
  96. *pT = '\0';
  97. strcpy(p, msgname);
  98. p += strlen(msgname);
  99. wsprintfA(msgnumstr, " %s%d: ", "RC", msgnum);
  100. strcpy(p, msgnumstr);
  101. p += strlen(msgnumstr);
  102. strcpy(p, msg);
  103. p += strlen(p);
  104. }
  105. p = mbuff;
  106. pT = mbuffT;
  107. while (*p) {
  108. if (*p == '\\' && p[1] == '\\')
  109. p++;
  110. *pT++ = *p++;
  111. }
  112. *pT = '\0';
  113. p = mbuffT; // error message to print
  114. if (lpfnMessageCallback)
  115. (*lpfnMessageCallback)(0, 0, mbuff);
  116. if (hWndCaller) {
  117. if (SendMessageA(hWndCaller, WM_RC_ERROR, TRUE, (LPARAM) mbuff) != 0)
  118. quit("\n");
  119. }
  120. return;
  121. }