diff options
author | Peng Wu <alexepico@gmail.com> | 2012-06-18 14:59:32 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-06-18 14:59:32 +0800 |
commit | 9d004b33d8fe47ae290c97e08785155d061784fd (patch) | |
tree | da73b71830f38b772cd2efd1adcf99e930c7cc55 /src | |
parent | 4c42f29cb8863cc5d6810a8a2a25c478e16292f7 (diff) | |
download | libpinyin-9d004b33d8fe47ae290c97e08785155d061784fd.tar.gz libpinyin-9d004b33d8fe47ae290c97e08785155d061784fd.tar.xz libpinyin-9d004b33d8fe47ae290c97e08785155d061784fd.zip |
begin to write multiple phrase library support
Diffstat (limited to 'src')
-rw-r--r-- | src/pinyin.cpp | 11 | ||||
-rw-r--r-- | src/pinyin.h | 7 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index baf64ea..cbbd2f3 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -47,6 +47,8 @@ struct _pinyin_context_t{ char * m_system_dir; char * m_user_dir; bool m_modified; + + gchar * m_phrase_indices[PHRASE_INDEX_LIBRARY_COUNT]; }; @@ -106,6 +108,9 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){ context->m_user_dir = g_strdup(userdir); context->m_modified = false; + memset(context->m_phrase_indices, 0, + sizeof(context->m_phrase_indices)); + check_format(context->m_user_dir); context->m_pinyin_table = new FacadeChewingTable; @@ -135,6 +140,8 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){ context->m_phrase_table->load(chunk, NULL); context->m_phrase_index = new FacadePhraseIndex; + + context->m_phrase_indices[1] = g_strdup("gb_char.bin"); MemoryChunk * log = new MemoryChunk; chunk = new MemoryChunk; filename = g_build_filename(context->m_system_dir, "gb_char.bin", NULL); if (!chunk->load(filename)) { @@ -148,6 +155,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){ g_free(filename); context->m_phrase_index->merge(1, log); + context->m_phrase_indices[2] = g_strdup("gbk_char.bin"); log = new MemoryChunk; chunk = new MemoryChunk; filename = g_build_filename(context->m_system_dir, "gbk_char.bin", NULL); if (!chunk->load(filename)) { @@ -272,6 +280,9 @@ void pinyin_fini(pinyin_context_t * context){ g_free(context->m_user_dir); context->m_modified = false; + g_free(context->m_phrase_indices[1]); + g_free(context->m_phrase_indices[2]); + delete context; } diff --git a/src/pinyin.h b/src/pinyin.h index dbb635a..43cec3e 100644 --- a/src/pinyin.h +++ b/src/pinyin.h @@ -81,6 +81,13 @@ struct _pinyin_instance_t{ */ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir); +bool pinyin_load_phrase_library(pinyin_context_t * context, + guint8 index, + const char * filename); + +bool pinyin_unload_phrase_library(pinyin_context_t * context, + guint8 index); + /** * pinyin_save: * @context: the pinyin context to be saved into user directory. |