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.
15 #include "ModuleList.h"
16 #include "support/docstring.h"
17 #include "support/filetools.h"
18 #include "support/lstrings.h"
27 using support::FileName;
28 using support::libFileSearch;
29 using support::makeDisplayPath;
31 //global variable: module list
32 ModuleList moduleList;
35 // used when sorting the module list.
37 : public std::binary_function<LyXModule, LyXModule, int>
40 int operator()(LyXModule const & lm1,
41 LyXModule const & lm2) const
43 return (lm1.name < lm2.name);
48 //Much of this is borrowed from TextClassList::read()
49 bool ModuleList::load() {
50 support::FileName const real_file = libFileSearch("", "lyxmodules.lst");
51 LYXERR(Debug::TCLASS) << "Reading modules from `"
52 << real_file << '\'' << endl;
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" << endl;
82 while (lex.isOK() && !finished) {
83 LYXERR(Debug::TCLASS) << "\tline by line" << endl;
89 string const modName = lex.getString();
90 LYXERR(Debug::TCLASS) << "Module name: " << modName << endl;
92 string const fname = lex.getString();
93 LYXERR(Debug::TCLASS) << "Filename: " << fname << endl;
95 string const desc = lex.getString();
96 LYXERR(Debug::TCLASS) << "Description: " << desc << endl;
99 string packages = lex.getString();
100 LYXERR(Debug::TCLASS) << "Packages: " << packages << endl;
102 while (!packages.empty()) {
104 packages = support::split(packages, p, ',');
107 // This code is run when we have
108 // modName, fname, desc, and pkgs
109 addLayoutModule(modName, fname, desc, pkgs);
116 LYXERR(Debug::TCLASS) << "End of parsing of lyxmodules.lst" << endl;
118 if (!moduleList.empty())
119 sort(moduleList.begin(), moduleList.end(), moduleSorter());
124 void ModuleList::addLayoutModule(string moduleName,
125 string filename, string description, vector<string> pkgs) {
127 lm.name = moduleName;
128 lm.filename = filename;
129 lm.description = description;
130 lm.packageList = pkgs;
131 modlist_.push_back(lm);
135 LyXModuleList::const_iterator ModuleList::begin() const
137 return modlist_.begin();
141 LyXModuleList::iterator ModuleList::begin()
143 return modlist_.begin();
147 LyXModuleList::const_iterator ModuleList::end() const
149 return modlist_.end();
153 LyXModuleList::iterator ModuleList::end()
155 return modlist_.end();
159 LyXModule * ModuleList::operator[](string const str) {
160 LyXModuleList::iterator it = modlist_.begin();
161 for (; it != modlist_.end(); ++it)
162 if (it->name == str) {
163 LyXModule & mod = *it;