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