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 name(n), filename(f), description(d), packageList(p), checked(false)
43 bool LyXModule::isAvailable() {
44 if (packageList.empty())
49 vector<string>::const_iterator it = packageList.begin();
50 vector<string>::const_iterator end = packageList.end();
51 for (; it != end; ++it) {
52 if (!LaTeXFeatures::isAvailable(*it))
61 // used when sorting the module list.
65 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
67 return lm1.name < lm2.name;
72 //Much of this is borrowed from TextClassList::read()
73 bool ModuleList::load()
75 FileName const real_file = libFileSearch("", "lyxmodules.lst");
76 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
78 if (real_file.empty()) {
79 lyxerr << "ModuleList::load(): unable to find "
81 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
82 << "'.\nNo modules will be available." << endl;
87 if (!lex.setFile(real_file)) {
88 lyxerr << "ModuleList::load():"
89 "lyxlex was not able to set file: "
90 << real_file << ".\nNo modules will be available." << endl;
95 lyxerr << "ModuleList::load():" <<
96 "unable to open modules file `"
97 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
98 << "'\nNo modules will be available."
103 bool finished = false;
104 // Parse modules files
105 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
106 while (lex.isOK() && !finished) {
107 LYXERR(Debug::TCLASS, "\tline by line");
109 case Lexer::LEX_FEOF:
113 string const modName = lex.getString();
114 LYXERR(Debug::TCLASS, "Module name: " << modName);
117 string const fname = lex.getString();
118 LYXERR(Debug::TCLASS, "Filename: " << fname);
121 string const desc = lex.getString();
122 LYXERR(Debug::TCLASS, "Description: " << desc);
126 string packages = lex.getString();
127 LYXERR(Debug::TCLASS, "Packages: " << packages);
129 while (!packages.empty()) {
131 packages = split(packages, p, ',');
134 // This code is run when we have
135 // modName, fname, desc, and pkgs
136 addLayoutModule(modName, fname, desc, pkgs);
140 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
142 if (!moduleList.empty())
143 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
148 void ModuleList::addLayoutModule(string const & moduleName,
149 string const & filename, string const & description,
150 vector<string> const & pkgs)
152 LyXModule lm(moduleName, filename, description, pkgs);
153 modlist_.push_back(lm);
157 LyXModuleList::const_iterator ModuleList::begin() const
159 return modlist_.begin();
163 LyXModuleList::iterator ModuleList::begin()
165 return modlist_.begin();
169 LyXModuleList::const_iterator ModuleList::end() const
171 return modlist_.end();
175 LyXModuleList::iterator ModuleList::end()
177 return modlist_.end();
181 LyXModule * ModuleList::operator[](string const & str)
183 LyXModuleList::iterator it = modlist_.begin();
184 for (; it != modlist_.end(); ++it)
185 if (it->name == str) {
186 LyXModule & mod = *it;