From 8b4a8a933a36d841c0bd789d8624ee8f1d0aeac5 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 11 Sep 2023 19:10:48 -0400 Subject: [PATCH] A fair amount of progress! --- main.c | 115 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 30 deletions(-) diff --git a/main.c b/main.c index d6e2514..d5cc4db 100644 --- a/main.c +++ b/main.c @@ -6,17 +6,18 @@ #include #include #include +#include #include -#define ZXDUMP_STRIDE_LINE 16 -#define ZXDUMP_STRIDE_GROUP 2 -#define ZXDUMP_CHARSET_LEN 64 +#define ZX_DUMP_STRIDE_LINE 16 +#define ZX_DUMP_STRIDE_GROUP 2 +#define ZX_DUMP_CHARSET_LEN 64 -#define ZXDUMP_FLAGS_NONE 0 -#define ZXDUMP_FLAGS_BASIC (1 << 0) +#define ZX_DUMP_FLAGS_NONE 0 +#define ZX_DUMP_FLAGS_BASIC (1 << 0) #define ZX_CHAR_LOW(c) \ - (c <= ZXDUMP_CHARSET_LEN) + (c <= ZX_DUMP_CHARSET_LEN) #define ZX_CHAR_INVERSE_START 0x80 #define ZX_CHAR_INVERSE_END 0xbf @@ -30,6 +31,9 @@ #define ZX_CHAR_TOKEN_LOW(c) \ (c >= ZX_CHAR_TOKEN_LOW_START && c <= ZX_CHAR_TOKEN_LOW_END) +#define ZX_CHAR_NEWLINE(c) \ + (c == 0x76) + #define ZX_CHAR_TOKEN_HIGH_START 0xc0 #define ZX_CHAR_TOKEN_HIGH_END 0xff @@ -42,7 +46,7 @@ typedef struct _zx_basic_line { uint16_t num, len; } zx_basic_line; -static uint32_t zx_charset[ZXDUMP_CHARSET_LEN] = { +static uint32_t zx_charset[ZX_DUMP_CHARSET_LEN] = { 0x0020, 0x2598, 0x259d, 0x2580, 0x2596, 0x258c, 0x259e, 0x259b, 0x2592, '.', '.', '"', 0x00a3, '$', ':', '?', '(', ')', '>', '<', '=', '+', '-', '*', @@ -128,7 +132,7 @@ static ssize_t hexdump_line(off_t offset, void *buf, size_t len, int tty) { } for (i=0; i 0 && (i % ZXDUMP_STRIDE_GROUP) == 0) { + if (i > 0 && (i % ZX_DUMP_STRIDE_GROUP) == 0) { if (putchar(' ') < 0) { goto error_io; } @@ -171,7 +175,7 @@ error_io: return -1; } -static ssize_t hexdump_fd(int fd) { +static ssize_t zx_dump_hex(int fd) { void *buf; ssize_t total = 0; int tty = isatty(fileno(stdout)); @@ -195,9 +199,9 @@ static ssize_t hexdump_fd(int fd) { break; } - for (i=0; i