home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / dbug-2.4-bin.lha / include / dbug.h
C/C++ Source or Header  |  1996-10-12  |  6KB  |  152 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.  *  FILE
  32.  *
  33.  *    dbug.h    user include file for programs using the dbug package
  34.  *
  35.  *  SYNOPSIS
  36.  *
  37.  *    #include "dbug.h"
  38.  *
  39.  *  SCCS ID
  40.  *
  41.  *    @(#)dbug.h    2.4 5/4/96
  42.  *
  43.  *  DESCRIPTION
  44.  *
  45.  *    Programs which use the dbug package must include this file.
  46.  *    It contains the appropriate macros to call support routines
  47.  *    in the dbug runtime library.
  48.  *
  49.  *    To enable compilation of the macro expansions define the
  50.  *    preprocessor symbol "DBUG".  Leaving it undefined will result
  51.  *    in null macros expansions so that the resulting code will be
  52.  *    the same as if there were no macros at all.
  53.  *
  54.  *    All externally visible symbol names follow the pattern
  55.  *    "_db_xxx..xx_" to minimize the possibility of a dbug package
  56.  *    symbol colliding with a user defined symbol.
  57.  *    
  58.  *    The DBUG_<N> style macros are obsolete and should not be used
  59.  *    in new code.  Macros to map them to instances of DBUG_PRINT
  60.  *    are provided for compatibility with older code.  They may go
  61.  *    away completely in subsequent releases.
  62.  *
  63.  *  AUTHOR
  64.  *
  65.  *    Fred Fish
  66.  *    fnf@amigalib.com
  67.  *
  68.  */
  69.  
  70. /*
  71.  *    Internally used dbug variables which must be global.
  72.  */
  73.  
  74. #ifdef DBUG
  75.     extern int _db_on_;            /* TRUE if debug currently enabled */
  76.     extern FILE *_db_fp_;        /* Current debug output stream */
  77.     extern char *_db_process_;        /* Name of current process */
  78.     extern int _db_keyword_ ();        /* Accept/reject keyword */
  79.     extern void _db_push_ ();        /* Push state, set up new state */
  80.     extern void _db_pop_ ();        /* Pop previous debug state */
  81.     extern void _db_enter_ ();        /* New user function entered */
  82.     extern void _db_return_ ();        /* User function return */
  83.     extern void _db_pargs_ ();        /* Remember args for line */
  84.     extern void _db_doprnt_ ();        /* Print debug output */
  85.     extern void _db_setjmp_ ();        /* Save debugger environment */
  86.     extern void _db_longjmp_ ();    /* Restore debugger environment */
  87. # endif
  88.  
  89. /*
  90.  *    These macros provide a user interface into functions in the
  91.  *    dbug runtime support library.  They isolate users from changes
  92.  *    in the MACROS and/or runtime support.
  93.  *
  94.  *    The symbols "__LINE__" and "__FILE__" are expanded by the
  95.  *    preprocessor to the current source file line number and file
  96.  *    name respectively.
  97.  *
  98.  *    WARNING ---  Because the DBUG_ENTER macro allocates space on
  99.  *    the user function's stack, it must precede any executable
  100.  *    statements in the user function.
  101.  *
  102.  */
  103.  
  104. # ifndef DBUG
  105. #    define DBUG_ENTER(a1)
  106. #    define DBUG_RETURN(a1) return(a1)
  107. #    define DBUG_VOID_RETURN return
  108. #    define DBUG_EXECUTE(keyword,a1)
  109. #    define DBUG_PRINT(keyword,arglist)
  110. #    define DBUG_2(keyword,format)        /* Obsolete */
  111. #    define DBUG_3(keyword,format,a1)        /* Obsolete */
  112. #    define DBUG_4(keyword,format,a1,a2)    /* Obsolete */
  113. #    define DBUG_5(keyword,format,a1,a2,a3)    /* Obsolete */
  114. #    define DBUG_PUSH_ENV(a1)
  115. #    define DBUG_PUSH(a1)
  116. #    define DBUG_POP()
  117. #    define DBUG_PROCESS(a1)
  118. #    define DBUG_FILE (stderr)
  119. #    define DBUG_SETJMP setjmp
  120. #    define DBUG_LONGJMP longjmp
  121. # else
  122. #    define DBUG_ENTER(a) \
  123.     auto char *_db_func_; auto char *_db_file_; auto int _db_level_; \
  124.     auto char **_db_framep_; \
  125.     _db_enter_ (a,__FILE__,__LINE__,&_db_func_,&_db_file_,&_db_level_, \
  126.             &_db_framep_)
  127. #    define DBUG_LEAVE \
  128.     (_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_))
  129. #    define DBUG_RETURN(a1) return (DBUG_LEAVE, (a1))
  130. /*   define DBUG_RETURN(a1) {DBUG_LEAVE; return(a1);}  Alternate form */
  131. #    define DBUG_VOID_RETURN {DBUG_LEAVE; return;}
  132. #    define DBUG_EXECUTE(keyword,a1) \
  133.     {if (_db_on_) {if (_db_keyword_ (keyword)) { a1 }}}
  134. #    define DBUG_PRINT(keyword,arglist) \
  135.     {if (_db_on_) {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;}}
  136. #    define DBUG_2(keyword,format) \
  137.     DBUG_PRINT(keyword,(format))        /* Obsolete */
  138. #    define DBUG_3(keyword,format,a1) \
  139.     DBUG_PRINT(keyword,(format,a1))        /* Obsolete */
  140. #    define DBUG_4(keyword,format,a1,a2) \
  141.     DBUG_PRINT(keyword,(format,a1,a2))    /* Obsolete */
  142. #    define DBUG_5(keyword,format,a1,a2,a3) \
  143.     DBUG_PRINT(keyword,(format,a1,a2,a3))    /* Obsolete */
  144. #    define DBUG_PUSH_ENV(a1) {extern char *getenv(); if (getenv(a1)) DBUG_PUSH(getenv(a1));}
  145. #    define DBUG_PUSH(a1) _db_push_ (a1)
  146. #    define DBUG_POP() _db_pop_ ()
  147. #    define DBUG_PROCESS(a1) (_db_process_ = a1)
  148. #    define DBUG_FILE (_db_fp_)
  149. #    define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
  150. #    define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
  151. # endif
  152.