summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfinter.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/bfinter.c b/bfinter.c
index cf4a102..587471c 100644
--- a/bfinter.c
+++ b/bfinter.c
@@ -62,9 +62,12 @@ byte tape_get(const Tape *tape,int idx){
return tape->buf[idx];
}
-void tape_print(const Tape *tape){
+// pass curidx=-1 for no highlight
+void tape_print(const Tape *tape,int curidx){
for(int i=0;i<=tape->maxidx;i++){
+ if(i==curidx)printf("\x1B[4m");
printf("%3d ",tape->buf[i]);
+ if(i==curidx)printf("\x1B[0m");
}
putchar('\n');
}
@@ -153,7 +156,7 @@ void interpret(const char *source,const int sourcelen,const Jumpmap *jm){
case ',': tape_set(tape,mp,(byte)getchar()); break;
case '[': if(!tape_get(tape,mp))ip=jm_get(jm,ip); break;
case ']': if(tape_get(tape,mp))ip=jm_get(jm,ip); break;
- case '#': tape_print(tape); break;
+ case '#': tape_print(tape,mp); break;
case '0': tape_set(tape,mp,0); break;
case '^': ip++; tape_set(tape,mp,tape_get(tape,mp)+(byte)source[ip]); break;
@@ -378,6 +381,7 @@ int main(int argc,char **argv){
Jumpmap *jm=jm_make(source,sourcelen);
+ clearerr(stdin);
interpret(source,sourcelen,jm);
jm_destroy(jm);