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.
This commit is contained in:
Ben Wiederhake 2021-10-31 02:05:45 +02:00 committed by Andreas Kling
parent 866c9cc1a5
commit a5dda0b0c5
Notes: sideshowbarker 2024-07-18 01:39:12 +09:00

View file

@ -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');
};