patch sent to the list yesteday

* buffer.[Ch]:
	* lyxtext.h:
	* paragraph_funcs.[Ch]: consolidate parts of Buffer::read() and
	InsetText::read() as LyXText::read()


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8190 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-12-03 15:27:16 +00:00
parent de27b3edef
commit 550785b004
8 changed files with 103 additions and 102 deletions

View File

@ -1,3 +1,11 @@
2003-12-03 André Pönitz <poenitz@gmx.net>
* buffer.[Ch]:
* lyxtext.h:
* paragraph_funcs.[Ch]: consolidate parts of Buffer::read() and
InsetText::read() as LyXText::read()
2003-12-02 Angus Leeming <leeming@lyx.org>
* lyxlex.[Ch] (operator void const *): add the 'const' to the return

View File

@ -390,6 +390,7 @@ void unknownClass(string const & unknown)
} // anon
int Buffer::readHeader(LyXLex & lex)
{
int unknown_tokens = 0;
@ -435,9 +436,8 @@ int Buffer::readHeader(LyXLex & lex)
// if par = 0 normal behavior
// else insert behavior
// Returns false if "\end_document" is not read (Asger)
bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
bool Buffer::readBody(LyXLex & lex)
{
Paragraph::depth_type depth = 0;
bool the_end_read = false;
if (paragraphs().empty()) {
@ -458,70 +458,13 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
tmpbuf.readHeader(lex);
}
while (lex.isOK()) {
lex.nextToken();
string const token = lex.getString();
if (token.empty())
continue;
lyxerr[Debug::PARSER] << "Handling token: `"
<< token << '\'' << endl;
if (token == "\\end_document") {
the_end_read = true;
continue;
}
readParagraph(lex, token, paragraphs(), pit, depth);
}
if (text().read(*this, lex))
the_end_read = true;
return the_end_read;
}
int Buffer::readParagraph(LyXLex & lex, string const & token,
ParagraphList & pars, ParagraphList::iterator & pit,
lyx::depth_type & depth)
{
static Change current_change;
int unknown = 0;
if (token == "\\begin_layout") {
lex.pushToken(token);
Paragraph par;
par.params().depth(depth);
if (params().tracking_changes)
par.trackChanges();
LyXFont f(LyXFont::ALL_INHERIT, params().language);
par.setFont(0, f);
// insert after
if (pit != pars.end())
++pit;
pit = pars.insert(pit, par);
// FIXME: goddamn InsetTabular makes us pass a Buffer
// not BufferParams
::readParagraph(*this, *pit, lex);
} else if (token == "\\begin_deeper") {
++depth;
} else if (token == "\\end_deeper") {
if (!depth) {
lex.printError("\\end_deeper: " "depth is already null");
} else {
--depth;
}
} else {
++unknown;
}
return unknown;
}
// needed to insert the selection
void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
LyXFont const & fn, string const & str)
@ -701,7 +644,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
}
bool the_end = readBody(lex, pit);
bool the_end = readBody(lex);
params().setPaperStuff();
if (!the_end) {
@ -1274,7 +1217,8 @@ void Buffer::getLabelList(std::vector<string> & list) const
// This is also a buffer property (ale)
void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys)
const
{
/// if this is a child document and the parent is already loaded
/// use the parent's list instead [ale990412]

View File

@ -94,13 +94,7 @@ public:
\param par if != 0 insert the file.
\return \c false if file is not completely read.
*/
bool readBody(LyXLex &, ParagraphList::iterator pit);
/// This parses a single token
int readParagraph(LyXLex &, std::string const & token,
ParagraphList & pars,
ParagraphList::iterator & pit,
lyx::depth_type & depth);
bool readBody(LyXLex &);
///
void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,

View File

@ -149,9 +149,6 @@ void InsetText::write(Buffer const & buf, ostream & os) const
void InsetText::read(Buffer const & buf, LyXLex & lex)
{
string token;
Paragraph::depth_type depth = 0;
clear(false);
#warning John, look here. Doesnt make much sense.
@ -161,32 +158,10 @@ void InsetText::read(Buffer const & buf, LyXLex & lex)
// delete the initial paragraph
Paragraph oldpar = *paragraphs().begin();
paragraphs().clear();
ParagraphList::iterator pit = paragraphs().begin();
bool res = text_.read(buf, lex);
init();
while (lex.isOK()) {
lex.nextToken();
token = lex.getString();
if (token.empty())
continue;
if (token == "\\end_inset") {
break;
}
if (token == "\\end_document") {
lex.printError("\\end_document read in inset! Error in document!");
return;
}
// FIXME: ugly.
const_cast<Buffer&>(buf).readParagraph(lex, token, paragraphs(), pit, depth);
}
pit = paragraphs().begin();
ParagraphList::iterator const end = paragraphs().end();
for (; pit != end; ++pit)
pit->setInsetOwner(this);
if (token != "\\end_inset") {
if (!res) {
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
}

View File

@ -393,6 +393,8 @@ public:
///
void write(Buffer const & buf, std::ostream & os) const;
/// returns whether we've seen our usual 'end' marker
bool read(Buffer const & buf, LyXLex & lex);
public:
///

View File

@ -303,7 +303,8 @@ int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
namespace {
int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
int readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
string const & token)
{
static LyXFont font;
static Change change;
@ -499,7 +500,7 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
}
int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
int readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex)
{
int unknown = 0;

View File

@ -64,7 +64,7 @@ int getEndLabel(ParagraphList::iterator pit,
ParagraphList const & plist);
/// read a paragraph from a .lyx file. Returns number of unrecognised tokens
int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex);
int readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex);
LyXFont const outerFont(ParagraphList::iterator pit,
ParagraphList const & plist);

View File

@ -29,6 +29,7 @@
#include "language.h"
#include "LColor.h"
#include "lyxlength.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "lyxrow.h"
#include "lyxrow_funcs.h"
@ -1629,7 +1630,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
// only used for inset right now. should also be used for main text
void LyXText::draw(PainterInfo & pi, int x, int y) const
void LyXText::draw(PainterInfo &, int x, int y) const
{
xo_ = x;
yo_ = y;
@ -1767,3 +1768,79 @@ void LyXText::write(Buffer const & buf, std::ostream & os) const
for (; pit != end; ++pit)
pit->write(buf, os, buf.params(), dth);
}
bool LyXText::read(Buffer const & buf, LyXLex & lex)
{
static Change current_change;
bool the_end_read = false;
ParagraphList::iterator pit = paragraphs().begin();
Paragraph::depth_type depth = 0;
while (lex.isOK()) {
lex.nextToken();
string token = lex.getString();
if (token.empty())
continue;
if (in_inset_) {
if (token == "\\end_inset") {
the_end_read = true;
break;
}
if (token == "\\end_document") {
lex.printError("\\end_document read in inset! Error in document!");
return false;
}
} else {
if (token == "\\end_document") {
the_end_read = true;
continue;
}
}
// FIXME: ugly.
int unknown = 0;
if (token == "\\begin_layout") {
lex.pushToken(token);
Paragraph par;
par.params().depth(depth);
if (buf.params().tracking_changes)
par.trackChanges();
LyXFont f(LyXFont::ALL_INHERIT, buf.params().language);
par.setFont(0, f);
// insert after
if (pit != paragraphs().end())
++pit;
pit = paragraphs().insert(pit, par);
// FIXME: goddamn InsetTabular makes us pass a Buffer
// not BufferParams
::readParagraph(buf, *pit, lex);
} else if (token == "\\begin_deeper") {
++depth;
} else if (token == "\\end_deeper") {
if (!depth) {
lex.printError("\\end_deeper: " "depth is already null");
} else {
--depth;
}
} else {
++unknown;
}
}
return the_end_read;
}