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
52 return vector<string>();
56 return prerequisites_;
61 bool LyXModule::isAvailable() const
66 if (package_list_.empty())
72 //check whether all of the required packages are available
73 vector<string>::const_iterator it = package_list_.begin();
74 vector<string>::const_iterator end = package_list_.end();
75 for (; it != end; ++it) {
76 if (!LaTeXFeatures::isAvailable(*it)) {
78 prerequisites_.push_back(*it);
86 bool LyXModule::isCompatible(string const & modname) const
89 if (find(excluded_modules_.begin(), excluded_modules_.end(), modname) !=
90 excluded_modules_.end())
93 LyXModule const * const lm = theModuleList[modname];
97 // does it exclude us?
98 vector<string> const excmods = lm->getExcludedModules();
99 if (find(excmods.begin(), excmods.end(), id_) != excmods.end())
106 bool LyXModule::areCompatible(string const & mod1, string const & mod2)
108 LyXModule const * const lm1 = theModuleList[mod1];
110 return lm1->isCompatible(mod2);
111 LyXModule const * const lm2 = theModuleList[mod2];
113 return lm2->isCompatible(mod1);
114 // Can't check it either way.
119 // used when sorting the module list.
122 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
124 return _(lm1.getName()) < _(lm2.getName());
129 // Much of this is borrowed from LayoutFileList::read()
130 bool ModuleList::read()
132 FileName const real_file = libFileSearch("", "lyxmodules.lst");
133 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
135 if (real_file.empty()) {
136 LYXERR0("unable to find modules file `lyxmodules.lst'.\n"
137 << "No modules will be available.");
142 if (!lex.setFile(real_file)) {
143 LYXERR0("lyxlex was not able to set file: "
144 << real_file << ".\nNo modules will be available.");
149 LYXERR0("unable to open modules file `"
150 << to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
151 << "'\nNo modules will be available.");
155 bool finished = false;
156 // Parse modules files
157 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
158 while (lex.isOK() && !finished) {
159 LYXERR(Debug::TCLASS, "\tline by line");
161 case Lexer::LEX_FEOF:
165 string const modname = lex.getString();
166 LYXERR(Debug::TCLASS, "Module name: " << modname);
169 string const fname = lex.getString();
170 LYXERR(Debug::TCLASS, "Filename: " << fname);
173 string const desc = lex.getString();
174 LYXERR(Debug::TCLASS, "Description: " << desc);
178 string str = lex.getString();
179 LYXERR(Debug::TCLASS, "Packages: " << str);
181 while (!str.empty()) {
183 str = split(str, p, ',');
188 str = lex.getString();
189 LYXERR(Debug::TCLASS, "Required: " << str);
191 while (!str.empty()) {
193 str = split(str, p, '|');
198 str = lex.getString();
199 LYXERR(Debug::TCLASS, "Excluded: " << str);
201 while (!str.empty()) {
203 str = split(str, p, '|');
208 string const catgy = lex.getString();
209 LYXERR(Debug::TCLASS, "Category: " << catgy);
210 // This code is run when we have
211 // modName, fname, desc, pkgs, req, exc, and catgy
212 addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy);
216 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
218 if (!theModuleList.empty())
219 sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
224 void ModuleList::addLayoutModule(string const & modname,
225 string const & filename, string const & description,
226 vector<string> const & pkgs, vector<string> const & req,
227 vector<string> const & exc, string const & catgy)
229 LyXModule lm(modname, filename, description, pkgs, req, exc, catgy);
230 modlist_.push_back(lm);
234 LyXModuleList::const_iterator ModuleList::begin() const
236 return modlist_.begin();
240 LyXModuleList::iterator ModuleList::begin()
242 return modlist_.begin();
246 LyXModuleList::const_iterator ModuleList::end() const
248 return modlist_.end();
252 LyXModuleList::iterator ModuleList::end()
254 return modlist_.end();
258 LyXModule const * ModuleList::operator[](string const & str) const
260 LyXModuleList::const_iterator it = modlist_.begin();
261 for (; it != modlist_.end(); ++it)
262 if (it->getID() == str) {
263 LyXModule const & mod = *it;
270 LyXModule * ModuleList::operator[](string const & str)
272 LyXModuleList::iterator it = modlist_.begin();
273 for (; it != modlist_.end(); ++it)
274 if (it->getID() == str) {
275 LyXModule & mod = *it;