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,
40 name(n), id(i), description(d), packageList(p),
41 requiredModules(r), excludedModules(e), category_(c),
44 filename = id + ".module";
48 bool LyXModule::isAvailable() {
52 if (packageList.empty())
57 //check whether all of the required packages are available
58 vector<string>::const_iterator it = packageList.begin();
59 vector<string>::const_iterator end = packageList.end();
60 for (; it != end; ++it) {
61 if (!LaTeXFeatures::isAvailable(*it)) {
72 bool LyXModule::isCompatible(string const & modName) const
75 if (find(excludedModules.begin(), excludedModules.end(), modName) !=
76 excludedModules.end())
79 LyXModule const * const lm = moduleList[modName];
83 // does it exclude us?
84 vector<string> const excMods = lm->getExcludedModules();
85 if (find(excMods.begin(), excMods.end(), id) != excMods.end())
92 bool LyXModule::areCompatible(string const & mod1, string const & mod2)
94 LyXModule const * const lm1 = moduleList[mod1];
96 return lm1->isCompatible(mod2);
97 LyXModule const * const lm2 = moduleList[mod2];
99 return lm2->isCompatible(mod1);
100 // Can't check it either way.
104 // used when sorting the module list.
108 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
110 return lm1.getName() < lm2.getName();
115 //Much of this is borrowed from LayoutFileList::read()
116 bool ModuleList::read()
118 FileName const real_file = libFileSearch("", "lyxmodules.lst");
119 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
121 if (real_file.empty()) {
122 LYXERR0("unable to find modules file `"
123 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
124 << "'.\nNo modules will be available.");
129 if (!lex.setFile(real_file)) {
130 LYXERR0("lyxlex was not able to set file: "
131 << real_file << ".\nNo modules will be available.");
136 LYXERR0("unable to open modules file `"
137 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
138 << "'\nNo modules will be available.");
142 bool finished = false;
143 // Parse modules files
144 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
145 while (lex.isOK() && !finished) {
146 LYXERR(Debug::TCLASS, "\tline by line");
148 case Lexer::LEX_FEOF:
152 string const modName = lex.getString();
153 LYXERR(Debug::TCLASS, "Module name: " << modName);
156 string const fname = lex.getString();
157 LYXERR(Debug::TCLASS, "Filename: " << fname);
160 string const desc = lex.getString();
161 LYXERR(Debug::TCLASS, "Description: " << desc);
165 string str = lex.getString();
166 LYXERR(Debug::TCLASS, "Packages: " << str);
168 while (!str.empty()) {
170 str = split(str, p, ',');
175 str = lex.getString();
176 LYXERR(Debug::TCLASS, "Required: " << str);
178 while (!str.empty()) {
180 str = split(str, p, '|');
185 str = lex.getString();
186 LYXERR(Debug::TCLASS, "Excluded: " << str);
188 while (!str.empty()) {
190 str = split(str, p, '|');
195 string const catgy = lex.getString();
196 LYXERR(Debug::TCLASS, "Category: " << catgy);
197 // This code is run when we have
198 // modName, fname, desc, pkgs, req, exc, and catgy
199 addLayoutModule(modName, fname, desc, pkgs, req, exc, catgy);
203 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
205 if (!moduleList.empty())
206 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
211 void ModuleList::addLayoutModule(string const & moduleName,
212 string const & filename, string const & description,
213 vector<string> const & pkgs, vector<string> const & req,
214 vector<string> const & exc, string const & catgy)
216 LyXModule lm(moduleName, filename, description, pkgs, req, exc, catgy);
217 modlist_.push_back(lm);
221 LyXModuleList::const_iterator ModuleList::begin() const
223 return modlist_.begin();
227 LyXModuleList::iterator ModuleList::begin()
229 return modlist_.begin();
233 LyXModuleList::const_iterator ModuleList::end() const
235 return modlist_.end();
239 LyXModuleList::iterator ModuleList::end()
241 return modlist_.end();
245 LyXModule * ModuleList::operator[](string const & str)
247 LyXModuleList::iterator it = modlist_.begin();
248 for (; it != modlist_.end(); ++it)
249 if (it->getID() == str) {
250 LyXModule & mod = *it;