diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-09-27 22:19:11 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-09-27 22:19:11 +0200 |
commit | 0bb9d719c86db457439ee8e012eb141c76eed307 (patch) | |
tree | 8bf572e09c977aef7b86446a8390b071120e75c9 | |
parent | ce00424be3963c97ef43d52e87a2da380559536c (diff) |
Add tape current cell highlight
-rw-r--r-- | bfinter.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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); |