X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FExternalTemplate.cpp;h=ba6922d123cfc04434596cfd6c5e9535acde6c48;hb=9176e60b7bcab3e355521a86ddb4c2778cd9b29e;hp=64f31343a67d13817daa093e40e5b6dfbd5c2d5c;hpb=1f945177b9628b213c60872df88f2d155c3d6c54;p=lyx.git diff --git a/src/insets/ExternalTemplate.cpp b/src/insets/ExternalTemplate.cpp index 64f31343a6..ba6922d123 100644 --- a/src/insets/ExternalTemplate.cpp +++ b/src/insets/ExternalTemplate.cpp @@ -74,7 +74,7 @@ class DumpPreambleDef { public: typedef TemplateManager::PreambleDefs::value_type value_type; - DumpPreambleDef(ostream & os) : os_(os) {} + explicit DumpPreambleDef(ostream & os) : os_(os) {} void operator()(value_type const & vt) { os_ << "PreambleDef " << vt.first << '\n' @@ -91,7 +91,7 @@ class DumpTemplate { public: typedef TemplateManager::Templates::value_type value_type; - DumpTemplate(ostream & os) : os_(os) {} + explicit DumpTemplate(ostream & os) : os_(os) {} void operator()(value_type const & vt) { Template const & et = vt.second; @@ -137,7 +137,7 @@ class DumpFormat { public: typedef Template::Formats::value_type value_type; - DumpFormat(ostream & o) : os_(o) {} + explicit DumpFormat(ostream & o) : os_(o) {} void operator()(value_type const & vt) const { Template::Format const & ft = vt.second; @@ -260,43 +260,91 @@ void TemplateManager::readTemplates(FileName const & path) { "templateend", TM_TEMPLATE_END } }; - Lexer lex(templatetags); + // Read the templates list + vector templateslist; + FileName const real_file = libFileSearch("", "xtemplates.lst"); + LYXERR(Debug::EXTERNAL, "Reading external templates from `" << real_file << '\''); - FileName const filename = libFileSearch("", "external_templates"); - if (filename.empty() || !lex.setFile(filename)) { - lex.printError("external::TemplateManager::readTemplates: " - "No template file"); + if (real_file.empty()) { + LYXERR0("unable to find external templates file `xtemplates.lst'.\n" + << "No external templates will be available."); return; } - char const * const preamble_end_tag = - templatetags[TM_PREAMBLEDEF_END-1].tag; + Lexer tlex; + if (!tlex.setFile(real_file)) { + LYXERR0("lyxlex was not able to set file: " + << real_file << ".\nNo external templates will be available."); + return; + } - 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)); + if (!tlex.isOK()) { + LYXERR0("unable to open external templates file `" + << to_utf8(makeDisplayPath(real_file.absFileName(), 1000)) + << "'\nNo external templates will be available."); + return; + } + + 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; } - break; + } - case TM_TEMPLATE: { - lex.next(); - string const name = lex.getString(); - Template & tmp = templates[name]; - tmp.lyxName = name; - tmp.readTemplate(lex); + LYXERR(Debug::EXTERNAL, "End of parsing of xtemplates.lst"); + + for (vector::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; } - break; - case TM_TEMPLATE_END: - lex.printError("Warning: End outside Template."); - break; + char const * const preamble_end_tag = + templatetags[TM_PREAMBLEDEF_END-1].tag; - case TM_PREAMBLEDEF_END: - lex.printError("Warning: End outside PreambleDef."); - break; + 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; + } } } } @@ -468,7 +516,7 @@ void setOptionFactory(Template::Format & format, string const & transform, transform_class_not_found(lyxerr, transformer_class); } -} // namespace anon +} // namespace void Template::Format::readFormat(Lexer & lex)