util.c (559B)
1 2 #include "util.h" 3 4 #include <stdio.h> 5 6 #define max(a,b) ((a) > (b) ? (a) : (b)) 7 void print_around(struct cursor *cur, int range) 8 { 9 unsigned char *c; 10 11 c = max(cur->p - range, cur->start); 12 for (; c < cur->end && c < (cur->p + range); c++) { 13 if (*c < 32) 14 printf("%02x", *c); 15 else 16 printf("%c", *c); 17 } 18 printf("\n"); 19 20 c = max(cur->p - range, cur->start); 21 for (; c < cur->end && c < (cur->p + range); c++) { 22 if (c == cur->p) { 23 printf("^"); 24 continue; 25 } 26 if (*c < 32) 27 printf(" "); 28 else 29 printf(" "); 30 } 31 printf("\n"); 32 } 33 #undef max