home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume10 / parseargs / syserr.c < prev    next >
C/C++ Source or Header  |  1990-02-16  |  2KB  |  128 lines

  1. #include <useful.h>
  2. #include <funclist.h>
  3.  
  4. VERSIONID("$Header: syserr.c,v 2.0 89/12/24 00:56:31 eric Exp $");
  5.  
  6. /*
  7. **  SYSERR -- indicate a system error
  8. **
  9. **    Parameters:
  10. **        m -- the printf() message to print.
  11. **        a, b, c, d, e -- parameters to the message
  12. **
  13. **    Returns:
  14. **        never
  15. **
  16. **    Side Effects:
  17. **        Terminates the process if no acceptable recover takes place.
  18. **
  19. **    Globals:
  20. **        SyserrFuncs -- a list of functions to call.
  21. **
  22. **    Author:
  23. **        Eric Allman
  24. **        University of California, Berkeley
  25. */
  26.  
  27. #ifdef FUNCLISTSTUFF
  28. FUNCLIST    *SyserrFuncs =        FUNCLISTNULL;
  29. #endif
  30.  
  31. VOID
  32. syserr(m, a, b, c, d, e)
  33.     char *m;
  34. {
  35.     static BOOL exiting = FALSE;
  36.  
  37.     /* print the error message */
  38.     _error_message(m, a, b, c, d, e);
  39.  
  40.     /* if we recursively syserr during exit, drop out now! */
  41.     if (exiting)
  42.         _exit(1);
  43.  
  44. #ifdef FUNCLISTSTUFF
  45.     /* call any possible cleanup functions */
  46.     funclist_call(SyserrFuncs, ARBNULL);
  47. #endif
  48.  
  49.     /* try a clean exit */
  50.     exiting = TRUE;
  51.     exit(1);
  52.     /*NOTREACHED*/
  53. }
  54. /*
  55. **  USRERR -- print a user error
  56. **
  57. **    Parameters:
  58. **        m -- the printf() message to print.
  59. **        a, b, c, d, e -- parameters to the message
  60. **
  61. **    Returns:
  62. **        none.
  63. **
  64. **    Side Effects:
  65. **        clears the global error number.
  66. */
  67.  
  68. #ifdef FUNCLISTSTUFF
  69. FUNCLIST    *UsrerrFuncs =        FUNCLISTNULL;
  70. #endif
  71.  
  72. VOID
  73. usrerr(m, a, b, c, d, e)
  74.     char *m;
  75. {
  76.     extern int errno;
  77.  
  78.     /* print the error message */
  79.     _error_message(m, a, b, c, d, e);
  80.  
  81. #ifdef FUNCLISTSTUFF
  82.     /* allow cleanup actions */
  83.     funclist_call(UsrerrFuncs, ARBNULL);
  84. #endif
  85.  
  86.     /* give us a clean slate */
  87.     errno = 0;
  88. }
  89. /*
  90. **  _ERROR_MESSAGE -- generic message printing routine.
  91. **
  92. **    Includes the program name with the message, as well as the
  93. **    various possible error codes.
  94. **
  95. **    Parameters:
  96. **        m -- the printf() message to print.
  97. **        a, b, c, d, e -- parameters to the message
  98. **
  99. **    Returns:
  100. **        none.
  101. **
  102. **    Side Effects:
  103. **        none.
  104. **
  105. **    Globals:
  106. **        ProgName -- the name of the program.
  107. */
  108.  
  109. STATIC VOID
  110. _error_message(m, a, b, c, d, e)
  111.     char *m;
  112. {
  113.     extern char *ProgName;
  114.     int saveerr;
  115.     extern int errno;
  116.  
  117.     saveerr = errno;
  118.     if (ProgName != CHARNULL)
  119.         fprintf(stderr, "%s: ", ProgName);
  120.     fprintf(stderr, m, a, b, c, d, e);
  121.     fprintf(stderr, "\n");
  122.     if (saveerr != 0)
  123.     {
  124.         errno = saveerr;
  125.         perror("System error");
  126.     }
  127. }
  128.