home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / BASH_112.ZIP / BASH-112.TAR / bash-1.12 / error.c < prev    next >
C/C++ Source or Header  |  1992-01-25  |  3KB  |  160 lines

  1. /* error.c -- Functions for handling errors. */
  2.  
  3. #include <stdio.h>
  4.  
  5. #if defined (HAVE_VFPRINTF)
  6. #include <varargs.h>
  7. #endif
  8.  
  9. #include <errno.h>
  10. extern int errno;
  11. extern char *strerror ();
  12.  
  13. #include "flags.h"
  14. #include "error.h"
  15.  
  16. /* Report an error having to do with FILENAME. */
  17. void
  18. file_error (filename)
  19.      char *filename;
  20. {
  21.   report_error ("%s: %s", filename, strerror (errno));
  22. }
  23.  
  24. #if !defined (HAVE_VFPRINTF)
  25. void
  26. programming_error (reason, arg1, arg2, arg3, arg4, arg5)
  27.      char *reason;
  28. {
  29.   extern char *the_current_maintainer;
  30.  
  31. #if defined (JOB_CONTROL)
  32.   {
  33.     extern pid_t shell_pgrp;
  34.     give_terminal_to (shell_pgrp);
  35.   }
  36. #endif /* JOB_CONTROL */
  37.  
  38.   report_error (reason, arg1, arg2);
  39.   fprintf (stderr, "Tell %s to fix this someday.\n", the_current_maintainer);
  40.  
  41. #if defined (MAKE_BUG_REPORTS)
  42.   if (1)
  43.     {
  44.       fprintf (stderr, "Mailing a bug report...");
  45.       fflush (stderr);
  46.       make_bug_report (reason, arg1, arg2, arg3, arg4, arg5);
  47.       fprintf (stderr, "done.\n");
  48.     }
  49. #endif /* MAKE_BUG_REPORTS */
  50.  
  51.   fprintf (stderr, "Stopping myself...");
  52.   fflush (stderr);
  53.   abort ();
  54. }
  55.  
  56. void
  57. report_error (format, arg1, arg2, arg3, arg4, arg5)
  58.      char *format;
  59. {
  60. #if defined (NOTDEF)
  61.   extern char *shell_name, *base_pathname ();
  62.  
  63.   fprintf (stderr, "%s: ", base_pathname (shell_name));
  64. #endif /* NOTDEF */
  65.  
  66.   fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);
  67.   fprintf (stderr, "\n");
  68.   if (exit_immediately_on_error)
  69.     exit (1);
  70. }  
  71.  
  72. void
  73. fatal_error (format, arg1, arg2, arg3, arg4, arg5)
  74.      char *format;
  75. {
  76.   report_error (format, arg1, arg2, arg3, arg4, arg5);
  77.   exit (2);
  78. }
  79.  
  80. #else /* We have VARARGS support, so use it. */
  81.  
  82. void
  83. programming_error (va_alist)
  84.      va_dcl
  85. {
  86.   extern char *the_current_maintainer, *shell_name;
  87.   extern char *base_pathname ();
  88.   va_list args;
  89.   char *format;
  90.  
  91. #if defined (JOB_CONTROL)
  92.   {
  93.     extern pid_t shell_pgrp;
  94.     give_terminal_to (shell_pgrp);
  95.   }
  96. #endif /* JOB_CONTROL */
  97.  
  98.   va_start (args);
  99.   format = va_arg (args, char *);
  100.   vfprintf (stderr, format, args);
  101.   fprintf (stderr, "\n");
  102.   va_end (args);
  103.  
  104.   fprintf (stderr, "Tell %s to fix this someday.\n", the_current_maintainer);
  105.  
  106. #if defined (MAKE_BUG_REPORTS)
  107.   if (1)
  108.     {
  109.       fprintf (stderr, "Mailing a bug report...");
  110.       fflush (stderr);
  111.       make_bug_report (va_alist);
  112.       fprintf (stderr, "done.\n");
  113.     }
  114. #endif
  115.   fprintf (stderr, "Stopping myself...");
  116.   fflush (stderr);
  117.   abort ();
  118. }
  119.  
  120. void
  121. report_error (va_alist)
  122.      va_dcl
  123. {
  124.   va_list args;
  125.   char *format;
  126.  
  127. #if defined (NOTDEF)
  128.   extern char *shell_name, *base_pathname ();
  129.  
  130.   fprintf (stderr, "%s: ", base_pathname (shell_name));
  131. #endif /* NOTDEF */
  132.   va_start (args);
  133.   format = va_arg (args, char *);
  134.   vfprintf (stderr, format, args);
  135.   fprintf (stderr, "\n");
  136.  
  137.   va_end (args);
  138.   if (exit_immediately_on_error)
  139.     exit (1);
  140. }
  141.  
  142. void
  143. fatal_error (va_alist)
  144.      va_dcl
  145. {
  146.   va_list args;
  147.   char *format;
  148.   extern char *shell_name, *base_pathname ();
  149.  
  150.   fprintf (stderr, "%s: ", base_pathname (shell_name));
  151.   va_start (args);
  152.   format = va_arg (args, char *);
  153.   vfprintf (stderr, format, args);
  154.   fprintf (stderr, "\n");
  155.  
  156.   va_end (args);
  157.   exit (2);
  158. }
  159. #endif /* HAVE_VFPRINTF */
  160.