error.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * GTools C compiler
  3. * =================
  4. * source file :
  5. * error handling
  6. *
  7. * Copyright 2001-2004 Paul Froissart.
  8. * Credits to Christoph van Wuellen and Matthew Brandt.
  9. * All commercial rights reserved.
  10. *
  11. * This compiler may be redistributed as long there is no
  12. * commercial interest. The compiler must not be redistributed
  13. * without its full sources. This notice must stay intact.
  14. */
  15. /*#include "define.h"
  16. #include "c.h"
  17. #include "cglbdec.h"*/
  18. #include <stdarg.h>
  19. #include <setjmp.h>
  20. extern int pause_on_error;
  21. #ifndef GTDEV
  22. //#ifdef PC
  23. void _err_attr err_int(int m) {
  24. clean_up();
  25. msg2("\nAn internal error occurred (error ID #%04d)\n"
  26. "Please report this bug to paul.froissart@libertysurf.fr\n",m);
  27. #ifdef PC
  28. fflush(outstr);
  29. if (pause_on_error)
  30. getchar();
  31. exit(16);
  32. #else
  33. ngetchx();
  34. exit(0);
  35. #endif
  36. }
  37. void err_usr(int m,...) {
  38. va_list args;
  39. va_start(args,m);
  40. #ifdef PC
  41. if (verbose)
  42. #endif
  43. msg("\nCompilation error:\n");
  44. if (err_force_line IS_INVALID && err_assembly)
  45. err_force_line=err_cur_line;
  46. locate();
  47. if (m==ERR_OTH) {
  48. char *s=va_arg(args,char *);
  49. vmsg(s,args);
  50. } else
  51. vmsg((char *)__err[m],args);
  52. msg("\n");
  53. va_end(args);
  54. clean_up();
  55. #ifdef PC
  56. fflush(outstr);
  57. if (pause_on_error)
  58. getchar();
  59. exit(16);
  60. #else
  61. ngetchx();
  62. exit(0);
  63. #endif
  64. }
  65. void _err_attr warn_int(int m) {
  66. msg2("\nAn unexpected event occurred (event ID #%04d)\n"
  67. "It might be possible to continue, but the generated code may "
  68. "contain bugs.\nDo you want to continue [y/n]?",m);
  69. #ifdef PC
  70. fflush(outstr);
  71. if ((pause_on_error && (msg("\nn\n"),1)) || getchar()=='n') {
  72. clean_up();
  73. exit(16);
  74. }
  75. msg("\n");
  76. #else
  77. while (!kbhit());
  78. if (ngetchx()=='n') {
  79. clean_up();
  80. exit(0);
  81. } else msg("\n");
  82. #endif
  83. }
  84. void warn_usr(char *s,...) {
  85. va_list args;
  86. va_start(args,s);
  87. locate();
  88. msg("warning: ");
  89. vmsg(s,args);
  90. msg("\n");
  91. va_end(args);
  92. }
  93. //#endif
  94. #else
  95. void _err_attr error_do(char *msg,int type) {
  96. char _func[100],file[40];
  97. char *func=0;
  98. int line,chr=0;
  99. if (func_sp) strcpy(func=_func,func_sp->name);
  100. strcpy(file,curname);
  101. if (err_force_line IS_INVALID && err_assembly)
  102. err_force_line=err_cur_line;
  103. if (err_force_line IS_VALID)
  104. line=err_force_line;
  105. else line=lineno,chr=0/*to be improved*/;
  106. if (et_iserror(type))
  107. clean_up();
  108. msg_process(msg,type,func,file,line,chr);
  109. if (et_iserror(type))
  110. exit(0);
  111. }
  112. void _noreturn assert_terminated();
  113. asm("assert_terminated:\n rts\n");
  114. void _err_attr err_int(int m) {
  115. char b[30];
  116. sprintf(b,"error ID #%04d",m);
  117. error_do(b,ET_INTERNAL_FAILURE);
  118. assert_terminated();
  119. }
  120. void err_usr(int m,...) {
  121. va_list args;
  122. va_start(args,m);
  123. char b[200];
  124. if (m==ERR_OTH) {
  125. char *s=va_arg(args,char *);
  126. vsprintf(b,s,args);
  127. } else
  128. vsprintf(b,(char *)__err[m],args);
  129. va_end(args);
  130. error_do(b,ET_ERROR);
  131. assert_terminated();
  132. }
  133. void _err_attr warn_int(int m) {
  134. char b[30];
  135. sprintf(b,"event ID #%04d",m);
  136. error_do(b,ET_INTERNAL_WARNING);
  137. }
  138. void warn_usr(char *s,...) {
  139. va_list args;
  140. va_start(args,s);
  141. char b[200];
  142. vsprintf(b,s,args);
  143. va_end(args);
  144. error_do(b,ET_WARNING);
  145. }
  146. #endif
  147. // vim:ts=4:sw=4