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 moduleList;
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):
39 name(n), id(i), description(d),
40 packageList(p), requiredModules(r), excludedModules(e),
43 filename = id + ".module";
47 bool LyXModule::isAvailable() {
48 if (packageList.empty())
53 //check whether all of the required packages are available
54 vector<string>::const_iterator it = packageList.begin();
55 vector<string>::const_iterator end = packageList.end();
56 for (; it != end; ++it) {
57 if (!LaTeXFeatures::isAvailable(*it)) {
67 // used when sorting the module list.
71 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
73 return lm1.getName() < lm2.getName();
78 //Much of this is borrowed from LayoutFileList::read()
79 bool ModuleList::load()
81 FileName const real_file = libFileSearch("", "lyxmodules.lst");
82 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
84 if (real_file.empty()) {
85 lyxerr << "ModuleList::load(): unable to find "
87 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
88 << "'.\nNo modules will be available." << endl;
93 if (!lex.setFile(real_file)) {
94 lyxerr << "ModuleList::load():"
95 "lyxlex was not able to set file: "
96 << real_file << ".\nNo modules will be available." << endl;
101 lyxerr << "ModuleList::load():" <<
102 "unable to open modules file `"
103 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
104 << "'\nNo modules will be available."
109 bool finished = false;
110 // Parse modules files
111 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
112 while (lex.isOK() && !finished) {
113 LYXERR(Debug::TCLASS, "\tline by line");
115 case Lexer::LEX_FEOF:
119 string const modName = lex.getString();
120 LYXERR(Debug::TCLASS, "Module name: " << modName);
123 string const fname = lex.getString();
124 LYXERR(Debug::TCLASS, "Filename: " << fname);
127 string const desc = lex.getString();
128 LYXERR(Debug::TCLASS, "Description: " << desc);
132 string str = lex.getString();
133 LYXERR(Debug::TCLASS, "Packages: " << str);
135 while (!str.empty()) {
137 str = split(str, p, ',');
142 str = lex.getString();
143 LYXERR(Debug::TCLASS, "Required: " << str);
145 while (!str.empty()) {
147 str = split(str, p, '|');
152 str = lex.getString();
153 LYXERR(Debug::TCLASS, "Excluded: " << str);
155 while (!str.empty()) {
157 str = split(str, p, '|');
160 // This code is run when we have
161 // modName, fname, desc, pkgs, req, and exc
162 addLayoutModule(modName, fname, desc, pkgs, req, exc);
166 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
168 if (!moduleList.empty())
169 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
174 void ModuleList::addLayoutModule(string const & moduleName,
175 string const & filename, string const & description,
176 vector<string> const & pkgs, vector<string> const & req,
177 vector<string> const & exc)
179 LyXModule lm(moduleName, filename, description, pkgs, req, exc);
180 modlist_.push_back(lm);
184 LyXModuleList::const_iterator ModuleList::begin() const
186 return modlist_.begin();
190 LyXModuleList::iterator ModuleList::begin()
192 return modlist_.begin();
196 LyXModuleList::const_iterator ModuleList::end() const
198 return modlist_.end();
202 LyXModuleList::iterator ModuleList::end()
204 return modlist_.end();
208 LyXModule * ModuleList::getModuleByName(string const & str)
210 LyXModuleList::iterator it = modlist_.begin();
211 for (; it != modlist_.end(); ++it)
212 if (it->getName() == str) {
213 LyXModule & mod = *it;
219 LyXModule * ModuleList::operator[](string const & str)
221 LyXModuleList::iterator it = modlist_.begin();
222 for (; it != modlist_.end(); ++it)
223 if (it->getID() == str) {
224 LyXModule & mod = *it;