From 3a6a3b7bcc570899b1814106ca5670b0d49b198a Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 12 Sep 2016 14:52:25 -0400 Subject: Add -c option to xx --- .bin/xx.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to '.bin') diff --git a/.bin/xx.c b/.bin/xx.c index d2d86574..153ba74e 100755 --- a/.bin/xx.c +++ b/.bin/xx.c @@ -1,17 +1,24 @@ #if 0 -exec cc -Weverything -o ~/.bin/xx $0 +exec cc -Weverything -Wno-vla -o ~/.bin/xx $0 #endif #include #include #include +#include int main(int argc, char **argv) { + size_t cols = 16; char *path = NULL; - if (argc > 1) - path = argv[1]; + while (getopt(argc, argv, "c:") > 0) + if (optopt == 'c') { + cols = (size_t) strtol(optarg, NULL, 10); + if (!cols) return EXIT_FAILURE; + } else return EXIT_FAILURE; + if (argc > optind) + path = argv[optind]; FILE *file = path ? fopen(path, "r") : stdin; if (!file) { @@ -19,7 +26,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - uint8_t buf[16]; + uint8_t buf[cols]; for (;;) { size_t n = fread(buf, 1, sizeof(buf), file); for (size_t i = 0; i < n; ++i) -- cgit 1.4.1