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 theModuleList;
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), package_list_(p),
41 required_modules_(r), excluded_modules_(e), category_(c),
44 filename_ = id_ + ".module";
48 bool LyXModule::isAvailable() const {
52 if (package_list_.empty())
57 //check whether all of the required packages are available
58 vector<string>::const_iterator it = package_list_.begin();
59 vector<string>::const_iterator end = package_list_.end();
60 for (; it != end; ++it) {
61 if (!LaTeXFeatures::isAvailable(*it)) {
72 bool LyXModule::isCompatible(string const & modname) const
75 if (find(excluded_modules_.begin(), excluded_modules_.end(), modname) !=
76 excluded_modules_.end())
79 LyXModule const * const lm = theModuleList[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 = theModuleList[mod1];
96 return lm1->isCompatible(mod2);
97 LyXModule const * const lm2 = theModuleList[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 (!theModuleList.empty())
206 sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
211 void ModuleList::addLayoutModule(string const & modname,
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(modname, 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 const * ModuleList::operator[](string const & str) const
247 LyXModuleList::const_iterator it = modlist_.begin();
248 for (; it != modlist_.end(); ++it)
249 if (it->getID() == str) {
250 LyXModule const & mod = *it;
256 LyXModule * ModuleList::operator[](string const & str)
258 LyXModuleList::iterator it = modlist_.begin();
259 for (; it != modlist_.end(); ++it)
260 if (it->getID() == str) {
261 LyXModule & mod = *it;