From 926b68c0aada3c3cf0e8278e63dce959f64bec39 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sun, 27 Jul 2003 00:39:35 +0000 Subject: [PATCH] Remove hard coding of command layouts. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7374 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/ChangeLog | 6 +++ src/tex2lyx/Makefile.am | 2 - src/tex2lyx/tex2lyx.C | 5 ++- src/tex2lyx/text.C | 82 ++++++++++++++++++++++++++--------------- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/tex2lyx/ChangeLog b/src/tex2lyx/ChangeLog index 5971822b06..899772c934 100644 --- a/src/tex2lyx/ChangeLog +++ b/src/tex2lyx/ChangeLog @@ -1,3 +1,9 @@ +2003-07-27 Angus Leeming + + * tex2lyx.C: add Debug::ANY hack. + + * text.C: remove hardcoded command layouts. + 2003-07-26 Jean-Marc Lasgouttes * text.C (parse_text): fix handling of \LaTeXe macro diff --git a/src/tex2lyx/Makefile.am b/src/tex2lyx/Makefile.am index dcfe5df8a2..5f5970764c 100644 --- a/src/tex2lyx/Makefile.am +++ b/src/tex2lyx/Makefile.am @@ -24,8 +24,6 @@ linked_files = \ lyxlex.C \ lyxlex_pimpl.C -# debug.C - tex2lyx_SOURCES = \ $(linked_files) \ Spacing.h \ diff --git a/src/tex2lyx/tex2lyx.C b/src/tex2lyx/tex2lyx.C index a08b26feb2..66326bef18 100644 --- a/src/tex2lyx/tex2lyx.C +++ b/src/tex2lyx/tex2lyx.C @@ -6,8 +6,8 @@ #include "tex2lyx.h" -#include "lyx_main.h" #include "debug.h" +#include "lyx_main.h" #include "lyxtextclass.h" #include @@ -30,10 +30,11 @@ using std::stringstream; using std::string; using std::vector; -// A hack to allow the thing to link in the lyxlayout stuff +// Hacks to allow the thing to link in the lyxlayout stuff string system_lyxdir = "../../../lib"; string build_lyxdir = "../../lib"; string user_lyxdir = "."; +Debug::type const Debug::ANY = Debug::type(0); DebugStream lyxerr; void LyX::emergencyCleanup() {} diff --git a/src/tex2lyx/text.C b/src/tex2lyx/text.C index 79ad1057d8..1f87652525 100644 --- a/src/tex2lyx/text.C +++ b/src/tex2lyx/text.C @@ -30,9 +30,6 @@ using lyx::support::suffixIs; namespace { -char const * known_headings[] = { "caption", "title", "author", "date", -"paragraph", "chapter", "section", "subsection", "subsubsection", 0 }; - char const * known_latex_commands[] = { "ref", "cite", "label", "index", "printindex", "pageref", "url", 0 }; @@ -135,6 +132,43 @@ void handle_par(ostream & os) } +struct isLayout { + isLayout(string const name) : name_(name) {} + bool operator()(LyXLayout_ptr const & ptr) { + return ptr.get() && ptr->latexname() == name_; + } +private: + string const name_; +}; + + +LyXLayout_ptr findLayout(LyXTextClass const & textclass, + string const & name) +{ + LyXTextClass::const_iterator it = textclass.begin(); + LyXTextClass::const_iterator end = textclass.end(); + it = std::find_if(it, end, isLayout(name)); + return (it == end) ? LyXLayout_ptr() : *it; +} + + +void output_layout(ostream & os, LyXLayout_ptr const & layout_ptr, + Parser & p, bool outer, LyXTextClass const & textclass) +{ + string name = layout_ptr->name(); + os << "\n\n\\layout " << name << "\n\n"; + if (layout_ptr->optionalargs > 0) { + string opt = p.getOpt(); + if (opt.size()) { + begin_inset(os, "OptArg\n"); + os << "collapsed true\n\n\\layout Standard\n\n" << opt; + end_inset(os); + } + } + parse_text(p, os, FLAG_ITEM, outer, textclass); + os << "\n\n\\layout Standard\n\n"; +} + } // anonymous namespace @@ -142,6 +176,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, LyXTextClass const & textclass) { while (p.good()) { + LyXLayout_ptr layout_ptr; Token const & t = p.get_token(); #ifdef FILEDEBUG @@ -372,21 +407,20 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, //cerr << "next token: '" << p.next_token().cs() << "'\n"; } - else if (is_known(t.cs(), known_headings)) { - string name = t.cs(); - if (p.next_token().asInput() == "*") { - p.get_token(); - name += "*"; - } - os << "\n\n\\layout " << cap(name) << "\n\n"; - string opt = p.getOpt(); - if (opt.size()) { - begin_inset(os, "OptArg\n"); - os << "collapsed true\n\n\\layout Standard\n\n" << opt; - end_inset(os); - } - parse_text(p, os, FLAG_ITEM, outer, textclass); - os << "\n\n\\layout Standard\n\n"; + // Must attempt to parse "Section*" before "Section". + else if ((p.next_token().asInput() == "*") && + // The single '=' is meant here. + (layout_ptr = findLayout(textclass, + t.cs() + '*')).get() && + layout_ptr->isCommand()) { + p.get_token(); + output_layout(os, layout_ptr, p, outer, textclass); + } + + // The single '=' is meant here. + else if ((layout_ptr = findLayout(textclass, t.cs())).get() && + layout_ptr->isCommand()) { + output_layout(os, layout_ptr, p, outer, textclass); } else if (t.cs() == "includegraphics") { @@ -600,18 +634,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "\\") os << "\n\\newline\n"; - else if (t.cs() == "lyxrightaddress") { - os << "\n\\layout Right Address\n"; - parse_text(p, os, FLAG_ITEM, outer, textclass); - os << "\n\\layout Standard\n"; - } - - else if (t.cs() == "lyxaddress") { - os << "\n\\layout Address\n"; - parse_text(p, os, FLAG_ITEM, outer, textclass); - os << "\n\\layout Standard\n"; - } - else if (t.cs() == "input") handle_ert(os, "\\input{" + p.verbatim_item() + "}\n"); -- 2.39.2