4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "ModuleList.h"
16 #include "LaTeXFeatures.h"
19 #include "support/debug.h"
20 #include "support/FileName.h"
21 #include "support/gettext.h"
22 #include "support/filetools.h"
23 #include "support/lstrings.h"
28 using namespace lyx::support;
33 //global variable: module list
34 ModuleList theModuleList;
37 LyXModule::LyXModule(string const & n, string const & i,
38 string const & d, vector<string> const & p,
39 vector<string> const & r, vector<string> const & e,
41 name_(n), id_(i), description_(d), package_list_(p),
42 required_modules_(r), excluded_modules_(e), category_(c),
45 filename_ = id_ + ".module";
49 vector<string> LyXModule::prerequisites() const {
51 return vector<string>();
55 return prerequisites_;
60 bool LyXModule::isAvailable() const {
64 if (package_list_.empty())
70 //check whether all of the required packages are available
71 vector<string>::const_iterator it = package_list_.begin();
72 vector<string>::const_iterator end = package_list_.end();
73 for (; it != end; ++it) {
74 if (!LaTeXFeatures::isAvailable(*it)) {
76 prerequisites_.push_back(*it);
84 bool LyXModule::isCompatible(string const & modname) const
87 if (find(excluded_modules_.begin(), excluded_modules_.end(), modname) !=
88 excluded_modules_.end())
91 LyXModule const * const lm = theModuleList[modname];
95 // does it exclude us?
96 vector<string> const excmods = lm->getExcludedModules();
97 if (find(excmods.begin(), excmods.end(), id_) != excmods.end())
104 bool LyXModule::areCompatible(string const & mod1, string const & mod2)
106 LyXModule const * const lm1 = theModuleList[mod1];
108 return lm1->isCompatible(mod2);
109 LyXModule const * const lm2 = theModuleList[mod2];
111 return lm2->isCompatible(mod1);
112 // Can't check it either way.
117 // used when sorting the module list.
121 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
123 return _(lm1.getName()) < _(lm2.getName());
128 // Much of this is borrowed from LayoutFileList::read()
129 bool ModuleList::read()
131 FileName const real_file = libFileSearch("", "lyxmodules.lst");
132 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
134 if (real_file.empty()) {
135 LYXERR0("unable to find modules file `lyxmodules.lst'.\n"
136 << "No modules will be available.");
141 if (!lex.setFile(real_file)) {
142 LYXERR0("lyxlex was not able to set file: "
143 << real_file << ".\nNo modules will be available.");
148 LYXERR0("unable to open modules file `"
149 << to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
150 << "'\nNo modules will be available.");
154 bool finished = false;
155 // Parse modules files
156 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
157 while (lex.isOK() && !finished) {
158 LYXERR(Debug::TCLASS, "\tline by line");
160 case Lexer::LEX_FEOF:
164 string const modname = lex.getString();
165 LYXERR(Debug::TCLASS, "Module name: " << modname);
168 string const fname = lex.getString();
169 LYXERR(Debug::TCLASS, "Filename: " << fname);
172 string const desc = lex.getString();
173 LYXERR(Debug::TCLASS, "Description: " << desc);
177 string str = lex.getString();
178 LYXERR(Debug::TCLASS, "Packages: " << str);
180 while (!str.empty()) {
182 str = split(str, p, ',');
187 str = lex.getString();
188 LYXERR(Debug::TCLASS, "Required: " << str);
190 while (!str.empty()) {
192 str = split(str, p, '|');
197 str = lex.getString();
198 LYXERR(Debug::TCLASS, "Excluded: " << str);
200 while (!str.empty()) {
202 str = split(str, p, '|');
207 string const catgy = lex.getString();
208 LYXERR(Debug::TCLASS, "Category: " << catgy);
209 // This code is run when we have
210 // modName, fname, desc, pkgs, req, exc, and catgy
211 addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy);
215 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
217 if (!theModuleList.empty())
218 sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
223 void ModuleList::addLayoutModule(string const & modname,
224 string const & filename, string const & description,
225 vector<string> const & pkgs, vector<string> const & req,
226 vector<string> const & exc, string const & catgy)
228 LyXModule lm(modname, filename, description, pkgs, req, exc, catgy);
229 modlist_.push_back(lm);
233 LyXModuleList::const_iterator ModuleList::begin() const
235 return modlist_.begin();
239 LyXModuleList::iterator ModuleList::begin()
241 return modlist_.begin();
245 LyXModuleList::const_iterator ModuleList::end() const
247 return modlist_.end();
251 LyXModuleList::iterator ModuleList::end()
253 return modlist_.end();
257 LyXModule const * ModuleList::operator[](string const & str) const
259 LyXModuleList::const_iterator it = modlist_.begin();
260 for (; it != modlist_.end(); ++it)
261 if (it->getID() == str) {
262 LyXModule const & mod = *it;
268 LyXModule * ModuleList::operator[](string const & str)
270 LyXModuleList::iterator it = modlist_.begin();
271 for (; it != modlist_.end(); ++it)
272 if (it->getID() == str) {
273 LyXModule & mod = *it;