Unify macro debugging code in eval and exec.

This commit is contained in:
Renaud 2015-01-15 14:36:19 +08:00
parent 259de639e4
commit e3c8805260
3 changed files with 58 additions and 104 deletions

95
eval.c
View File

@ -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.
*

5
eval.h
View File

@ -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? */

62
exec.c
View File

@ -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