	Printing debugging information

	The [[debug()]] function accepts a [[printf]]-style variable
	length argument list, which it prints on [[stderr]], but only
	if the preprocessor symbol [[DEBUG]] is defined. If not, the
	routine reduces to nothing (that is, if the compiler optimizes
	empty functions away).

<<*>>=
#include <config.h>

#ifndef DEBUG
#define debug if (0)
EXPORTDEF(debug)
#define debug0 if (0)
EXPORTDEF(debug0)
#define enter if (0)
EXPORTDEF(enter)
#define leave if (0)
EXPORTDEF(leave)
#else /* DEBUG */


#define INDENT 2

static int indent = 0;

EXPORT void debug(char *format,...)
{
    int i;
    va_list args;
    va_start(args, format);
    for (i = 0; i < indent; i++) putc(' ', stderr);
    vfprintf(stderr, format, args);
    va_end(args);
}

EXPORT void debug0(char *format,...)
{
    va_list args;
    va_start(args, format);
    vfprintf(stderr, format, args);
    va_end(args);
}

EXPORT void enter(char *format,...)
{
    int i;
    va_list args;
    va_start(args, format);
    for (i = 0; i < indent; i++) putc(' ', stderr);
    fprintf(stderr, "> ");
    vfprintf(stderr, format, args);
    indent += INDENT;
    va_end(args);
}

EXPORT void leave(char *format,...)
{
    int i;
    va_list args;
    va_start(args, format);
    indent -= INDENT;
    for (i = 0; i < indent; i++) putc(' ', stderr);
    fprintf(stderr, "< ");
    vfprintf(stderr, format, args);
    va_end(args);
}

#endif /* DEBUG */
