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
53 return prerequisites_;
57 bool LyXModule::isAvailable() const
59 if (package_list_.empty())
65 //check whether all of the required packages are available
66 vector<string>::const_iterator it = package_list_.begin();
67 vector<string>::const_iterator end = package_list_.end();
68 for (; it != end; ++it) {
69 if (!LaTeXFeatures::isAvailable(*it)) {
71 prerequisites_.push_back(*it);
78 bool LyXModule::isCompatible(string const & modname) const
81 if (find(excluded_modules_.begin(), excluded_modules_.end(), modname) !=
82 excluded_modules_.end())
85 LyXModule const * const lm = theModuleList[modname];
89 // does it exclude us?
90 vector<string> const excmods = lm->getExcludedModules();
91 if (find(excmods.begin(), excmods.end(), id_) != excmods.end())
98 bool LyXModule::areCompatible(string const & mod1, string const & mod2)
100 LyXModule const * const lm1 = theModuleList[mod1];
102 return lm1->isCompatible(mod2);
103 LyXModule const * const lm2 = theModuleList[mod2];
105 return lm2->isCompatible(mod1);
106 // Can't check it either way.
111 // used when sorting the module list.
114 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
116 return _(lm1.getName()) < _(lm2.getName());
121 // Much of this is borrowed from LayoutFileList::read()
122 bool ModuleList::read()
124 FileName const real_file = libFileSearch("", "lyxmodules.lst");
125 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
127 if (real_file.empty()) {
128 LYXERR0("unable to find modules file `lyxmodules.lst'.\n"
129 << "No modules will be available.");
134 if (!lex.setFile(real_file)) {
135 LYXERR0("lyxlex was not able to set file: "
136 << real_file << ".\nNo modules will be available.");
141 LYXERR0("unable to open modules file `"
142 << to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
143 << "'\nNo modules will be available.");
147 bool finished = false;
148 // Parse modules files
149 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
150 while (lex.isOK() && !finished) {
151 LYXERR(Debug::TCLASS, "\tline by line");
153 case Lexer::LEX_FEOF:
157 string const modname = lex.getString();
158 LYXERR(Debug::TCLASS, "Module name: " << modname);
161 string const fname = lex.getString();
162 LYXERR(Debug::TCLASS, "Filename: " << fname);
165 string const desc = lex.getString();
166 LYXERR(Debug::TCLASS, "Description: " << desc);
170 string str = lex.getString();
171 LYXERR(Debug::TCLASS, "Packages: " << str);
173 while (!str.empty()) {
175 str = split(str, p, ',');
180 str = lex.getString();
181 LYXERR(Debug::TCLASS, "Required: " << str);
183 while (!str.empty()) {
185 str = split(str, p, '|');
190 str = lex.getString();
191 LYXERR(Debug::TCLASS, "Excluded: " << str);
193 while (!str.empty()) {
195 str = split(str, p, '|');
200 string const catgy = lex.getString();
201 LYXERR(Debug::TCLASS, "Category: " << catgy);
202 // This code is run when we have
203 // modName, fname, desc, pkgs, req, exc, and catgy
204 addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy);
208 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
210 if (!theModuleList.empty())
211 sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
216 void ModuleList::addLayoutModule(string const & modname,
217 string const & filename, string const & description,
218 vector<string> const & pkgs, vector<string> const & req,
219 vector<string> const & exc, string const & catgy)
221 LyXModule lm(modname, filename, description, pkgs, req, exc, catgy);
222 modlist_.push_back(lm);
226 LyXModuleList::const_iterator ModuleList::begin() const
228 return modlist_.begin();
232 LyXModuleList::iterator ModuleList::begin()
234 return modlist_.begin();
238 LyXModuleList::const_iterator ModuleList::end() const
240 return modlist_.end();
244 LyXModuleList::iterator ModuleList::end()
246 return modlist_.end();
250 LyXModule const * ModuleList::operator[](string const & str) const
252 LyXModuleList::const_iterator it = modlist_.begin();
253 for (; it != modlist_.end(); ++it)
254 if (it->getID() == str) {
255 LyXModule const & mod = *it;
262 LyXModule * ModuleList::operator[](string const & str)
264 LyXModuleList::iterator it = modlist_.begin();
265 for (; it != modlist_.end(); ++it)
266 if (it->getID() == str) {
267 LyXModule & mod = *it;