From 567498ffa39760b28e860346259ff464e00ca8d8 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 19 Feb 2018 17:47:25 -0500 Subject: Add pngo command line options --- bin/pngo.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'bin/pngo.c') diff --git a/bin/pngo.c b/bin/pngo.c index 993593f4..90ebeea8 100644 --- a/bin/pngo.c +++ b/bin/pngo.c @@ -529,7 +529,7 @@ static void optimize(const char *inPath, const char *outPath) { if (outPath) { path = outPath; - file = fopen(path, "wx"); + file = fopen(path, "w"); if (!file) err(EX_CANTCREAT, "%s", path); } else { path = "(stdout)"; @@ -548,7 +548,27 @@ static void optimize(const char *inPath, const char *outPath) { } int main(int argc, char *argv[]) { - if (argc < 2) return EX_USAGE; - optimize(argv[1], NULL); + bool stdio = false; + char *output = NULL; + + int opt; + while (0 < (opt = getopt(argc, argv, "co:"))) { + switch (opt) { + case 'c': stdio = true; break; + case 'o': output = optarg; break; + default: return EX_USAGE; + } + } + + if (optind < argc) { + if (output || stdio) { + optimize(argv[optind], output); + } else { + optimize(argv[optind], argv[optind]); + } + } else { + optimize(NULL, output); + } + return EX_OK; } -- cgit 1.4.1