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() {
51 if (packageList
.empty())
56 //check whether all of the required packages are available
57 vector
<string
>::const_iterator it
= packageList
.begin();
58 vector
<string
>::const_iterator end
= packageList
.end();
59 for (; it
!= end
; ++it
) {
60 if (!LaTeXFeatures::isAvailable(*it
)) {
71 bool LyXModule::isCompatible(string
const & modName
) const
74 if (find(excludedModules
.begin(), excludedModules
.end(), modName
) !=
75 excludedModules
.end())
78 LyXModule
const * const lm
= moduleList
[modName
];
82 // does it exclude us?
83 vector
<string
> const excMods
= lm
->getExcludedModules();
84 if (find(excMods
.begin(), excMods
.end(), id
) != excMods
.end())
91 bool LyXModule::areCompatible(string
const & mod1
, string
const & mod2
)
93 LyXModule
const * const lm1
= moduleList
[mod1
];
95 return lm1
->isCompatible(mod2
);
96 LyXModule
const * const lm2
= moduleList
[mod2
];
98 return lm2
->isCompatible(mod1
);
99 // Can't check it either way.
103 // used when sorting the module list.
107 int operator()(LyXModule
const & lm1
, LyXModule
const & lm2
) const
109 return lm1
.getName() < lm2
.getName();
114 //Much of this is borrowed from LayoutFileList::read()
115 bool ModuleList::read()
117 FileName
const real_file
= libFileSearch("", "lyxmodules.lst");
118 LYXERR(Debug::TCLASS
, "Reading modules from `" << real_file
<< '\'');
120 if (real_file
.empty()) {
121 LYXERR0("unable to find modules file `"
122 << to_utf8(makeDisplayPath(real_file
.absFilename(), 1000))
123 << "'.\nNo modules will be available.");
128 if (!lex
.setFile(real_file
)) {
129 LYXERR0("lyxlex was not able to set file: "
130 << real_file
<< ".\nNo modules will be available.");
135 LYXERR0("unable to open modules file `"
136 << to_utf8(makeDisplayPath(real_file
.absFilename(), 1000))
137 << "'\nNo modules will be available.");
141 bool finished
= false;
142 // Parse modules files
143 LYXERR(Debug::TCLASS
, "Starting parsing of lyxmodules.lst");
144 while (lex
.isOK() && !finished
) {
145 LYXERR(Debug::TCLASS
, "\tline by line");
147 case Lexer::LEX_FEOF
:
151 string
const modName
= lex
.getString();
152 LYXERR(Debug::TCLASS
, "Module name: " << modName
);
155 string
const fname
= lex
.getString();
156 LYXERR(Debug::TCLASS
, "Filename: " << fname
);
159 string
const desc
= lex
.getString();
160 LYXERR(Debug::TCLASS
, "Description: " << desc
);
164 string str
= lex
.getString();
165 LYXERR(Debug::TCLASS
, "Packages: " << str
);
167 while (!str
.empty()) {
169 str
= split(str
, p
, ',');
174 str
= lex
.getString();
175 LYXERR(Debug::TCLASS
, "Required: " << str
);
177 while (!str
.empty()) {
179 str
= split(str
, p
, '|');
184 str
= lex
.getString();
185 LYXERR(Debug::TCLASS
, "Excluded: " << str
);
187 while (!str
.empty()) {
189 str
= split(str
, p
, '|');
192 // This code is run when we have
193 // modName, fname, desc, pkgs, req, and exc
194 addLayoutModule(modName
, fname
, desc
, pkgs
, req
, exc
);
198 LYXERR(Debug::TCLASS
, "End of parsing of lyxmodules.lst");
200 if (!moduleList
.empty())
201 sort(moduleList
.begin(), moduleList
.end(), ModuleSorter());
206 void ModuleList::addLayoutModule(string
const & moduleName
,
207 string
const & filename
, string
const & description
,
208 vector
<string
> const & pkgs
, vector
<string
> const & req
,
209 vector
<string
> const & exc
)
211 LyXModule
lm(moduleName
, filename
, description
, pkgs
, req
, exc
);
212 modlist_
.push_back(lm
);
216 LyXModuleList::const_iterator
ModuleList::begin() const
218 return modlist_
.begin();
222 LyXModuleList::iterator
ModuleList::begin()
224 return modlist_
.begin();
228 LyXModuleList::const_iterator
ModuleList::end() const
230 return modlist_
.end();
234 LyXModuleList::iterator
ModuleList::end()
236 return modlist_
.end();
240 LyXModule
* ModuleList::operator[](string
const & str
)
242 LyXModuleList::iterator it
= modlist_
.begin();
243 for (; it
!= modlist_
.end(); ++it
)
244 if (it
->getID() == str
) {
245 LyXModule
& mod
= *it
;