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"
19 #include "support/filetools.h"
20 #include "support/lstrings.h"
29 using support::FileName;
30 using support::libFileSearch;
31 using support::makeDisplayPath;
33 //global variable: module list
34 ModuleList moduleList;
37 // used when sorting the module list.
41 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
43 return lm1.name < lm2.name;
48 //Much of this is borrowed from TextClassList::read()
49 bool ModuleList::load()
51 support::FileName const real_file = libFileSearch("", "lyxmodules.lst");
52 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
54 if (real_file.empty()) {
55 lyxerr << "ModuleList::load(): unable to find "
57 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
58 << "'.\nNo modules will be available." << endl;
63 if (!lex.setFile(real_file)) {
64 lyxerr << "ModuleList::load():"
65 "lyxlex was not able to set file: "
66 << real_file << ".\nNo modules will be available." << endl;
71 lyxerr << "ModuleList::load():" <<
72 "unable to open modules file `"
73 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
74 << "'\nNo modules will be available."
79 bool finished = false;
80 // Parse modules files
81 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
82 while (lex.isOK() && !finished) {
83 LYXERR(Debug::TCLASS, "\tline by line");
89 string const modName = lex.getString();
90 LYXERR(Debug::TCLASS, "Module name: " << modName);
93 string const fname = lex.getString();
94 LYXERR(Debug::TCLASS, "Filename: " << fname);
97 string const desc = lex.getString();
98 LYXERR(Debug::TCLASS, "Description: " << desc);
102 string packages = lex.getString();
103 LYXERR(Debug::TCLASS, "Packages: " << packages);
105 while (!packages.empty()) {
107 packages = support::split(packages, p, ',');
110 // This code is run when we have
111 // modName, fname, desc, and pkgs
112 addLayoutModule(modName, fname, desc, pkgs);
116 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
118 if (!moduleList.empty())
119 std::sort(moduleList.begin(), moduleList.end(), ModuleSorter());
124 void ModuleList::addLayoutModule(string const & moduleName,
125 string const & filename, string const & description,
126 vector<string> const & pkgs)
129 lm.name = moduleName;
130 lm.filename = filename;
131 lm.description = description;
132 lm.packageList = pkgs;
133 modlist_.push_back(lm);
137 LyXModuleList::const_iterator ModuleList::begin() const
139 return modlist_.begin();
143 LyXModuleList::iterator ModuleList::begin()
145 return modlist_.begin();
149 LyXModuleList::const_iterator ModuleList::end() const
151 return modlist_.end();
155 LyXModuleList::iterator ModuleList::end()
157 return modlist_.end();
161 LyXModule * ModuleList::operator[](string const & str)
163 LyXModuleList::iterator it = modlist_.begin();
164 for (; it != modlist_.end(); ++it)
165 if (it->name == str) {
166 LyXModule & mod = *it;