home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / unproto / part01 / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-07  |  1.6 KB  |  79 lines

  1. /*++
  2. /* NAME
  3. /*    error 3
  4. /* SUMMARY
  5. /*    diagnostics
  6. /* PACKAGE
  7. /*    unproto
  8. /* SYNOPSIS
  9. /*    #include "error.h"
  10. /*
  11. /*    void error(quit, text)
  12. /*    int quit;
  13. /*    char *text;
  14. /*
  15. /*    void error_where(quit, path, line, text)
  16. /*    int quit;
  17. /*    char *path;
  18. /*    int line;
  19. /*    char *text;
  20. /* DESCRIPTION
  21. /*    The routines in this file print a diagnostic (text) and optionally
  22. /*    terminate the program (quit != 0) with exit status "quit".
  23. /*
  24. /*    error() provides a default context, i.e. the source-file
  25. /*    coordinate of the last read token.
  26. /*
  27. /*    error_where() allows the caller to explicitly specify context: path
  28. /*    is a source-file name, and line is a line number.
  29. /*
  30. /*    context is ignored if the line number is zero or if the path
  31. /*    is an empty string.
  32. /* AUTHOR(S)
  33. /*    Wietse Venema
  34. /*    Eindhoven University of Technology
  35. /*    Department of Mathematics and Computer Science
  36. /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  37. /* LAST MODIFICATION
  38. /*    91/11/30 21:10:35
  39. /* VERSION/RELEASE
  40. /*    1.1
  41. /*--*/
  42.  
  43. static char error_sccsid[] = "@(#) error.c 1.1 91/11/30 21:10:35";
  44.  
  45. /* C library */
  46.  
  47. #include <stdio.h>
  48.  
  49. void exit();
  50.  
  51. /* Application-specific stuff */
  52.  
  53. #include "token.h"
  54. #include "error.h"
  55.  
  56. /* error - report problem (implicit context) and optionally quit */
  57.  
  58. void    error(quit, text)
  59. int     quit;
  60. char   *text;
  61. {
  62.     error_where(quit, curr_path, curr_line, text);
  63. }
  64.  
  65. /* error_where - report problem (explicit context) and optionally quit */
  66.  
  67. void    error_where(quit, path, line, text)
  68. int     quit;
  69. char   *path;
  70. int     line;
  71. char   *text;
  72. {
  73.     if (line && path[0])
  74.     fprintf(stderr, "%s, line %d: ", path, line);
  75.     fprintf(stderr, "%s\n", text);
  76.     if (quit)
  77.     exit(quit);
  78. }
  79.