1
This commit is contained in:
Alex Yatskov 2016-12-03 18:24:56 -08:00
parent e9b315f4ec
commit be0bcdfd0c
4 changed files with 34 additions and 38 deletions

3
.gitmodules vendored
View File

@ -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

View File

@ -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)

@ -1 +0,0 @@
Subproject commit 1692ce12291a9d79cf6b425037a7d1a0e3c0aba5

64
main.c
View File

@ -16,54 +16,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#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;