]> git.lyx.org Git - lyx.git/blobdiff - src/Thesaurus.cpp
Clean-up the code with respect to PassThru insets and layouts.
[lyx.git] / src / Thesaurus.cpp
index 83eed55ea0133963468f4c9c1e4fc68688f2f35e..d21453ab0fb01dc2e75e92487509411ce4cd3a95 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <algorithm>
 #include <cstring>
+#include <fstream>
 
 using namespace std;
 using namespace lyx::support;
@@ -91,10 +92,28 @@ pair<string,string> Thesaurus::Private::getThesaurus(string const & path, docstr
        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;
@@ -104,7 +123,7 @@ pair<string,string> Thesaurus::Private::getThesaurus(string const & path, docstr
                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;
@@ -164,6 +183,8 @@ bool Thesaurus::thesaurusAvailable(docstring const & lang) const
 
 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());
 }