From fff35792df8d7ae0e65a20b2e507f7fabbd8becb Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 17 Jun 2013 13:45:56 +0800 Subject: fixes load_text --- src/storage/chewing_large_table.cpp | 9 +++++---- src/storage/phrase_index.cpp | 16 ++++++++++------ src/storage/phrase_large_table2.cpp | 13 +++++++------ 3 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index 85246c3..2eb8658 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -668,10 +668,11 @@ bool ChewingLargeTable::load_text(FILE * infile) { size_t freq; while (!feof(infile)) { - fscanf(infile, "%s", pinyin); - fscanf(infile, "%s", phrase); - fscanf(infile, "%u", &token); - fscanf(infile, "%ld", &freq); + int num = fscanf(infile, "%s %s %u %ld", + pinyin, phrase, &token, &freq); + + if (4 != num) + continue; if(feof(infile)) break; diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp index 5f468b3..930d606 100644 --- a/src/storage/phrase_index.cpp +++ b/src/storage/phrase_index.cpp @@ -519,14 +519,18 @@ bool FacadePhraseIndex::load_text(guint8 phrase_index, FILE * infile){ char phrase[256]; phrase_token_t token; size_t freq; + PhraseItem * item_ptr = new PhraseItem; phrase_token_t cur_token = 0; - while ( !feof(infile)){ - fscanf(infile, "%s", pinyin); - fscanf(infile, "%s", phrase); - fscanf(infile, "%u", &token); - fscanf(infile, "%ld", &freq); - if ( feof(infile) ) + + while (!feof(infile)){ + int num = fscanf(infile, "%s %s %u %ld", + pinyin, phrase, &token, &freq); + + if (4 != num) + continue; + + if (feof(infile)) break; assert(PHRASE_INDEX_LIBRARY_INDEX(token) == phrase_index ); diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp index fadbbe3..f7d8ae2 100644 --- a/src/storage/phrase_large_table2.cpp +++ b/src/storage/phrase_large_table2.cpp @@ -472,13 +472,14 @@ bool PhraseLargeTable2::load_text(FILE * infile){ phrase_token_t token; size_t freq; - while ( !feof(infile) ) { - fscanf(infile, "%s", pinyin); - fscanf(infile, "%s", phrase); - fscanf(infile, "%u", &token); - fscanf(infile, "%ld", &freq); + while (!feof(infile)) { + int num = fscanf(infile, "%s %s %u %ld", + pinyin, phrase, &token, &freq); - if ( feof(infile) ) + if (4 != num) + continue; + + if (feof(infile)) break; glong phrase_len = g_utf8_strlen(phrase, -1); -- cgit