diff --git a/src/woff2_compress.cc b/src/woff2_compress.cc index 80e3108..6e846c8 100644 --- a/src/woff2_compress.cc +++ b/src/woff2_compress.cc @@ -6,20 +6,37 @@ /* 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"); + fprintf(stderr, "%s\n", USAGESTRING.c_str()); return 1; } + string argument = argv[1]; + if (argument == "--help" || argument == "-h") { + 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") { + fprintf(stdout, "%s\n", USAGESTRING.c_str()); + return 0; + } + + if (argument == "--version" || argument == "-v") { + fprintf(stdout, "%s %s\n", APPLICATION.c_str(), VERSION.c_str()); + 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..8790538 --- /dev/null +++ b/src/woff2_compress.h @@ -0,0 +1,23 @@ +/* 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 "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("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 diff --git a/src/woff2_decompress.cc b/src/woff2_decompress.cc index de088b9..e8e7d09 100644 --- a/src/woff2_decompress.cc +++ b/src/woff2_decompress.cc @@ -7,18 +7,35 @@ /* 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; 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; + } + + string argument = argv[1]; + if (argument == "--help" || argument == "-h") { + 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") { + fprintf(stdout, "%s\n", USAGESTRING.c_str()); + return 0; + } + + if (argument == "--version" || argument == "-v") { + fprintf(stdout, "%s %s\n", APPLICATION.c_str(), VERSION.c_str()); + return 0; } string filename(argv[1]); diff --git a/src/woff2_decompress.h b/src/woff2_decompress.h new file mode 100644 index 0000000..0eb1d9f --- /dev/null +++ b/src/woff2_decompress.h @@ -0,0 +1,23 @@ +/* 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 "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("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