From 74bedb5e3a736f745ac63dc31db6fbb5dd62d329 Mon Sep 17 00:00:00 2001 From: SuperNovaa41 Date: Wed, 12 Feb 2025 12:59:04 -0500 Subject: [PATCH] adds offset flag --- src/hex.c | 4 +++- src/include/hex.h | 2 ++ src/main.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hex.c b/src/hex.c index f90d480..b9e0748 100644 --- a/src/hex.c +++ b/src/hex.c @@ -16,6 +16,8 @@ void init_flags(struct flags* flags) flags->customcols = false; flags->coloured = true; + flags->offset = 0; + flags->octets = 2; flags->len = -1; // -1 means til EOF flags->uppercase = false; @@ -154,7 +156,7 @@ static void c_output(char** text, FILE* stream) void display_hex_chunk(hex_chunk_t* chunk, FILE* stream) { if (!flags.postscript && !flags.c_style) - write_offset(chunk->line * flags.cols, stream); + write_offset((chunk->line * flags.cols) + flags.offset, stream); if (flags.c_style) c_output(&(chunk->hex), stream); diff --git a/src/include/hex.h b/src/include/hex.h index 0438ae1..64da916 100644 --- a/src/include/hex.h +++ b/src/include/hex.h @@ -26,6 +26,8 @@ struct flags { uint cols; // choose the amount of columns to display (default 16) // done bool customcols; + + uint offset; uint octets; // number of octets per line (default 2) // done int len; // max len to stop at //done diff --git a/src/main.c b/src/main.c index a1a5a4b..c871d5a 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ static struct argp_option options[] = { {0, 'i', 0, 0, "output in C include file style.", 0}, {0, 'C', 0, 0, "capitalize variable names in C include file style (-i).", 0}, {0, 'n', "name", 0, "set the variable name used in C include output (-i).", 0}, + {0, 'o', "off", 0, "add to the displayed file position.", 0}, {0} }; @@ -42,6 +43,9 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state) case 'g': flags->octets = atoi(arg); break; + case 'o': + flags->offset = atoi(arg); + break; case 'R': if (strcmp(arg, "none") == 0) flags->coloured = false;