From 343fd43b95960f59a3bf901f59503757b81a5592 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 12 Dec 2024 16:46:35 -0500 Subject: fix Makefile, dashes in hex dump, red for codepoints > U+10FFFF, fix spacing. --- uxd.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'uxd.c') diff --git a/uxd.c b/uxd.c index cff81cf..d71d6d5 100644 --- a/uxd.c +++ b/uxd.c @@ -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; -- cgit v1.2.3