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.

210 lines
5.7 KiB

  1. // ERROR.C -- error handling functions
  2. //
  3. // Copyright (c) 1988-1990, Microsoft Corporation. All rights reserved.
  4. //
  5. // Revision History:
  6. // 23-Feb-1994 HV Change Copyright years to 1988-94
  7. // 01-Feb-1994 HV Move messages to external file.
  8. // 29-Oct-1993 HV Change the version scheme.
  9. // 15-Oct-1993 HV Use tchar.h instead of mbstring.h directly, change STR*() to _ftcs*()
  10. // 18-May-1993 HV Change reference to messageTable[] to __MSGTAB. The new
  11. // (and more standard) mkmsg.exe output __MSGTAB instead
  12. // of messageTable. See message.h
  13. // 10-May-1993 HV Add include file mbstring.h
  14. // Change the str* functions to STR*
  15. // 08-Jun-1992 SS add IDE feedback support
  16. // 08-Jun-1992 SS Port to DOSX32
  17. // 23-Feb-1990 SB Version No correctly displayed
  18. // 31-Jan-1990 SB Debug version changes
  19. // 05-Jan-1990 SB Rev no in std format; #ifdef LEADING_ZERO for old code
  20. // 07-Dec-1989 SB Changed CopyRight Years to 1988-90; Add #ifdef DEBUG_HEAP
  21. // 06-Nov-1989 SB Error messages now show NMAKE and not argv0
  22. // 04-Sep-1989 SB heapdump() has two extra parameters
  23. // 18-Aug-1989 SB For -z nothing done by makeMessage; Fix later
  24. // 05-Jul-1989 SB localize rest of the messages in makeError()
  25. // 14-Jun-1989 SB modified to localize all messages and auto update version no
  26. // 05-Jun-1989 SB modified heapdump(), has a previous member in the list too
  27. // 14-Apr-1989 SB modified heapdump() for better error messages when DEBUG
  28. // 05-Apr-1989 SB made functions NEAR; all funcs to one code segment
  29. // modified heapdump() to give better heap violations
  30. // 22-Mar-1989 SB del call to unlinkTmpFiles() ;add call to delScriptFiles().
  31. // 17-Mar-1989 SB heapdump() has an additional check built-in
  32. // 10-Mar-1989 SB Changed makeMessage() for -z to get echo CMD's into PWB.SHL
  33. // 16-Feb-1989 SB changed makeError() and makeMessage() to handle -help
  34. // 09-Jan-1989 SB changes in makeError() to handle -help correctly
  35. // 05-Dec-1988 SB Added CDECL for makeError(), makeMessage(); Pascal calling
  36. // #ifdef'd heapdump prototype
  37. // 20-Oct-1988 SB Changed some eoln comments to be in the same column
  38. // 12-Oct-1988 SB Made GetFarMsg() to be Model independent & efficient
  39. // 17-Aug-1988 RB Clean up.
  40. // 24-Jun-1988 rj Added doError flag to unlinkTmpFiles call.
  41. #include "precomp.h"
  42. #pragma hdrstop
  43. #include "verstamp.h"
  44. #define FATAL 1 // error levels for
  45. #define ERROR 2 // systems lanuguages
  46. #define RESERVED 3 // products
  47. #define WARNING 4
  48. #define CopyRightYrs "1988-2000"
  49. #define NmakeStr "NMAKE"
  50. void __cdecl
  51. makeError (
  52. unsigned lineNumber,
  53. unsigned msg,
  54. ...)
  55. {
  56. unsigned exitCode = 2; // general program err
  57. unsigned level;
  58. va_list args; // More arguments
  59. va_start(args, msg); // Point 'args' at first extra arg
  60. if (ON(gFlags,F1_CRYPTIC_OUTPUT) && (msg / 1000) == WARNING) {
  61. return;
  62. }
  63. displayBanner();
  64. if (lineNumber) {
  65. fprintf(stderr, "%s(%u) : ", fName, lineNumber);
  66. } else {
  67. fprintf(stderr, "%s : ", NmakeStr);
  68. }
  69. switch (level = msg / 1000) {
  70. case FATAL:
  71. makeMessage(FATAL_ERROR_MESSAGE);
  72. if (msg == OUT_OF_MEMORY) {
  73. exitCode = 4;
  74. }
  75. break;
  76. case ERROR:
  77. makeMessage(ERROR_MESSAGE);
  78. break;
  79. case WARNING:
  80. makeMessage(WARNING_MESSAGE);
  81. break;
  82. }
  83. fprintf(stderr, " U%04d: ",msg); // U for utilities
  84. vfprintf(stderr, get_err(msg), args);
  85. putc('\n', stderr);
  86. fflush(stderr);
  87. if (level == FATAL) {
  88. fprintf(stderr, "Stop.\n");
  89. delScriptFiles();
  90. #if !defined(NDEBUG)
  91. printStats();
  92. #endif
  93. exit(exitCode);
  94. }
  95. }
  96. void __cdecl
  97. makeMessage(
  98. unsigned msg,
  99. ...)
  100. {
  101. va_list args;
  102. FILE *stream = stdout;
  103. va_start(args, msg);
  104. if (msg != USER_MESSAGE && ON(gFlags, F1_CRYPTIC_OUTPUT)) {
  105. return;
  106. }
  107. displayBanner();
  108. if (msg >= FATAL_ERROR_MESSAGE && msg <= COPYRIGHT_MESSAGE_2) {
  109. stream = stderr;
  110. }
  111. if (msg == COPYRIGHT_MESSAGE_1) {
  112. putc('\n', stream);
  113. }
  114. vfprintf(stream, get_err(msg), args);
  115. if ((msg < COMMANDS_MESSAGE || msg > STOP_MESSAGE) && msg != MESG_LAST) {
  116. putc('\n', stream);
  117. }
  118. fflush(stream);
  119. }
  120. // displayBanner - display SignOn Banner
  121. //
  122. // Scope: Global
  123. //
  124. // Purpose: Displays SignOn Banner (Version & Copyright Message)
  125. //
  126. // Assumes: If rup is 0 then build version is to be suppressed
  127. //
  128. // Modifies Globals:
  129. // bannerDisplayed -- Set to TRUE
  130. //
  131. // Notes:
  132. // 1> Display Banner to stderr for compatibility with Microsoft C Compiler.
  133. // 2> rmj, rmm, rup are set by SLM as #define's in VERSION.H
  134. // 3> szCopyrightYrs is a macro set in this file
  135. void
  136. displayBanner()
  137. {
  138. if (bannerDisplayed) {
  139. return;
  140. }
  141. bannerDisplayed = TRUE;
  142. makeMessage(COPYRIGHT_MESSAGE_1, VER_PRODUCTVERSION_STR);
  143. makeMessage(COPYRIGHT_MESSAGE_2, CopyRightYrs);
  144. fflush(stderr);
  145. }
  146. // usage - prints the usage message
  147. //
  148. // Scope: Extern
  149. //
  150. // Purpose: Prints a usage message
  151. //
  152. // Output: to screen
  153. //
  154. // Assumes: The usage messages are in order between MESG_FIRST and MESG_LAST in the
  155. // messages file.
  156. void
  157. usage(void)
  158. {
  159. unsigned mesg;
  160. for (mesg = MESG_FIRST; mesg < MESG_A; ++mesg) {
  161. makeMessage(mesg, "NMAKE");
  162. }
  163. for (mesg = MESG_A; mesg <= MESG_LAST; mesg++) {
  164. if (mesg == MESG_M) {
  165. mesg++;
  166. }
  167. if (mesg == MESG_V) {
  168. mesg++;
  169. }
  170. makeMessage(mesg);
  171. }
  172. }