#include <algorithm>
#include <cstring>
+#include <fstream>
using namespace std;
using namespace lyx::support;
FileNameList const data_files = base.dirList("dat");
string idx;
string data;
+ string basename;
LYXERR(Debug::FILES, "thesaurus path: " << path);
for (FileNameList::const_iterator it = idx_files.begin(); it != idx_files.end(); ++it) {
- if (contains(it->onlyFileName(), to_ascii(lang))) {
+ basename = it->onlyFileNameWithoutExt();
+ if (contains(basename, to_ascii(lang))) {
+ ifstream ifs(it->absFileName().c_str());
+ if (ifs) {
+ // check for appropriate version of index file
+ string encoding; // first line is encoding
+ int items = 0; // second line is no. of items
+ getline(ifs,encoding);
+ ifs >> items;
+ if (ifs.fail()) {
+ LYXERR(Debug::FILES, "ignore irregular thesaurus idx file: " << it->absFileName());
+ continue;
+ }
+ if (encoding.length() == 0 || encoding.find_first_of(',') != string::npos) {
+ LYXERR(Debug::FILES, "ignore version1 thesaurus idx file: " << it->absFileName());
+ continue;
+ }
+ }
idx = it->absFileName();
LYXERR(Debug::FILES, "selected thesaurus idx file: " << idx);
break;
return make_pair(string(), string());
}
for (support::FileNameList::const_iterator it = data_files.begin(); it != data_files.end(); ++it) {
- if (contains(it->onlyFileName(), to_ascii(lang))) {
+ if (contains(it->onlyFileName(), basename)) {
data = it->absFileName();
LYXERR(Debug::FILES, "selected thesaurus data file: " << data);
break;
bool Thesaurus::thesaurusInstalled(docstring const & lang) const
{
+ if (thesaurusAvailable(lang))
+ return true;
pair<string, string> files = d->getThesaurus(lang);
return (!files.first.empty() && !files.second.empty());
}