From 2d9f5b9da15f96cfb5e30107b0cf115ed3c2ad4c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 16 Nov 2016 19:56:24 -0800 Subject: [PATCH] Add hook stuff --- CMakeLists.txt | 2 +- hooks.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ hooks.h | 23 ++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 hooks.c create mode 100644 hooks.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 51b7aa1..a297f30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,5 +2,5 @@ cmake_minimum_required(VERSION 3.5) project(zero-epwing) include_directories(eb) link_directories(eb/eb/.libs jansson/lib) -add_executable(zero-epwing main.c util.c convert.c) +add_executable(zero-epwing main.c util.c convert.c hooks.c) target_link_libraries(zero-epwing libeb.a libz.a libjansson.a) diff --git a/hooks.c b/hooks.c new file mode 100644 index 0000000..1f489f7 --- /dev/null +++ b/hooks.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2016 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "hooks.h" +#include "eb/eb/eb.h" +#include "eb/eb/text.h" + +#define HOOK_TAG_HELPER(FUNC_NAME, TAG_NAME) \ + static EB_Error_Code hook_##FUNC_NAME##_begin(\ + EB_Book* book,\ + EB_Appendix* appendix,\ + void* container,\ + EB_Hook_Code code,\ + int argc,\ + const unsigned int argv[]\ + ) {\ + eb_write_text_string(book, "<" #TAG_NAME ">");\ + (void)appendix;\ + (void)container;\ + (void)code;\ + (void)argc;\ + (void)argv;\ + return 0;\ + } + +#define HOOK_TAG_SINGLE(NAME) \ + HOOK_TAG_HELPER(NAME, NAME) + +#define HOOK_TAG_PAIR(NAME) \ + HOOK_TAG_HELPER(NAME##_begin, #NAME); \ + HOOK_TAG_HELPER(NAME##_end, "/" #NAME); + +HOOK_TAG_PAIR(candidate); /* EB_HOOK_BEGIN_CANDIDATE */ +HOOK_TAG_PAIR(color_bmp); /* EB_HOOK_BEGIN_COLOR_BMP */ +HOOK_TAG_PAIR(color_jpeg); /* EB_HOOK_BEGIN_COLOR_JPEG */ +HOOK_TAG_PAIR(decoration); /* EB_HOOK_BEGIN_DECORATION */ +HOOK_TAG_PAIR(emphasis); /* EB_HOOK_BEGIN_EMPHASIS */ +HOOK_TAG_PAIR(gray_graphic); /* EB_HOOK_BEGIN_GRAY_GRAPHIC */ +HOOK_TAG_PAIR(in_color_bmp); /* EB_HOOK_BEGIN_IN_COLOR_BMP */ +HOOK_TAG_PAIR(in_color_jpeg); /* EB_HOOK_BEGIN_IN_COLOR_JPEG */ +HOOK_TAG_PAIR(keyword); /* EB_HOOK_BEGIN_KEYWORD */ +HOOK_TAG_PAIR(mono_graphic); /* EB_HOOK_BEGIN_MONO_GRAPHIC */ +HOOK_TAG_PAIR(mpeg); /* EB_HOOK_BEGIN_MPEG */ +HOOK_TAG_PAIR(narrow); /* EB_HOOK_BEGIN_NARROW */ +HOOK_TAG_PAIR(no_newline); /* EB_HOOK_BEGIN_NO_NEWLINE */ +HOOK_TAG_PAIR(reference); /* EB_HOOK_BEGIN_REFERENCE */ +HOOK_TAG_PAIR(subscript); /* EB_HOOK_BEGIN_SUBSCRIPT */ +HOOK_TAG_PAIR(superscript); /* EB_HOOK_BEGIN_SUPERSCRIPT */ +HOOK_TAG_PAIR(wave); /* EB_HOOK_BEGIN_WAVE */ + +HOOK_TAG_SINGLE(gb2312); /* EB_HOOK_GB2312 */ +HOOK_TAG_SINGLE(iso8859_1); /* EB_HOOK_ISO8859_1 */ +HOOK_TAG_SINGLE(narrow_font); /* EB_HOOK_NARROW_FONT */ +HOOK_TAG_SINGLE(narrow_jisx0208); /* EB_HOOK_NARROW_JISX0208 */ +HOOK_TAG_SINGLE(newline); /* EB_HOOK_NEWLINE */ +HOOK_TAG_SINGLE(set_indent); /* EB_HOOK_SET_INDENT */ +HOOK_TAG_SINGLE(wide_font); /* EB_HOOK_WIDE_FONT */ +HOOK_TAG_SINGLE(wide_jisx0208); /* EB_HOOK_WIDE_JISX0208 */ +HOOK_TAG_SINGLE(null); /* EB_HOOK_NULL */ diff --git a/hooks.h b/hooks.h new file mode 100644 index 0000000..ed8fc0e --- /dev/null +++ b/hooks.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2016 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef HOOKS_H +#define HOOKS_H + + +#endif