summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-06-19 11:13:46 +0800
committerPeng Wu <alexepico@gmail.com>2017-06-19 11:16:32 +0800
commit97ca682a1099ae6da6ceacd9b15f654562567013 (patch)
tree77fe351a7979dd5121587d1b186c576f2df6e93a
parent5607752c2b989849923676f4a925e5315a3303d4 (diff)
downloadlibpinyin-97ca682a1099ae6da6ceacd9b15f654562567013.zip
libpinyin-97ca682a1099ae6da6ceacd9b15f654562567013.tar.gz
libpinyin-97ca682a1099ae6da6ceacd9b15f654562567013.tar.xz
update pinyin.cpp and zhuyin.cpp
-rw-r--r--src/pinyin.cpp48
-rw-r--r--src/zhuyin.cpp48
2 files changed, 8 insertions, 88 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 71acecc..0c396f1 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -362,7 +362,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
context->m_user_bigram = new Bigram;
filename = g_build_filename(context->m_user_dir, USER_BIGRAM, NULL);
- context->m_user_bigram->load_db(filename);
+ context->m_user_bigram->attach(filename, ATTACH_READWRITE|ATTACH_CREATE);
g_free(filename);
gfloat lambda = context->m_system_table_info.get_lambda();
@@ -829,53 +829,13 @@ bool pinyin_save(pinyin_context_t * context){
}
/* save user pinyin table */
- gchar * tmpfilename = g_build_filename
- (context->m_user_dir, USER_PINYIN_INDEX ".tmp", NULL);
- unlink(tmpfilename);
- gchar * filename = g_build_filename
- (context->m_user_dir, USER_PINYIN_INDEX, NULL);
-
- context->m_pinyin_table->store(tmpfilename);
-
- int result = rename(tmpfilename, filename);
- if (0 != result)
- fprintf(stderr, "rename %s to %s failed.\n",
- tmpfilename, filename);
-
- g_free(tmpfilename);
- g_free(filename);
+ context->m_pinyin_table->sync();
/* save user phrase table */
- tmpfilename = g_build_filename
- (context->m_user_dir, USER_PHRASE_INDEX ".tmp", NULL);
- unlink(tmpfilename);
- filename = g_build_filename
- (context->m_user_dir, USER_PHRASE_INDEX, NULL);
-
- context->m_phrase_table->store(tmpfilename);
-
- result = rename(tmpfilename, filename);
- if (0 != result)
- fprintf(stderr, "rename %s to %s failed.\n",
- tmpfilename, filename);
-
- g_free(tmpfilename);
- g_free(filename);
+ context->m_phrase_table->sync();
/* save user bi-gram */
- tmpfilename = g_build_filename
- (context->m_user_dir, USER_BIGRAM ".tmp", NULL);
- unlink(tmpfilename);
- filename = g_build_filename(context->m_user_dir, USER_BIGRAM, NULL);
- context->m_user_bigram->save_db(tmpfilename);
-
- result = rename(tmpfilename, filename);
- if (0 != result)
- fprintf(stderr, "rename %s to %s failed.\n",
- tmpfilename, filename);
-
- g_free(tmpfilename);
- g_free(filename);
+ context->m_user_bigram->sync();
mark_version(context);
diff --git a/src/zhuyin.cpp b/src/zhuyin.cpp
index f4e28d8..3b98df5 100644
--- a/src/zhuyin.cpp
+++ b/src/zhuyin.cpp
@@ -340,7 +340,7 @@ zhuyin_context_t * zhuyin_init(const char * systemdir, const char * userdir){
context->m_user_bigram = new Bigram;
filename = g_build_filename(context->m_user_dir, USER_BIGRAM, NULL);
- context->m_user_bigram->load_db(filename);
+ context->m_user_bigram->attach(filename, ATTACH_READWRITE|ATTACH_CREATE);
g_free(filename);
gfloat lambda = context->m_system_table_info.get_lambda();
@@ -644,53 +644,13 @@ bool zhuyin_save(zhuyin_context_t * context){
}
/* save user pinyin table */
- gchar * tmpfilename = g_build_filename
- (context->m_user_dir, USER_PINYIN_INDEX ".tmp", NULL);
- unlink(tmpfilename);
- gchar * filename = g_build_filename
- (context->m_user_dir, USER_PINYIN_INDEX, NULL);
-
- context->m_pinyin_table->store(tmpfilename);
-
- int result = rename(tmpfilename, filename);
- if (0 != result)
- fprintf(stderr, "rename %s to %s failed.\n",
- tmpfilename, filename);
-
- g_free(tmpfilename);
- g_free(filename);
+ context->m_pinyin_table->sync();
/* save user phrase table */
- tmpfilename = g_build_filename
- (context->m_user_dir, USER_PHRASE_INDEX ".tmp", NULL);
- unlink(tmpfilename);
- filename = g_build_filename
- (context->m_user_dir, USER_PHRASE_INDEX, NULL);
-
- context->m_phrase_table->store(tmpfilename);
-
- result = rename(tmpfilename, filename);
- if (0 != result)
- fprintf(stderr, "rename %s to %s failed.\n",
- tmpfilename, filename);
-
- g_free(tmpfilename);
- g_free(filename);
+ context->m_phrase_table->sync();
/* save user bi-gram */
- tmpfilename = g_build_filename
- (context->m_user_dir, USER_BIGRAM ".tmp", NULL);
- unlink(tmpfilename);
- filename = g_build_filename(context->m_user_dir, USER_BIGRAM, NULL);
- context->m_user_bigram->save_db(tmpfilename);
-
- result = rename(tmpfilename, filename);
- if (0 != result)
- fprintf(stderr, "rename %s to %s failed.\n",
- tmpfilename, filename);
-
- g_free(tmpfilename);
- g_free(filename);
+ context->m_user_bigram->sync();
mark_version(context);