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 "support/debug.h"
17 #include "LaTeXFeatures.h"
20 #include "support/FileName.h"
21 #include "support/filetools.h"
22 #include "support/lstrings.h"
28 using namespace lyx::support;
33 //global variable: module list
34 ModuleList moduleList;
37 LyXModule::LyXModule(string const & n, string const & f,
38 string const & d, vector<string> const & p,
39 vector<string> const & r, vector<string> const & e):
40 name(n), filename(f), description(d),
41 packageList(p), requiredModules(r), excludedModules(e),
46 bool LyXModule::isAvailable() {
47 if (packageList.empty())
52 //check whether all of the required packages are available
53 vector<string>::const_iterator it = packageList.begin();
54 vector<string>::const_iterator end = packageList.end();
55 for (; it != end; ++it) {
56 if (!LaTeXFeatures::isAvailable(*it)) {
66 // used when sorting the module list.
70 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
72 return lm1.getName() < lm2.getName();
77 //Much of this is borrowed from TextClassList::read()
78 bool ModuleList::load()
80 FileName const real_file = libFileSearch("", "lyxmodules.lst");
81 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
83 if (real_file.empty()) {
84 lyxerr << "ModuleList::load(): unable to find "
86 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
87 << "'.\nNo modules will be available." << endl;
92 if (!lex.setFile(real_file)) {
93 lyxerr << "ModuleList::load():"
94 "lyxlex was not able to set file: "
95 << real_file << ".\nNo modules will be available." << endl;
100 lyxerr << "ModuleList::load():" <<
101 "unable to open modules file `"
102 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
103 << "'\nNo modules will be available."
108 bool finished = false;
109 // Parse modules files
110 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
111 while (lex.isOK() && !finished) {
112 LYXERR(Debug::TCLASS, "\tline by line");
114 case Lexer::LEX_FEOF:
118 string const modName = lex.getString();
119 LYXERR(Debug::TCLASS, "Module name: " << modName);
122 string const fname = lex.getString();
123 LYXERR(Debug::TCLASS, "Filename: " << fname);
126 string const desc = lex.getString();
127 LYXERR(Debug::TCLASS, "Description: " << desc);
131 string str = lex.getString();
132 LYXERR(Debug::TCLASS, "Packages: " << str);
134 while (!str.empty()) {
136 str = split(str, p, ',');
141 str = lex.getString();
142 LYXERR(Debug::TCLASS, "Required: " << str);
144 while (!str.empty()) {
146 str = split(str, p, '|');
151 str = lex.getString();
152 LYXERR(Debug::TCLASS, "Excluded: " << str);
154 while (!str.empty()) {
156 str = split(str, p, '|');
159 // This code is run when we have
160 // modName, fname, desc, pkgs, req, and exc
161 addLayoutModule(modName, fname, desc, pkgs, req, exc);
165 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
167 if (!moduleList.empty())
168 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
173 void ModuleList::addLayoutModule(string const & moduleName,
174 string const & filename, string const & description,
175 vector<string> const & pkgs, vector<string> const & req,
176 vector<string> const & exc)
178 LyXModule lm(moduleName, filename, description, pkgs, req, exc);
179 modlist_.push_back(lm);
183 LyXModuleList::const_iterator ModuleList::begin() const
185 return modlist_.begin();
189 LyXModuleList::iterator ModuleList::begin()
191 return modlist_.begin();
195 LyXModuleList::const_iterator ModuleList::end() const
197 return modlist_.end();
201 LyXModuleList::iterator ModuleList::end()
203 return modlist_.end();
207 LyXModule * ModuleList::operator[](string const & str)
209 LyXModuleList::iterator it = modlist_.begin();
210 for (; it != modlist_.end(); ++it)
211 if (it->getName() == str) {
212 LyXModule & mod = *it;