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

  1. /*--------------------------------------------------------------------*/
  2. /*    p r i n t m s g . c                                             */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. /*
  13.  *    $Id: printmsg.c 1.5 1993/10/12 00:47:04 ahd Exp $
  14.  *
  15.  *    $Log: printmsg.c $
  16.  *     Revision 1.5  1993/10/12  00:47:04  ahd
  17.  *     Normalize comments
  18.  *
  19.  *     Revision 1.4  1993/09/20  04:38:11  ahd
  20.  *     TCP/IP support from Dave Watt
  21.  *     't' protocol support
  22.  *     OS/2 2.x support
  23.  *
  24.  *     Revision 1.3  1993/04/10  21:26:04  ahd
  25.  *     Use unique buffer for printmsg() time stamp
  26.  *
  27.  * Revision 1.2  1992/11/20  12:39:37  ahd
  28.  * Move heapcheck to check heap *EVERY* call
  29.  *
  30.  */
  31.  
  32. #include <stdarg.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <time.h>
  37.  
  38. #ifdef __CORE__
  39. #define __HEAPCHECK__
  40. #endif
  41.  
  42. #ifdef __HEAPCHECK__
  43. #include <alloc.h>
  44. #else
  45. #ifdef __CORELEFT__
  46. #include <alloc.h>
  47. #endif
  48. #endif
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*                    UUPC/extended include files                     */
  52. /*--------------------------------------------------------------------*/
  53.  
  54. #include "lib.h"
  55. #include "dater.h"
  56. #include "logger.h"
  57.  
  58. /*--------------------------------------------------------------------*/
  59. /*                          Global variables                          */
  60. /*--------------------------------------------------------------------*/
  61.  
  62. #ifdef __HEAPCHECK__
  63. currentfile();
  64. #endif
  65.  
  66. int debuglevel = 1;
  67. FILE *logfile = stdout;
  68.  
  69. #ifdef __CORE__
  70. long  *lowcore = NULL;
  71. char  *copyright = (char *) 4;
  72. char  *copywrong = NULL;
  73. #endif
  74.  
  75. /*--------------------------------------------------------------------*/
  76. /*    As this routine is called from everywhere, we turn on stack     */
  77. /*    checking here to handle the off-chance we screwed up and        */
  78. /*    blew the stack.  This may catch it late, but it will catch      */
  79. /*    it.                                                             */
  80. /*--------------------------------------------------------------------*/
  81.  
  82. #ifdef __TURBOC__
  83. #pragma -N
  84. #else
  85. #pragma check_stack( on )
  86. #endif
  87.  
  88. char *full_log_file_name = "UUPC log file";
  89.  
  90. /*--------------------------------------------------------------------*/
  91. /*   p r i n t m s g                                                  */
  92. /*                                                                    */
  93. /*   Print an error message if its severity level is high enough.     */
  94. /*   Print message on standard output if not in remote mode           */
  95. /*   (call-in).  Always log the error message into the log file.      */
  96. /*                                                                    */
  97. /*   Modified by ahd 10/01/89 to check for Turbo C NULL pointers      */
  98. /*   being de-referenced anywhere in program.  Fixed 12/14/89         */
  99. /*                                                                    */
  100. /*   Modified by ahd 04/18/91 to use true variable parameter list,    */
  101. /*   supplied by Harald Boegeholz                                     */
  102. /*--------------------------------------------------------------------*/
  103.  
  104. void printmsg(int level, char *fmt, ...)
  105. {
  106.    va_list arg_ptr;
  107.  
  108. #ifdef __CORELEFT__
  109.    static unsigned freecore = 63 * 1024;
  110.    unsigned nowfree;
  111. #endif
  112.  
  113. #ifdef __HEAPCHECK__
  114.       static boolean recurse = FALSE;
  115.       int heapstatus;
  116.  
  117.       heapstatus = heapcheck();
  118.       if (heapstatus == _HEAPCORRUPT)
  119.          printf("\a*** HEAP IS CORRUPTED ***\a\n");
  120.  
  121. #endif
  122.  
  123. #ifdef __CORE__
  124.    if (*lowcore != 0L)
  125.    {
  126.       putchar('\a');
  127.       debuglevel = level;  /* Force this last message to print ahd    */
  128.    }
  129. #endif
  130.  
  131.  
  132. #ifdef __CORELEFT__
  133.    nowfree = coreleft();
  134.    if (nowfree < freecore)
  135.    {
  136.       freecore = (nowfree / 10) * 9;
  137.       printmsg(0,"Free memory = %u bytes", nowfree);
  138.    }
  139. #endif
  140.  
  141.    if (level <= debuglevel)
  142.    {
  143.  
  144.       FILE *stream = (logfile == NULL) ? stderr : logfile;
  145.  
  146.       va_start(arg_ptr,fmt);
  147.  
  148.       if ((stream != stdout) && (stream != stderr))
  149.       {
  150.          char now[DATEBUF];
  151.          vfprintf(stderr, fmt, arg_ptr);
  152.          fputc('\n',stderr);
  153.  
  154.          if ( debuglevel > 1 )
  155.             fprintf(stream, "(%d) ", level);
  156.          else
  157.             fprintf(stream, "%s ", dater( time( NULL ), now));
  158.  
  159.       } /* if (stream != stdout) */
  160.  
  161.       if (!ferror(stream))
  162.          vfprintf(stream, fmt, arg_ptr);
  163.  
  164.       if (!ferror(stream))
  165.          fputc('\n',stream);
  166.  
  167.       if (ferror(stream))
  168.       {
  169.          perror(full_log_file_name);
  170.          abort();
  171.       } /* if */
  172.  
  173. #ifdef __HEAPCHECK__
  174.       if ( !recurse )
  175.       {
  176.          recurse = TRUE;
  177. #ifdef __CORE__
  178.          if (*lowcore != 0L)
  179.             panic();
  180.     /*     if (!equal(copyright,copywrong))
  181.             panic();                         */
  182. #endif
  183.          if (heapstatus == _HEAPCORRUPT)
  184.             panic();
  185.          recurse = FALSE;
  186.       }
  187. #endif
  188.  
  189.  
  190. /*--------------------------------------------------------------------*/
  191. /*                        Massive debug mode?                         */
  192. /*--------------------------------------------------------------------*/
  193.  
  194.    if ((debuglevel > 10) &&  ((level+2) < debuglevel))
  195.       fflush( logfile );
  196.  
  197.    } /* if (level <= debuglevel) */
  198.  
  199. } /*printmsg*/
  200.