PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/cc65-2.13.2/src/ca65/error.c

https://github.com/gilligan/snesdev
C | 219 lines | 96 code | 65 blank | 58 comment | 1 complexity | bcaa0f7761f1f3204a93e618640f9cda MD5 | raw file
  1. /*****************************************************************************/
  2. /* */
  3. /* error.c */
  4. /* */
  5. /* Error handling for the ca65 macroassembler */
  6. /* */
  7. /* */
  8. /* */
  9. /* (C) 1998-2008 Ullrich von Bassewitz */
  10. /* Roemerstrasse 52 */
  11. /* D-70794 Filderstadt */
  12. /* EMail: uz@cc65.org */
  13. /* */
  14. /* */
  15. /* This software is provided 'as-is', without any expressed or implied */
  16. /* warranty. In no event will the authors be held liable for any damages */
  17. /* arising from the use of this software. */
  18. /* */
  19. /* Permission is granted to anyone to use this software for any purpose, */
  20. /* including commercial applications, and to alter it and redistribute it */
  21. /* freely, subject to the following restrictions: */
  22. /* */
  23. /* 1. The origin of this software must not be misrepresented; you must not */
  24. /* claim that you wrote the original software. If you use this software */
  25. /* in a product, an acknowledgment in the product documentation would be */
  26. /* appreciated but is not required. */
  27. /* 2. Altered source versions must be plainly marked as such, and must not */
  28. /* be misrepresented as being the original software. */
  29. /* 3. This notice may not be removed or altered from any source */
  30. /* distribution. */
  31. /* */
  32. /*****************************************************************************/
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <stdarg.h>
  36. /* common */
  37. #include "strbuf.h"
  38. /* ca65 */
  39. #include "error.h"
  40. #include "filetab.h"
  41. #include "nexttok.h"
  42. /*****************************************************************************/
  43. /* Data */
  44. /*****************************************************************************/
  45. /* Warning level */
  46. unsigned WarnLevel = 1;
  47. /* Statistics */
  48. unsigned ErrorCount = 0;
  49. unsigned WarningCount = 0;
  50. /*****************************************************************************/
  51. /* Warnings */
  52. /*****************************************************************************/
  53. void WarningMsg (const FilePos* Pos, unsigned Level, const char* Format, va_list ap)
  54. /* Print warning message. */
  55. {
  56. if (Level <= WarnLevel) {
  57. StrBuf S = STATIC_STRBUF_INITIALIZER;
  58. SB_VPrintf (&S, Format, ap);
  59. SB_Terminate (&S);
  60. fprintf (stderr, "%s(%lu): Warning: %s\n",
  61. SB_GetConstBuf (GetFileName (Pos->Name)),
  62. Pos->Line,
  63. SB_GetConstBuf (&S));
  64. ++WarningCount;
  65. SB_Done (&S);
  66. }
  67. }
  68. void Warning (unsigned Level, const char* Format, ...)
  69. /* Print warning message. */
  70. {
  71. va_list ap;
  72. va_start (ap, Format);
  73. WarningMsg (&CurPos, Level, Format, ap);
  74. va_end (ap);
  75. }
  76. void PWarning (const FilePos* Pos, unsigned Level, const char* Format, ...)
  77. /* Print warning message giving an explicit file and position. */
  78. {
  79. va_list ap;
  80. va_start (ap, Format);
  81. WarningMsg (Pos, Level, Format, ap);
  82. va_end (ap);
  83. }
  84. /*****************************************************************************/
  85. /* Errors */
  86. /*****************************************************************************/
  87. void ErrorMsg (const FilePos* Pos, const char* Format, va_list ap)
  88. /* Print an error message */
  89. {
  90. StrBuf S = STATIC_STRBUF_INITIALIZER;
  91. SB_VPrintf (&S, Format, ap);
  92. SB_Terminate (&S);
  93. fprintf (stderr, "%s(%lu): Error: %s\n",
  94. SB_GetConstBuf (GetFileName (Pos->Name)),
  95. Pos->Line,
  96. SB_GetConstBuf (&S));
  97. ++ErrorCount;
  98. SB_Done (&S);
  99. }
  100. void Error (const char* Format, ...)
  101. /* Print an error message */
  102. {
  103. va_list ap;
  104. va_start (ap, Format);
  105. ErrorMsg (&CurPos, Format, ap);
  106. va_end (ap);
  107. }
  108. void PError (const FilePos* Pos, const char* Format, ...)
  109. /* Print an error message giving an explicit file and position. */
  110. {
  111. va_list ap;
  112. va_start (ap, Format);
  113. ErrorMsg (Pos, Format, ap);
  114. va_end (ap);
  115. }
  116. void ErrorSkip (const char* Format, ...)
  117. /* Print an error message and skip the rest of the line */
  118. {
  119. va_list ap;
  120. va_start (ap, Format);
  121. ErrorMsg (&CurPos, Format, ap);
  122. va_end (ap);
  123. SkipUntilSep ();
  124. }
  125. /*****************************************************************************/
  126. /* Code */
  127. /*****************************************************************************/
  128. void Fatal (const char* Format, ...)
  129. /* Print a message about a fatal error and die */
  130. {
  131. va_list ap;
  132. StrBuf S = STATIC_STRBUF_INITIALIZER;
  133. va_start (ap, Format);
  134. SB_VPrintf (&S, Format, ap);
  135. SB_Terminate (&S);
  136. va_end (ap);
  137. fprintf (stderr, "Fatal error: %s\n", SB_GetConstBuf (&S));
  138. SB_Done (&S);
  139. /* And die... */
  140. exit (EXIT_FAILURE);
  141. }
  142. void Internal (const char* Format, ...)
  143. /* Print a message about an internal assembler error and die. */
  144. {
  145. va_list ap;
  146. StrBuf S = STATIC_STRBUF_INITIALIZER;
  147. va_start (ap, Format);
  148. SB_VPrintf (&S, Format, ap);
  149. SB_Terminate (&S);
  150. va_end (ap);
  151. fprintf (stderr, "Internal assembler error: %s\n", SB_GetConstBuf (&S));
  152. SB_Done (&S);
  153. exit (EXIT_FAILURE);
  154. }