home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / pnterr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  4.1 KB  |  119 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       p n t e r r . c                                              */
  3. /*                                                                    */
  4. /*       Report error message from NT 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: pnterr.c 1.2 1993/10/12 00:46:16 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: pnterr.c $
  24.  * Revision 1.2  1993/10/12  00:46:16  ahd
  25.  * Normalize comments
  26.  *
  27.  * Revision 1.1  1993/09/25  03:02:37  ahd
  28.  * Initial revision
  29.  *
  30.  * Revision 1.1  1993/09/24  21:43:27  dmwatt
  31.  * Initial revision
  32.  *
  33.  *
  34.  */
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                        System include files                        */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #include <windows.h>
  41.  
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include <time.h>
  46. #include <io.h>
  47. #include <errno.h>
  48.  
  49. /*--------------------------------------------------------------------*/
  50. /*                    UUPC/extended include files                     */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. #include "lib.h"
  54. #include "pnterr.h"
  55.  
  56. currentfile();
  57.  
  58. /*--------------------------------------------------------------------*/
  59. /*    p N T e r r                                                     */
  60. /*                                                                    */
  61. /*    Perform a perror() with logging                                 */
  62. /*--------------------------------------------------------------------*/
  63.  
  64. void pNTErr(const size_t lineno,
  65.              const char *fname,
  66.              const char *prefix,
  67.              DWORD rc)
  68. {
  69.    char buf[BUFSIZ];
  70.    static boolean recursion  = FALSE;
  71.    int l;
  72.    boolean redirect = ((logfile != stdout) && !isatty(fileno(stdout)));
  73.  
  74.    DWORD xrc;
  75.    xrc = FormatMessage(
  76.                 FORMAT_MESSAGE_FROM_SYSTEM,
  77.                 NULL, rc, LANG_USER_DEFAULT, buf, BUFSIZ, NULL);
  78.  
  79.    if ( xrc == 0 )
  80.    {
  81.  
  82.       if ( ! recursion )
  83.       {
  84.          recursion = TRUE;
  85.          printNTerror( "FormatMessage", xrc );
  86.          recursion = FALSE;
  87.       } /* recursion */
  88.  
  89.       sprintf(buf, "NT API error %u in %s at line %d, cannot find message",
  90.                    (unsigned int) rc,
  91.                    fname,
  92.                    lineno );
  93.  
  94.    } /* if ( xrc == 0 ) */
  95.  
  96. /*--------------------------------------------------------------------*/
  97. /*    Drop extra new from error message if we have room in our        */
  98. /*    small buffer                                                    */
  99. /*--------------------------------------------------------------------*/
  100.  
  101.    l = strlen( buf );
  102.  
  103.    if (( buf[l-1] == '\n') & (l < sizeof buf ))
  104.       buf[l-1] = '\0';          /* Drop extra newline from string     */
  105.  
  106. /*--------------------------------------------------------------------*/
  107. /*           Display the message with option file location            */
  108. /*--------------------------------------------------------------------*/
  109.  
  110.    printmsg(2,"NT API error %d in %s at line %d ...",
  111.             (int) rc, fname, lineno );
  112.  
  113.    printmsg(0,"%s: %s", prefix, buf);
  114.  
  115.    if ( redirect )
  116.       fprintf(stdout,"%s: %s\n", prefix, buf);
  117.  
  118. } /* pNTErr */
  119.