X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FExternalTemplate.C;h=cdf429ea22951b613498d814fb4d6fd60e077803;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=ffcdd4330535d653db87aaa1d70d97d4fa53ac98;hpb=adaef99e60e28eba8c413a3472cc71e234718af0;p=lyx.git diff --git a/src/insets/ExternalTemplate.C b/src/insets/ExternalTemplate.C index ffcdd43305..cdf429ea22 100644 --- a/src/insets/ExternalTemplate.C +++ b/src/insets/ExternalTemplate.C @@ -4,7 +4,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. + * Copyright 1995-2001 The LyX Team. * * ====================================================== */ @@ -19,8 +19,10 @@ #include "ExternalTemplate.h" #include "lyxlex.h" +#include "debug.h" #include "support/path.h" #include "support/LAssert.h" +#include "support/filetools.h" using std::endl; using std::ostream; @@ -32,25 +34,25 @@ extern string user_lyxdir; // We have to have dummy default commands for security reasons! ExternalTemplate::ExternalTemplate() - : viewCommand("true"), editCommand("true") {} ExternalTemplate::FormatTemplate::FormatTemplate() - : updateCommand("true") {} +{} ExternalTemplateManager::ExternalTemplateManager() { // gimp gnuchess gnuplot ical netscape tetris xpaint readTemplates(user_lyxdir); - dumpTemplates(); + if (lyxerr.debugging()) + dumpTemplates(); } class dumpTemplate { public: - dumpTemplate(std::ostream & o) + dumpTemplate(ostream & o) : ost(o) {} void operator()(ExternalTemplateManager::Templates::value_type const & vt) { ExternalTemplate const & et = vt.second; @@ -82,6 +84,7 @@ public: ost << "\tFormat " << vt.first << "\n" << "\t\tProduct " << ft.product << "\n" << "\t\tUpdateCommand " << ft.updateCommand << "\n" + << "\t\tUpdateResult " << ft.updateResult << "\n" << "\t\tRequirement " << ft.requirement << "\n" << "\t\tPreamble\n" << ft.preamble @@ -126,6 +129,12 @@ ExternalTemplateManager::getTemplates() const } +ExternalTemplate const & ExternalTemplateManager::getTemplateByName(string const & name) +{ + return templates[name]; +} + + void ExternalTemplateManager::readTemplates(string const & path) { Path p(path); @@ -142,21 +151,23 @@ void ExternalTemplateManager::readTemplates(string const & path) string filename = LibFileSearch("", "external_templates"); if (filename.empty()) { - lyxerr << "No template file" << endl; + lyxerr << "ExternalTemplateManager::readTemplates: " + "No template file" << endl; return; } LyXLex lex(templatetags, TM_END); if (!lex.setFile(filename)) { - lyxerr << "No template file" << endl; + lyxerr << "ExternalTemplateManager::readTemplates: " + "No template file" << endl; return; } - while (lex.IsOK()) { + while (lex.isOK()) { switch (lex.lex()) { case TM_TEMPLATE: { lex.next(); - string temp = lex.GetString(); + string const temp = lex.getString(); ExternalTemplate & tmp = templates[temp]; tmp.lyxName = temp; tmp.readTemplate(lex); @@ -164,8 +175,7 @@ void ExternalTemplateManager::readTemplates(string const & path) break; case TM_END: - lyxerr << "TemplateEnd: " << lex.GetString() << endl; - lyxerr << "Warning: End outside Template." << endl; + lex.printError("Warning: End outside Template."); break; } } @@ -198,11 +208,11 @@ void ExternalTemplate::readTemplate(LyXLex & lex) pushpophelper pph(lex, templateoptiontags, TO_END); - while (lex.IsOK()) { + while (lex.isOK()) { switch (lex.lex()) { case TO_GUINAME: lex.next(true); - guiName = lex.GetString(); + guiName = lex.getString(); break; case TO_HELPTEXT: @@ -211,41 +221,36 @@ void ExternalTemplate::readTemplate(LyXLex & lex) case TO_FILTER: lex.next(true); - fileRegExp = lex.GetString(); + fileRegExp = lex.getString(); break; case TO_VIEWCMD: lex.next(true); - viewCommand = lex.GetString(); - // For security reasons, a command may not be empty! - if (viewCommand.empty()) - viewCommand = "true"; + viewCommand = lex.getString(); break; case TO_EDITCMD: lex.next(true); - editCommand = lex.GetString(); - // For security reasons, a command may not be empty! - if (editCommand.empty()) - editCommand = "true"; + editCommand = lex.getString(); break; case TO_AUTOMATIC: lex.next(); - automaticProduction = lex.GetBool(); + automaticProduction = lex.getBool(); break; case TO_FORMAT: lex.next(true); - formats[lex.GetString()].readFormat(lex); + formats[lex.getString()].readFormat(lex); break; case TO_END: return; default: - lyxerr << "Default: " << lex.GetString() << endl; - Assert(false); + lex.printError("ExternalTemplate::readTemplate: " + "Wrong tag: $$Token"); + lyx::Assert(false); break; } } @@ -257,6 +262,7 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex) enum FormatTags { FO_PRODUCT = 1, FO_UPDATECMD, + FO_UPDATERESULT, FO_REQUIREMENT, FO_PREAMBLE, FO_END @@ -267,29 +273,32 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex) { "preamble", FO_PREAMBLE }, { "product", FO_PRODUCT }, { "requirement", FO_REQUIREMENT }, - { "updatecommand", FO_UPDATECMD } + { "updatecommand", FO_UPDATECMD }, + { "updateresult", FO_UPDATERESULT } }; pushpophelper pph(lex, formattags, FO_END); - while (lex.IsOK()) { + while (lex.isOK()) { switch (lex.lex()) { case FO_PRODUCT: lex.next(true); - product = lex.GetString(); + product = lex.getString(); break; case FO_UPDATECMD: lex.next(true); - updateCommand = lex.GetString(); - // For security reasons, a command may not be empty! - if (updateCommand.empty()) - updateCommand = "true"; + updateCommand = lex.getString(); + break; + + case FO_UPDATERESULT: + lex.next(true); + updateResult = lex.getString(); break; case FO_REQUIREMENT: lex.next(true); - requirement = lex.GetString(); + requirement = lex.getString(); break; case FO_PREAMBLE: @@ -297,7 +306,8 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex) break; case FO_END: - lyxerr << "FormatEnd: " << lex.GetString() << endl; + if (lyxerr.debugging()) + lex.printError("FormatEnd"); return; } }