Slight reorganisation
This commit is contained in:
parent
7b71a6dfc1
commit
5bc8a00f02
1 changed files with 12 additions and 11 deletions
23
main.c
23
main.c
|
@ -9,15 +9,10 @@
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#define ZX_DUMP_STRIDE_LINE 16
|
#define ZX_CHARSET_LEN 64
|
||||||
#define ZX_DUMP_STRIDE_GROUP 2
|
|
||||||
#define ZX_DUMP_CHARSET_LEN 64
|
|
||||||
|
|
||||||
#define ZX_DUMP_FLAGS_NONE 0
|
|
||||||
#define ZX_DUMP_FLAGS_BASIC (1 << 0)
|
|
||||||
|
|
||||||
#define ZX_CHAR_LOW(c) \
|
#define ZX_CHAR_LOW(c) \
|
||||||
(c <= ZX_DUMP_CHARSET_LEN)
|
(c <= ZX_CHARSET_LEN)
|
||||||
|
|
||||||
#define ZX_CHAR_INVERSE_START 0x80
|
#define ZX_CHAR_INVERSE_START 0x80
|
||||||
#define ZX_CHAR_INVERSE_END 0xbf
|
#define ZX_CHAR_INVERSE_END 0xbf
|
||||||
|
@ -56,7 +51,7 @@ typedef struct _zx_basic_line {
|
||||||
#define ZX_BASIC_STATE_SIZE 116
|
#define ZX_BASIC_STATE_SIZE 116
|
||||||
#define ZX_BASIC_LINE_LAST 0x7676
|
#define ZX_BASIC_LINE_LAST 0x7676
|
||||||
|
|
||||||
static uint32_t zx_charset[ZX_DUMP_CHARSET_LEN] = {
|
static uint32_t zx_charset[ZX_CHARSET_LEN] = {
|
||||||
0x0020, 0x2598, 0x259d, 0x2580, 0x2596, 0x258c, 0x259e, 0x259b,
|
0x0020, 0x2598, 0x259d, 0x2580, 0x2596, 0x258c, 0x259e, 0x259b,
|
||||||
0x2592, '.', '.', '"', 0x00a3, '$', ':', '?',
|
0x2592, '.', '.', '"', 0x00a3, '$', ':', '?',
|
||||||
'(', ')', '>', '<', '=', '+', '-', '*',
|
'(', ')', '>', '<', '=', '+', '-', '*',
|
||||||
|
@ -134,6 +129,9 @@ error_io:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ZX_HEXDUMP_STRIDE_LINE 16
|
||||||
|
#define ZX_HEXDUMP_STRIDE_GROUP 2
|
||||||
|
|
||||||
static ssize_t hexdump_line(off_t offset, void *buf, size_t len, int tty) {
|
static ssize_t hexdump_line(off_t offset, void *buf, size_t len, int tty) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
@ -142,7 +140,7 @@ static ssize_t hexdump_line(off_t offset, void *buf, size_t len, int tty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<len; i++) {
|
for (i=0; i<len; i++) {
|
||||||
if (i > 0 && (i % ZX_DUMP_STRIDE_GROUP) == 0) {
|
if (i > 0 && (i % ZX_HEXDUMP_STRIDE_GROUP) == 0) {
|
||||||
if (putchar(' ') < 0) {
|
if (putchar(' ') < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
|
@ -209,9 +207,9 @@ static ssize_t zx_dump_hex(int fd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<len; i+=ZX_DUMP_STRIDE_LINE) {
|
for (i=0; i<len; i+=ZX_HEXDUMP_STRIDE_LINE) {
|
||||||
size_t left = len - i,
|
size_t left = len - i,
|
||||||
linesz = left < ZX_DUMP_STRIDE_LINE? left: ZX_DUMP_STRIDE_LINE;
|
linesz = left < ZX_HEXDUMP_STRIDE_LINE? left: ZX_HEXDUMP_STRIDE_LINE;
|
||||||
|
|
||||||
if (hexdump_line(offset, buf, linesz, tty) < 0) {
|
if (hexdump_line(offset, buf, linesz, tty) < 0) {
|
||||||
goto error_hexdump_line;
|
goto error_hexdump_line;
|
||||||
|
@ -347,6 +345,9 @@ static void usage(const char *prog, char *message, ...) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ZX_DUMP_FLAGS_NONE 0
|
||||||
|
#define ZX_DUMP_FLAGS_BASIC (1 << 0)
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int fd,
|
int fd,
|
||||||
flags = ZX_DUMP_FLAGS_NONE,
|
flags = ZX_DUMP_FLAGS_NONE,
|
||||||
|
|
Loading…
Add table
Reference in a new issue