diff options
author | June McEnroe <programble@gmail.com> | 2017-07-16 21:16:16 -0400 |
---|---|---|
committer | June McEnroe <programble@gmail.com> | 2017-07-16 21:16:16 -0400 |
commit | 4823b44f263149bb7fe422b58c9dbb324272faf3 (patch) | |
tree | a4e89a844b807816a4f970fb46a12cd1e14e4b9c /curtis/.bin/xx.c | |
parent | Rewrite README, create LICENSE (diff) | |
download | src-4823b44f263149bb7fe422b58c9dbb324272faf3.tar.gz src-4823b44f263149bb7fe422b58c9dbb324272faf3.zip |
Remove color from xx, group ASCII
Diffstat (limited to '')
-rwxr-xr-x | curtis/.bin/xx.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/curtis/.bin/xx.c b/curtis/.bin/xx.c index 1c77fcd5..78d8db4c 100755 --- a/curtis/.bin/xx.c +++ b/curtis/.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; } } |