]> git.lyx.org Git - features.git/commitdiff
Remove hard coding of command layouts.
authorAngus Leeming <leeming@lyx.org>
Sun, 27 Jul 2003 00:39:35 +0000 (00:39 +0000)
committerAngus Leeming <leeming@lyx.org>
Sun, 27 Jul 2003 00:39:35 +0000 (00:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7374 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/ChangeLog
src/tex2lyx/Makefile.am
src/tex2lyx/tex2lyx.C
src/tex2lyx/text.C

index 5971822b06a8e9bcbdf530c35123d1fa6c82a46e..899772c934d8958aec9f1f3bad8a671cac66dd6b 100644 (file)
@@ -1,3 +1,9 @@
+2003-07-27  Angus Leeming  <leeming@lyx.org>
+
+       * tex2lyx.C: add Debug::ANY hack.
+
+       * text.C: remove hardcoded command layouts.
+
 2003-07-26  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * text.C (parse_text): fix handling of \LaTeXe macro
index dcfe5df8a2c5c3fe12072cb8521e56a1d45a31d3..5f5970764c3d35c7b78d6ea2e9920b35c81071e6 100644 (file)
@@ -24,8 +24,6 @@ linked_files = \
        lyxlex.C \
        lyxlex_pimpl.C
 
-#      debug.C
-
 tex2lyx_SOURCES = \
        $(linked_files) \
        Spacing.h \
index a08b26feb277e7c0e299a51e88dd3ce70a58828c..66326bef180cd66cba39d93ab19c801f4d39fc01 100644 (file)
@@ -6,8 +6,8 @@
 
 #include "tex2lyx.h"
 
-#include "lyx_main.h"
 #include "debug.h"
+#include "lyx_main.h"
 #include "lyxtextclass.h"
 
 #include <cctype>
@@ -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() {}
index 79ad1057d89231a12bb85daf05d9c4bfc8507941..1f87652525e09796bc42a487487ca08fec8e74a2 100644 (file)
@@ -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");