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/filetools.h"
22 #include "support/lstrings.h"
27 using namespace lyx::support;
32 //global variable: module list
33 ModuleList moduleList;
36 LyXModule::LyXModule(string const & n, string const & i,
37 string const & d, vector<string> const & p,
38 vector<string> const & r, vector<string> const & e):
39 name(n), id(i), description(d),
40 packageList(p), requiredModules(r), excludedModules(e),
43 filename = id + ".module";
47 bool LyXModule::isAvailable() {
48 if (packageList.empty())
53 //check whether all of the required packages are available
54 vector<string>::const_iterator it = packageList.begin();
55 vector<string>::const_iterator end = packageList.end();
56 for (; it != end; ++it) {
57 if (!LaTeXFeatures::isAvailable(*it)) {
67 bool LyXModule::isCompatible(string const & modName) const
70 if (find(excludedModules.begin(), excludedModules.end(), modName) !=
71 excludedModules.end())
74 LyXModule const * const lm = moduleList[modName];
78 // does it exclude us?
79 vector<string> const excMods = lm->getExcludedModules();
80 if (find(excMods.begin(), excMods.end(), id) != excMods.end())
87 bool LyXModule::areCompatible(string const & mod1, string const & mod2)
89 LyXModule const * const lm1 = moduleList[mod1];
91 return lm1->isCompatible(mod2);
92 LyXModule const * const lm2 = moduleList[mod2];
94 return lm2->isCompatible(mod1);
95 // Can't check it either way.
99 // used when sorting the module list.
103 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
105 return lm1.getName() < lm2.getName();
110 //Much of this is borrowed from LayoutFileList::read()
111 bool ModuleList::load()
113 FileName const real_file = libFileSearch("", "lyxmodules.lst");
114 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
116 if (real_file.empty()) {
117 LYXERR0("unable to find modules file `"
118 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
119 << "'.\nNo modules will be available.");
124 if (!lex.setFile(real_file)) {
125 LYXERR0("lyxlex was not able to set file: "
126 << real_file << ".\nNo modules will be available.");
131 LYXERR0("unable to open modules file `"
132 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
133 << "'\nNo modules will be available.");
137 bool finished = false;
138 // Parse modules files
139 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
140 while (lex.isOK() && !finished) {
141 LYXERR(Debug::TCLASS, "\tline by line");
143 case Lexer::LEX_FEOF:
147 string const modName = lex.getString();
148 LYXERR(Debug::TCLASS, "Module name: " << modName);
151 string const fname = lex.getString();
152 LYXERR(Debug::TCLASS, "Filename: " << fname);
155 string const desc = lex.getString();
156 LYXERR(Debug::TCLASS, "Description: " << desc);
160 string str = lex.getString();
161 LYXERR(Debug::TCLASS, "Packages: " << str);
163 while (!str.empty()) {
165 str = split(str, p, ',');
170 str = lex.getString();
171 LYXERR(Debug::TCLASS, "Required: " << str);
173 while (!str.empty()) {
175 str = split(str, p, '|');
180 str = lex.getString();
181 LYXERR(Debug::TCLASS, "Excluded: " << str);
183 while (!str.empty()) {
185 str = split(str, p, '|');
188 // This code is run when we have
189 // modName, fname, desc, pkgs, req, and exc
190 addLayoutModule(modName, fname, desc, pkgs, req, exc);
194 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
196 if (!moduleList.empty())
197 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
202 void ModuleList::addLayoutModule(string const & moduleName,
203 string const & filename, string const & description,
204 vector<string> const & pkgs, vector<string> const & req,
205 vector<string> const & exc)
207 LyXModule lm(moduleName, filename, description, pkgs, req, exc);
208 modlist_.push_back(lm);
212 LyXModuleList::const_iterator ModuleList::begin() const
214 return modlist_.begin();
218 LyXModuleList::iterator ModuleList::begin()
220 return modlist_.begin();
224 LyXModuleList::const_iterator ModuleList::end() const
226 return modlist_.end();
230 LyXModuleList::iterator ModuleList::end()
232 return modlist_.end();
236 LyXModule * ModuleList::operator[](string const & str)
238 LyXModuleList::iterator it = modlist_.begin();
239 for (; it != modlist_.end(); ++it)
240 if (it->getID() == str) {
241 LyXModule & mod = *it;