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,
40 string const & c, bool const local):
41 name_(n), id_(i), description_(d), package_list_(p),
42 required_modules_(r), excluded_modules_(e), category_(c),
43 checked_(false), available_(false), local_(local)
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);
204 bool const local = lex.getString() == "true";
205 LYXERR(Debug::TCLASS, "Local: " << local);
206 // This code is run when we have
207 // modName, fname, desc, pkgs, req, exc, catgy, and local
208 addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy, local);
212 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
214 if (!theModuleList.empty())
215 sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
220 void ModuleList::addLayoutModule(string const & modname,
221 string const & filename, string const & description,
222 vector<string> const & pkgs, vector<string> const & req,
223 vector<string> const & exc, string const & catgy, bool const local)
225 LyXModule lm(modname, filename, description, pkgs, req, exc, catgy, local);
226 modlist_.push_back(lm);
230 LyXModuleList::const_iterator ModuleList::begin() const
232 return modlist_.begin();
236 LyXModuleList::iterator ModuleList::begin()
238 return modlist_.begin();
242 LyXModuleList::const_iterator ModuleList::end() const
244 return modlist_.end();
248 LyXModuleList::iterator ModuleList::end()
250 return modlist_.end();
254 LyXModule const * ModuleList::operator[](string const & str) const
256 LyXModuleList::const_iterator it = modlist_.begin();
257 for (; it != modlist_.end(); ++it)
258 if (it->getID() == str) {
259 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;