home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / pos2err.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  4.9 KB  |  150 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.3 1993/10/12 00:47:04 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: pos2err.c $
  24.  * Revision 1.3  1993/10/12  00:47:04  ahd
  25.  * Normalize comments
  26.  *
  27.  * Revision 1.2  1993/09/30  03:06:28  ahd
  28.  * Handle selected errors with special messages
  29.  *
  30.  * Revision 1.1  1993/09/24  03:43:27  ahd
  31.  * Initial revision
  32.  *
  33.  *
  34.  */
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                        System include files                        */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #define INCL_DOSMISC
  41. #define INCL_ERRORS
  42. #include <os2.h>
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <time.h>
  48. #include <errno.h>
  49.  
  50. #include <dos.h>
  51. #include <io.h>
  52.  
  53. /*--------------------------------------------------------------------*/
  54. /*                    UUPC/extended include files                     */
  55. /*--------------------------------------------------------------------*/
  56.  
  57. #include "lib.h"
  58. #include "pos2err.h"
  59.  
  60. currentfile();
  61.  
  62. /*--------------------------------------------------------------------*/
  63. /*    p O S 2 e r r                                                   */
  64. /*                                                                    */
  65. /*    Perform a perror() with logging                                 */
  66. /*--------------------------------------------------------------------*/
  67.  
  68. void pOS2Err(const size_t lineno,
  69.              const char *fname,
  70.              const char *prefix,
  71.              unsigned int rc)
  72. {
  73.    char buf[BUFSIZ];
  74.    static boolean recursion  = FALSE;
  75.    int l;
  76.    static char sysMsgs[] = "oso001.msg";
  77.    boolean redirect = ((logfile != stdout) && !isatty(fileno(stdout)));
  78.  
  79. #ifdef __OS2__
  80.    ULONG len, xrc;
  81. #else
  82.    USHORT len, xrc;
  83. #endif
  84.  
  85.    switch( rc )
  86.    {
  87.       case ERROR_TS_WAKEUP:
  88.          strcpy( buf, "Interrupted System Call");
  89.          break;
  90.  
  91.       case ERROR_GEN_FAILURE:
  92.          strcpy( buf, "Invalid parameter, Port IRQ conflict, or device failure");
  93.          break;
  94.  
  95.       default:
  96.          xrc = DosGetMessage( (PCHAR) NULL,
  97.                               0,
  98.                               (PCHAR) buf,
  99.                               sizeof buf,
  100.                               rc,
  101.                               (PSZ) sysMsgs,
  102.                               &len );
  103.  
  104.          if ( xrc != 0 )
  105.          {
  106.  
  107.             if ( ! recursion )
  108.             {
  109.                recursion = TRUE;
  110.                printOS2error( "DosGetMessage", xrc );
  111.                recursion = FALSE;
  112.             } /* recursion */
  113.  
  114.             sprintf(buf, "OS/2 API error %d in %s at line %d,"
  115.                          " cannot find message",
  116.                          (int) rc,
  117.                          fname,
  118.                          lineno );
  119.  
  120.          } /* if ( xrc != 0 ) */
  121.          else
  122.             buf[ len ] = '\0';
  123.          break;
  124.  
  125.    } /* switch */
  126.  
  127. /*--------------------------------------------------------------------*/
  128. /*    Drop extra new from error message if we have room in our        */
  129. /*    small buffer                                                    */
  130. /*--------------------------------------------------------------------*/
  131.  
  132.    l = strlen( buf );
  133.  
  134.    if (( buf[l-1] == '\n') & (l < sizeof buf ))
  135.       buf[l-1] = '\0';          /* Drop extra newline from string     */
  136.  
  137. /*--------------------------------------------------------------------*/
  138. /*           Display the message with option file location            */
  139. /*--------------------------------------------------------------------*/
  140.  
  141.    printmsg(2,"OS/2 API error %d in %s at line %d ...",
  142.             (int) rc, fname, lineno );
  143.  
  144.    printmsg(0,"%s: %s", prefix, buf);
  145.  
  146.    if ( redirect )
  147.       fprintf(stdout,"%s: %s\n", prefix, buf);
  148.  
  149. } /* pOS2Err */
  150.