error.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. #ifndef NORCSID
  6. static char rcsid[]= "$Id$";
  7. #endif
  8. #if __STDC__
  9. #include <stdarg.h>
  10. #endif
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #if __STDC__
  14. void error(char *fmt, ...);
  15. #else
  16. void error();
  17. #endif
  18. int nerrors=0;
  19. void yyerror(char *s)
  20. {
  21. error("Parser gives %s",s);
  22. }
  23. void goodbye()
  24. {
  25. error("This was fatal, goodbye!");
  26. #ifndef NDEBUG
  27. abort();
  28. #endif
  29. }
  30. #if __STDC__
  31. /*VARARGS1*/
  32. void error(char *fmt, ...)
  33. {
  34. extern int lineno;
  35. extern char *filename;
  36. va_list ap;
  37. fprintf(stderr,"\"%s\", line %d:",filename,lineno);
  38. va_start(ap, fmt);
  39. vfprintf(stderr, fmt, ap);
  40. fprintf(stderr, "\n");
  41. va_end(ap);
  42. nerrors++;
  43. }
  44. /*VARARGS1*/
  45. void fatal(char *fmt, ...)
  46. {
  47. extern int lineno;
  48. extern char *filename;
  49. va_list ap;
  50. fprintf(stderr,"\"%s\", line %d:",filename,lineno);
  51. va_start(ap, fmt);
  52. vfprintf(stderr, fmt, ap);
  53. fprintf(stderr, "\n");
  54. va_end(ap);
  55. nerrors++;
  56. errorexit();
  57. goodbye();
  58. exit(-1);
  59. }
  60. #else /* __STDC__ */
  61. /*VARARGS1*/
  62. fatal(s,a,b,c,d) char *s; {
  63. error(s,a,b,c,d);
  64. errorexit();
  65. goodbye();
  66. exit(-1);
  67. }
  68. /*VARARGS1*/
  69. error(s,a,b,c,d) char *s; {
  70. extern int lineno;
  71. extern char *filename;
  72. fprintf(stderr,"\"%s\", line %d:",filename,lineno);
  73. fprintf(stderr,s,a,b,c,d);
  74. fprintf(stderr,"\n");
  75. nerrors++;
  76. }
  77. #endif
  78. #ifndef NDEBUG
  79. void badassertion(char *string, char *file, int line)
  80. {
  81. fprintf(stderr,"\"%s\", line %d: Assertion failed \"%s\"\n",
  82. file,line,string);
  83. goodbye();
  84. }
  85. #endif
  86. void tabovf(char *string)
  87. {
  88. fatal("%s overflow", string);
  89. }