3 * \file CiteEnginesList.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "CiteEnginesList.h"
17 #include "LaTeXFeatures.h"
20 #include "support/debug.h"
21 #include "support/FileName.h"
22 #include "support/gettext.h"
23 #include "support/filetools.h"
24 #include "support/lstrings.h"
29 using namespace lyx::support;
34 //global variable: cite engine list
35 CiteEnginesList theCiteEnginesList;
38 LyXCiteEngine::LyXCiteEngine(string const & n, string const & i,
39 vector<string> const & cet, string const & d,
40 vector<string> const & p,
41 vector<string> const & r, vector<string> const & e):
42 name_(n), id_(i), engine_types_(cet), description_(d), package_list_(p),
43 required_engines_(r), excluded_engines_(e),
44 checked_(false), available_(false)
46 filename_ = id_ + ".citeengine";
50 vector<string> LyXCiteEngine::prerequisites() const
54 return prerequisites_;
58 bool LyXCiteEngine::isAvailable() const
60 if (package_list_.empty())
66 //check whether all of the required packages are available
67 vector<string>::const_iterator it = package_list_.begin();
68 vector<string>::const_iterator end = package_list_.end();
69 for (; it != end; ++it) {
70 if (!LaTeXFeatures::isAvailable(*it)) {
72 prerequisites_.push_back(*it);
79 bool LyXCiteEngine::isCompatible(string const & cename) const
82 if (find(excluded_engines_.begin(), excluded_engines_.end(), cename) !=
83 excluded_engines_.end())
86 LyXCiteEngine const * const lm = theCiteEnginesList[cename];
90 // does it exclude us?
91 vector<string> const excengs = lm->getExcludedEngines();
92 if (find(excengs.begin(), excengs.end(), id_) != excengs.end())
99 bool LyXCiteEngine::areCompatible(string const & eng1, string const & eng2)
101 LyXCiteEngine const * const lm1 = theCiteEnginesList[eng1];
103 return lm1->isCompatible(eng2);
104 LyXCiteEngine const * const lm2 = theCiteEnginesList[eng2];
106 return lm2->isCompatible(eng1);
107 // Can't check it either way.
112 // used when sorting the cite engine list.
115 int operator()(LyXCiteEngine const & ce1, LyXCiteEngine const & ce2) const
117 return _(ce1.getName()) < _(ce2.getName());
122 // Much of this is borrowed from LayoutFileList::read()
123 bool CiteEnginesList::read()
125 FileName const real_file = libFileSearch("", "lyxciteengines.lst");
126 LYXERR(Debug::TCLASS, "Reading cite engines from `" << real_file << '\'');
128 if (real_file.empty()) {
129 LYXERR0("unable to find cite engines file `citeengines.lst'.\n"
130 << "No cite engines will be available.");
135 if (!lex.setFile(real_file)) {
136 LYXERR0("lyxlex was not able to set file: "
137 << real_file << ".\nNo cite engines will be available.");
142 LYXERR0("unable to open cite engines file `"
143 << to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
144 << "'\nNo cite engines will be available.");
148 bool finished = false;
149 // Parse cite engines files
150 LYXERR(Debug::TCLASS, "Starting parsing of lyxciteengines.lst");
151 while (lex.isOK() && !finished) {
152 LYXERR(Debug::TCLASS, "\tline by line");
154 case Lexer::LEX_FEOF:
158 string const cename = lex.getString();
159 LYXERR(Debug::TCLASS, "Engine name: " << cename);
162 string const fname = lex.getString();
163 LYXERR(Debug::TCLASS, "Filename: " << fname);
166 string cet = lex.getString();
167 LYXERR(Debug::TCLASS, "Engine Type: " << cet);
169 while (!cet.empty()) {
171 cet = split(cet, p, '|');
176 string const desc = lex.getString();
177 LYXERR(Debug::TCLASS, "Description: " << desc);
181 string str = lex.getString();
182 LYXERR(Debug::TCLASS, "Packages: " << str);
184 while (!str.empty()) {
186 str = split(str, p, ',');
191 str = lex.getString();
192 LYXERR(Debug::TCLASS, "Required: " << str);
194 while (!str.empty()) {
196 str = split(str, p, '|');
201 str = lex.getString();
202 LYXERR(Debug::TCLASS, "Excluded: " << str);
204 while (!str.empty()) {
206 str = split(str, p, '|');
209 // This code is run when we have
210 // cename, fname, desc, pkgs, req and exc
211 addCiteEngine(cename, fname, cets, desc, pkgs, req, exc);
215 LYXERR(Debug::TCLASS, "End of parsing of lyxciteengines.lst");
217 if (!theCiteEnginesList.empty())
218 sort(theCiteEnginesList.begin(), theCiteEnginesList.end(), EngineSorter());
223 void CiteEnginesList::addCiteEngine(string const & cename,
224 string const & filename, vector<string> const & cets, string const & description,
225 vector<string> const & pkgs, vector<string> const & req,
226 vector<string> const & exc)
228 LyXCiteEngine ce(cename, filename, cets, description, pkgs, req, exc);
229 englist_.push_back(ce);
233 LyXCiteEnginesList::const_iterator CiteEnginesList::begin() const
235 return englist_.begin();
239 LyXCiteEnginesList::iterator CiteEnginesList::begin()
241 return englist_.begin();
245 LyXCiteEnginesList::const_iterator CiteEnginesList::end() const
247 return englist_.end();
251 LyXCiteEnginesList::iterator CiteEnginesList::end()
253 return englist_.end();
257 LyXCiteEngine const * CiteEnginesList::operator[](string const & str) const
259 LyXCiteEnginesList::const_iterator it = englist_.begin();
260 for (; it != englist_.end(); ++it)
261 if (it->getID() == str) {
262 LyXCiteEngine const & eng = *it;
269 LyXCiteEngine * CiteEnginesList::operator[](string const & str)
271 LyXCiteEnginesList::iterator it = englist_.begin();
272 for (; it != englist_.end(); ++it)
273 if (it->getID() == str) {
274 LyXCiteEngine & eng = *it;