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/FileName.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
27 using namespace lyx::support;
32 //global variable: module list
33 ModuleList moduleList;
36 // used when sorting the module list.
40 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
42 return lm1.name < lm2.name;
47 //Much of this is borrowed from TextClassList::read()
48 bool ModuleList::load()
50 FileName const real_file = libFileSearch("", "lyxmodules.lst");
51 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
53 if (real_file.empty()) {
54 lyxerr << "ModuleList::load(): unable to find "
56 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
57 << "'.\nNo modules will be available." << endl;
62 if (!lex.setFile(real_file)) {
63 lyxerr << "ModuleList::load():"
64 "lyxlex was not able to set file: "
65 << real_file << ".\nNo modules will be available." << endl;
70 lyxerr << "ModuleList::load():" <<
71 "unable to open modules file `"
72 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
73 << "'\nNo modules will be available."
78 bool finished = false;
79 // Parse modules files
80 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
81 while (lex.isOK() && !finished) {
82 LYXERR(Debug::TCLASS, "\tline by line");
88 string const modName = lex.getString();
89 LYXERR(Debug::TCLASS, "Module name: " << modName);
92 string const fname = lex.getString();
93 LYXERR(Debug::TCLASS, "Filename: " << fname);
96 string const desc = lex.getString();
97 LYXERR(Debug::TCLASS, "Description: " << desc);
101 string packages = lex.getString();
102 LYXERR(Debug::TCLASS, "Packages: " << packages);
104 while (!packages.empty()) {
106 packages = split(packages, p, ',');
109 // This code is run when we have
110 // modName, fname, desc, and pkgs
111 addLayoutModule(modName, fname, desc, pkgs);
115 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
117 if (!moduleList.empty())
118 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
123 void ModuleList::addLayoutModule(string const & moduleName,
124 string const & filename, string const & description,
125 vector<string> const & pkgs)
128 lm.name = moduleName;
129 lm.filename = filename;
130 lm.description = description;
131 lm.packageList = pkgs;
132 modlist_.push_back(lm);
136 LyXModuleList::const_iterator ModuleList::begin() const
138 return modlist_.begin();
142 LyXModuleList::iterator ModuleList::begin()
144 return modlist_.begin();
148 LyXModuleList::const_iterator ModuleList::end() const
150 return modlist_.end();
154 LyXModuleList::iterator ModuleList::end()
156 return modlist_.end();
160 LyXModule * ModuleList::operator[](string const & str)
162 LyXModuleList::iterator it = modlist_.begin();
163 for (; it != modlist_.end(); ++it)
164 if (it->name == str) {
165 LyXModule & mod = *it;