home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 322_01 / trace.h < prev    next >
C/C++ Source or Header  |  1990-08-06  |  3KB  |  102 lines

  1. /*ib------------------------------------------------------------------*/
  2. /*  FILE NAME:      trace.h.
  3.  *  FILE DESCR:     Macros for Tracing.
  4.  *  PROJECT NAME:   general.
  5.  *  PROJECT DESCR:  general definitions and functions.
  6.  *  SOURCE LANG:    c.
  7.  *  SOURCE VARIANT: Lattice C/6.0.
  8.  *  AUTHOR:         Bill Rogers.
  9.  *  DATE WRITTEN    89/11/19.
  10.  *  COPYRIGHT:      None.
  11.  *  GENERAL DESCR:
  12.  *      These macros are activated by the compiler command line
  13.  *      argument:
  14.  *
  15.  *          -dTRACE
  16.  *
  17.  *      The forms of the printed line to "stderr" are:
  18.  *
  19.  *          <file>:<line>:<func>:Begin: RCsid=
  20.  *              <rcsid>
  21.  *          <file>:<line>:<func>:<type>:<var name>=<var value>
  22.  *          <file>:<line>:<func>:End
  23.  *
  24.  *      The macros are:
  25.  *
  26.  *          T_FUNC(x)   Define function name
  27.  *
  28.  *          T_BEGIN()   Display function "begin"
  29.  *          T_END()     Display function "end"
  30.  *
  31.  *          T_BOOL(x)   Display boolean
  32.  *          T_CHAR(x)   Display character
  33.  *          T_DBL(x)    Display double
  34.  *          T_HEX(x)    Display unsigned integer in hexadecimal
  35.  *          T_INT(x)    Display integer
  36.  *          T_FLOAT(x)  Display float
  37.  *          T_LHEX(x)   Display unsigned long integer in hexadecimal
  38.  *          T_LONG(x)   Display long
  39.  *          T_PTR(x)    Display pointer as segment:offset
  40.  *          T_STR(x)    Display string
  41.  */
  42. #ifndef trace_h
  43. #define trace_h
  44. /*  RCS ID:         */
  45.         const static char rcsid_trace_h[] = 
  46.         "$Id: trace.h 1.10 89/11/24 14:42:36 Bill_Rogers Exp $";
  47. /*ie------------------------------------------------------------------*/
  48.  
  49. #if defined(TRACE)
  50.  
  51. #include    <stdio.h>
  52. #include    <string.h>
  53.  
  54. /*  Predefined, as These Fields Appear on Every Line */
  55.  
  56. #define TT_PR       fprintf(stderr,"%-10s:%5d:%-12s:%-5s "
  57. #define TT_AR       __FILE__,__LINE__,TT_FUNC
  58.  
  59. /*  "Trace" Macros */
  60.  
  61. #define T_FUNC(x)   const static char TT_FUNC[] = # x ;
  62.  
  63. #define T_BEGIN()   TT_PR "%-16s=\n    %-s\n" ,TT_AR,"begin","RCsid",\
  64.                         RCsid);
  65. #define T_END()     TT_PR "\n"                ,TT_AR,"end"  );
  66.  
  67. #define T_BOOL(x)   TT_PR "%-16s=%s\n"        ,TT_AR,"bool" ,# x,\
  68.                         x == 0 ? "FALSE" : "TRUE");
  69. #define T_CHAR(x)   TT_PR "%-16s='%c'\n"      ,TT_AR,"char" ,# x,\
  70.                         x >= ' ' ? x : '.');
  71. #define T_DBL(x)    TT_PR "%-16s=%+.15e\n"    ,TT_AR,"dbl"  ,# x,x);
  72. #define T_HEX(x)    TT_PR "%-16s=%04X\n"      ,TT_AR,"hex"  ,# x,x);
  73. #define T_INT(x)    TT_PR "%-16s=%+6d\n"      ,TT_AR,"int"  ,# x,x);
  74. #define T_FLOAT(x)  TT_PR "%-16s=%+e\n"       ,TT_AR,"float",# x,x);
  75. #define T_LHEX(x)   TT_PR "%-16s=%08lX\n"     ,TT_AR,"lhex" ,# x,x);
  76. #define T_LONG(x)   TT_PR "%-16s=%+10ld\n"    ,TT_AR,"long" ,# x,x);
  77. #define T_PTR(x)    TT_PR "%-16s=%0lP\n"      ,TT_AR,"ptr"  ,# x,x);
  78. #define T_STR(x)    TT_PR "%-16s=\n    '%s'\n",TT_AR,"str"  ,# x,x);
  79.  
  80. #else
  81.  
  82. #define T_FUNC(x)
  83.  
  84. #define T_BEGIN()
  85. #define T_END()
  86.  
  87. #define T_BOOL(x)
  88. #define T_CHAR(x)
  89. #define T_DBL(x) 
  90. #define T_HEX(x) 
  91. #define T_INT(x) 
  92. #define T_FLOAT(x)
  93. #define T_LHEX(x) 
  94. #define T_LONG(x) 
  95. #define T_PTR(x)  
  96. #define T_STR(x)  
  97.  
  98. #endif      /* TRACE */
  99.  
  100. #endif      /* trace_h */
  101. /*--------------------------------------------------------------------*/
  102.