1
This commit is contained in:
Alex Yatskov 2016-11-18 23:04:03 -08:00
parent a793f9206f
commit 10cabbe554

145
hooks.c
View File

@ -24,8 +24,10 @@
* Boilerplate * Boilerplate
*/ */
#define HOOK_TAG_HELPER(FUNC_NAME, TAG_NAME) \ #define HOOK_FUNC_NAME(NAME) hook_##NAME
static EB_Error_Code hook_##FUNC_NAME##_begin(\
#define HOOK_TAGGER(NAME) \
static EB_Error_Code HOOK_FUNC_NAME(NAME)(\
EB_Book* book,\ EB_Book* book,\
EB_Appendix* appendix,\ EB_Appendix* appendix,\
void* container,\ void* container,\
@ -33,60 +35,64 @@
int argc,\ int argc,\
const unsigned int argv[]\ const unsigned int argv[]\
) {\ ) {\
eb_write_text_string(book, "<" #TAG_NAME ">");\
(void)appendix;\ (void)appendix;\
(void)container;\ (void)container;\
(void)code;\ (void)code;\
(void)argc;\ (void)argc;\
(void)argv;\ (void)argv;\
eb_write_text_string(book, "<" #NAME ">");\
return 0;\ 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);
#define MAX_REPLACEMENT 64 #define MAX_REPLACEMENT 64
/* /*
* Paired tags * Basic tag printers
*/ */
HOOK_TAG_PAIR(candidate); /* EB_HOOK_BEGIN_CANDIDATE */ HOOK_TAGGER(begin_candidate); /* EB_HOOK_BEGIN_CANDIDATE */
HOOK_TAG_PAIR(color_bmp); /* EB_HOOK_BEGIN_COLOR_BMP */ HOOK_TAGGER(begin_color_bmp); /* EB_HOOK_BEGIN_COLOR_BMP */
HOOK_TAG_PAIR(color_jpeg); /* EB_HOOK_BEGIN_COLOR_JPEG */ HOOK_TAGGER(begin_color_jpeg); /* EB_HOOK_BEGIN_COLOR_JPEG */
HOOK_TAG_PAIR(decoration); /* EB_HOOK_BEGIN_DECORATION */ HOOK_TAGGER(begin_decoration); /* EB_HOOK_BEGIN_DECORATION */
HOOK_TAG_PAIR(emphasis); /* EB_HOOK_BEGIN_EMPHASIS */ HOOK_TAGGER(begin_emphasis); /* EB_HOOK_BEGIN_EMPHASIS */
HOOK_TAG_PAIR(gray_graphic); /* EB_HOOK_BEGIN_GRAY_GRAPHIC */ HOOK_TAGGER(begin_gray_graphic); /* EB_HOOK_BEGIN_GRAY_GRAPHIC */
HOOK_TAG_PAIR(in_color_bmp); /* EB_HOOK_BEGIN_IN_COLOR_BMP */ HOOK_TAGGER(begin_in_color_bmp); /* EB_HOOK_BEGIN_IN_COLOR_BMP */
HOOK_TAG_PAIR(in_color_jpeg); /* EB_HOOK_BEGIN_IN_COLOR_JPEG */ HOOK_TAGGER(begin_in_color_jpeg); /* EB_HOOK_BEGIN_IN_COLOR_JPEG */
HOOK_TAG_PAIR(keyword); /* EB_HOOK_BEGIN_KEYWORD */ HOOK_TAGGER(begin_keyword); /* EB_HOOK_BEGIN_KEYWORD */
HOOK_TAG_PAIR(mono_graphic); /* EB_HOOK_BEGIN_MONO_GRAPHIC */ HOOK_TAGGER(begin_mono_graphic); /* EB_HOOK_BEGIN_MONO_GRAPHIC */
HOOK_TAG_PAIR(mpeg); /* EB_HOOK_BEGIN_MPEG */ HOOK_TAGGER(begin_mpeg); /* EB_HOOK_BEGIN_MPEG */
HOOK_TAG_PAIR(narrow); /* EB_HOOK_BEGIN_NARROW */ HOOK_TAGGER(begin_narrow); /* EB_HOOK_BEGIN_NARROW */
HOOK_TAG_PAIR(no_newline); /* EB_HOOK_BEGIN_NO_NEWLINE */ HOOK_TAGGER(begin_no_newline); /* EB_HOOK_BEGIN_NO_NEWLINE */
HOOK_TAG_PAIR(reference); /* EB_HOOK_BEGIN_REFERENCE */ HOOK_TAGGER(begin_reference); /* EB_HOOK_BEGIN_REFERENCE */
HOOK_TAG_PAIR(subscript); /* EB_HOOK_BEGIN_SUBSCRIPT */ HOOK_TAGGER(begin_subscript); /* EB_HOOK_BEGIN_SUBSCRIPT */
HOOK_TAG_PAIR(superscript); /* EB_HOOK_BEGIN_SUPERSCRIPT */ HOOK_TAGGER(begin_superscript); /* EB_HOOK_BEGIN_SUPERSCRIPT */
HOOK_TAG_PAIR(wave); /* EB_HOOK_BEGIN_WAVE */ HOOK_TAGGER(begin_wave); /* EB_HOOK_BEGIN_WAVE */
HOOK_TAGGER(end_candidate_group); /* EB_HOOK_END_CANDIDATE_GROUP */
HOOK_TAGGER(end_candidate_leaf); /* EB_HOOK_END_CANDIDATE_LEAF */
HOOK_TAGGER(end_color_graphic); /* EB_HOOK_END_COLOR_GRAPHIC */
HOOK_TAGGER(end_decoration); /* EB_HOOK_END_DECORATION */
HOOK_TAGGER(end_emphasis); /* EB_HOOK_END_EMPHASIS */
HOOK_TAGGER(end_gray_graphic); /* EB_HOOK_END_GRAY_GRAPHIC */
HOOK_TAGGER(end_in_color_graphic); /* EB_HOOK_SET_END_IN_COLOR_GRAPHIC */
HOOK_TAGGER(end_keyword); /* EB_HOOK_END_KEYWORD */
HOOK_TAGGER(end_mono_graphic); /* EB_HOOK_END_MONO_GRAPHIC */
HOOK_TAGGER(end_mpeg); /* EB_HOOK_END_MPEG */
HOOK_TAGGER(end_narrow); /* EB_HOOK_END_NARROW */
HOOK_TAGGER(end_no_newline); /* EB_HOOK_END_NO_NEWLINE */
HOOK_TAGGER(end_reference); /* EB_HOOK_END_REFERENCE */
HOOK_TAGGER(end_subscript); /* EB_HOOK_END_SUBSCRIPT */
HOOK_TAGGER(end_superscript); /* EB_HOOK_END_SUPERSCRIPT */
HOOK_TAGGER(end_wave); /* EB_HOOK_END_WAVE */
HOOK_TAGGER(gb2312); /* EB_HOOK_GB2312 */
HOOK_TAGGER(iso8859_1); /* EB_HOOK_ISO8859_1 */
HOOK_TAGGER(narrow_jisx0208); /* EB_HOOK_NARROW_JISX0208 */
HOOK_TAGGER(newline); /* EB_HOOK_NEWLINE */
HOOK_TAGGER(set_indent); /* EB_HOOK_SET_INDENT */
HOOK_TAGGER(wide_jisx0208); /* EB_HOOK_WIDE_JISX0208 */
HOOK_TAGGER(null); /* EB_HOOK_NULL */
/* /*
* Single tags * Gaiji processing
*/
HOOK_TAG_SINGLE(gb2312); /* EB_HOOK_GB2312 */
HOOK_TAG_SINGLE(iso8859_1); /* EB_HOOK_ISO8859_1 */
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_jisx0208); /* EB_HOOK_WIDE_JISX0208 */
HOOK_TAG_SINGLE(null); /* EB_HOOK_NULL */
/*
* Gaiji nonsense
*/ */
static EB_Error_Code hook_narrow_font( /* EB_HOOK_NARROW_FONT */ static EB_Error_Code hook_narrow_font( /* EB_HOOK_NARROW_FONT */
@ -160,3 +166,60 @@ static EB_Error_Code hook_wide_font( /* EB_HOOK_WIDE_FONT */
return 0; return 0;
} }
/*
* Hook table
*/
static const EB_Hook s_hooks[] = {
{ EB_HOOK_BEGIN_CANDIDATE, HOOK_FUNC_NAME(begin_candidate) },
{ EB_HOOK_BEGIN_COLOR_BMP, HOOK_FUNC_NAME(begin_color_bmp) },
{ EB_HOOK_BEGIN_COLOR_JPEG, HOOK_FUNC_NAME(begin_color_jpeg) },
{ EB_HOOK_BEGIN_DECORATION, HOOK_FUNC_NAME(begin_decoration) },
{ EB_HOOK_BEGIN_EMPHASIS, HOOK_FUNC_NAME(begin_emphasis) },
{ EB_HOOK_BEGIN_GRAY_GRAPHIC, HOOK_FUNC_NAME(begin_gray_graphic) },
{ EB_HOOK_BEGIN_IN_COLOR_BMP, HOOK_FUNC_NAME(begin_in_color_bmp) },
{ EB_HOOK_BEGIN_IN_COLOR_JPEG, HOOK_FUNC_NAME(begin_in_color_jpeg) },
{ EB_HOOK_BEGIN_KEYWORD, HOOK_FUNC_NAME(begin_keyword) },
{ EB_HOOK_BEGIN_MONO_GRAPHIC, HOOK_FUNC_NAME(begin_mono_graphic) },
{ EB_HOOK_BEGIN_MPEG, HOOK_FUNC_NAME(begin_mpeg) },
{ EB_HOOK_BEGIN_NARROW, HOOK_FUNC_NAME(begin_narrow) },
{ EB_HOOK_BEGIN_NO_NEWLINE, HOOK_FUNC_NAME(begin_no_newline) },
{ EB_HOOK_BEGIN_REFERENCE, HOOK_FUNC_NAME(begin_reference) },
{ EB_HOOK_BEGIN_SUBSCRIPT, HOOK_FUNC_NAME(begin_subscript) },
{ EB_HOOK_BEGIN_SUPERSCRIPT, HOOK_FUNC_NAME(begin_superscript) },
{ EB_HOOK_BEGIN_WAVE, HOOK_FUNC_NAME(begin_wave) },
{ EB_HOOK_END_CANDIDATE_GROUP, HOOK_FUNC_NAME(end_candidate_group) },
{ EB_HOOK_END_CANDIDATE_LEAF, HOOK_FUNC_NAME(end_candidate_leaf) },
{ EB_HOOK_END_COLOR_GRAPHIC, HOOK_FUNC_NAME(end_color_graphic) },
{ EB_HOOK_END_DECORATION, HOOK_FUNC_NAME(end_decoration) },
{ EB_HOOK_END_EMPHASIS, HOOK_FUNC_NAME(end_emphasis) },
{ EB_HOOK_END_GRAY_GRAPHIC, HOOK_FUNC_NAME(end_gray_graphic) },
{ EB_HOOK_END_IN_COLOR_GRAPHIC, HOOK_FUNC_NAME(end_in_color_graphic) },
{ EB_HOOK_END_KEYWORD, HOOK_FUNC_NAME(end_keyword) },
{ EB_HOOK_END_MONO_GRAPHIC, HOOK_FUNC_NAME(end_mono_graphic) },
{ EB_HOOK_END_MPEG, HOOK_FUNC_NAME(end_mpeg) },
{ EB_HOOK_END_NARROW, HOOK_FUNC_NAME(end_narrow) },
{ EB_HOOK_END_NO_NEWLINE, HOOK_FUNC_NAME(end_no_newline) },
{ EB_HOOK_END_REFERENCE, HOOK_FUNC_NAME(end_reference) },
{ EB_HOOK_END_SUBSCRIPT, HOOK_FUNC_NAME(end_subscript) },
{ EB_HOOK_END_SUPERSCRIPT, HOOK_FUNC_NAME(end_superscript) },
{ EB_HOOK_END_WAVE, HOOK_FUNC_NAME(end_wave) },
{ EB_HOOK_GB2312, HOOK_FUNC_NAME(gb2312) },
{ EB_HOOK_ISO8859_1, HOOK_FUNC_NAME(iso8859_1) },
{ EB_HOOK_NARROW_FONT, HOOK_FUNC_NAME(narrow_font) },
{ EB_HOOK_NARROW_JISX0208, HOOK_FUNC_NAME(narrow_jisx0208) },
{ EB_HOOK_NEWLINE, HOOK_FUNC_NAME(newline) },
{ EB_HOOK_SET_INDENT, HOOK_FUNC_NAME(set_indent) },
{ EB_HOOK_WIDE_FONT, HOOK_FUNC_NAME(wide_font) },
{ EB_HOOK_WIDE_JISX0208, HOOK_FUNC_NAME(wide_jisx0208) },
{ EB_HOOK_NULL, HOOK_FUNC_NAME(null) },
};
/*
* Exported functions
*/
void hooks_install(EB_Hookset* hookset) {
(void)hookset;
}