From a5dda0b0c5a2135ffa371a4929350853cb5be0c7 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 31 Oct 2021 02:05:45 +0200 Subject: [PATCH] hexdump: Make non-ASCII output easier to read Enclose the ASCII-interpretation in pipes, show non-ASCII bytes as a dot, and fix the length of the last line. Note that this makes it more similar to the behavior of many other implementations. --- Userland/Utilities/hexdump.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/hexdump.cpp b/Userland/Utilities/hexdump.cpp index f817d20b59..53f493d8f2 100644 --- a/Userland/Utilities/hexdump.cpp +++ b/Userland/Utilities/hexdump.cpp @@ -45,15 +45,16 @@ int main(int argc, char** argv) out(" "); } - out(" "); + out(" |"); - for (size_t i = 0; i < 16; ++i) { - if (i < line.size() && isprint(line[i])) + for (size_t i = 0; i < line.size(); ++i) { + if (isprint(line[i])) putchar(line[i]); else - putchar(' '); + putchar('.'); } + putchar('|'); putchar('\n'); };