summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-02-19 17:47:25 -0500
committerJune McEnroe <june@causal.agency>2018-02-19 17:47:25 -0500
commit567498ffa39760b28e860346259ff464e00ca8d8 (patch)
treeda6254d8356e8bf79dfc6fb448a221437b7982b2
parentClean up pngo optimization functions (diff)
downloadsrc-567498ffa39760b28e860346259ff464e00ca8d8.tar.gz
src-567498ffa39760b28e860346259ff464e00ca8d8.zip
Add pngo command line options
-rw-r--r--bin/README4
-rw-r--r--bin/pngo.c26
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 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;
 }
400'>2020-04-26Iterate through nested multiparts to find content for AtomJune McEnroe 2020-04-26Include Cc address in reply mailtosJune McEnroe 2020-04-26Use %R for RFC numbers in STANDARDS sectionJune McEnroe 2020-04-26Add mailto spec to STANDARDSJune McEnroe 2020-04-26Increase space between nav itemsJune McEnroe 2020-04-26Add mailto address for the archiveJune McEnroe 2020-04-26Put dates on new lines in indexJune McEnroe 2020-04-26Include <> around Message-Id in mailto: URLsJune McEnroe 2020-04-26Add link to index on thread pagesJune McEnroe 2020-04-26Fall back to Content-Type name parameter for attachmentsJune McEnroe 2020-04-26Remove margins in article.message headerJune McEnroe 2020-04-26Generate index.atomJune McEnroe 2020-04-26Generate XHTML content in Atom entriesJune McEnroe 2020-04-25Style index pageJune McEnroe 2020-04-25Render index.htmlJune McEnroe 2020-04-25Wrap <summary> replies count in <data>June McEnroe 2020-04-25Accumulate thread envelopes before concatenationJune McEnroe 2020-04-24Free envelope in concatDataJune McEnroe 2020-04-24Use replyTo address in mailto:June McEnroe 2020-04-23Wrap quoted lines in <q>June McEnroe