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