aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-01-17 14:00:02 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2017-01-17 14:13:57 +0100
commitd2aed617839fe03df68039fd6fb31767be1e8cae (patch)
treea781d490af8d538496833c673da8da553fa7de79
parent1c3a1172d317e7040e951013fc25f51126ef0d04 (diff)
downloadhex-d2aed617839fe03df68039fd6fb31767be1e8cae.tar.gz
hex-d2aed617839fe03df68039fd6fb31767be1e8cae.tar.xz
hex-d2aed617839fe03df68039fd6fb31767be1e8cae.zip
Make app_decode() more functional
-rw-r--r--hex.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/hex.c b/hex.c
index 96a6ffe..a5c08cf 100644
--- a/hex.c
+++ b/hex.c
@@ -419,10 +419,10 @@ app_draw_view (void)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static uint64_t
-app_decode (const uint8_t *p, size_t len)
+app_decode (const uint8_t *p, size_t len, enum endianity endianity)
{
uint64_t val = 0;
- if (g_ctx.endianity == ENDIANITY_BE)
+ if (endianity == ENDIANITY_BE)
for (size_t i = 0; i < len; i++)
val = val << 8 | (uint64_t) p[i];
else
@@ -528,21 +528,21 @@ app_draw_footer (void)
}
if (len >= 2)
{
- uint16_t val = app_decode (p, 2);
+ uint16_t val = app_decode (p, 2, g_ctx.endianity);
app_footer_field (&x, 'x', 2, " %04x ", val);
app_footer_field (&u, 'u', 2, " %6u ", val);
app_footer_field (&s, 's', 2, " %6d ", (int16_t) val);
}
if (len >= 4)
{
- uint32_t val = app_decode (p, 4);
+ uint32_t val = app_decode (p, 4, g_ctx.endianity);
app_footer_field (&x, 'x', 4, " %08x ", val);
app_footer_field (&u, 'u', 4, " %11u ", val);
app_footer_field (&s, 's', 4, " %11d ", (int32_t) val);
}
if (len >= 8)
{
- uint64_t val = app_decode (p, 8);
+ uint64_t val = app_decode (p, 8, g_ctx.endianity);
app_footer_field (&x, 'x', 8, " %016" PRIx64, val);
app_footer_field (&u, 'u', 8, " %20" PRIu64, val);
app_footer_field (&s, 's', 8, " %20" PRId64, (int64_t) val);