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>
* text.C (parse_text): fix handling of \LaTeXe macro

View File

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

View 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() {}

View 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() == "*") {
// 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();
name += "*";
output_layout(os, layout_ptr, p, outer, textclass);
}
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";
// 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");