2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-26 05:18:04 +00:00
|
|
|
* \file ExternalTemplate.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* 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"
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2000-11-08 09:39:46 +00:00
|
|
|
#include "support/filetools.h"
|
2003-09-04 17:01:00 +00:00
|
|
|
#include "support/lstrings.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
#include "support/Package.h"
|
|
|
|
#include "support/Path.h"
|
2003-09-05 13:03:23 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
using namespace lyx::support;
|
2003-09-05 09:01:27 +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
|
|
|
|
|
|
|
typedef Translator<TransformID, string> TransformIDTranslator;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
static 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;
|
|
|
|
}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
static TransformIDTranslator const & transformIDTranslator()
|
|
|
|
{
|
|
|
|
static TransformIDTranslator const translator = initIDTranslator();
|
|
|
|
return translator;
|
|
|
|
}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
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
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
readTemplates(package().user_support());
|
2003-09-04 17:01:00 +00:00
|
|
|
if (lyxerr.debugging(Debug::EXTERNAL)) {
|
|
|
|
dumpPreambleDefs(lyxerr);
|
|
|
|
lyxerr << '\n';
|
|
|
|
dumpTemplates(lyxerr);
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
class DumpPreambleDef {
|
2003-09-04 17:01:00 +00:00
|
|
|
public:
|
2003-10-01 10:16:00 +00:00
|
|
|
typedef TemplateManager::PreambleDefs::value_type value_type;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
DumpPreambleDef(ostream & o) : ost(o) {}
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
void operator()(value_type const & vt) {
|
|
|
|
ost << "PreambleDef " << vt.first << '\n'
|
|
|
|
<< vt.second
|
|
|
|
<< "PreambleDefEnd" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ostream & ost;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
class DumpTemplate {
|
2000-06-12 11:27:15 +00:00
|
|
|
public:
|
2003-10-01 10:16:00 +00:00
|
|
|
typedef TemplateManager::Templates::value_type value_type;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
DumpTemplate(ostream & o) : ost(o) {}
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
<< "\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;
|
|
|
|
};
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
class DumpFormat {
|
2000-06-12 11:27:15 +00:00
|
|
|
public:
|
2003-10-01 10:16:00 +00:00
|
|
|
typedef Template::Formats::value_type value_type;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
DumpFormat(ostream & o) : ost(o) {}
|
2003-09-04 17:01:00 +00:00
|
|
|
|
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'
|
2005-04-05 11:00:09 +00:00
|
|
|
<< "\t\tUpdateResult " << ft.updateResult << '\n';
|
|
|
|
|
|
|
|
vector<string>::const_iterator qit = ft.requirements.begin();
|
|
|
|
vector<string>::const_iterator qend = ft.requirements.end();
|
|
|
|
for (; qit != qend; ++qit) {
|
2007-12-12 19:28:07 +00:00
|
|
|
lyxerr << "req:" << *qit << endl;
|
2005-04-05 11:00:09 +00:00
|
|
|
ost << "\t\tRequirement " << *qit << '\n';
|
|
|
|
}
|
2003-09-23 17:04:25 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
typedef Template::Format::FileMap FileMap;
|
|
|
|
FileMap::const_iterator rit = ft.referencedFiles.begin();
|
|
|
|
FileMap::const_iterator rend = ft.referencedFiles.end();
|
|
|
|
for (; rit != rend; ++rit) {
|
|
|
|
vector<string>::const_iterator fit = rit->second.begin();
|
|
|
|
vector<string>::const_iterator fend = rit->second.end();
|
|
|
|
for (; fit != fend; ++fit) {
|
|
|
|
ost << "\t\tReferencedFile " << rit->first
|
|
|
|
<< " \"" << *fit << "\"\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
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
for_each(formats.begin(), formats.end(), DumpFormat(os));
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
for_each(preambledefs.begin(), preambledefs.end(), DumpPreambleDef(os));
|
2003-09-04 17:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
void TemplateManager::dumpTemplates(ostream & os) const
|
2003-09-04 17:01:00 +00:00
|
|
|
{
|
2007-11-28 22:12:03 +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
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
string const trimmed_name = trim(name);
|
2003-09-04 17:01:00 +00:00
|
|
|
if (trimmed_name.empty())
|
|
|
|
return string();
|
|
|
|
|
|
|
|
PreambleDefs::const_iterator it = preambledefs.find(trimmed_name);
|
|
|
|
if (it == preambledefs.end())
|
|
|
|
return string();
|
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:57:42 +00:00
|
|
|
void TemplateManager::readTemplates(FileName const & path)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
PathChanger 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
|
|
|
};
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
Lexer lex(templatetags, TM_TEMPLATE_END);
|
2000-06-13 17:10:47 +00:00
|
|
|
|
2007-12-12 19:57:42 +00:00
|
|
|
FileName const filename = libFileSearch("", "external_templates");
|
2003-09-04 17:01:00 +00:00
|
|
|
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"
|
2007-12-12 19:28:07 +00:00
|
|
|
<< endl;
|
2003-10-07 22:59:58 +00:00
|
|
|
} else {
|
|
|
|
ids.push_back(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void Template::readTemplate(Lexer & 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_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 },
|
|
|
|
{ "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
|
|
|
};
|
|
|
|
|
2007-04-26 11:30:54 +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_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 {
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
void transform_not_found(ostream & os, string const & transform)
|
2003-10-07 22:59:58 +00:00
|
|
|
{
|
|
|
|
os << "external::Format::readFormat. Transformation \""
|
2007-12-12 19:28:07 +00:00
|
|
|
<< transform << "\" is unrecognized." << endl;
|
2003-10-07 22:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
void transform_class_not_found(ostream & os, string const & tclass)
|
2003-10-07 22:59:58 +00:00
|
|
|
{
|
|
|
|
os << "external::Format::readFormat. Transformation class \""
|
2007-12-12 19:28:07 +00:00
|
|
|
<< tclass << "\" is unrecognized." << endl;
|
2003-10-07 22:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void Template::Format::readFormat(Lexer & 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,
|
2004-06-01 13:39:33 +00:00
|
|
|
FO_REFERENCEDFILE,
|
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 },
|
2004-06-01 13:39:33 +00:00
|
|
|
{ "referencedfile", FO_REFERENCEDFILE },
|
2000-06-12 11:27:15 +00:00
|
|
|
{ "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
|
|
|
};
|
|
|
|
|
2007-04-26 11:30:54 +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);
|
2005-04-05 11:00:09 +00:00
|
|
|
requirements.push_back(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;
|
|
|
|
}
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
case FO_REFERENCEDFILE: {
|
|
|
|
lex.next(true);
|
|
|
|
string const format = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
string const file = lex.getString();
|
|
|
|
referencedFiles[format].push_back(file);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
case FO_END:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-01 10:16:00 +00:00
|
|
|
|
|
|
|
} // namespace external
|
|
|
|
} // namespace lyx
|
2007-08-30 18:03:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|