From e3c88052609d8dce8908bffa4e1f1625d655443b Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Thu, 15 Jan 2015 14:36:19 +0800 Subject: [PATCH] Unify macro debugging code in eval and exec. --- eval.c | 95 +++++++++++++++++++++++++++------------------------------- eval.h | 5 ++-- exec.c | 62 ++++++++------------------------------ 3 files changed, 58 insertions(+), 104 deletions(-) diff --git a/eval.c b/eval.c index de88f0f..944259a 100644 --- a/eval.c +++ b/eval.c @@ -50,11 +50,6 @@ static int gettyp( char *token) ; -#if DEBUGM -/* vars needed for macro debugging output */ -char outline[ NSTRING] ; /* global string to hold debug line text */ -#endif - /* Emacs global flag bit definitions (for gflags). */ /* if GFREAD is set, current buffer will be set on first file (read in) */ #define GFREAD 1 @@ -791,58 +786,56 @@ int setvar(int f, int n) /* if $debug == TRUE, every assignment will echo a statment to that effect here. */ - if (macbug) { - char *sp ; /* temp string pointer */ - - strcpy(outline, "((("); - - /* assignment status */ - strcat(outline, ltos(status)); - strcat(outline, ":"); - - /* variable name */ - strcat(outline, var); - strcat(outline, ":"); - - /* and lastly the value we tried to assign */ - strcat(outline, value); - strcat(outline, ")))"); - - /* expand '%' to "%%" so mlwrite wont bitch */ - sp = outline; - while (*sp) - if (*sp++ == '%') { - char *ep ; /* ptr to end of outline */ - - /* advance to the end */ - ep = --sp; - while (*ep++); - /* null terminate the string one out */ - *(ep + 1) = 0; - /* copy backwards */ - while (ep-- > sp) - *(ep + 1) = *ep; - - /* and advance sp past the new % */ - sp += 2; - } - - /* write out the debug line */ - mlforce(outline); - update(TRUE); - - /* and get the keystroke to hold the output */ - if (get1key() == abortc) { - mlforce("(Macro aborted)"); - status = FALSE; - } - } + if( macbug) + if( abortc == mdbugout( "(((%s:%s:%s)))", ltos( status), var, value)) + status = FALSE ; #endif /* and return it */ return status; } +#if DEBUGM +int mdbugout( char *fmt, char *s1, char *s2, char *s3) { + char outline[ NSTRING] ; /* global string to hold debug line text */ + int c ; /* input from kbd */ + char *sp ; /* temp string pointer */ + + /* assignment status ; variable name ; value we tried to assign */ + sprintf( outline, fmt, s1, s2, s3) ; + + /* expand '%' to "%%" so mlwrite wont bitch */ + sp = outline; + while (*sp) + if (*sp++ == '%') { + char *ep ; /* ptr to end of outline */ + + /* advance to the end */ + ep = --sp; + while (*ep++); + /* null terminate the string one out */ + *(ep + 1) = 0; + /* copy backwards */ + while (ep-- > sp) + *(ep + 1) = *ep; + + /* and advance sp past the new % */ + sp += 2; + } + + /* write out the debug line */ + mlforce(outline); + update(TRUE); + + /* and get the keystroke to hold the output */ + c = get1key() ; + if( c == abortc) + mlforce("(Macro aborted)"); + + return c ; +} +#endif + /* * Find a variables type and name. * diff --git a/eval.h b/eval.h index 38a0861..1778061 100644 --- a/eval.h +++ b/eval.h @@ -4,12 +4,11 @@ #define DEBUGM 1 /* $debug triggers macro debugging */ - #if DEBUGM -/* Vars needed for macro debugging output. */ -extern char outline[] ; /* Global string to hold debug line text. */ +int mdbugout( char *fmt, char *s1, char *s2, char *s3) ; #endif + extern int macbug ; /* macro debuging flag */ extern int cmdstatus ; /* last command status */ extern int flickcode ; /* do flicker supression? */ diff --git a/exec.c b/exec.c index 2c12675..e2be224 100644 --- a/exec.c +++ b/exec.c @@ -632,56 +632,18 @@ static int dobuf(struct buffer *bp) gets echoed and a key needs to be pressed to continue ^G will abort the command */ - if (macbug) { - char *sp ; /* temp for building debug string */ - int c ; /* temp character */ - - strcpy(outline, "<<<"); - - /* debug macro name */ - strcat(outline, bp->b_bname); - strcat(outline, ":"); - - /* debug if levels */ - strcat(outline, i_to_a(execlevel)); - strcat(outline, ":"); - - /* and lastly the line */ - strcat(outline, eline); - strcat(outline, ">>>"); - - /* change all '%' to ':' so mlwrite won't expect arguments */ - sp = outline; - while (*sp) - if (*sp++ == '%') { - char *ep ; /* ptr to end of outline */ - - /* advance to the end */ - ep = --sp; - while (*ep++); - /* null terminate the string one out */ - *(ep + 1) = 0; - /* copy backwards */ - while (ep-- > sp) - *(ep + 1) = *ep; - - /* and advance sp past the new % */ - sp += 2; - } - - /* write out the debug line */ - mlforce(outline); - update(TRUE); - - /* and get the keystroke */ - if ((c = get1key()) == abortc) { - mlforce("(Macro aborted)"); - freewhile(whlist); - return FALSE; - } - - if (c == metac) - macbug = FALSE; + if( macbug) { + int c ; + + /* debug macro name, if levels and lastly the line */ + c = mdbugout( "<<<%s:%s:%s>>>", bp->b_bname, i_to_a( execlevel), + eline) ; + if( c == abortc) { + freewhile( whlist) ; + return FALSE ; + } else if( c == metac) { + macbug = FALSE ; + } } #endif