From be0bcdfd0c1537255075d49d409a97bac9a64a38 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 3 Dec 2016 18:24:56 -0800 Subject: [PATCH] WIP --- .gitmodules | 3 --- CMakeLists.txt | 4 ++-- argparse | 1 - main.c | 64 +++++++++++++++++++++++++------------------------- 4 files changed, 34 insertions(+), 38 deletions(-) delete mode 160000 argparse diff --git a/.gitmodules b/.gitmodules index 7dac0e3..9472fac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "jansson"] path = jansson url = https://github.com/akheron/jansson.git -[submodule "argparse"] - path = argparse - url = https://github.com/FooSoft/argparse diff --git a/CMakeLists.txt b/CMakeLists.txt index 00ef7a8..46a44ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) project(zero-epwing) include_directories(eb) -link_directories(eb/eb/.libs jansson/lib argparse) +link_directories(eb/eb/.libs jansson/lib) add_executable(zero-epwing main.c book.c font.c convert.c hooks.c) -target_link_libraries(zero-epwing libm.a libeb.a libm.a libz.a libjansson.a libargparse.a m) +target_link_libraries(zero-epwing libm.a libeb.a libm.a libz.a libjansson.a) diff --git a/argparse b/argparse deleted file mode 160000 index 1692ce1..0000000 --- a/argparse +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1692ce12291a9d79cf6b425037a7d1a0e3c0aba5 diff --git a/main.c b/main.c index 286bbd7..8691419 100644 --- a/main.c +++ b/main.c @@ -16,54 +16,54 @@ * along with this program. If not, see . */ -#include #include +#include +#include -#include "argparse/argparse.h" #include "util.h" #include "book.h" #include "font.h" -/* - * Local types - */ - -typedef struct { - char dict_path[256]; - char font_path[256]; - int flags; -} Options; - /* * Entry point */ -int main(int argc, const char *argv[]) { +int main(int argc, char *argv[]) { char* dict_path = NULL; char* font_path = NULL; int flags = 0; - struct argparse_option options[] = { - OPT_HELP(), - OPT_STRING('d', "dict", &dict_path, "dictionary resource to process", NULL, 0, 0), - OPT_STRING('f', "font", &font_path, "font definition file for translation", NULL, 0, 0), - OPT_BOOLEAN('p', "pretty-print", &flags, "output pretty-printed JSON", NULL, 0, 0), - OPT_BOOLEAN('m', "markup", &flags, "output formatting tags", 0, 0, 0), - OPT_BOOLEAN('s', "positions", &flags, "output positional data", NULL, 0, 0), - OPT_BOOLEAN('t', "font-tags", &flags, "output missing font data tags", NULL, 0, 0), - OPT_END() - }; - - struct argparse argparse; - - argparse_init(&argparse, options, NULL, 0); - argparse_parse(&argparse, argc, argv); - - if (dict_path == NULL) { - argparse_usage(&argparse); - return 1; + char c = 0; + while ((c = getopt(argc, argv, "f:d:pmst")) != -1) { + switch (c) { + case 'f': + font_path = optarg; + break; + case 'p': + flags |= FLAG_PRETTY_PRINT; + break; + case 'm': + flags |= FLAG_HOOK_MARKUP; + break; + case 's': + flags |= FLAG_POSITIONS; + break; + case 't': + flags |= FLAG_FONT_TAGS; + break; + default: + abort(); + break; + } } + if (optind == argc) { + fprintf(stderr, "dictionary must be provided provided\n"); + abort(); + } + + dict_path = argv[optind]; + Font_Context context; if (!font_context_init(&context, font_path == 0 ? NULL : font_path)) { return 1;