From 0525fcc61da3bbba220fbb97fb3662858c54c0a2 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 12 Sep 2016 15:20:15 -0400 Subject: Add -a flag to xx --- .bin/xx.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to '.bin') diff --git a/.bin/xx.c b/.bin/xx.c index f0bc15af..ad71ac98 100755 --- a/.bin/xx.c +++ b/.bin/xx.c @@ -2,24 +2,28 @@ exec cc -Weverything -Wno-vla -o ~/.bin/xx $0 #endif +#include #include #include #include #include enum { - OFFSETS = 1, + ASCII = 1, + OFFSETS = 2, }; int main(int argc, char **argv) { size_t cols = 16; size_t group = 8; - uint8_t flags = OFFSETS; + uint8_t flags = ASCII | OFFSETS; char *path = NULL; - while (getopt(argc, argv, "c:g:o") > 0) - if (optopt == 'c') { + while (getopt(argc, argv, "ac:g:o") > 0) + if (optopt == 'a') { + flags ^= ASCII; + } else if (optopt == 'c') { cols = (size_t) strtol(optarg, NULL, 10); if (!cols) return EXIT_FAILURE; } else if (optopt == 'g') { @@ -48,6 +52,14 @@ int main(int argc, char **argv) printf("%02x ", buf[i]); } + if (flags & ASCII) { + for (i = n; i < cols; ++i) + printf(" "); + printf(" "); + for (i = 0; i < n; ++i) + printf("%c", isprint(buf[i]) ? buf[i] : '.'); + } + printf("\n"); offset += n; if (n < sizeof(buf)) break; -- cgit 1.4.1