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

  1. /*--------------------------------------------------------------------*/
  2. /*       p o s 2 e r r  . c                                           */
  3. /*                                                                    */
  4. /*       Report error message from OS/2 error library                 */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: pos2err.c 1.2 1993/09/30 03:06:28 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: pos2err.c $
  24.  * Revision 1.2  1993/09/30  03:06:28  ahd
  25.  * Handle selected errors with special messages
  26.  *
  27.  * Revision 1.1  1993/09/24  03:43:27  ahd
  28.  * Initial revision
  29.  *
  30.  *
  31.  */
  32.  
  33. /*--------------------------------------------------------------------*/
  34. /*                        System include files                        */
  35. /*--------------------------------------------------------------------*/
  36.  
  37. #define INCL_DOSMISC
  38. #define INCL_ERRORS
  39. #include <os2.h>
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <time.h>
  45. #include <errno.h>
  46.  
  47. #include <dos.h>
  48. #include <io.h>
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*                    UUPC/extended include files                     */
  52. /*--------------------------------------------------------------------*/
  53.  
  54. #include "lib.h"
  55. #include "pos2err.h"
  56.  
  57. currentfile();
  58.  
  59. /*--------------------------------------------------------------------*/
  60. /*    p O S 2 e r r                                                   */
  61. /*                                                                    */
  62. /*    Perform a perror() with logging                                 */
  63. /*--------------------------------------------------------------------*/
  64.  
  65. void pOS2Err(const size_t lineno,
  66.              const char *fname,
  67.              const char *prefix,
  68.              unsigned int rc)
  69. {
  70.    char buf[BUFSIZ];
  71.    static boolean recursion  = FALSE;
  72.    int l;
  73.    static char sysMsgs[] = "oso001.msg";
  74.    boolean redirect = ((logfile != stdout) && !isatty(fileno(stdout)));
  75.  
  76. #ifdef __OS2__
  77.    ULONG len, xrc;
  78. #else
  79.    USHORT len, xrc;
  80. #endif
  81.  
  82.    switch( rc )
  83.    {
  84.       case ERROR_TS_WAKEUP:
  85.          strcpy( buf, "Interrupted System Call");
  86.          break;
  87.  
  88.       case ERROR_GEN_FAILURE:
  89.          strcpy( buf, "Invalid parameter, Port IRQ conflict, or device failure");
  90.          break;
  91.  
  92.       default:
  93.          xrc = DosGetMessage( (PCHAR) NULL,
  94.                               0,
  95.                               (PCHAR) buf,
  96.                               sizeof buf,
  97.                               rc,
  98.                               (PSZ) sysMsgs,
  99.                               &len );
  100.  
  101.          if ( xrc != 0 )
  102.          {
  103.  
  104.             if ( ! recursion )
  105.             {
  106.                recursion = TRUE;
  107.                printOS2error( "DosGetMessage", xrc );
  108.                recursion = FALSE;
  109.             } /* recursion */
  110.  
  111.             sprintf(buf, "OS/2 API error %d in %s at line %d,"
  112.                          " cannot find message",
  113.                          (int) rc,
  114.                          fname,
  115.                          lineno );
  116.  
  117.          } /* if ( xrc != 0 ) */
  118.          else
  119.             buf[ len ] = '\0';
  120.          break;
  121.  
  122.    } /* switch */
  123.  
  124. /*--------------------------------------------------------------------*/
  125. /*    Drop extra new from error message if we have room in our        */
  126. /*    small buffer                                                    */
  127. /*--------------------------------------------------------------------*/
  128.  
  129.    l = strlen( buf );
  130.  
  131.    if (( buf[l-1] == '\n') & (l < sizeof buf ))
  132.       buf[l-1] = '\0';          /* Drop extra newline from string      */
  133.  
  134. /*--------------------------------------------------------------------*/
  135. /*           Display the message with option file location            */
  136. /*--------------------------------------------------------------------*/
  137.  
  138.    printmsg(2,"OS/2 API error %d in %s at line %d ...",
  139.             (int) rc, fname, lineno );
  140.  
  141.    printmsg(0,"%s: %s", prefix, buf);
  142.  
  143.    if ( redirect )
  144.       fprintf(stdout,"%s: %s\n", prefix, buf);
  145.  
  146. } /* pOS2Err */
  147.