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"
28 using namespace lyx::support
;
33 //global variable: module list
34 ModuleList moduleList
;
37 LyXModule::LyXModule(string
const & n
, string
const & i
,
38 string
const & d
, vector
<string
> const & p
,
39 vector
<string
> const & r
, vector
<string
> const & e
):
40 name(n
), id(i
), description(d
),
41 packageList(p
), requiredModules(r
), excludedModules(e
),
44 filename
= id
+ ".module";
48 bool LyXModule::isAvailable() {
49 if (packageList
.empty())
54 //check whether all of the required packages are available
55 vector
<string
>::const_iterator it
= packageList
.begin();
56 vector
<string
>::const_iterator end
= packageList
.end();
57 for (; it
!= end
; ++it
) {
58 if (!LaTeXFeatures::isAvailable(*it
)) {
68 // used when sorting the module list.
72 int operator()(LyXModule
const & lm1
, LyXModule
const & lm2
) const
74 return lm1
.getName() < lm2
.getName();
79 //Much of this is borrowed from LayoutFileList::read()
80 bool ModuleList::load()
82 FileName
const real_file
= libFileSearch("", "lyxmodules.lst");
83 LYXERR(Debug::TCLASS
, "Reading modules from `" << real_file
<< '\'');
85 if (real_file
.empty()) {
86 lyxerr
<< "ModuleList::load(): unable to find "
88 << to_utf8(makeDisplayPath(real_file
.absFilename(), 1000))
89 << "'.\nNo modules will be available." << endl
;
94 if (!lex
.setFile(real_file
)) {
95 lyxerr
<< "ModuleList::load():"
96 "lyxlex was not able to set file: "
97 << real_file
<< ".\nNo modules will be available." << endl
;
102 lyxerr
<< "ModuleList::load():" <<
103 "unable to open modules file `"
104 << to_utf8(makeDisplayPath(real_file
.absFilename(), 1000))
105 << "'\nNo modules will be available."
110 bool finished
= false;
111 // Parse modules files
112 LYXERR(Debug::TCLASS
, "Starting parsing of lyxmodules.lst");
113 while (lex
.isOK() && !finished
) {
114 LYXERR(Debug::TCLASS
, "\tline by line");
116 case Lexer::LEX_FEOF
:
120 string
const modName
= lex
.getString();
121 LYXERR(Debug::TCLASS
, "Module name: " << modName
);
124 string
const fname
= lex
.getString();
125 LYXERR(Debug::TCLASS
, "Filename: " << fname
);
128 string
const desc
= lex
.getString();
129 LYXERR(Debug::TCLASS
, "Description: " << desc
);
133 string str
= lex
.getString();
134 LYXERR(Debug::TCLASS
, "Packages: " << str
);
136 while (!str
.empty()) {
138 str
= split(str
, p
, ',');
143 str
= lex
.getString();
144 LYXERR(Debug::TCLASS
, "Required: " << str
);
146 while (!str
.empty()) {
148 str
= split(str
, p
, '|');
153 str
= lex
.getString();
154 LYXERR(Debug::TCLASS
, "Excluded: " << str
);
156 while (!str
.empty()) {
158 str
= split(str
, p
, '|');
161 // This code is run when we have
162 // modName, fname, desc, pkgs, req, and exc
163 addLayoutModule(modName
, fname
, desc
, pkgs
, req
, exc
);
167 LYXERR(Debug::TCLASS
, "End of parsing of lyxmodules.lst");
169 if (!moduleList
.empty())
170 sort(moduleList
.begin(), moduleList
.end(), ModuleSorter());
175 void ModuleList::addLayoutModule(string
const & moduleName
,
176 string
const & filename
, string
const & description
,
177 vector
<string
> const & pkgs
, vector
<string
> const & req
,
178 vector
<string
> const & exc
)
180 LyXModule
lm(moduleName
, filename
, description
, pkgs
, req
, exc
);
181 modlist_
.push_back(lm
);
185 LyXModuleList::const_iterator
ModuleList::begin() const
187 return modlist_
.begin();
191 LyXModuleList::iterator
ModuleList::begin()
193 return modlist_
.begin();
197 LyXModuleList::const_iterator
ModuleList::end() const
199 return modlist_
.end();
203 LyXModuleList::iterator
ModuleList::end()
205 return modlist_
.end();
209 LyXModule
* ModuleList::getModuleByName(string
const & str
)
211 LyXModuleList::iterator it
= modlist_
.begin();
212 for (; it
!= modlist_
.end(); ++it
)
213 if (it
->getName() == str
) {
214 LyXModule
& mod
= *it
;
220 LyXModule
* ModuleList::operator[](string
const & str
)
222 LyXModuleList::iterator it
= modlist_
.begin();
223 for (; it
!= modlist_
.end(); ++it
)
224 if (it
->getID() == str
) {
225 LyXModule
& mod
= *it
;