home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / INTERNET / UPC2S1.ZIP / PRINTERR.C < prev    next >
C/C++ Source or Header  |  1993-09-20  |  5KB  |  135 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    p r i n t e r r . c                                             */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1989, 1992 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. /*--------------------------------------------------------------------*/
  13. /*                          RCS Information                           */
  14. /*--------------------------------------------------------------------*/
  15.  
  16. /*
  17.  *    $Id: printerr.c 1.5 1993/09/20 04:38:11 ahd Exp $
  18.  *
  19.  *    Revision history:
  20.  *    $Log: printerr.c $
  21.  *     Revision 1.5  1993/09/20  04:38:11  ahd
  22.  *     TCP/IP support from Dave Watt
  23.  *     't' protocol support
  24.  *     OS/2 2.x support
  25.  *
  26.  *     Revision 1.4  1993/07/22  23:19:50  ahd
  27.  *     First pass for Robert Denny's Windows 3.x support changes
  28.  *
  29.  *     Revision 1.3  1993/04/11  00:32:05  ahd
  30.  *     Global edits for year, TEXT, etc.
  31.  *
  32.  * Revision 1.2  1992/11/19  02:57:19  ahd
  33.  * drop rcsid
  34.  *
  35.  * Revision 1.1  1992/11/16  05:00:26  ahd
  36.  * Initial revision
  37.  *
  38.  */
  39.  
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <time.h>
  45. #include <errno.h>
  46.  
  47. #ifndef __GNUC__
  48. #include <dos.h>
  49. #include <io.h>
  50. #endif
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*                    UUPC/extended include files                     */
  54. /*--------------------------------------------------------------------*/
  55.  
  56. #include "lib.h"
  57.  
  58. /*--------------------------------------------------------------------*/
  59. /*    p r i n t e r r                                                 */
  60. /*                                                                    */
  61. /*    Perform a perror() with logging                                 */
  62. /*--------------------------------------------------------------------*/
  63.  
  64. void prterror(const size_t lineno, const char *fname, const char *prefix)
  65. {
  66.    char buf[50];
  67.    char *s = strerror(errno);
  68.    int l = strlen( s );
  69.  
  70.    boolean redirect = ((logfile != stdout) && !isatty(fileno(stdout)));
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*    Drop extra new from error message if we have room in our        */
  74. /*    small buffer                                                    */
  75. /*--------------------------------------------------------------------*/
  76.  
  77.    if (( s[l-1] == '\n') & (l < sizeof buf ))
  78.    {
  79.       s = strcpy( buf, s);    /* Make buf copy of string we use below*/
  80.       s[l-1] = '\0';          /* Drop extra newline from string      */
  81.    }
  82.  
  83. /*--------------------------------------------------------------------*/
  84. /*           Display the message with option file location            */
  85. /*--------------------------------------------------------------------*/
  86.  
  87.    printmsg(2,"Run time library error in %s at line %d ...",
  88.             fname, lineno);
  89.  
  90.    printmsg(0,"%s: %s", prefix, s);
  91.    if ( redirect )
  92.       fprintf(stdout,"%s: %s\n", prefix, s);
  93.  
  94. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__OS2__)
  95.    if (_osmajor >= 3 )
  96.    {
  97.       union REGS regs;
  98.       struct SREGS sregs;
  99.       regs.h.ah = 0x59;       /* Extended error information          */
  100.       regs.x.bx = 0x00;       /* Set up for call                     */
  101.       intdosx(®s, ®s, &sregs);
  102.  
  103.       printmsg(1,"Extended DOS Error Information: "
  104.             "Number = %d, Class = %d, Action = %d, Locus = %d",
  105.                   (int) regs.x.ax, (int) regs.h.bh,
  106.                   (int) regs.h.bl, (int) regs.h.ch );
  107.  
  108.       if ( redirect )
  109.       {
  110.          fprintf(stdout, "Extended DOS Error Information: "
  111.             "Number = %d, Class = %d, Action = %d, Locus = %d",
  112.                   (int) regs.x.ax, (int) regs.h.bh,
  113.                   (int) regs.h.bl, (int) regs.h.ch );
  114.          fputc('\n',stdout);  /* Allows compiler to avoid generating
  115.                                  second almost duplicate literal str */
  116.       } /* if ( redirect ) */
  117.  
  118. /*--------------------------------------------------------------------*/
  119. /*               Abort if that is the suggested action                */
  120. /*--------------------------------------------------------------------*/
  121.  
  122.       switch( regs.h.bl )
  123.       {
  124.          case 0x04:
  125.          case 0x05:
  126.                bugout( lineno, fname);
  127.  
  128.          default:
  129.                break;
  130.       } /* switch */
  131.    } /* (_osmajor >= 3 ) */
  132. #endif
  133.  
  134. } /* printerr */
  135.