diff options
author | June McEnroe <programble@gmail.com> | 2018-02-19 17:47:25 -0500 |
---|---|---|
committer | June McEnroe <programble@gmail.com> | 2018-02-19 17:47:25 -0500 |
commit | d9c728bc52946c36cd521dec98ace82749ad63f9 (patch) | |
tree | 7149fa569b210b9dee12e88e894496f38f97c8cc | |
parent | Clean up pngo optimization functions (diff) | |
download | src-d9c728bc52946c36cd521dec98ace82749ad63f9.tar.gz src-d9c728bc52946c36cd521dec98ace82749ad63f9.zip |
Add pngo command line options
-rw-r--r-- | bin/README | 4 | ||||
-rw-r--r-- | bin/pngo.c | 26 |
2 files changed, 27 insertions, 3 deletions
diff --git a/bin/README b/bin/README index 32f9862d..4e4a8d9d 100644 --- a/bin/README +++ b/bin/README @@ -86,6 +86,10 @@ PNG optimizer. Does not support interlaced PNGs. - Applies a simple filter type heuristic - Applies zlib's best compression + pngo foo.png + pngo -o bar.png foo.png + pngo -c foo.png | xx + wake Broadcasts a wake-on-LAN packet to one of my machines. diff --git a/bin/pngo.c b/bin/pngo.c index 7151cb37..47ca4d9b 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; } |