home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libnet / mktrace.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.2 KB  |  90 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. #include "mkutils.h"
  19. #include "mktrace.h"
  20.  
  21. /* If you want to trace netlib, set this to 1, or use CTRL-ALT-T
  22.  * stroke (preferred method) to toggle it on and off */
  23. int MKLib_trace_flag=0;
  24.  
  25. PUBLIC void NET_ToggleTrace(void) {
  26.     if(MKLib_trace_flag)
  27.         MKLib_trace_flag = 0;
  28.     else
  29.         MKLib_trace_flag = 1;    
  30. }
  31.  
  32. /* Map netlib trace messages into nspr logger so that they are
  33.  * thread safe. */
  34. #if defined(DEBUG) || defined(NETLIB_TRACE_ON)
  35.  
  36. PRLogModuleInfo* NETLIB=NULL;
  37. #define out PR_LOG_ALWAYS
  38.  
  39.  
  40. /* Used by NET_NTrace() */
  41. PRIVATE void net_Trace(char *msg) {
  42. #if defined(XP_WIN32) || defined(XP_OS2)
  43.     if(MKLib_trace_flag) {
  44.         FE_Trace(msg);
  45.         FE_Trace("\n");
  46.     }
  47. #endif
  48.     PR_LOG(NETLIB, out, (msg));
  49. }
  50.  
  51.  
  52. /* Called to trace a message */
  53. void NET_NTrace(char *msg, int32 length) {
  54.     char * new_string = XP_ALLOC(length+1);
  55.     if(!new_string)
  56.         return;
  57.     strncpy(new_string, msg, length);
  58.     new_string[length] = '\0';
  59.  
  60. #ifdef XP_WIN
  61.     /* AFX can't handle anystring larger than 512 bytes */
  62.     if(length > 511)
  63.         new_string[511] = '\0';
  64. #endif
  65.  
  66.     net_Trace(new_string);
  67.     FREE(new_string);
  68. }
  69.  
  70.  
  71. /* #define'd in mktrace.h to TRACEMSG */
  72. void _MK_TraceMsg(char *fmt, ...) {
  73.     va_list ap;
  74.     char buf[512];
  75.  
  76.     va_start(ap, fmt);
  77.     PR_vsnprintf(buf, sizeof(buf), fmt, ap);
  78.  
  79. #if defined(DEBUG) && defined(XP_WIN)
  80.     if(MKLib_trace_flag) {
  81.         FE_Trace(buf);
  82.         FE_Trace("\n");
  83.     }
  84. #else
  85.     PR_LOG(NETLIB, out, (buf));
  86. #endif
  87. }
  88.  
  89. #endif /* DEBUG || NETLIB_TRACE_ON */
  90.