home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / diff.lzh / diff / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-04-24  |  3.2 KB  |  119 lines

  1. static char RCSid[]="$Id: error.c_v 1.1 96/04/23 02:52:26 hiro Exp $";
  2. /* error.c -- error handler for noninteractive utilities
  3.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. /* Written by David MacKenzie.  */
  20.  
  21. #ifdef HAVE_CONFIG_H
  22. #if defined (CONFIG_BROKETS)
  23. /* We use <config.h> instead of "config.h" so that a compilation
  24.    using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
  25.    (which it would do because it found this file in $srcdir).  */
  26. #include <config.h>
  27. #else
  28. #include "config.h"
  29. #endif
  30. #endif
  31.  
  32. #include <stdio.h>
  33.  
  34. #ifdef HAVE_VPRINTF
  35.  
  36. #if __STDC__
  37. #include <stdarg.h>
  38. #define VA_START(args, lastarg) va_start(args, lastarg)
  39. #else /* !__STDC__ */
  40. #include <varargs.h>
  41. #define VA_START(args, lastarg) va_start(args)
  42. #endif /* !__STDC__ */
  43.  
  44. #else /* !HAVE_VPRINTF */
  45.  
  46. #ifdef HAVE_DOPRNT
  47. #define va_alist args
  48. #define va_dcl int args;
  49. #else /* !HAVE_DOPRNT */
  50. #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
  51. #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
  52. #endif /* !HAVE_DOPRNT */
  53.  
  54. #endif /* !HAVE_VPRINTF */
  55.  
  56. #ifdef STDC_HEADERS
  57. #include <stdlib.h>
  58. #include <string.h>
  59. #else /* !STDC_HEADERS */
  60. void exit ();
  61. #endif /* !STDC_HEADERS */
  62.  
  63. extern char *program_name;
  64.  
  65. #ifndef HAVE_STRERROR
  66. static char *
  67. private_strerror (errnum)
  68.      int errnum;
  69. {
  70.   extern char *sys_errlist[];
  71.   extern int sys_nerr;
  72.  
  73.   if (errnum > 0 && errnum <= sys_nerr)
  74.     return sys_errlist[errnum];
  75.   return "Unknown system error";
  76. }
  77. #define strerror private_strerror
  78. #endif /* !HAVE_STRERROR */
  79.  
  80. /* Print the program name and error message MESSAGE, which is a printf-style
  81.    format string with optional args.
  82.    If ERRNUM is nonzero, print its corresponding system error message.
  83.    Exit with status STATUS if it is nonzero.  */
  84. /* VARARGS */
  85. void
  86. #if defined (HAVE_VPRINTF) && __STDC__
  87. error (int status, int errnum, char *message, ...)
  88. #else /* !HAVE_VPRINTF or !__STDC__ */
  89. error (status, errnum, message, va_alist)
  90.      int status;
  91.      int errnum;
  92.      char *message;
  93.      va_dcl
  94. #endif /* !HAVE_VPRINTF or !__STDC__ */
  95. {
  96. #ifdef HAVE_VPRINTF
  97.   va_list args;
  98. #endif /* HAVE_VPRINTF */
  99.  
  100.   fprintf (stderr, "%s: ", program_name);
  101. #ifdef HAVE_VPRINTF
  102.   VA_START (args, message);
  103.   vfprintf (stderr, message, args);
  104.   va_end (args);
  105. #else /* !HAVE_VPRINTF */
  106. #ifdef HAVE_DOPRNT
  107.   _doprnt (message, &args, stderr);
  108. #else /* !HAVE_DOPRNT */
  109.   fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
  110. #endif /* !HAVE_DOPRNT */
  111. #endif /* !HAVE_VPRINTF */
  112.   if (errnum)
  113.     fprintf (stderr, ": %s", strerror (errnum));
  114.   putc ('\n', stderr);
  115.   fflush (stderr);
  116.   if (status)
  117.     exit (status);
  118. }
  119.