adds offset flag

This commit is contained in:
SuperNovaa41 2025-02-12 12:59:04 -05:00
parent 4b00322be0
commit 74bedb5e3a
3 changed files with 9 additions and 1 deletions

View File

@ -16,6 +16,8 @@ void init_flags(struct flags* flags)
flags->customcols = false; flags->customcols = false;
flags->coloured = true; flags->coloured = true;
flags->offset = 0;
flags->octets = 2; flags->octets = 2;
flags->len = -1; // -1 means til EOF flags->len = -1; // -1 means til EOF
flags->uppercase = false; 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) void display_hex_chunk(hex_chunk_t* chunk, FILE* stream)
{ {
if (!flags.postscript && !flags.c_style) 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) if (flags.c_style)
c_output(&(chunk->hex), stream); c_output(&(chunk->hex), stream);

View File

@ -26,6 +26,8 @@ struct flags {
uint cols; // choose the amount of columns to display (default 16) // done uint cols; // choose the amount of columns to display (default 16) // done
bool customcols; bool customcols;
uint offset;
uint octets; // number of octets per line (default 2) // done uint octets; // number of octets per line (default 2) // done
int len; // max len to stop at //done int len; // max len to stop at //done

View File

@ -22,6 +22,7 @@ static struct argp_option options[] = {
{0, 'i', 0, 0, "output in C include file style.", 0}, {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, '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, 'n', "name", 0, "set the variable name used in C include output (-i).", 0},
{0, 'o', "off", 0, "add <off> to the displayed file position.", 0},
{0} {0}
}; };
@ -42,6 +43,9 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state)
case 'g': case 'g':
flags->octets = atoi(arg); flags->octets = atoi(arg);
break; break;
case 'o':
flags->offset = atoi(arg);
break;
case 'R': case 'R':
if (strcmp(arg, "none") == 0) if (strcmp(arg, "none") == 0)
flags->coloured = false; flags->coloured = false;