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 `lyxmodules.lst'.\n"
123 << "No modules will be available.");
128 if (!lex.setFile(real_file)) {
129 LYXERR0("lyxlex was not able to set file: "
130 << real_file << ".\nNo modules will be available.");
135 LYXERR0("unable to open modules file `"
136 << to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
137 << "'\nNo modules will be available.");
141 bool finished = false;
142 // Parse modules files
143 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
144 while (lex.isOK() && !finished) {
145 LYXERR(Debug::TCLASS, "\tline by line");
147 case Lexer::LEX_FEOF:
151 string const modname = lex.getString();
152 LYXERR(Debug::TCLASS, "Module name: " << modname);
155 string const fname = lex.getString();
156 LYXERR(Debug::TCLASS, "Filename: " << fname);
159 string const desc = lex.getString();
160 LYXERR(Debug::TCLASS, "Description: " << desc);
164 string str = lex.getString();
165 LYXERR(Debug::TCLASS, "Packages: " << str);
167 while (!str.empty()) {
169 str = split(str, p, ',');
174 str = lex.getString();
175 LYXERR(Debug::TCLASS, "Required: " << str);
177 while (!str.empty()) {
179 str = split(str, p, '|');
184 str = lex.getString();
185 LYXERR(Debug::TCLASS, "Excluded: " << str);
187 while (!str.empty()) {
189 str = split(str, p, '|');
194 string const catgy = lex.getString();
195 LYXERR(Debug::TCLASS, "Category: " << catgy);
196 // This code is run when we have
197 // modName, fname, desc, pkgs, req, exc, and catgy
198 addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy);
202 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
204 if (!theModuleList.empty())
205 sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
210 void ModuleList::addLayoutModule(string const & modname,
211 string const & filename, string const & description,
212 vector<string> const & pkgs, vector<string> const & req,
213 vector<string> const & exc, string const & catgy)
215 LyXModule lm(modname, filename, description, pkgs, req, exc, catgy);
216 modlist_.push_back(lm);
220 LyXModuleList::const_iterator ModuleList::begin() const
222 return modlist_.begin();
226 LyXModuleList::iterator ModuleList::begin()
228 return modlist_.begin();
232 LyXModuleList::const_iterator ModuleList::end() const
234 return modlist_.end();
238 LyXModuleList::iterator ModuleList::end()
240 return modlist_.end();
244 LyXModule const * ModuleList::operator[](string const & str) const
246 LyXModuleList::const_iterator it = modlist_.begin();
247 for (; it != modlist_.end(); ++it)
248 if (it->getID() == str) {
249 LyXModule const & mod = *it;
255 LyXModule * ModuleList::operator[](string const & str)
257 LyXModuleList::iterator it = modlist_.begin();
258 for (; it != modlist_.end(); ++it)
259 if (it->getID() == str) {
260 LyXModule & mod = *it;