home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume18 / mcqueer-lib / diagnostic.c next >
Encoding:
C/C++ Source or Header  |  1989-11-09  |  1.9 KB  |  82 lines

  1. #include <stdio.h>
  2.  
  3. /*
  4. ** generic error message routines.  Diag_xxx, may be externally set by caller.
  5. **
  6. ** possible portability problem - use of several "long" arguments to pass
  7. ** stack through to underlying printf() family routine.
  8. */
  9.  
  10. /*
  11. **
  12. **    Copyright (c) 1987, Robert L. McQueer
  13. **        All Rights Reserved
  14. **
  15. ** Permission granted for use, modification and redistribution of this
  16. ** software provided that no use is made for commercial gain without the
  17. ** written consent of the author, that all copyright notices remain intact,
  18. ** and that all changes are clearly documented.  No warranty of any kind
  19. ** concerning any use which may be made of this software is offered or implied.
  20. **
  21. */
  22.  
  23. char *Diag_file = "";        /* filename for use in diagnostic message */
  24. int Diag_line = 1;        /* diagnostic line number */
  25. int Diag_count = 0;        /* diagnostic counter */
  26. FILE *Diag_fp = stderr;        /* output stream for messages */
  27. char *Diag_cmd = "?";        /* command name for fatal() / usage() */
  28.  
  29. static int (*Fatcall)() = NULL;
  30.  
  31. /*
  32. ** print nonfatal diagnostic with line number from an input file.  Format
  33. ** compatible with "context"
  34. */
  35. diagnostic(s,a,b,c,d,e,f)
  36. char *s;
  37. long a,b,c,d,e,f;
  38. {
  39.     fprintf(Diag_fp,"%s line %d: ",Diag_file,Diag_line);
  40.     fprintf(Diag_fp,s,a,b,c,d,e,f);
  41.     fprintf(Diag_fp,"\n");
  42.     ++Diag_count;
  43. }
  44.  
  45. /*
  46. ** print fatal error message and exit.  May call user set cleanup routine first.
  47. ** argument list passed to fatal() will also be passed to cleanup routine.
  48. */
  49. fatal (s,a,b,c,d,e,f)
  50. char *s;
  51. long a,b,c,d,e,f;
  52. {
  53.     fprintf (Diag_fp,"%s: ",Diag_cmd);
  54.     fprintf (Diag_fp,s,a,b,c,d,e,f);
  55.     fprintf (Diag_fp,"\n");
  56.     if (Fatcall != NULL)
  57.         (*Fatcall) (s,a,b,c,d,e,f);
  58.     exit (1);
  59. }
  60.  
  61. /*
  62. ** set cleanup routine for fatal() calls
  63. */
  64. fat_set (fn)
  65. int (*fn) ();
  66. {
  67.     Fatcall = fn;
  68. }
  69.  
  70. /*
  71. ** print usage message and exit.
  72. */
  73. usage (s,a,b,c,d,e,f)
  74. char *s;
  75. long a,b,c,d,e,f;
  76. {
  77.     fprintf (Diag_fp,"usage: %s ",Diag_cmd);
  78.     fprintf (Diag_fp,s,a,b,c,d,e,f);
  79.     fprintf (Diag_fp,"\n");
  80.     exit (1);
  81. }
  82.