[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Proposal: /etc /usr/etc /usr/local/etc



Hi,
>>"Vadim" == Vadim Vygonets <vadik@cs.huji.ac.il> writes:

Vadim>  But putting { } (blocks) in a macro isn't possible, as far as
Vadim>  I know.  We need { } anyway, regardles of wether we use malloc.

	Oh, pish. Here's an excerpt from my basic Debugging
 header. Look at the begin and end blocks.

	manoj

/*
 * Macros are dangerous if they use an  if--then--else control statement,
 * because  they may  be  used in  an   if--then--else control  statement
 * themselsves, and should be enclosed  in the following block to prevent
 * problems (like dangling else statements).
 */

#ifdef BEGIN_BLOCK
#undef BEGIN_BLOCK
#endif /*  BEGIN_BLOCK */
#ifdef END_BLOCK
#undef END_BLOCK
#endif /* END_BLOCK */

#define BEGIN_BLOCK do {
#define END_BLOCK  } while (0)

/* Debugging */

/*
 * DEBUGMASK provides explicit control over which debug  levels are to be
 * turned on, ie, DEBUGMASK = 0xFFFFFFFFL gives 32 DEBUG levels (all on);
 * DEBUGMASK =  0x00000001L  turns  on  level  1, DEBUGMASK = 0x00000009L
 * turns on level 1 and 4, and so on.
 */

#ifndef DEBUGMASK
#       define DEBUGMASK 0xFFFFFFFFL    /* 32 DEBUG levels (all on) */
#else
#       ifndef DEBUG
#               define DEBUG 1  /* default level, in case the user did */
                                /* not turn it on*/
#       endif
#endif

/* DEBUG takes integral values >= 0 */
#ifdef DEBUG

#define MAX_DEBUGLEVEL 32

/*
 * A drop in replacement for assert.h
 */

#define ASSERT(expr)\
BEGIN_BLOCK     \
   if(!(expr)) /* so assert is false*/ \
     {\
      fprintf(stderr,(char *)"------------------------------------------\n");\
       fprintf (stderr, (char *)"D %s(%d):\n\tAssert failed, %s\n", __FILE__,\
               __LINE__, #expr);\
       exit (33); /* a nice , non standard value*/ \
     }\
END_BLOCK


 /* Macro to print debug messages. example pargs is
  * (stderr, "%s", "abcd"). Level takes values 1 to 32
  * All messages at or below level DEBUG are suppressed. Assigning
  * a high value for DEBUG ( = 32 ) can suppress all the messages.
  */
#define DEBUGMSG(level, pargs) \
  BEGIN_BLOCK \
  if (level && (level >= DEBUG) && (DEBUGMASK & \
      (unsigned long int)(level <MAX_DEBUGLEVEL ? 1 << (level - 1): \
           1 << (level % MAX_DEBUGLEVEL)))) \
    fprintf pargs; \
  END_BLOCK

#define DEBUGN(level,pargs) \
BEGIN_BLOCK\
  if(level && (level >= DEBUG && (DEBUGMASK &  \
      (unsigned long int)(level <MAX_DEBUGLEVEL ? 1 << (level - 1): \
           1 << (level % MAX_DEBUGLEVEL))))) \
       {\
          /* that is, this is a a valid debug statement */ \
      fprintf(stderr,(char *)"------------------------------------------\n");\
          fprintf(stderr,(char *)"D %s(%d):[%d]\n\t", __FILE__,__LINE__,level);\
          fprintf pargs;\
          fprintf(stderr,(char *)"\n");\
        }\
END_BLOCK



#define DEBUG0(level,str) DEBUGN(level, (stderr,str))
#define DEBUG1(level,str,a1) DEBUGN(level, (stderr,str,a1))
#define DEBUG2(level,str,a1,a2) DEBUGN(level, (stderr,str,a1,a2))
#define DEBUG3(level,str,a1,a2,a3) DEBUGN(level, (stderr,str,a1,a2,a3))
#define DEBUG4(level,str,a1,a2,a3,a4) DEBUGN(level, (stderr,str,a1,a2,a3,a4))
#define DEBUG5(level,str,a1,a2,a3,a4,a5) \
     DEBUGN(level, (stderr,str,a1,a2,a3,a4,a5))
#else /* DEBUG not defined */
#define DEBUGMSG(level, pargs)
#ifdef DEBUGMASK
#       undef  DEBUGMASK
#       define DEBUGMASK        /* remove the definition */
#endif /* DEBUGMASK */
#define ASSERT(expr)
#define DEBUG0(level,s)
#define DEBUG1(level,s,a1)
#define DEBUG2(level,s,a1,a2)
#define DEBUG3(level,s,a1,a2,a3)
#define DEBUG4(level,s,a1,a2,a3,a4)
#define DEBUG5(level,s,a1,a2,a3,a4,a5)
#define DEBUGN(level,pargs)
#endif /* DEBUG */



-- 
 Monty Python "In accordance with our principles of free enterprise
 and healthy competition, I'm going to ask you two to fight to the
 death for it."
Manoj Srivastava               <url:mailto:srivasta@acm.org>
Mobile, Alabama USA            <url:http://www.datasync.com/%7Esrivasta/>


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: