From 7c113a69989d34def84ca1c65dce41f71d46d8aa Mon Sep 17 00:00:00 2001 From: Chris Simpkins Date: Wed, 21 Mar 2018 19:18:22 -0400 Subject: [PATCH 1/4] added support for help/version/usage to woff2_compress executable --- src/woff2_compress.cc | 28 ++++++++++++++++++++++------ src/woff2_compress.h | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/woff2_compress.h diff --git a/src/woff2_compress.cc b/src/woff2_compress.cc index 80e3108..1502ca1 100644 --- a/src/woff2_compress.cc +++ b/src/woff2_compress.cc @@ -6,20 +6,36 @@ /* A commandline tool for compressing ttf format files to woff2. */ -#include - -#include "file.h" -#include - +#include "woff2_compress.h" int main(int argc, char **argv) { using std::string; if (argc != 2) { - fprintf(stderr, "One argument, the input filename, must be provided.\n"); + fprintf(stderr, "Please include an argument with your command.\n"); return 1; } + std::string argument = argv[1]; + if (argument == "--help" || argument == "-h") { + std::cout << APPLICATION << std::endl; + std::cout << AUTHOR << std::endl; + std::cout << LICENSE << std::endl; + std::cout << HELPSTRING << std::endl; + std::cout << "\n" + USAGESTRING << std::endl; + return 0; + } + + if (argument == "--usage") { + std::cout << USAGESTRING << std::endl; + return 0; + } + + if (argument == "--version" || argument == "-v") { + std::cout << APPLICATION + " " + VERSION << std::endl; + return 0; + } + string filename(argv[1]); string outfilename = filename.substr(0, filename.find_last_of(".")) + ".woff2"; fprintf(stdout, "Processing %s => %s\n", diff --git a/src/woff2_compress.h b/src/woff2_compress.h new file mode 100644 index 0000000..7b5aaba --- /dev/null +++ b/src/woff2_compress.h @@ -0,0 +1,24 @@ +/* Copyright 2018 Google Inc. All Rights Reserved. + + Distributed under MIT license. + See file LICENSE for detail or copy at https://opensource.org/licenses/MIT +*/ + +#ifndef WOFF2_WOFF2_COMPRESS_H_ +#define WOFF2_WOFF2_COMPRESS_H_ + +#include +#include + +#include "file.h" +#include + +#define VERSION string("v1.0.3") + +#define APPLICATION string("woff2_compress") +#define AUTHOR string("Copyright 2013 Google Inc.") +#define LICENSE string("MIT License") +#define HELPSTRING string("\nInclude a single *.ttf or *.otf font file path argument to compile to a *.woff2 font file.") +#define USAGESTRING string("Usage: woff2_compress [font file path]") + +#endif // WOFF2_WOFF2_COMPRESS_H_ \ No newline at end of file From f151763d96bf940e5fa536c70820a31c68c81e54 Mon Sep 17 00:00:00 2001 From: Chris Simpkins Date: Wed, 21 Mar 2018 19:18:50 -0400 Subject: [PATCH 2/4] added support for help/version/usage to woff2_decompress executable --- src/woff2_decompress.cc | 26 +++++++++++++++++++++----- src/woff2_decompress.h | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/woff2_decompress.h diff --git a/src/woff2_decompress.cc b/src/woff2_decompress.cc index de088b9..d1ee260 100644 --- a/src/woff2_decompress.cc +++ b/src/woff2_decompress.cc @@ -7,11 +7,7 @@ /* A very simple commandline tool for decompressing woff2 format files to true type font files. */ -#include - -#include "./file.h" -#include - +#include "woff2_decompress.h" int main(int argc, char **argv) { using std::string; @@ -21,6 +17,26 @@ int main(int argc, char **argv) { return 1; } + std::string argument = argv[1]; + if (argument == "--help" || argument == "-h") { + std::cout << APPLICATION << std::endl; + std::cout << AUTHOR << std::endl; + std::cout << LICENSE << std::endl; + std::cout << HELPSTRING << std::endl; + std::cout << "\n" + USAGESTRING << std::endl; + return 0; + } + + if (argument == "--usage"){ + std::cout << USAGESTRING << std::endl; + return 0; + } + + if (argument == "--version" || argument == "-v") { + std::cout << APPLICATION + " " + VERSION << std::endl; + return 0; + } + string filename(argv[1]); string outfilename = filename.substr(0, filename.find_last_of(".")) + ".ttf"; diff --git a/src/woff2_decompress.h b/src/woff2_decompress.h new file mode 100644 index 0000000..5969fd4 --- /dev/null +++ b/src/woff2_decompress.h @@ -0,0 +1,24 @@ +/* Copyright 2018 Google Inc. All Rights Reserved. + + Distributed under MIT license. + See file LICENSE for detail or copy at https://opensource.org/licenses/MIT +*/ + +#ifndef WOFF2_WOFF2_DECOMPRESS_H_ +#define WOFF2_WOFF2_DECOMPRESS_H_ + +#include +#include + +#include "file.h" +#include + +#define VERSION string("v1.0.3") + +#define APPLICATION string("woff2_decompress") +#define AUTHOR string("Copyright 2013 Google Inc.") +#define LICENSE string("MIT License") +#define HELPSTRING string("\nInclude a single *.woff2 font file path as an argument to decode to a *.ttf font.") +#define USAGESTRING string("Usage: woff2_decompress [font file path]") + +#endif // WOFF2_WOFF2_DECOMPRESS_H_ \ No newline at end of file From d58ca7f66f388321186b3978ceaf6eac70cc7917 Mon Sep 17 00:00:00 2001 From: Chris Simpkins Date: Thu, 22 Mar 2018 14:51:28 -0400 Subject: [PATCH 3/4] refactor woff2_compress help/usage/version to use fprintf --- src/woff2_compress.cc | 23 ++++++++++++----------- src/woff2_compress.h | 3 +-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/woff2_compress.cc b/src/woff2_compress.cc index 1502ca1..6e846c8 100644 --- a/src/woff2_compress.cc +++ b/src/woff2_compress.cc @@ -13,27 +13,28 @@ int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Please include an argument with your command.\n"); + fprintf(stderr, "%s\n", USAGESTRING.c_str()); return 1; } - std::string argument = argv[1]; + string argument = argv[1]; if (argument == "--help" || argument == "-h") { - std::cout << APPLICATION << std::endl; - std::cout << AUTHOR << std::endl; - std::cout << LICENSE << std::endl; - std::cout << HELPSTRING << std::endl; - std::cout << "\n" + USAGESTRING << std::endl; - return 0; + fprintf(stdout, "%s\n", APPLICATION.c_str()); + fprintf(stdout, "%s\n", AUTHOR.c_str()); + fprintf(stdout, "%s\n", LICENSE.c_str()); + fprintf(stdout, "\n%s\n", HELPSTRING.c_str()); + fprintf(stdout, "\n%s\n", USAGESTRING.c_str()); + return 0; } if (argument == "--usage") { - std::cout << USAGESTRING << std::endl; - return 0; + fprintf(stdout, "%s\n", USAGESTRING.c_str()); + return 0; } if (argument == "--version" || argument == "-v") { - std::cout << APPLICATION + " " + VERSION << std::endl; - return 0; + fprintf(stdout, "%s %s\n", APPLICATION.c_str(), VERSION.c_str()); + return 0; } string filename(argv[1]); diff --git a/src/woff2_compress.h b/src/woff2_compress.h index 7b5aaba..8790538 100644 --- a/src/woff2_compress.h +++ b/src/woff2_compress.h @@ -8,7 +8,6 @@ #define WOFF2_WOFF2_COMPRESS_H_ #include -#include #include "file.h" #include @@ -18,7 +17,7 @@ #define APPLICATION string("woff2_compress") #define AUTHOR string("Copyright 2013 Google Inc.") #define LICENSE string("MIT License") -#define HELPSTRING string("\nInclude a single *.ttf or *.otf font file path argument to compile to a *.woff2 font file.") +#define HELPSTRING string("Include a single *.ttf or *.otf font file path argument to compile to a *.woff2 font file.") #define USAGESTRING string("Usage: woff2_compress [font file path]") #endif // WOFF2_WOFF2_COMPRESS_H_ \ No newline at end of file From 2f5128b11d680d3fb1d4dcb81f6979952ceb2d1c Mon Sep 17 00:00:00 2001 From: Chris Simpkins Date: Thu, 22 Mar 2018 14:51:49 -0400 Subject: [PATCH 4/4] refactored woff2_decompress help/usage/version to use fprintf --- src/woff2_decompress.cc | 23 ++++++++++++----------- src/woff2_decompress.h | 3 +-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/woff2_decompress.cc b/src/woff2_decompress.cc index d1ee260..e8e7d09 100644 --- a/src/woff2_decompress.cc +++ b/src/woff2_decompress.cc @@ -13,27 +13,28 @@ int main(int argc, char **argv) { using std::string; if (argc != 2) { - fprintf(stderr, "One argument, the input filename, must be provided.\n"); - return 1; + fprintf(stderr, "Please include an argument with your command.\n"); + fprintf(stderr, "%s\n", USAGESTRING.c_str()); + return 1; } - std::string argument = argv[1]; + string argument = argv[1]; if (argument == "--help" || argument == "-h") { - std::cout << APPLICATION << std::endl; - std::cout << AUTHOR << std::endl; - std::cout << LICENSE << std::endl; - std::cout << HELPSTRING << std::endl; - std::cout << "\n" + USAGESTRING << std::endl; + fprintf(stdout, "%s\n", APPLICATION.c_str()); + fprintf(stdout, "%s\n", AUTHOR.c_str()); + fprintf(stdout, "%s\n", LICENSE.c_str()); + fprintf(stdout, "\n%s\n", HELPSTRING.c_str()); + fprintf(stdout, "\n%s\n", USAGESTRING.c_str()); return 0; } - if (argument == "--usage"){ - std::cout << USAGESTRING << std::endl; + if (argument == "--usage") { + fprintf(stdout, "%s\n", USAGESTRING.c_str()); return 0; } if (argument == "--version" || argument == "-v") { - std::cout << APPLICATION + " " + VERSION << std::endl; + fprintf(stdout, "%s %s\n", APPLICATION.c_str(), VERSION.c_str()); return 0; } diff --git a/src/woff2_decompress.h b/src/woff2_decompress.h index 5969fd4..0eb1d9f 100644 --- a/src/woff2_decompress.h +++ b/src/woff2_decompress.h @@ -8,7 +8,6 @@ #define WOFF2_WOFF2_DECOMPRESS_H_ #include -#include #include "file.h" #include @@ -18,7 +17,7 @@ #define APPLICATION string("woff2_decompress") #define AUTHOR string("Copyright 2013 Google Inc.") #define LICENSE string("MIT License") -#define HELPSTRING string("\nInclude a single *.woff2 font file path as an argument to decode to a *.ttf font.") +#define HELPSTRING string("Include a single *.woff2 font file path argument to decode to a *.ttf font.") #define USAGESTRING string("Usage: woff2_decompress [font file path]") #endif // WOFF2_WOFF2_DECOMPRESS_H_ \ No newline at end of file