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 "LaTeXFeatures.h"
19 #include "support/debug.h"
20 #include "support/FileName.h"
21 #include "support/filetools.h"
22 #include "support/lstrings.h"
27 using namespace lyx::support
;
32 //global variable: module list
33 ModuleList moduleList
;
36 LyXModule::LyXModule(string
const & n
, string
const & i
,
37 string
const & d
, vector
<string
> const & p
,
38 vector
<string
> const & r
, vector
<string
> const & e
):
39 name(n
), id(i
), description(d
),
40 packageList(p
), requiredModules(r
), excludedModules(e
),
43 filename
= id
+ ".module";
47 bool LyXModule::isAvailable() {
48 if (packageList
.empty())
53 //check whether all of the required packages are available
54 vector
<string
>::const_iterator it
= packageList
.begin();
55 vector
<string
>::const_iterator end
= packageList
.end();
56 for (; it
!= end
; ++it
) {
57 if (!LaTeXFeatures::isAvailable(*it
)) {
67 // used when sorting the module list.
71 int operator()(LyXModule
const & lm1
, LyXModule
const & lm2
) const
73 return lm1
.getName() < lm2
.getName();
78 //Much of this is borrowed from LayoutFileList::read()
79 bool ModuleList::load()
81 FileName
const real_file
= libFileSearch("", "lyxmodules.lst");
82 LYXERR(Debug::TCLASS
, "Reading modules from `" << real_file
<< '\'');
84 if (real_file
.empty()) {
85 LYXERR0("unable to find modules file `"
86 << to_utf8(makeDisplayPath(real_file
.absFilename(), 1000))
87 << "'.\nNo modules will be available.");
92 if (!lex
.setFile(real_file
)) {
93 LYXERR0("lyxlex was not able to set file: "
94 << real_file
<< ".\nNo modules will be available.");
99 LYXERR0("unable to open modules file `"
100 << to_utf8(makeDisplayPath(real_file
.absFilename(), 1000))
101 << "'\nNo modules will be available.");
105 bool finished
= false;
106 // Parse modules files
107 LYXERR(Debug::TCLASS
, "Starting parsing of lyxmodules.lst");
108 while (lex
.isOK() && !finished
) {
109 LYXERR(Debug::TCLASS
, "\tline by line");
111 case Lexer::LEX_FEOF
:
115 string
const modName
= lex
.getString();
116 LYXERR(Debug::TCLASS
, "Module name: " << modName
);
119 string
const fname
= lex
.getString();
120 LYXERR(Debug::TCLASS
, "Filename: " << fname
);
123 string
const desc
= lex
.getString();
124 LYXERR(Debug::TCLASS
, "Description: " << desc
);
128 string str
= lex
.getString();
129 LYXERR(Debug::TCLASS
, "Packages: " << str
);
131 while (!str
.empty()) {
133 str
= split(str
, p
, ',');
138 str
= lex
.getString();
139 LYXERR(Debug::TCLASS
, "Required: " << str
);
141 while (!str
.empty()) {
143 str
= split(str
, p
, '|');
148 str
= lex
.getString();
149 LYXERR(Debug::TCLASS
, "Excluded: " << str
);
151 while (!str
.empty()) {
153 str
= split(str
, p
, '|');
156 // This code is run when we have
157 // modName, fname, desc, pkgs, req, and exc
158 addLayoutModule(modName
, fname
, desc
, pkgs
, req
, exc
);
162 LYXERR(Debug::TCLASS
, "End of parsing of lyxmodules.lst");
164 if (!moduleList
.empty())
165 sort(moduleList
.begin(), moduleList
.end(), ModuleSorter());
170 void ModuleList::addLayoutModule(string
const & moduleName
,
171 string
const & filename
, string
const & description
,
172 vector
<string
> const & pkgs
, vector
<string
> const & req
,
173 vector
<string
> const & exc
)
175 LyXModule
lm(moduleName
, filename
, description
, pkgs
, req
, exc
);
176 modlist_
.push_back(lm
);
180 LyXModuleList::const_iterator
ModuleList::begin() const
182 return modlist_
.begin();
186 LyXModuleList::iterator
ModuleList::begin()
188 return modlist_
.begin();
192 LyXModuleList::const_iterator
ModuleList::end() const
194 return modlist_
.end();
198 LyXModuleList::iterator
ModuleList::end()
200 return modlist_
.end();
204 LyXModule
* ModuleList::getModuleByName(string
const & str
)
206 LyXModuleList::iterator it
= modlist_
.begin();
207 for (; it
!= modlist_
.end(); ++it
)
208 if (it
->getName() == str
) {
209 LyXModule
& mod
= *it
;
215 LyXModule
* ModuleList::operator[](string
const & str
)
217 LyXModuleList::iterator it
= modlist_
.begin();
218 for (; it
!= modlist_
.end(); ++it
)
219 if (it
->getID() == str
) {
220 LyXModule
& mod
= *it
;