error.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 lint
  6. static char rcsid[] = "$Id$";
  7. #endif
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <out.h>
  11. #include "const.h"
  12. static short nerrors = 0;
  13. static diag();
  14. stop()
  15. {
  16. extern char *outputname;
  17. extern int exitstatus;
  18. if (nerrors) {
  19. unlink(outputname);
  20. exit(nerrors);
  21. }
  22. exit(exitstatus);
  23. }
  24. /* VARARGS1 */
  25. fatal(format, a1, a2, a3, a4)
  26. char *format;
  27. {
  28. nerrors++;
  29. diag("fatal", format, a1, a2, a3, a4);
  30. stop();
  31. }
  32. /* VARARGS1 */
  33. warning(format, a1, a2, a3, a4)
  34. char *format;
  35. {
  36. diag("warning", format, a1, a2, a3, a4);
  37. }
  38. /* VARARGS1 */
  39. error(format, a1, a2, a3, a4)
  40. char *format;
  41. {
  42. nerrors++;
  43. diag("error", format, a1, a2, a3, a4);
  44. }
  45. /* VARARGS1 */
  46. do_verbose(format, a1, a2, a3, a4)
  47. char *format;
  48. {
  49. diag((char *) 0, format, a1, a2, a3, a4);
  50. }
  51. static
  52. diag(tail, format, a1, a2, a3, a4)
  53. char *tail;
  54. char *format;
  55. {
  56. extern char *progname, *archname, *modulname;
  57. fprintf(stderr, "%s: ", progname);
  58. if (archname && modulname)
  59. fprintf(stderr, "%s(%.14s): ", archname, modulname);
  60. else if (archname)
  61. fprintf(stderr, "%s: ", archname);
  62. else if (modulname)
  63. fprintf(stderr, "%s: ", modulname);
  64. fprintf(stderr, format, a1, a2, a3, a4);
  65. if (tail) fprintf(stderr, " (%s)\n", tail);
  66. else putc('\n', stderr);
  67. }