From 74095ec4d92c4e70352d199447790b3fe096d4a1 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 10 Sep 2023 22:59:40 -0400 Subject: SO CLOSE --- main.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 9d762b5..69a3966 100644 --- a/main.c +++ b/main.c @@ -37,6 +37,22 @@ static void usage(int argc, char **argv, char *message, ...) { exit(1); } +static inline size_t utf8_encode(uint8_t *buf, uint16_t codepoint) { + if ((codepoint & 0x007f) == codepoint) { + buf[0] = codepoint & 0xff; + return 1; + } else if ((codepoint & 0x07ff) == codepoint) { + buf[0] = (codepoint & 0x07c0) >> 6; + buf[1] = codepoint & 0x003f; + return 2; + } else if ((codepoint & 0xffff) == codepoint) { + buf[0] = (codepoint & 0xf000) >> 12; + buf[1] = (codepoint & 0x0fc0) >> 6; + buf[2] = codepoint & 0x003f; + return 3; + } +} + static ssize_t dump_line(off_t offset, void *buf, size_t len) { size_t i; @@ -69,23 +85,15 @@ static ssize_t dump_line(off_t offset, void *buf, size_t len) { for (i=0; i> 8), - 0x80 | (printable & 0x003f) - }; - - if (fwrite(sequence, 2, 1, stdout) < 1) { - goto error_io; - } - } else { - if (putchar((uint8_t)(printable & 0x00ff)) < 0) { - goto error_io; - } + if (fwrite(sequence, len, 1, stdout) < 1) { + goto error_io; } } else { if (putchar('.') < 0) { -- cgit v1.2.3