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-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.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"
|
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"
|
2013-02-06 10:36:58 +00:00
|
|
|
#include "support/PathChanger.h"
|
2011-07-14 17:00:35 +00:00
|
|
|
#include "support/Translator.h"
|
2003-09-05 13:03:23 +00:00
|
|
|
|
2020-05-13 18:44:03 +00:00
|
|
|
#include <algorithm>
|
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()
|
2010-05-10 12:34:34 +00:00
|
|
|
: inputFormat("*"), automaticProduction(false), preview_mode(PREVIEW_OFF)
|
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
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
DumpPreambleDef(ostream & os) : os_(os) {}
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
void operator()(value_type const & vt) {
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "PreambleDef " << vt.first << '\n'
|
2016-09-25 10:37:40 +00:00
|
|
|
<< to_utf8(vt.second)
|
2003-09-04 17:01:00 +00:00
|
|
|
<< "PreambleDefEnd" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2008-04-03 20:55:09 +00:00
|
|
|
ostream & os_;
|
2003-09-04 17:01:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
DumpTemplate(ostream & os) : os_(os) {}
|
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
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "Template " << et.lyxName << '\n'
|
2003-09-04 17:01:00 +00:00
|
|
|
<< "\tGuiName " << et.guiName << '\n'
|
2000-06-12 11:27:15 +00:00
|
|
|
<< "\tHelpText\n"
|
2016-09-25 10:37:40 +00:00
|
|
|
<< to_utf8(et.helpText)
|
2000-06-12 11:27:15 +00:00
|
|
|
<< "\tHelpTextEnd\n"
|
2003-09-04 17:01:00 +00:00
|
|
|
<< "\tInputFormat " << et.inputFormat << '\n'
|
|
|
|
<< "\tFileFilter " << et.fileRegExp << '\n'
|
2008-06-13 07:34:55 +00:00
|
|
|
<< "\tAutomaticProduction " << et.automaticProduction << '\n'
|
|
|
|
<< "\tPreview ";
|
|
|
|
switch (et.preview_mode) {
|
|
|
|
case PREVIEW_OFF:
|
|
|
|
os_ << "Off\n";
|
|
|
|
break;
|
|
|
|
case PREVIEW_GRAPHICS:
|
|
|
|
os_ << "Graphics\n";
|
|
|
|
break;
|
|
|
|
case PREVIEW_INSTANT:
|
|
|
|
os_ << "InstantPreview\n";
|
|
|
|
break;
|
|
|
|
}
|
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) {
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "\tTransform "
|
2003-10-07 22:59:58 +00:00
|
|
|
<< transformIDTranslator().find(*it) << '\n';
|
|
|
|
}
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
et.dumpFormats(os_);
|
|
|
|
os_ << "TemplateEnd" << endl;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2008-04-03 20:55:09 +00:00
|
|
|
ostream & os_;
|
2000-06-12 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
DumpFormat(ostream & o) : os_(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;
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "\tFormat " << vt.first << '\n'
|
2003-09-04 17:01:00 +00:00
|
|
|
<< "\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;
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "\t\tRequirement " << *qit << '\n';
|
2005-04-05 11:00:09 +00:00
|
|
|
}
|
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) {
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "\t\tOption "
|
2003-10-07 22:59:58 +00:00
|
|
|
<< 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) {
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "\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) {
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "\t\tReferencedFile " << rit->first
|
2004-06-01 13:39:33 +00:00
|
|
|
<< " \"" << *fit << "\"\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
os_ << "\tFormatEnd\n";
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
private:
|
2008-04-03 20:55:09 +00:00
|
|
|
ostream & os_;
|
2000-06-12 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-05 21:36:26 +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
|
|
|
|
2016-09-25 10:37:40 +00:00
|
|
|
docstring 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())
|
2016-09-25 10:37:40 +00:00
|
|
|
return docstring();
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
PreambleDefs::const_iterator it = preambledefs.find(trimmed_name);
|
|
|
|
if (it == preambledefs.end())
|
2016-09-25 10:37:40 +00:00
|
|
|
return docstring();
|
2003-09-04 17:01:00 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
enum {
|
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
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword 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
|
|
|
};
|
|
|
|
|
2017-03-26 13:32:01 +00:00
|
|
|
// Read the templates list
|
|
|
|
vector<string> templateslist;
|
|
|
|
FileName const real_file = libFileSearch("", "xtemplates.lst");
|
|
|
|
LYXERR(Debug::EXTERNAL, "Reading external templates from `" << real_file << '\'');
|
|
|
|
|
|
|
|
if (real_file.empty()) {
|
|
|
|
LYXERR0("unable to find external templates file `xtemplates.lst'.\n"
|
|
|
|
<< "No external templates will be available.");
|
|
|
|
return;
|
|
|
|
}
|
2000-06-13 17:10:47 +00:00
|
|
|
|
2017-03-26 13:32:01 +00:00
|
|
|
Lexer tlex;
|
|
|
|
if (!tlex.setFile(real_file)) {
|
|
|
|
LYXERR0("lyxlex was not able to set file: "
|
|
|
|
<< real_file << ".\nNo external templates will be available.");
|
2000-06-12 11:27:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2017-03-26 13:32:01 +00:00
|
|
|
if (!tlex.isOK()) {
|
|
|
|
LYXERR0("unable to open external templates file `"
|
|
|
|
<< to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
|
|
|
|
<< "'\nNo external templates will be available.");
|
|
|
|
return;
|
|
|
|
}
|
2003-09-04 17:01:00 +00:00
|
|
|
|
2017-03-26 13:32:01 +00:00
|
|
|
bool finished = false;
|
|
|
|
// Parse external templates files
|
|
|
|
LYXERR(Debug::EXTERNAL, "Starting parsing of xtemplates.lst");
|
|
|
|
while (tlex.isOK() && !finished) {
|
|
|
|
LYXERR(Debug::EXTERNAL, "\tline by line");
|
|
|
|
switch (tlex.lex()) {
|
|
|
|
case Lexer::LEX_FEOF:
|
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
string const name = tlex.getString();
|
|
|
|
LYXERR(Debug::EXTERNAL, "Template name: " << name);
|
|
|
|
templateslist.push_back(name);
|
|
|
|
break;
|
2003-09-04 17:01:00 +00:00
|
|
|
}
|
2017-03-26 13:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LYXERR(Debug::EXTERNAL, "End of parsing of xtemplates.lst");
|
|
|
|
|
|
|
|
for (vector<string>::const_iterator it = templateslist.begin(); it != templateslist.end(); ++it) {
|
|
|
|
FileName const filename = libFileSearch("xtemplates", *it);
|
|
|
|
LYXERR(Debug::EXTERNAL, "Reading template file " << filename.absFileName());
|
|
|
|
Lexer lex(templatetags);
|
|
|
|
if (filename.empty() || !lex.setFile(filename)) {
|
|
|
|
lex.printError("external::TemplateManager::readTemplates: "
|
|
|
|
"No template file");
|
|
|
|
return;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2017-03-26 13:32:01 +00:00
|
|
|
char const * const preamble_end_tag =
|
|
|
|
templatetags[TM_PREAMBLEDEF_END-1].tag;
|
2003-09-04 17:01:00 +00:00
|
|
|
|
2017-03-26 13:32:01 +00:00
|
|
|
while (lex.isOK()) {
|
|
|
|
switch (lex.lex()) {
|
|
|
|
case TM_PREAMBLEDEF: {
|
|
|
|
lex.next();
|
|
|
|
string const name = lex.getString();
|
|
|
|
preambledefs[name] = lex.getLongString(from_ascii(preamble_end_tag));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TM_TEMPLATE: {
|
|
|
|
lex.next();
|
|
|
|
string const name = lex.getString();
|
|
|
|
Template & tmp = templates[name];
|
|
|
|
tmp.lyxName = name;
|
|
|
|
tmp.readTemplate(lex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TM_TEMPLATE_END:
|
|
|
|
lex.printError("Warning: End outside Template.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TM_PREAMBLEDEF_END:
|
|
|
|
lex.printError("Warning: End outside PreambleDef.");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void Template::readTemplate(Lexer & lex)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2008-04-02 23:06:22 +00:00
|
|
|
enum {
|
2000-06-12 11:27:15 +00:00
|
|
|
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,
|
2008-06-13 07:34:55 +00:00
|
|
|
TO_PREVIEW,
|
2003-10-07 22:59:58 +00:00
|
|
|
TO_TRANSFORM,
|
2000-06-12 11:27:15 +00:00
|
|
|
TO_FORMAT,
|
|
|
|
TO_END
|
|
|
|
};
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword templateoptiontags[] = {
|
2000-06-12 11:27:15 +00:00
|
|
|
{ "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 },
|
2008-06-15 14:23:45 +00:00
|
|
|
{ "preview", TO_PREVIEW },
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "templateend", TO_END },
|
|
|
|
{ "transform", TO_TRANSFORM }
|
2000-06-12 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
PushPopHelper pph(lex, templateoptiontags);
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.setContext("Template::readTemplate");
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2008-04-05 21:24:57 +00:00
|
|
|
string token;
|
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:
|
2016-09-25 10:37:40 +00:00
|
|
|
helpText = lex.getLongString(from_ascii("HelpTextEnd"));
|
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_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
|
|
|
|
2008-06-13 07:34:55 +00:00
|
|
|
case TO_PREVIEW:
|
|
|
|
lex >> token;
|
|
|
|
if (token == "InstantPreview")
|
|
|
|
preview_mode = PREVIEW_INSTANT;
|
|
|
|
else if (token == "Graphics")
|
|
|
|
preview_mode = PREVIEW_GRAPHICS;
|
|
|
|
else
|
|
|
|
preview_mode = PREVIEW_OFF;
|
|
|
|
break;
|
|
|
|
|
2008-04-05 21:36:26 +00:00
|
|
|
case TO_TRANSFORM: {
|
2008-04-05 21:24:57 +00:00
|
|
|
lex >> token;
|
|
|
|
TransformID id = transformIDTranslator().find(token);
|
|
|
|
if (int(id) == -1)
|
|
|
|
LYXERR0("Transform " << token << " is not recognized");
|
|
|
|
else
|
2008-04-05 21:36:26 +00:00
|
|
|
transformIds.push_back(id);
|
2003-10-07 22:59:58 +00:00
|
|
|
break;
|
2008-04-05 21:36:26 +00:00
|
|
|
}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void Template::Format::readFormat(Lexer & lex)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2008-04-03 20:55:09 +00:00
|
|
|
enum {
|
2000-06-12 11:27:15 +00:00
|
|
|
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
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword formattags[] = {
|
2000-06-12 11:27:15 +00:00
|
|
|
{ "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
|
|
|
};
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
PushPopHelper pph(lex, formattags);
|
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
|