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 vector<string> LyXModule::prerequisites() const {
50 return vector<string>();
54 return prerequisites_;
59 bool LyXModule::isAvailable() const {
63 if (package_list_.empty())
69 //check whether all of the required packages are available
70 vector<string>::const_iterator it = package_list_.begin();
71 vector<string>::const_iterator end = package_list_.end();
72 for (; it != end; ++it) {
73 if (!LaTeXFeatures::isAvailable(*it)) {
75 prerequisites_.push_back(*it);
83 bool LyXModule::isCompatible(string const & modname) const
86 if (find(excluded_modules_.begin(), excluded_modules_.end(), modname) !=
87 excluded_modules_.end())
90 LyXModule const * const lm = theModuleList[modname];
94 // does it exclude us?
95 vector<string> const excmods = lm->getExcludedModules();
96 if (find(excmods.begin(), excmods.end(), id_) != excmods.end())
103 bool LyXModule::areCompatible(string const & mod1, string const & mod2)
105 LyXModule const * const lm1 = theModuleList[mod1];
107 return lm1->isCompatible(mod2);
108 LyXModule const * const lm2 = theModuleList[mod2];
110 return lm2->isCompatible(mod1);
111 // Can't check it either way.
115 // used when sorting the module list.
119 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
121 return lm1.getName() < lm2.getName();
126 //Much of this is borrowed from LayoutFileList::read()
127 bool ModuleList::read()
129 FileName const real_file = libFileSearch("", "lyxmodules.lst");
130 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
132 if (real_file.empty()) {
133 LYXERR0("unable to find modules file `lyxmodules.lst'.\n"
134 << "No modules will be available.");
139 if (!lex.setFile(real_file)) {
140 LYXERR0("lyxlex was not able to set file: "
141 << real_file << ".\nNo modules will be available.");
146 LYXERR0("unable to open modules file `"
147 << to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
148 << "'\nNo modules will be available.");
152 bool finished = false;
153 // Parse modules files
154 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
155 while (lex.isOK() && !finished) {
156 LYXERR(Debug::TCLASS, "\tline by line");
158 case Lexer::LEX_FEOF:
162 string const modname = lex.getString();
163 LYXERR(Debug::TCLASS, "Module name: " << modname);
166 string const fname = lex.getString();
167 LYXERR(Debug::TCLASS, "Filename: " << fname);
170 string const desc = lex.getString();
171 LYXERR(Debug::TCLASS, "Description: " << desc);
175 string str = lex.getString();
176 LYXERR(Debug::TCLASS, "Packages: " << str);
178 while (!str.empty()) {
180 str = split(str, p, ',');
185 str = lex.getString();
186 LYXERR(Debug::TCLASS, "Required: " << str);
188 while (!str.empty()) {
190 str = split(str, p, '|');
195 str = lex.getString();
196 LYXERR(Debug::TCLASS, "Excluded: " << str);
198 while (!str.empty()) {
200 str = split(str, p, '|');
205 string const catgy = lex.getString();
206 LYXERR(Debug::TCLASS, "Category: " << catgy);
207 // This code is run when we have
208 // modName, fname, desc, pkgs, req, exc, and catgy
209 addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy);
213 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
215 if (!theModuleList.empty())
216 sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
221 void ModuleList::addLayoutModule(string const & modname,
222 string const & filename, string const & description,
223 vector<string> const & pkgs, vector<string> const & req,
224 vector<string> const & exc, string const & catgy)
226 LyXModule lm(modname, filename, description, pkgs, req, exc, catgy);
227 modlist_.push_back(lm);
231 LyXModuleList::const_iterator ModuleList::begin() const
233 return modlist_.begin();
237 LyXModuleList::iterator ModuleList::begin()
239 return modlist_.begin();
243 LyXModuleList::const_iterator ModuleList::end() const
245 return modlist_.end();
249 LyXModuleList::iterator ModuleList::end()
251 return modlist_.end();
255 LyXModule const * ModuleList::operator[](string const & str) const
257 LyXModuleList::const_iterator it = modlist_.begin();
258 for (; it != modlist_.end(); ++it)
259 if (it->getID() == str) {
260 LyXModule const & mod = *it;
266 LyXModule * ModuleList::operator[](string const & str)
268 LyXModuleList::iterator it = modlist_.begin();
269 for (; it != modlist_.end(); ++it)
270 if (it->getID() == str) {
271 LyXModule & mod = *it;