home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XS.ZIP / LIB / PRINTERR.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  5KB  |  124 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.  *    $Header: E:\SRC\UUPC\LIB\RCS\PRINTERR.C 1.2 1992/11/19 02:57:19 ahd Exp $
  18.  *
  19.  *    Revision history:
  20.  *    $Log: PRINTERR.C $
  21.  * Revision 1.2  1992/11/19  02:57:19  ahd
  22.  * drop rcsid
  23.  *
  24.  * Revision 1.1  1992/11/16  05:00:26  ahd
  25.  * Initial revision
  26.  *
  27.  */
  28.  
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <time.h>
  34. #include <errno.h>
  35.  
  36. #ifndef __GNUC__
  37. #include <dos.h>
  38. #include <io.h>
  39. #endif
  40.  
  41. /*--------------------------------------------------------------------*/
  42. /*                    UUPC/extended include files                     */
  43. /*--------------------------------------------------------------------*/
  44.  
  45. #include "lib.h"
  46.  
  47. /*--------------------------------------------------------------------*/
  48. /*    p r i n t e r r                                                 */
  49. /*                                                                    */
  50. /*    Perform a perror() with logging                                 */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. void prterror(const size_t lineno, const char *fname, const char *prefix)
  54. {
  55.    char buf[50];
  56.    char *s = strerror(errno);
  57.    int l = strlen( s );
  58.  
  59.    boolean redirect = ((logfile != stdout) && !isatty(fileno(stdout)));
  60.  
  61. /*--------------------------------------------------------------------*/
  62. /*    Drop extra new from error message if we have room in our        */
  63. /*    small buffer                                                    */
  64. /*--------------------------------------------------------------------*/
  65.  
  66.    if (( s[l-1] == '\n') & (l < sizeof buf ))
  67.    {
  68.       s = strcpy( buf, s);    /* Make buf copy of string we use below*/
  69.       s[l-1] = '\0';          /* Drop extra newline from string      */
  70.    }
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*           Display the message with option file location            */
  74. /*--------------------------------------------------------------------*/
  75.  
  76.    printmsg(2,"Run time library error in %s at line %d ...",
  77.             fname, lineno);
  78.  
  79.    printmsg(0,"%s: %s", prefix, s);
  80.    if ( redirect )
  81.       fprintf(stdout,"%s: %s\n", prefix, s);
  82.  
  83. #ifdef __TURBOC__
  84.    if (_osmajor >= 3 )
  85.    {
  86.       union REGS regs;
  87.       struct SREGS sregs;
  88.       regs.h.ah = 0x59;       /* Extended error information          */
  89.       regs.x.bx = 0x00;       /* Set up for call                     */
  90.       intdosx(®s, ®s, &sregs);
  91.  
  92.       printmsg(1,"Extended DOS Error Information: "
  93.             "Number = %d, Class = %d, Action = %d, Locus = %d",
  94.                   (int) regs.x.ax, (int) regs.h.bh,
  95.                   (int) regs.h.bl, (int) regs.h.ch );
  96.  
  97.       if ( redirect )
  98.       {
  99.          fprintf(stdout, "Extended DOS Error Information: "
  100.             "Number = %d, Class = %d, Action = %d, Locus = %d",
  101.                   (int) regs.x.ax, (int) regs.h.bh,
  102.                   (int) regs.h.bl, (int) regs.h.ch );
  103.          fputc('\n',stdout);  /* Allows compiler to avoid generating
  104.                                  second almost duplicate literal str */
  105.       } /* if ( redirect ) */
  106.  
  107. /*--------------------------------------------------------------------*/
  108. /*               Abort if that is the suggested action                */
  109. /*--------------------------------------------------------------------*/
  110.  
  111.       switch( regs.h.bl )
  112.       {
  113.          case 0x04:
  114.          case 0x05:
  115.                bugout( lineno, fname);
  116.  
  117.          default:
  118.                break;
  119.       } /* switch */
  120.    } /* (_osmajor >= 3 ) */
  121. #endif
  122.  
  123. } /* printerr */
  124.