Remove hard coding of command layouts.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7374 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-07-27 00:39:35 +00:00
parent 672ab42137
commit 926b68c0aa
4 changed files with 61 additions and 34 deletions

View 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> 2003-07-26 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* text.C (parse_text): fix handling of \LaTeXe macro * text.C (parse_text): fix handling of \LaTeXe macro

View File

@ -24,8 +24,6 @@ linked_files = \
lyxlex.C \ lyxlex.C \
lyxlex_pimpl.C lyxlex_pimpl.C
# debug.C
tex2lyx_SOURCES = \ tex2lyx_SOURCES = \
$(linked_files) \ $(linked_files) \
Spacing.h \ Spacing.h \

View File

@ -6,8 +6,8 @@
#include "tex2lyx.h" #include "tex2lyx.h"
#include "lyx_main.h"
#include "debug.h" #include "debug.h"
#include "lyx_main.h"
#include "lyxtextclass.h" #include "lyxtextclass.h"
#include <cctype> #include <cctype>
@ -30,10 +30,11 @@ using std::stringstream;
using std::string; using std::string;
using std::vector; 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 system_lyxdir = "../../../lib";
string build_lyxdir = "../../lib"; string build_lyxdir = "../../lib";
string user_lyxdir = "."; string user_lyxdir = ".";
Debug::type const Debug::ANY = Debug::type(0);
DebugStream lyxerr; DebugStream lyxerr;
void LyX::emergencyCleanup() {} void LyX::emergencyCleanup() {}

View File

@ -30,9 +30,6 @@ using lyx::support::suffixIs;
namespace { namespace {
char const * known_headings[] = { "caption", "title", "author", "date",
"paragraph", "chapter", "section", "subsection", "subsubsection", 0 };
char const * known_latex_commands[] = { "ref", "cite", "label", "index", char const * known_latex_commands[] = { "ref", "cite", "label", "index",
"printindex", "pageref", "url", 0 }; "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 } // anonymous namespace
@ -142,6 +176,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
LyXTextClass const & textclass) LyXTextClass const & textclass)
{ {
while (p.good()) { while (p.good()) {
LyXLayout_ptr layout_ptr;
Token const & t = p.get_token(); Token const & t = p.get_token();
#ifdef FILEDEBUG #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"; //cerr << "next token: '" << p.next_token().cs() << "'\n";
} }
else if (is_known(t.cs(), known_headings)) { // Must attempt to parse "Section*" before "Section".
string name = t.cs(); else if ((p.next_token().asInput() == "*") &&
if (p.next_token().asInput() == "*") { // The single '=' is meant here.
p.get_token(); (layout_ptr = findLayout(textclass,
name += "*"; t.cs() + '*')).get() &&
} layout_ptr->isCommand()) {
os << "\n\n\\layout " << cap(name) << "\n\n"; p.get_token();
string opt = p.getOpt(); output_layout(os, layout_ptr, p, outer, textclass);
if (opt.size()) { }
begin_inset(os, "OptArg\n");
os << "collapsed true\n\n\\layout Standard\n\n" << opt; // The single '=' is meant here.
end_inset(os); else if ((layout_ptr = findLayout(textclass, t.cs())).get() &&
} layout_ptr->isCommand()) {
parse_text(p, os, FLAG_ITEM, outer, textclass); output_layout(os, layout_ptr, p, outer, textclass);
os << "\n\n\\layout Standard\n\n";
} }
else if (t.cs() == "includegraphics") { else if (t.cs() == "includegraphics") {
@ -600,18 +634,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "\\") else if (t.cs() == "\\")
os << "\n\\newline\n"; 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") else if (t.cs() == "input")
handle_ert(os, "\\input{" + p.verbatim_item() + "}\n"); handle_ert(os, "\\input{" + p.verbatim_item() + "}\n");