phrase_index.compat();
- new_chunk = new MemoryChunk;
- phrase_index.store(1, new_chunk);
- new_chunk->save("gb_char.bin");
- phrase_index.load(1, new_chunk);
+ if (!save_phrase_index(&phrase_index))
+ exit(ENOENT);
- new_chunk = new MemoryChunk;
- phrase_index.store(2, new_chunk);
- new_chunk->save("gbk_char.bin");
- phrase_index.load(2, new_chunk);
-
return 0;
}
taglib_fini();
- chunk = new MemoryChunk;
- phrase_index.store(1, chunk);
- chunk->save("gb_char.bin");
- phrase_index.load(1, chunk);
-
- chunk = new MemoryChunk;
- phrase_index.store(2, chunk);
- chunk->save("gbk_char.bin");
- phrase_index.load(2, chunk);
+ if (!save_phrase_index(&phrase_index))
+ exit(ENOENT);
return 0;
}
free(linebuf);
- MemoryChunk * new_chunk = new MemoryChunk;
- phrase_index.store(1, new_chunk);
- new_chunk->save("gb_char.bin");
- phrase_index.load(1, new_chunk);
-
- new_chunk = new MemoryChunk;
- phrase_index.store(2, new_chunk);
- new_chunk->save("gbk_char.bin");
- phrase_index.load(2, new_chunk);
+ if (!save_phrase_index(&phrase_index))
+ exit(ENOENT);
return 0;
}
}
#endif
- MemoryChunk * new_chunk = new MemoryChunk;
- phrase_index.store(1, new_chunk);
- new_chunk->save("gb_char.bin");
- phrase_index.load(1, new_chunk);
-
- new_chunk = new MemoryChunk;
- phrase_index.store(2, new_chunk);
- new_chunk->save("gbk_char.bin");
- phrase_index.load(2, new_chunk);
+ if (!save_phrase_index(&phrase_index))
+ exit(ENOENT);
return 0;
}
chunk = new MemoryChunk;
bool retval = chunk->load(bin_file);
if (!retval) {
- fprintf(stderr, "open %s failed!\n", bin_file);
+ fprintf(stderr, "load %s failed!\n", bin_file);
return false;
}
return true;
}
+static bool save_phrase_index(FacadePhraseIndex * phrase_index) {
+ MemoryChunk * new_chunk = NULL;
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ const char * bin_file = pinyin_phrase_files[i];
+ if (NULL == bin_file)
+ continue;
+
+ new_chunk = new MemoryChunk;
+ phrase_index->store(i, new_chunk);
+ bool retval = new_chunk->save(bin_file);
+ if (!retval) {
+ fprintf(stderr, "save %s failed.", bin_file);
+ return false;
+ }
+
+ phrase_index->load(i, new_chunk);
+ }
+ return true;
+}
#endif