From b2a223c0fc280af42e6745e25ae2ba82cc89c9e7 Mon Sep 17 00:00:00 2001 From: Nick Frost Date: Sat, 28 Oct 2017 13:52:13 -0700 Subject: [PATCH] Print version info on -v and --version --- src/zopfli/zopfli.h | 2 ++ src/zopfli/zopfli_bin.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/zopfli/zopfli.h b/src/zopfli/zopfli.h index c079662a..ff5d1239 100644 --- a/src/zopfli/zopfli.h +++ b/src/zopfli/zopfli.h @@ -27,6 +27,8 @@ Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala) extern "C" { #endif +#define ZOPFLI_VERSION "1.0.1" + /* Options used throughout the program. */ diff --git a/src/zopfli/zopfli_bin.c b/src/zopfli/zopfli_bin.c index a42badef..febef228 100644 --- a/src/zopfli/zopfli_bin.c +++ b/src/zopfli/zopfli_bin.c @@ -141,6 +141,10 @@ static char StringsEqual(const char* str1, const char* str2) { return strcmp(str1, str2) == 0; } +static void ShowVersion() { + fprintf(stderr, "zopfli version %s\n", ZOPFLI_VERSION); +} + int main(int argc, char* argv[]) { ZopfliOptions options; ZopfliFormat output_type = ZOPFLI_FORMAT_GZIP; @@ -178,11 +182,20 @@ int main(int argc, char* argv[]) { " --gzip output to gzip format (default)\n" " --zlib output to zlib format instead of gzip\n" " --deflate output to deflate format instead of gzip\n" - " --splitlast ignored, left for backwards compatibility\n"); + " --splitlast ignored, left for backwards compatibility\n" + " --version show version and exit\n"); + return 0; + } + else if (StringsEqual(arg, "--version")) { + ShowVersion(); return 0; } } + if (options.verbose) { + ShowVersion(); + } + if (options.numiterations < 1) { fprintf(stderr, "Error: must have 1 or more iterations\n"); return 0;