diff options
author | Peng Wu <alexepico@gmail.com> | 2011-09-26 12:56:47 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-09-26 12:56:47 +0800 |
commit | 0258a5e5058f9ce22e0428e66f5fd33eb64f3e24 (patch) | |
tree | 75e3b4cf3b8e48215a0ebd6c3402d7059dd2769b | |
parent | 48fa6408f09833129bf56e33bdb3aa949ca213aa (diff) | |
download | libpinyin-0258a5e5058f9ce22e0428e66f5fd33eb64f3e24.tar.gz libpinyin-0258a5e5058f9ce22e0428e66f5fd33eb64f3e24.tar.xz libpinyin-0258a5e5058f9ce22e0428e66f5fd33eb64f3e24.zip |
add more checks
-rw-r--r-- | src/pinyin.cpp | 43 | ||||
-rw-r--r-- | tests/test_pinyin.cpp | 4 |
2 files changed, 38 insertions, 9 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 233d9d9..dae72df 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -1,3 +1,27 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2011 Peng Wu <alexepico@gmail.com> + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + + + #include "pinyin.h" #include "pinyin_internal.h" @@ -36,8 +60,8 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){ gchar * filename = g_build_filename (context->m_system_dir, "pinyin_index.bin", NULL); if (!chunk->load(filename)) { - fprintf(stderr, "open %s failed!\n", filename); - exit(ENOENT); + fprintf(stderr, "open %s failed!\n", filename); + return NULL; } context->m_pinyin_table->load(chunk); @@ -49,13 +73,19 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){ context->m_phrase_table = new PhraseLargeTable; chunk = new MemoryChunk; filename = g_build_filename(context->m_system_dir, "phrase_index.bin", NULL); - chunk->load(filename); + if (!chunk->load(filename)) { + fprintf(stderr, "open %s failed!\n", filename); + return NULL; + } context->m_phrase_table->load(chunk); context->m_phrase_index = new FacadePhraseIndex; MemoryChunk * log = new MemoryChunk; chunk = new MemoryChunk; filename = g_build_filename(context->m_system_dir, "gb_char.bin", NULL); - chunk->load(filename); + if (!chunk->load(filename)) { + fprintf(stderr, "open %s failed!\n", filename); + return NULL; + } context->m_phrase_index->load(1, chunk); filename = g_build_filename(context->m_user_dir, "gb_char.dbin", NULL); log->load(filename); @@ -63,7 +93,10 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){ log = new MemoryChunk; chunk = new MemoryChunk; filename = g_build_filename(context->m_system_dir, "gbk_char.bin", NULL); - chunk->load(filename); + if (!chunk->load(filename)) { + fprintf(stderr, "open %s failed!\n", filename); + return NULL; + } context->m_phrase_index->load(2, chunk); filename = g_build_filename(context->m_user_dir, "gbk_char.dbin", NULL); log->load(filename); diff --git a/tests/test_pinyin.cpp b/tests/test_pinyin.cpp index 5fe97ee..920c324 100644 --- a/tests/test_pinyin.cpp +++ b/tests/test_pinyin.cpp @@ -41,10 +41,6 @@ int main(int argc, char * argv[]){ break; } - if (linebuf[0] == '\0') { - continue; - } - pinyin_parse_more_full_pinyins(instance, linebuf); pinyin_guess_sentence(instance); |