diff options
author | B. Watson <urchlay@slackware.uk> | 2024-12-12 16:46:35 -0500 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-12-12 16:48:20 -0500 |
commit | 343fd43b95960f59a3bf901f59503757b81a5592 (patch) | |
tree | 6654e44cb883739cffbab0a7753b106f8d5c5360 /uxd.c | |
parent | e5735eacb8a55c147c7829c3bc9f2dfea895b165 (diff) | |
download | uxd-343fd43b95960f59a3bf901f59503757b81a5592.tar.gz |
fix Makefile, dashes in hex dump, red for codepoints > U+10FFFF, fix spacing.
Diffstat (limited to 'uxd.c')
-rw-r--r-- | uxd.c | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -135,6 +135,7 @@ void print_line(void) { /* line up the rightmost field (human-readable) */ while(spacing--) printf(" "); + if(dump_column < (MAX_DUMP_COLS / 2)) putchar(' '); printf(" %s\n", right_buf); @@ -178,12 +179,21 @@ void append_left(unsigned char byte, int dash, int fgcolor, int bgcolor) { append_color(left_buf, fgcolor, bgcolor); sprintf(tmpbuf, "%02x", byte); strcat(left_buf, tmpbuf); - if(dash) strcat(left_buf, "-"); - append_color_off(left_buf); - if(!dash) strcat(left_buf, " "); - if(dump_column == 7) strcat(left_buf, " "); dump_column++; + + if(dash) { + strcat(left_buf, "-"); + if(dump_column == (MAX_DUMP_COLS / 2)) + strcat(left_buf, "-"); + append_color_off(left_buf); + } else { + append_color_off(left_buf); + strcat(left_buf, " "); + if(dump_column == (MAX_DUMP_COLS / 2)) + strcat(left_buf, " "); + } + if(dump_column == MAX_DUMP_COLS) print_line(); @@ -208,6 +218,14 @@ int is_bom(unsigned char *b) { return (b[0] == 0xef && b[1] == 0xbb && b[2] == 0xbf); } +/* U+10FFFF is the last valid codepoint. It encodes to f4 8f bf bf. */ +int is_out_of_range(int count, unsigned char *b) { + if(count < 3) return 0; + if(b[0] < 0xf4) return 0; + if(b[1] < 0x90) return 0; + return 1; +} + /* return value: false = EOF, true = more data to read */ int dump_utf8_char(void) { unsigned char bytes[] = { 0, 0, 0, 0, 0 }; @@ -265,6 +283,9 @@ int dump_utf8_char(void) { } } + if(is_out_of_range(cont_count, bytes)) + bad = 1; + if(bad) { fg = BAD_FG; bg = BAD_BG; |