2002-09-25 14:26:13 +00:00
|
|
|
/**
|
|
|
|
* \file ExternalTemplate.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
* \author Asger Alstrup Nielsen
|
2003-10-07 22:59:58 +00:00
|
|
|
* \author Angus Leeming
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ExternalTemplate.h"
|
|
|
|
|
2000-11-08 09:39:46 +00:00
|
|
|
#include "debug.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
|
2000-11-08 09:39:46 +00:00
|
|
|
#include "support/filetools.h"
|
2003-09-04 17:01:00 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "support/path.h"
|
2003-07-27 22:13:29 +00:00
|
|
|
#include "support/path_defines.h"
|
2003-10-07 22:59:58 +00:00
|
|
|
#include "support/translator.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
2003-09-05 13:03:23 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
namespace support = lyx::support;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
using std::endl;
|
2000-06-13 10:33:57 +00:00
|
|
|
using std::for_each;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2003-09-05 09:01:27 +00:00
|
|
|
using std::ostream;
|
2003-09-23 17:04:25 +00:00
|
|
|
using std::vector;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace external {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef Translator<TransformID, string> TransformIDTranslator;
|
|
|
|
TransformIDTranslator const & transformIDTranslator();
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
// We have to have dummy default commands for security reasons!
|
|
|
|
Template::Template()
|
2003-06-04 09:16:29 +00:00
|
|
|
: inputFormat("*")
|
2000-06-12 11:27:15 +00:00
|
|
|
{}
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
Template::Format::Format()
|
2001-11-02 16:18:07 +00:00
|
|
|
{}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
TemplateManager::TemplateManager()
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-09-04 17:01:00 +00:00
|
|
|
readTemplates(support::user_lyxdir());
|
|
|
|
if (lyxerr.debugging(Debug::EXTERNAL)) {
|
|
|
|
dumpPreambleDefs(lyxerr);
|
|
|
|
lyxerr << '\n';
|
|
|
|
dumpTemplates(lyxerr);
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
class dumpPreambleDef {
|
|
|
|
public:
|
2003-10-01 10:16:00 +00:00
|
|
|
typedef TemplateManager::PreambleDefs::value_type value_type;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
dumpPreambleDef(ostream & o) : ost(o) {}
|
|
|
|
|
|
|
|
void operator()(value_type const & vt) {
|
|
|
|
ost << "PreambleDef " << vt.first << '\n'
|
|
|
|
<< vt.second
|
|
|
|
<< "PreambleDefEnd" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ostream & ost;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
class dumpTemplate {
|
|
|
|
public:
|
2003-10-01 10:16:00 +00:00
|
|
|
typedef TemplateManager::Templates::value_type value_type;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
dumpTemplate(ostream & o) : ost(o) {}
|
|
|
|
|
|
|
|
void operator()(value_type const & vt) {
|
2003-10-01 10:16:00 +00:00
|
|
|
Template const & et = vt.second;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
ost << "Template " << et.lyxName << '\n'
|
|
|
|
<< "\tGuiName " << et.guiName << '\n'
|
2000-06-12 11:27:15 +00:00
|
|
|
<< "\tHelpText\n"
|
|
|
|
<< et.helpText
|
|
|
|
<< "\tHelpTextEnd\n"
|
2003-09-04 17:01:00 +00:00
|
|
|
<< "\tInputFormat " << et.inputFormat << '\n'
|
|
|
|
<< "\tFileFilter " << et.fileRegExp << '\n'
|
|
|
|
<< "\tEditCommand " << et.editCommand << '\n'
|
|
|
|
<< "\tAutomaticProduction " << et.automaticProduction << '\n';
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
typedef vector<TransformID> IDs;
|
|
|
|
IDs::const_iterator it = et.transformIds.begin();
|
|
|
|
IDs::const_iterator end = et.transformIds.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
ost << "\tTransform "
|
|
|
|
<< transformIDTranslator().find(*it) << '\n';
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
et.dumpFormats(ost);
|
|
|
|
ost << "TemplateEnd" << endl;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ostream & ost;
|
|
|
|
};
|
|
|
|
|
|
|
|
class dumpFormat {
|
|
|
|
public:
|
2003-10-01 10:16:00 +00:00
|
|
|
typedef Template::Formats::value_type value_type;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
dumpFormat(ostream & o) : ost(o) {}
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
void operator()(value_type const & vt) const {
|
2003-10-01 10:16:00 +00:00
|
|
|
Template::Format const & ft = vt.second;
|
2003-09-04 17:01:00 +00:00
|
|
|
ost << "\tFormat " << vt.first << '\n'
|
|
|
|
<< "\t\tProduct " << ft.product << '\n'
|
|
|
|
<< "\t\tUpdateFormat " << ft.updateFormat << '\n'
|
|
|
|
<< "\t\tUpdateResult " << ft.updateResult << '\n'
|
2003-09-23 17:04:25 +00:00
|
|
|
<< "\t\tRequirement " << ft.requirement << '\n';
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
typedef vector<Template::Option> Options;
|
|
|
|
Options::const_iterator oit = ft.options.begin();
|
|
|
|
Options::const_iterator oend = ft.options.end();
|
|
|
|
for (; oit != oend; ++oit) {
|
|
|
|
ost << "\t\tOption "
|
|
|
|
<< oit->name
|
|
|
|
<< ": "
|
|
|
|
<< oit->option
|
|
|
|
<< '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string>::const_iterator pit = ft.preambleNames.begin();
|
|
|
|
vector<string>::const_iterator pend = ft.preambleNames.end();
|
|
|
|
for (; pit != pend; ++pit) {
|
|
|
|
ost << "\t\tPreamble " << *pit << '\n';
|
2003-09-23 17:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ost << "\tFormatEnd\n";
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
ostream & ost;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
void Template::dumpFormats(ostream & os) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
for_each(formats.begin(), formats.end(), dumpFormat(os));
|
|
|
|
}
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
void TemplateManager::dumpPreambleDefs(ostream & os) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-09-04 17:01:00 +00:00
|
|
|
for_each(preambledefs.begin(), preambledefs.end(), dumpPreambleDef(os));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
void TemplateManager::dumpTemplates(ostream & os) const
|
2003-09-04 17:01:00 +00:00
|
|
|
{
|
|
|
|
for_each(templates.begin(), templates.end(), dumpTemplate(os));
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
TemplateManager & TemplateManager::get()
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-10-01 10:16:00 +00:00
|
|
|
static TemplateManager externalTemplateManager;
|
2000-06-12 11:27:15 +00:00
|
|
|
return externalTemplateManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
TemplateManager::Templates const &
|
|
|
|
TemplateManager::getTemplates() const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
return templates;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
Template const *
|
|
|
|
TemplateManager::getTemplateByName(string const & name) const
|
2001-03-12 11:22:26 +00:00
|
|
|
{
|
2003-09-25 10:49:13 +00:00
|
|
|
Templates::const_iterator it = templates.find(name);
|
|
|
|
return (it == templates.end()) ? 0 : &it->second;
|
2001-03-12 11:22:26 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
string const
|
2003-10-01 10:16:00 +00:00
|
|
|
TemplateManager::getPreambleDefByName(string const & name) const
|
2003-09-04 17:01:00 +00:00
|
|
|
{
|
|
|
|
string const trimmed_name = support::trim(name);
|
|
|
|
if (trimmed_name.empty())
|
|
|
|
return string();
|
|
|
|
|
|
|
|
PreambleDefs::const_iterator it = preambledefs.find(trimmed_name);
|
|
|
|
if (it == preambledefs.end())
|
|
|
|
return string();
|
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
void TemplateManager::readTemplates(string const & path)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-09-04 17:01:00 +00:00
|
|
|
support::Path p(path);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
enum TemplateTags {
|
2003-09-04 17:01:00 +00:00
|
|
|
TM_PREAMBLEDEF = 1,
|
|
|
|
TM_PREAMBLEDEF_END,
|
|
|
|
TM_TEMPLATE,
|
|
|
|
TM_TEMPLATE_END
|
2000-06-12 11:27:15 +00:00
|
|
|
};
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
keyword_item templatetags[] = {
|
2003-09-04 17:01:00 +00:00
|
|
|
{ "preambledef", TM_PREAMBLEDEF },
|
|
|
|
{ "preambledefend", TM_PREAMBLEDEF_END },
|
2000-06-12 11:27:15 +00:00
|
|
|
{ "template", TM_TEMPLATE },
|
2003-09-04 17:01:00 +00:00
|
|
|
{ "templateend", TM_TEMPLATE_END }
|
2000-06-12 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
LyXLex lex(templatetags, TM_TEMPLATE_END);
|
2000-06-13 17:10:47 +00:00
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
string filename = support::LibFileSearch("", "external_templates");
|
|
|
|
if (filename.empty() || !lex.setFile(filename)) {
|
2003-10-01 10:16:00 +00:00
|
|
|
lex.printError("external::TemplateManager::readTemplates: "
|
2003-09-04 17:01:00 +00:00
|
|
|
"No template file");
|
2000-06-12 11:27:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
char const * const preamble_end_tag =
|
|
|
|
templatetags[TM_PREAMBLEDEF_END-1].tag;
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
while (lex.isOK()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (lex.lex()) {
|
2003-09-04 17:01:00 +00:00
|
|
|
case TM_PREAMBLEDEF: {
|
|
|
|
lex.next();
|
|
|
|
string const name = lex.getString();
|
|
|
|
preambledefs[name] = lex.getLongString(preamble_end_tag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case TM_TEMPLATE: {
|
|
|
|
lex.next();
|
2003-09-04 17:01:00 +00:00
|
|
|
string const name = lex.getString();
|
2003-10-01 10:16:00 +00:00
|
|
|
Template & tmp = templates[name];
|
2003-09-04 17:01:00 +00:00
|
|
|
tmp.lyxName = name;
|
2000-06-12 11:27:15 +00:00
|
|
|
tmp.readTemplate(lex);
|
|
|
|
}
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-09-04 17:01:00 +00:00
|
|
|
case TM_TEMPLATE_END:
|
2000-12-28 16:22:28 +00:00
|
|
|
lex.printError("Warning: End outside Template.");
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
case TM_PREAMBLEDEF_END:
|
|
|
|
lex.printError("Warning: End outside PreambleDef.");
|
|
|
|
break;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void add(vector<TransformID> & ids, string const & name)
|
|
|
|
{
|
|
|
|
TransformID id = transformIDTranslator().find(name);
|
|
|
|
if (int(id) == -1) {
|
|
|
|
lyxerr << "external::Template::readTemplate\n"
|
|
|
|
<< "Transform " << name << " is not recognized"
|
|
|
|
<< std::endl;
|
|
|
|
} else {
|
|
|
|
ids.push_back(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
void Template::readTemplate(LyXLex & lex)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
enum TemplateOptionTags {
|
|
|
|
TO_GUINAME = 1,
|
|
|
|
TO_HELPTEXT,
|
2003-06-04 09:16:29 +00:00
|
|
|
TO_INPUTFORMAT,
|
2000-06-12 11:27:15 +00:00
|
|
|
TO_FILTER,
|
|
|
|
TO_EDITCMD,
|
|
|
|
TO_AUTOMATIC,
|
2003-10-07 22:59:58 +00:00
|
|
|
TO_TRANSFORM,
|
2000-06-12 11:27:15 +00:00
|
|
|
TO_FORMAT,
|
|
|
|
TO_END
|
|
|
|
};
|
|
|
|
|
|
|
|
keyword_item templateoptiontags[] = {
|
|
|
|
{ "automaticproduction", TO_AUTOMATIC },
|
|
|
|
{ "editcommand", TO_EDITCMD },
|
|
|
|
{ "filefilter", TO_FILTER },
|
|
|
|
{ "format", TO_FORMAT },
|
|
|
|
{ "guiname", TO_GUINAME },
|
|
|
|
{ "helptext", TO_HELPTEXT },
|
2003-06-04 09:16:29 +00:00
|
|
|
{ "inputformat", TO_INPUTFORMAT },
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "templateend", TO_END },
|
|
|
|
{ "transform", TO_TRANSFORM }
|
2000-06-12 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pushpophelper pph(lex, templateoptiontags, TO_END);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
while (lex.isOK()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
switch (lex.lex()) {
|
|
|
|
case TO_GUINAME:
|
|
|
|
lex.next(true);
|
2001-08-06 19:13:25 +00:00
|
|
|
guiName = lex.getString();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case TO_HELPTEXT:
|
|
|
|
helpText = lex.getLongString("HelpTextEnd");
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
case TO_INPUTFORMAT:
|
2000-06-12 11:27:15 +00:00
|
|
|
lex.next(true);
|
2003-06-04 09:16:29 +00:00
|
|
|
inputFormat = lex.getString();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
case TO_FILTER:
|
2000-06-12 11:27:15 +00:00
|
|
|
lex.next(true);
|
2003-06-04 09:16:29 +00:00
|
|
|
fileRegExp = lex.getString();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case TO_EDITCMD:
|
|
|
|
lex.next(true);
|
2001-08-06 19:13:25 +00:00
|
|
|
editCommand = lex.getString();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case TO_AUTOMATIC:
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
automaticProduction = lex.getBool();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
case TO_TRANSFORM:
|
|
|
|
lex.next(true);
|
|
|
|
add(transformIds, lex.getString());
|
|
|
|
break;
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case TO_FORMAT:
|
|
|
|
lex.next(true);
|
2001-08-06 19:13:25 +00:00
|
|
|
formats[lex.getString()].readFormat(lex);
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case TO_END:
|
|
|
|
return;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
default:
|
2003-10-01 10:16:00 +00:00
|
|
|
lex.printError("external::Template::readTemplate: "
|
2000-12-28 16:22:28 +00:00
|
|
|
"Wrong tag: $$Token");
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(false);
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void transform_not_found(std::ostream & os, string const & transform)
|
|
|
|
{
|
|
|
|
os << "external::Format::readFormat. Transformation \""
|
|
|
|
<< transform << "\" is unrecognized." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void transform_class_not_found(std::ostream & os, string const & tclass)
|
|
|
|
{
|
|
|
|
os << "external::Format::readFormat. Transformation class \""
|
|
|
|
<< tclass << "\" is unrecognized." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setCommandFactory(Template::Format & format, string const & transform,
|
|
|
|
string const & transformer_class)
|
|
|
|
{
|
|
|
|
bool class_found = false;
|
|
|
|
if (transform == "Resize" && transformer_class == "ResizeLatexCommand") {
|
|
|
|
class_found = true;
|
|
|
|
ResizeCommandFactory factory = ResizeLatexCommand::factory;
|
|
|
|
format.command_transformers[Resize] =
|
|
|
|
TransformStore(Resize, factory);
|
|
|
|
|
|
|
|
} else if (transform == "Rotate" &&
|
|
|
|
transformer_class == "RotationLatexCommand") {
|
|
|
|
class_found = true;
|
|
|
|
RotationCommandFactory factory = RotationLatexCommand::factory;
|
|
|
|
format.command_transformers[Rotate] =
|
|
|
|
TransformStore(Rotate, factory);
|
|
|
|
|
|
|
|
} else
|
|
|
|
transform_not_found(lyxerr, transform);
|
|
|
|
|
|
|
|
if (!class_found)
|
|
|
|
transform_class_not_found(lyxerr, transformer_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setOptionFactory(Template::Format & format, string const & transform,
|
|
|
|
string const & transformer_class)
|
|
|
|
{
|
|
|
|
bool class_found = false;
|
|
|
|
if (transform == "Clip" && transformer_class == "ClipLatexOption") {
|
|
|
|
class_found = true;
|
|
|
|
ClipOptionFactory factory = ClipLatexOption::factory;
|
|
|
|
format.option_transformers[Clip] =
|
|
|
|
TransformStore(Clip, factory);
|
|
|
|
|
|
|
|
} else if (transform == "Extra" && transformer_class == "ExtraOption") {
|
|
|
|
class_found = true;
|
|
|
|
ExtraOptionFactory factory = ExtraOption::factory;
|
|
|
|
format.option_transformers[Extra] =
|
|
|
|
TransformStore(Extra, factory);
|
|
|
|
|
|
|
|
} else if (transform == "Resize" &&
|
|
|
|
transformer_class == "ResizeLatexOption") {
|
|
|
|
class_found = true;
|
|
|
|
ResizeOptionFactory factory = ResizeLatexOption::factory;
|
|
|
|
format.option_transformers[Resize] =
|
|
|
|
TransformStore(Resize, factory);
|
|
|
|
|
|
|
|
} else if (transform == "Rotate" &&
|
|
|
|
transformer_class == "RotationLatexOption") {
|
|
|
|
class_found = true;
|
|
|
|
RotationOptionFactory factory = RotationLatexOption::factory;
|
|
|
|
format.option_transformers[Rotate] =
|
|
|
|
TransformStore(Rotate, factory);
|
|
|
|
|
|
|
|
} else
|
|
|
|
transform_not_found(lyxerr, transform);
|
|
|
|
|
|
|
|
if (!class_found)
|
|
|
|
transform_class_not_found(lyxerr, transformer_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
void Template::Format::readFormat(LyXLex & lex)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
enum FormatTags {
|
|
|
|
FO_PRODUCT = 1,
|
2003-06-04 09:16:29 +00:00
|
|
|
FO_UPDATEFORMAT,
|
2001-11-02 16:18:07 +00:00
|
|
|
FO_UPDATERESULT,
|
2000-06-12 11:27:15 +00:00
|
|
|
FO_REQUIREMENT,
|
2003-10-07 22:59:58 +00:00
|
|
|
FO_OPTION,
|
2000-06-12 11:27:15 +00:00
|
|
|
FO_PREAMBLE,
|
2003-10-07 22:59:58 +00:00
|
|
|
FO_TRANSFORMCOMMAND,
|
|
|
|
FO_TRANSFORMOPTION,
|
2000-06-12 11:27:15 +00:00
|
|
|
FO_END
|
|
|
|
};
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
keyword_item formattags[] = {
|
|
|
|
{ "formatend", FO_END },
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "option", FO_OPTION },
|
2000-06-12 11:27:15 +00:00
|
|
|
{ "preamble", FO_PREAMBLE },
|
|
|
|
{ "product", FO_PRODUCT },
|
|
|
|
{ "requirement", FO_REQUIREMENT },
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "transformcommand", FO_TRANSFORMCOMMAND },
|
|
|
|
{ "transformoption", FO_TRANSFORMOPTION },
|
2003-06-04 09:16:29 +00:00
|
|
|
{ "updateformat", FO_UPDATEFORMAT },
|
2001-11-02 16:18:07 +00:00
|
|
|
{ "updateresult", FO_UPDATERESULT }
|
2000-06-12 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pushpophelper pph(lex, formattags, FO_END);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
while (lex.isOK()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (lex.lex()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
case FO_PRODUCT:
|
|
|
|
lex.next(true);
|
2001-08-06 19:13:25 +00:00
|
|
|
product = lex.getString();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
case FO_UPDATEFORMAT:
|
2000-06-12 11:27:15 +00:00
|
|
|
lex.next(true);
|
2003-06-04 09:16:29 +00:00
|
|
|
updateFormat = lex.getString();
|
2001-11-02 16:18:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FO_UPDATERESULT:
|
|
|
|
lex.next(true);
|
|
|
|
updateResult = lex.getString();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case FO_REQUIREMENT:
|
|
|
|
lex.next(true);
|
2001-08-06 19:13:25 +00:00
|
|
|
requirement = lex.getString();
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case FO_PREAMBLE:
|
2003-09-04 17:01:00 +00:00
|
|
|
lex.next(true);
|
2003-09-23 17:04:25 +00:00
|
|
|
preambleNames.push_back(lex.getString());
|
2000-06-12 11:27:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
case FO_TRANSFORMCOMMAND: {
|
|
|
|
lex.next(true);
|
|
|
|
string const name = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
setCommandFactory(*this, name, lex.getString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case FO_TRANSFORMOPTION: {
|
|
|
|
lex.next(true);
|
|
|
|
string const name = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
setOptionFactory(*this, name, lex.getString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case FO_OPTION: {
|
|
|
|
lex.next(true);
|
|
|
|
string const name = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
string const opt = lex.getString();
|
|
|
|
options.push_back(Option(name, opt));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case FO_END:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-01 10:16:00 +00:00
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
TransformIDTranslator const initIDTranslator()
|
|
|
|
{
|
|
|
|
TransformIDTranslator translator(TransformID(-1), "");
|
|
|
|
translator.addPair(Rotate, "Rotate");
|
|
|
|
translator.addPair(Resize, "Resize");
|
|
|
|
translator.addPair(Clip, "Clip");
|
|
|
|
translator.addPair(Extra, "Extra");
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TransformIDTranslator const & transformIDTranslator()
|
|
|
|
{
|
|
|
|
static TransformIDTranslator const translator = initIDTranslator();
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
} // namespace external
|
|
|
|
} // namespace lyx
|