diff options
author | June McEnroe <june@causal.agency> | 2017-07-16 21:16:16 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2017-07-16 21:16:16 -0400 |
commit | f97dabd478d498a39b8384f72883a257949b5529 (patch) | |
tree | 53785b9ef0ae454aebaededca0c50507db88ae82 /home | |
parent | Rewrite README, create LICENSE (diff) | |
download | src-f97dabd478d498a39b8384f72883a257949b5529.tar.gz src-f97dabd478d498a39b8384f72883a257949b5529.zip |
Remove color from xx, group ASCII
Diffstat (limited to 'home')
-rwxr-xr-x | home/.bin/xx.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/home/.bin/xx.c b/home/.bin/xx.c index 1c77fcd5..78d8db4c 100755 --- a/home/.bin/xx.c +++ b/home/.bin/xx.c @@ -21,16 +21,11 @@ static bool allZero(const uint8_t *buf, size_t len) { enum { FLAG_ASCII = 1 << 0, - FLAG_COLOR = 1 << 1, - FLAG_OFFSET = 1 << 2, - FLAG_SKIP = 1 << 3, - FLAG_UNDUMP = 1 << 4, + FLAG_OFFSET = 1 << 1, + FLAG_SKIP = 1 << 2, + FLAG_UNDUMP = 1 << 3, }; -static void color(size_t i) { - printf("\x1b[%c%cm", (i % 8) ? '3' : '9', (char)(i % 8 + '0')); -} - static void dump(size_t cols, size_t group, uint8_t flags, FILE *file) { uint8_t buf[cols]; size_t offset = 0, len = 0; @@ -39,8 +34,6 @@ static void dump(size_t cols, size_t group, uint8_t flags, FILE *file) { len = fread(buf, 1, sizeof(buf), file); if (!len) break; - if (flags & FLAG_COLOR) printf("\x1b[39m"); - if ((flags & FLAG_SKIP) && len == sizeof(buf)) { static bool skip; if (allZero(buf, len)) { @@ -57,7 +50,6 @@ static void dump(size_t cols, size_t group, uint8_t flags, FILE *file) { for (size_t i = 0; i < len; ++i) { if (group && i && !(i % group)) printf(" "); - if (flags & FLAG_COLOR) color(i); printf("%02x ", buf[i]); } @@ -67,7 +59,7 @@ static void dump(size_t cols, size_t group, uint8_t flags, FILE *file) { } printf(" "); for (size_t i = 0; i < len; ++i) { - if (flags & FLAG_COLOR) color(i); + if (group && i && !(i % group)) printf(" "); printf("%c", isprint(buf[i]) ? buf[i] : '.'); } } @@ -93,17 +85,16 @@ int main(int argc, char *argv[]) { char *path = NULL; int opt; - while (0 < (opt = getopt(argc, argv, "aCc:fg:hku"))) { + while (0 < (opt = getopt(argc, argv, "ac:fg:hku"))) { switch (opt) { case 'a': flags ^= FLAG_ASCII; break; - case 'C': flags ^= FLAG_COLOR; break; case 'f': flags ^= FLAG_OFFSET; break; case 'k': flags ^= FLAG_SKIP; break; case 'u': flags ^= FLAG_UNDUMP; break; case 'c': cols = strtoul(optarg, NULL, 10); break; case 'g': group = strtoul(optarg, NULL, 10); break; default: - fprintf(stderr, "usage: xx [-aCfku] [-c cols] [-g group] [file]\n"); + fprintf(stderr, "usage: xx [-afku] [-c cols] [-g group] [file]\n"); return (opt == 'h') ? EX_OK : EX_USAGE; } } |