debug.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
949N/A#pragma prototyped
949N/A#ifndef DEBUG
949N/A
949N/Aint _STUB_debug; /* Some compilers require a statement in the file */
949N/A
949N/A#else
949N/A
949N/A#include "tkshlib.h"
949N/A#include <ast.h>
949N/A
949N/Astatic int debugLevel, debugInitialized;
949N/Astatic void dinit(void);
949N/Astatic void printState(char *file, int line);
949N/Astatic Sfio_t *outFile;
949N/Astatic Interp *debugInterp;
949N/A
1176N/Aint __dprintfLevel()
949N/A{
949N/A return debugLevel;
949N/A}
949N/A
1176N/Avoid __dprintfInterp(Tcl_Interp *interp)
949N/A{
949N/A debugInterp = (Interp *) interp;
949N/A}
1176N/A
1176N/Aint __dprintfOK(char *file, int line, int level)
1176N/A{
949N/A if (!debugInitialized)
949N/A dinit();
949N/A if (debugLevel < level)
949N/A return 0;
949N/A printState(file, line);
1176N/A return 1;
1176N/A}
1176N/A
949N/Avoid __dprintf(char *format, char *a1, char *a2, char *a3, char *a4,
949N/A char *a5, char *a6, char *a7, char *a8, char *a9, char *a10)
949N/A{
949N/A sfprintf(outFile, format, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);
949N/A}
1176N/A
1176N/Avoid __dprintfNum(char *before, int num, char *after)
1176N/A{
949N/A sfprintf(outFile, "%s%d%s", before,num,after);
949N/A}
949N/A
949N/Avoid __dprintfArgs(char *string, int argc, char *argv[])
949N/A{
1176N/A int arg;
1176N/A sfprintf(outFile, string);
1176N/A if (argc)
949N/A {
949N/A for (arg=0; arg < argc; arg++)
949N/A sfprintf(outFile, " <%.10s>", argv[arg]);
949N/A }
949N/A else
949N/A {
949N/A for (arg=0; argv[arg]; arg++)
949N/A sfprintf(outFile, " <%.10s>", argv[arg]);
949N/A }
949N/A sfprintf(outFile, "\n");
1176N/A}
1176N/A
1176N/Astatic void dinit()
949N/A{
949N/A char *lev;
949N/A
949N/A debugInitialized = 1;
949N/A if ((lev = getenv("JDEBUG")))
1176N/A {
1176N/A debugLevel = atoi(lev);
1176N/A if (debugLevel == 0)
949N/A debugLevel = 1;
949N/A /* outFile = sfopen(NIL(Sfio_t *), "goober", "w+"); */
949N/A outFile = sfstderr;
949N/A sfprintf(outFile,"Debug routines initialized,compiled %s %s\n",
949N/A __DATE__, __TIME__);
1176N/A }
1176N/A}
1176N/A
949N/Astatic void printState(char *file, int line)
949N/A{
949N/A sfprintf(outFile, "[%s]%s:%d: ",
949N/A Tksh_InterpString(debugInterp->interpType), file, line);
949N/A}
1176N/A
1176N/A
1176N/A#endif
949N/A