diff options
author | June McEnroe <curtis.mcenroe@adgear.com> | 2016-09-12 15:09:35 -0400 |
---|---|---|
committer | June McEnroe <curtis.mcenroe@adgear.com> | 2016-09-12 15:09:35 -0400 |
commit | 8d756c5a20512b34bedf53398e92571e92020230 (patch) | |
tree | 0842f9c52e13ca7fd1ca67a78f61c52f56b8b3cf | |
parent | Add -g option to xx (diff) | |
download | src-8d756c5a20512b34bedf53398e92571e92020230.tar.gz src-8d756c5a20512b34bedf53398e92571e92020230.zip |
Add -o flag to xx
Diffstat (limited to '')
-rwxr-xr-x | .bin/xx.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/.bin/xx.c b/.bin/xx.c index 3aac12f6..f0bc15af 100755 --- a/.bin/xx.c +++ b/.bin/xx.c @@ -7,18 +7,25 @@ exec cc -Weverything -Wno-vla -o ~/.bin/xx $0 #include <stdlib.h> #include <unistd.h> +enum { + OFFSETS = 1, +}; + int main(int argc, char **argv) { size_t cols = 16; size_t group = 8; + uint8_t flags = OFFSETS; char *path = NULL; - while (getopt(argc, argv, "c:g:") > 0) + while (getopt(argc, argv, "c:g:o") > 0) if (optopt == 'c') { cols = (size_t) strtol(optarg, NULL, 10); if (!cols) return EXIT_FAILURE; } else if (optopt == 'g') { group = (size_t) strtol(optarg, NULL, 10); + } else if (optopt == 'o') { + flags ^= OFFSETS; } else return EXIT_FAILURE; if (argc > optind) path = argv[optind]; @@ -30,15 +37,19 @@ int main(int argc, char **argv) } uint8_t buf[cols]; + size_t offset = 0, n, i; for (;;) { - size_t n = fread(buf, 1, sizeof(buf), file); + n = fread(buf, 1, sizeof(buf), file); - for (size_t i = 0; i < n; ++i) { + if (flags & OFFSETS) + printf("%08zx: ", offset); + for (i = 0; i < n; ++i) { if (group && i && !(i % group)) printf(" "); printf("%02x ", buf[i]); } printf("\n"); + offset += n; if (n < sizeof(buf)) break; } if (ferror(file)) { |