implements decimal offset
This commit is contained in:
parent
e8326d0e9b
commit
c6474c801b
13
src/hex.c
13
src/hex.c
@ -12,10 +12,10 @@ void init_flags(struct flags* flags)
|
|||||||
flags->autoskip = false;
|
flags->autoskip = false;
|
||||||
flags->binary = false;
|
flags->binary = false;
|
||||||
flags->cols = 16;
|
flags->cols = 16;
|
||||||
flags->octets = 4;
|
flags->octets = 2;
|
||||||
flags->len = -1; // -1 means til EOF
|
flags->len = -1; // -1 means til EOF
|
||||||
flags->uppercase = false;
|
flags->uppercase = false;
|
||||||
flags->decimaloffset = false;
|
flags->decimaloffset = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +51,12 @@ void display_hex_chunk(hex_chunk_t* chunk, FILE* stream)
|
|||||||
{
|
{
|
||||||
uint i, j;
|
uint i, j;
|
||||||
bool newline;
|
bool newline;
|
||||||
|
if (flags.decimaloffset)
|
||||||
|
fprintf(stream, "%08d", chunk->line * flags.cols);
|
||||||
|
else
|
||||||
|
fprintf(stream, "%08x", chunk->line * flags.cols);
|
||||||
|
fprintf(stream, ": %s", GREEN_TEXT_STR);
|
||||||
|
|
||||||
fprintf(stream, "%08x: %s", chunk->line * flags.cols, GREEN_TEXT_STR);
|
|
||||||
newline = false;
|
newline = false;
|
||||||
for (i = 0; i < (flags.cols * 2); i += (flags.octets * 2)) {
|
for (i = 0; i < (flags.cols * 2); i += (flags.octets * 2)) {
|
||||||
for (j = 0; j < (flags.octets * 2); j += 2) {
|
for (j = 0; j < (flags.octets * 2); j += 2) {
|
||||||
@ -60,7 +64,8 @@ void display_hex_chunk(hex_chunk_t* chunk, FILE* stream)
|
|||||||
((chunk->hex + i) + j)[1] == 'a')
|
((chunk->hex + i) + j)[1] == 'a')
|
||||||
newline = true;
|
newline = true;
|
||||||
|
|
||||||
fprintf(stream, "%s%2.2s%s", (newline ? YELLOW_TEXT_STR : ""), chunk->hex + i + j, (newline ? GREEN_TEXT_STR : ""));
|
fprintf(stream, "%s%2.2s%s", (newline ? YELLOW_TEXT_STR : ""),
|
||||||
|
chunk->hex + i + j, (newline ? GREEN_TEXT_STR : ""));
|
||||||
|
|
||||||
}
|
}
|
||||||
fprintf(stream, " ");
|
fprintf(stream, " ");
|
||||||
|
@ -26,7 +26,7 @@ struct flags {
|
|||||||
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
|
||||||
bool uppercase; // do uppercase hex chars // done
|
bool uppercase; // do uppercase hex chars // done
|
||||||
bool decimaloffset; // do decimal offset instead of hex
|
bool decimaloffset; // do decimal offset instead of hex // done
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: implement flags and stuff
|
// TODO: implement flags and stuff
|
||||||
|
Loading…
x
Reference in New Issue
Block a user