diff options
Diffstat (limited to 'src/engine.c')
-rw-r--r-- | src/engine.c | 93 |
1 files changed, 90 insertions, 3 deletions
diff --git a/src/engine.c b/src/engine.c index 5f7a3ff..5bb8b7a 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2,8 +2,95 @@ #include <string.h> #include "internal.h" +#include "plugin.h" +#include "rccconfig.h" -int rccEngineInit(rcc_engine_context engine_ctx, rcc_context ctx) { +#include "engine.h" + +#ifdef RCC_RCD_SUPPORT +# ifdef RCC_RCD_DYNAMIC +# include "fake_rcd.h" +# else +# include <librcd.h> +# endif /* RCC_RCD_DYNAMIC */ +#endif /* RCC_RCD_SUPPORT */ + +static rcc_library_handle rcd_handle = NULL; + +rcc_charset_id rccAutoengineRussian(rcc_engine_context ctx, const char *buf, int len) { +#ifdef RCC_RCD_SUPPORT + rcc_charset_id id; +# ifdef RCC_RCD_DYNAMIC + if (!rcdGetRussianCharset) return (rcc_charset_id)-1; +# endif /* RCC_RCD_DYNAMIC */ + return (rcc_charset_id)rcdGetRussianCharset(buf,len); +#else /* RCC_RCD_SUPPORT */ + return (rcc_charset_id)-1; +#endif /* RCC_RCD_SUPPORT */ +} + + +static int rccRCDLibraryLoad() { +#ifdef RCC_RCD_DYNAMIC + if (rcd_handle) return 0; + + rcd_handle = rccLibraryOpen(RCC_RCD_LIB); + if (!rcd_handle) return -1; + + rcdGetRussianCharset = rccLibraryFind(rcd_handle,"rcdGetRussianCharset"); + if (!rcdGetRussianCharset) { + rccLibraryClose(rcd_handle); + rcd_handle = NULL; +# ifdef RCC_DEBUG + perror( "rccRCD. Incomplete function set in library" ); +# endif /* RCC_DEBUG */ + return -1; + } +#endif /* RCC_RCD_DYNAMIC */ + + return 0; +} + +static void rccRCDLibraryUnload() { +#ifdef RCC_RCD_DYNAMIC + if (rcd_handle) { + rccLibraryClose(rcd_handle); + rcd_handle = NULL; + } +#endif /* RCC_RCD_DYNAMIC */ +} + +int rccEngineInit() { +#ifdef RCC_RCD_DYNAMIC + int err; + unsigned int i,j,flag; + rcc_engine **engines; + int *charsets; + + err = rccRCDLibraryLoad(); + if (err) { + for (i=0;rcc_default_languages[i].sn;i++) { + engines = rcc_default_languages[i].engines; + for (flag=0,j=0;engines[j];j++) { + if (flag) engines[j-1] = engines[j]; + else if (engines[j] == &rcc_russian_engine) flag=1; + } + if (flag) engines[j-1] = NULL; + } + } +#endif /* RCC_RCD_DYNAMIC */ + + return rccEncaInit(); +} + +void rccEngineFree() { + rccEncaFree(); +#ifdef RCC_RCD_DYNAMIC + rccRCDLibraryUnload(); +#endif /* RCC_RCD_DYNAMIC */ +} + +int rccEngineInitContext(rcc_engine_context engine_ctx, rcc_context ctx) { if ((!ctx)||(!engine_ctx)) return -1; engine_ctx->ctx = ctx; @@ -12,7 +99,7 @@ int rccEngineInit(rcc_engine_context engine_ctx, rcc_context ctx) { return 0; } -void rccEngineFree(rcc_engine_context engine_ctx) { +void rccEngineFreeContext(rcc_engine_context engine_ctx) { if (!engine_ctx) return; if (engine_ctx->free_func) { @@ -31,7 +118,7 @@ int rccEngineConfigure(rcc_engine_context ctx) { if ((!ctx)||(!ctx->ctx)) return -1; - rccEngineFree(ctx); + rccEngineFreeContext(ctx); language_id = rccGetCurrentLanguage(ctx->ctx); if (language_id == (rcc_language_id)-1) return -1; |