]> git.lyx.org Git - lyx.git/blobdiff - src/Thesaurus.cpp
More related to #7224: It's OK for layouts not to provide a ListCommand
[lyx.git] / src / Thesaurus.cpp
index 870f967f41578ba7fcbb70c6c5a6dd4ed174e952..bf657762c1c2d4a423d3998a7dc8245734d3e132 100644 (file)
@@ -100,9 +100,16 @@ pair<string,string> Thesaurus::Private::getThesaurus(string const & path, docstr
                if (contains(basename, to_ascii(lang))) {
                        ifstream ifs(it->absFileName().c_str());
                        if (ifs) {
-                               string s;
-                               getline(ifs,s);
-                               if (s.find_first_of(',') != string::npos) {
+                               // 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;
                                }
@@ -215,17 +222,17 @@ Thesaurus::Meanings Thesaurus::lookup(docstring const & t, docstring const & lan
        // they are needed for the CleanUpAfterLookup routine
        mentry * pm = pmean;
        docstring meaning;
-       docstring ret;
        for (int i = 0; i < count; i++) {
+               vector<docstring> ret;
                meaning = from_iconv_encoding(string(pm->defn), encoding);
                // remove silly item
                if (support::prefixIs(meaning, '-'))
                        meaning = support::ltrim(meaning, "- ");
                for (int j = 0; j < pm->count; j++) {
-                       ret = from_iconv_encoding(string(pm->psyns[j]), encoding);
+                       ret.push_back(from_iconv_encoding(string(pm->psyns[j]), encoding));
                }
-       meanings[meaning].push_back(ret);
-       pm++;
+               meanings[meaning] = ret;
+               ++pm;
        }
        // now clean up all allocated memory
        mythes->CleanUpAfterLookup(&pmean, count);