home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / PAX20.ZIP / DBUG.H < prev    next >
C/C++ Source or Header  |  1990-11-12  |  6KB  |  158 lines

  1. /******************************************************************************
  2.  *                                          *
  3.  *                               N O T I C E                      *
  4.  *                                          *
  5.  *                  Copyright Abandoned, 1987, Fred Fish              *
  6.  *                                          *
  7.  *                                          *
  8.  *    This previously copyrighted work has been placed into the  public     *
  9.  *    domain  by  the  author  and  may be freely used for any purpose,     *
  10.  *    private or commercial.                              *
  11.  *                                          *
  12.  *    Because of the number of inquiries I was receiving about the  use     *
  13.  *    of this product in commercially developed works I have decided to     *
  14.  *    simply make it public domain to further its unrestricted use.   I     *
  15.  *    specifically  would  be  most happy to see this material become a     *
  16.  *    part of the standard Unix distributions by AT&T and the  Berkeley     *
  17.  *    Computer  Science  Research Group, and a standard part of the GNU     *
  18.  *    system from the Free Software Foundation.                  *
  19.  *                                          *
  20.  *    I would appreciate it, as a courtesy, if this notice is  left  in     *
  21.  *    all copies and derivative works.  Thank you.                  *
  22.  *                                          *
  23.  *    The author makes no warranty of any kind  with  respect  to  this     *
  24.  *    product  and  explicitly disclaims any implied warranties of mer-     *
  25.  *    chantability or fitness for any particular purpose.              *
  26.  *                                          *
  27.  ******************************************************************************
  28.  */
  29.  
  30.  
  31. /*
  32.  *  FILE
  33.  *
  34.  *    dbug.h    user include file for programs using the dbug package
  35.  *
  36.  *  SYNOPSIS
  37.  *
  38.  *    #include <local/dbug.h>
  39.  *
  40.  *  SCCS ID
  41.  *
  42.  *    @(#)dbug.h    1.11 9/5/87
  43.  *
  44.  *  DESCRIPTION
  45.  *
  46.  *    Programs which use the dbug package must include this file.
  47.  *    It contains the appropriate macros to call support routines
  48.  *    in the dbug runtime library.
  49.  *
  50.  *    To disable compilation of the macro expansions define the
  51.  *    preprocessor symbol "DBUG_OFF".  This will result in null
  52.  *    macros expansions so that the resulting code will be smaller
  53.  *    and faster.  (The difference may be smaller than you think
  54.  *    so this step is recommended only when absolutely necessary).
  55.  *    In general, tradeoffs between space and efficiency are
  56.  *    decided in favor of efficiency since space is seldom a
  57.  *    problem on the new machines).
  58.  *
  59.  *    All externally visible symbol names follow the pattern
  60.  *    "_db_xxx..xx_" to minimize the possibility of a dbug package
  61.  *    symbol colliding with a user defined symbol.
  62.  *
  63.  *    The DBUG_<N> style macros are obsolete and should not be used
  64.  *    in new code.  Macros to map them to instances of DBUG_PRINT
  65.  *    are provided for compatibility with older code.  They may go
  66.  *    away completely in subsequent releases.
  67.  *
  68.  *  AUTHOR
  69.  *
  70.  *    Fred Fish
  71.  *    (Currently employed by Motorola Computer Division, Tempe, Az.)
  72.  *    hao!noao!mcdsun!fnf
  73.  *    (602) 438-3614
  74.  *
  75.  */
  76.  
  77.  
  78. /*
  79.  *    Internally used dbug variables which must be global.
  80.  */
  81.  
  82. #ifndef DBUG_OFF
  83.     extern int _db_on_;            /* TRUE if debug currently enabled */
  84.     extern FILE *_db_fp_;        /* Current debug output stream */
  85.     extern char *_db_process_;        /* Name of current process */
  86.     extern int _db_keyword_ ();        /* Accept/reject keyword */
  87.     extern void _db_push_ ();        /* Push state, set up new state */
  88.     extern void _db_pop_ ();        /* Pop previous debug state */
  89.     extern void _db_enter_ ();        /* New user function entered */
  90.     extern void _db_return_ ();        /* User function return */
  91.     extern void _db_pargs_ ();        /* Remember args for line */
  92.     extern void _db_doprnt_ ();        /* Print debug output */
  93.     extern void _db_setjmp_ ();        /* Save debugger environment */
  94.     extern void _db_longjmp_ ();    /* Restore debugger environment */
  95. # endif
  96.  
  97.  
  98. /*
  99.  *    These macros provide a user interface into functions in the
  100.  *    dbug runtime support library.  They isolate users from changes
  101.  *    in the MACROS and/or runtime support.
  102.  *
  103.  *    The symbols "__LINE__" and "__FILE__" are expanded by the
  104.  *    preprocessor to the current source file line number and file
  105.  *    name respectively.
  106.  *
  107.  *    WARNING ---  Because the DBUG_ENTER macro allocates space on
  108.  *    the user function's stack, it must precede any executable
  109.  *    statements in the user function.
  110.  *
  111.  */
  112.  
  113. # ifdef DBUG_OFF
  114. #    define DBUG_ENTER(a1)
  115. #    define DBUG_RETURN(a1) return(a1)
  116. #    define DBUG_VOID_RETURN return
  117. #    define DBUG_EXECUTE(keyword,a1)
  118. #    define DBUG_PRINT(keyword,arglist)
  119. #    define DBUG_2(keyword,format)        /* Obsolete */
  120. #    define DBUG_3(keyword,format,a1)        /* Obsolete */
  121. #    define DBUG_4(keyword,format,a1,a2)    /* Obsolete */
  122. #    define DBUG_5(keyword,format,a1,a2,a3)    /* Obsolete */
  123. #    define DBUG_PUSH(a1)
  124. #    define DBUG_POP()
  125. #    define DBUG_PROCESS(a1)
  126. #    define DBUG_FILE (stderr)
  127. #    define DBUG_SETJMP setjmp
  128. #    define DBUG_LONGJMP longjmp
  129. # else
  130. #    define DBUG_ENTER(a) \
  131.     auto char *_db_func_, *_db_file_; \
  132.     int _db_level_; \
  133.     _db_enter_ (a,__FILE__,__LINE__,&_db_func_,&_db_file_,&_db_level_)
  134. #    define DBUG_LEAVE \
  135.     (_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_))
  136. #    define DBUG_RETURN(a1) return (DBUG_LEAVE, (a1))
  137. /*   define DBUG_RETURN(a1) {DBUG_LEAVE; return(a1);}  Alternate form */
  138. #    define DBUG_VOID_RETURN {DBUG_LEAVE; return;}
  139. #    define DBUG_EXECUTE(keyword,a1) \
  140.     {if (_db_on_) {if (_db_keyword_ (keyword)) { a1 ; }}}
  141. #    define DBUG_PRINT(keyword,arglist) \
  142.     {if (_db_on_) {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;}}
  143. #    define DBUG_2(keyword,format) \
  144.     DBUG_PRINT(keyword,(format))        /* Obsolete */
  145. #    define DBUG_3(keyword,format,a1) \
  146.     DBUG_PRINT(keyword,(format,a1))        /* Obsolete */
  147. #    define DBUG_4(keyword,format,a1,a2) \
  148.     DBUG_PRINT(keyword,(format,a1,a2))    /* Obsolete */
  149. #    define DBUG_5(keyword,format,a1,a2,a3) \
  150.     DBUG_PRINT(keyword,(format,a1,a2,a3))    /* Obsolete */
  151. #    define DBUG_PUSH(a1) _db_push_ (a1)
  152. #    define DBUG_POP() _db_pop_ ()
  153. #    define DBUG_PROCESS(a1) (_db_process_ = a1)
  154. #    define DBUG_FILE (_db_fp_)
  155. #    define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
  156. #    define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
  157. # endif
  158.