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 n, string f, string d,
39 name(n), filename(f), description(d), packageList(p), checked(false)
43 bool LyXModule::isAvailable() {
44 if (packageList.empty())
48 vector<string>::const_iterator it = packageList.begin();
49 vector<string>::const_iterator end = packageList.end();
50 for (; it != end; ++it) {
51 if (!LaTeXFeatures::isAvailable(*it))
60 // used when sorting the module list.
64 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
66 return lm1.name < lm2.name;
71 //Much of this is borrowed from TextClassList::read()
72 bool ModuleList::load()
74 FileName const real_file = libFileSearch("", "lyxmodules.lst");
75 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
77 if (real_file.empty()) {
78 lyxerr << "ModuleList::load(): unable to find "
80 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
81 << "'.\nNo modules will be available." << endl;
86 if (!lex.setFile(real_file)) {
87 lyxerr << "ModuleList::load():"
88 "lyxlex was not able to set file: "
89 << real_file << ".\nNo modules will be available." << endl;
94 lyxerr << "ModuleList::load():" <<
95 "unable to open modules file `"
96 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
97 << "'\nNo modules will be available."
102 bool finished = false;
103 // Parse modules files
104 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
105 while (lex.isOK() && !finished) {
106 LYXERR(Debug::TCLASS, "\tline by line");
108 case Lexer::LEX_FEOF:
112 string const modName = lex.getString();
113 LYXERR(Debug::TCLASS, "Module name: " << modName);
116 string const fname = lex.getString();
117 LYXERR(Debug::TCLASS, "Filename: " << fname);
120 string const desc = lex.getString();
121 LYXERR(Debug::TCLASS, "Description: " << desc);
125 string packages = lex.getString();
126 LYXERR(Debug::TCLASS, "Packages: " << packages);
128 while (!packages.empty()) {
130 packages = split(packages, p, ',');
133 // This code is run when we have
134 // modName, fname, desc, and pkgs
135 addLayoutModule(modName, fname, desc, pkgs);
139 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
141 if (!moduleList.empty())
142 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
147 void ModuleList::addLayoutModule(string const & moduleName,
148 string const & filename, string const & description,
149 vector<string> const & pkgs)
151 LyXModule lm(moduleName, filename, description, pkgs);
152 modlist_.push_back(lm);
156 LyXModuleList::const_iterator ModuleList::begin() const
158 return modlist_.begin();
162 LyXModuleList::iterator ModuleList::begin()
164 return modlist_.begin();
168 LyXModuleList::const_iterator ModuleList::end() const
170 return modlist_.end();
174 LyXModuleList::iterator ModuleList::end()
176 return modlist_.end();
180 LyXModule * ModuleList::operator[](string const & str)
182 LyXModuleList::iterator it = modlist_.begin();
183 for (; it != modlist_.end(); ++it)
184 if (it->name == str) {
185 LyXModule & mod = *it;