traceppp.h

来自「PPPoE协议在Psos中的实现源代码」· C头文件 代码 · 共 150 行

H
150
字号
/************************************************************************/
/*                                                                      */
/*   MODULE: trace.h                                                   */
/*   PRODUCT: pNA+, OpEN TCP/IP PPP driver                              */
/*   PURPOSE: Logging routine                                           */
/*   DATE:    September 23, 1999                                        */
/*                                                                      */
/*----------------------------------------------------------------------*/
/*                                                                      */
/*              Copyright 1996, Integrated Systems Inc.                 */
/*                      ALL RIGHTS RESERVED                             */
/*                                                                      */
/*   This computer program is the property of Integrated Systems Inc.   */
/*   Santa Clara, California, U.S.A. and may not be copied              */
/*   in any form or by any means, whether in part or in whole,          */
/*   except under license expressly granted by Integrated Systems Inc.  */
/*                                                                      */
/*   All copies of this program, whether in part or in whole, and       */
/*   whether modified or not, must display this and all other           */
/*   embedded copyright and ownership notices in full.                  */
/*                                                                      */
/*----------------------------------------------------------------------*/

#ifndef TRACE_H
#define TRACE_H

/*
 * We provide a simple mechanism where tracing statements of the form
 *
 *       TRACEF ("The value of x is %d, y is %d.\r\n" _ x _ y);
 *
 * may be added to code. If the code is compiled with TRACING=1, the
 * effect as as a write to stderr, displaying the file name and line number;
 * otherwise, no code is generated.
 *
 *    There are also helper macros to trace out the values of variables.
 *
 *       TRACE_d (s->i);
 *
 * results in something like
 *
 *       file.c,123:   s->i 23
 *
 *    To provide more complicated conditional tracing code, use
 *
 *       #if TRACING
 * not
 *
 *       #ifdef TRACING
 *
 * since then you will get an error if this file is not included, or if you
 * misspell TRACING.
 */

#ifndef TRACING
#define TRACING 1
#endif

#define _            ,
#define STR(s)       STRINGISE (s)
#define STRINGISE(s) #s
#define WHETHER(b)   ((b)? "true": "false")

#if TRACING
#ifdef __TCS__
#include <tmlib/dprintf.h>
#endif

/*We define a helper function. This is duplicated in every file for which
   tracing is enabled.*/
static void trace_c_
(
   unsigned char c
)
{
#ifdef __TCS__
   if ((0x20u <= c && c < 0x7Fu && !(c == '"' || c == '\'' || c == '\\')) ||
         0xA0u < c)
      _dp ("%c", c);
   else
      switch (c)
      {
         case 0:    _dp ("\\0");        break;
         case '\a': _dp ("\\a");        break;
         case '\b': _dp ("\\b");        break;
         case '\t': _dp ("\\t");        break;
         case '\n': _dp ("\\n");        break;
         case '\v': _dp ("\\v");        break;
         case '\f': _dp ("\\f");        break;
         case '\r': _dp ("\\r");        break;
         case '"':  _dp ("\\\"");       break;
         case '\'': _dp ("\\'");        break;
         case '\\': _dp ("\\\\");       break;
         default:   _dp ("\\x%.2X", c); break;
      }
#endif
}

#ifdef __TCS__
#define TRACEF(f) \
   _dp (__FILE__ "," STR (__LINE__) ":\t" f)

#define TRACE_c(c) (_dp (__FILE__ "," STR (__LINE__) ":\t" #c " '"), \
      trace_c_ (c), _dp ("'\r\n"))

#define TRACE_mem(mem, end)                                                \
{                                                                          \
   unsigned char *v_;                                                      \
                                                                           \
   _dp (__FILE__ "," STR (__LINE__) ":\t" #mem " \"");                     \
   for (v_ = (unsigned char *) (mem); v_ != (unsigned char *) (end); ++v_) \
      trace_c_ (*v_);                                                      \
   _dp ("\"\r\n");                                                           \
}

#define TRACE_str(s)                                   \
{                                                      \
   unsigned char *v_;                                  \
                                                       \
   _dp (__FILE__ "," STR (__LINE__) ":\t" #s " \"");   \
   for (v_ = (unsigned char *) (s); *v_ != '\0'; ++v_) \
      trace_c_ (*v_);                                  \
   _dp ("\"\r\n");                                       \
}
#else
#define TRACEF(f)           ((void) 0)
#define TRACE_c(c)          ((void) 0)
#define TRACE_mem(mem, end) {}
#define TRACE_str(s)        {}
#endif

#define TRACE_b(b) TRACEF (#b " %s\r\n"    _ WHETHER (b))
#define TRACE_d(d) TRACEF (#d " %ld\r\n"   _ (long) (d))
#define TRACE_k(k) TRACEF (#k "\r\n")
#define TRACE_p(p) TRACEF (#p " 0x%lX\r\n" _ (unsigned long) (void *) (p))
#define TRACE_x(x) TRACEF (#x " 0x%lX\r\n" _ (unsigned long) (x))

#define TRACE_q(q)                  \
   TRACEF                           \
   (                                \
      #q " %d.%d.%d.%d\r\n" _         \
      ((unsigned char *) (q)) [0] _ \
      ((unsigned char *) (q)) [1] _ \
      ((unsigned char *) (q)) [2] _ \
      ((unsigned char *) (q)) [3]   \
   )
#endif

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?