- string file_ = file;
- // do we need to add the suffix?
- if (!(getExtension(file) == type))
- file_ += '.' + type;
-
- lyxerr << "Searching for file " << file_ << endl;
-
- string lstfile = type + "Files.lst";
- if (type == "cls")
- lstfile = "clsFiles.lst";
- else if (type == "sty")
- lstfile = "styFiles.lst";
- else if (type == "bst")
- lstfile = "bstFiles.lst";
- else if (type == "bib")
- lstfile = "bibFiles.lst";
- FileName const abslstfile = libFileSearch(string(), lstfile);
- if (abslstfile.empty()) {
- lyxerr << "File `'" << lstfile << "' not found." << endl;
- return string();
- }
- string const allClasses = getFileContents(abslstfile);
- int entries = 0;
- string classfile = token(allClasses, '\n', entries);
- int count = 0;
- while ((!contains(classfile, file) ||
- (onlyFilename(classfile) != file)) &&
- (++count < 1000)) {
- classfile = token(allClasses, '\n', ++entries);
- }
-
- // now we have filename with full path
- lyxerr << "with full path: " << classfile << endl;
-
- return classfile;
+ QString lstfile = type + "Files.lst";
+ FileName const abslstfile = libFileSearch(QString(), lstfile);
+ if (abslstfile.empty())
+ return QString();
+ QString cs = toqstr(abslstfile.fileContents("UTF-8"));
+ cs.replace("\r", "");
+ QStringList const result = cs.split("\n").filter(file);
+ if (result.empty())
+ return QString();
+ return result.at(0);