shuffle (la)texstream around a bit

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19460 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-08-12 14:54:54 +00:00
parent 2515a3bded
commit 31d782b820
5 changed files with 51 additions and 39 deletions

View File

@ -47,6 +47,7 @@
#include "ParIterator.h" #include "ParIterator.h"
#include "sgml.h" #include "sgml.h"
#include "TexRow.h" #include "TexRow.h"
#include "TexStream.h"
#include "TocBackend.h" #include "TocBackend.h"
#include "Undo.h" #include "Undo.h"
#include "version.h" #include "version.h"
@ -920,6 +921,8 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
if (!openFileWrite(ofs, fname)) if (!openFileWrite(ofs, fname))
return false; return false;
//TexStream ts(ofs.rdbuf(), &texrow());
bool failed_export = false; bool failed_export = false;
try { try {
writeLaTeXSource(ofs, original_path, writeLaTeXSource(ofs, original_path,

View File

@ -25,6 +25,8 @@ LYX_POST_LIBS = frontends/controllers/liblyxcontrollers.la \
OTHERLIBS = $(BOOST_LIBS) $(INTLLIBS) $(AIKSAURUS_LIBS) @LIBS@ $(SOCKET_LIBS) OTHERLIBS = $(BOOST_LIBS) $(INTLLIBS) $(AIKSAURUS_LIBS) @LIBS@ $(SOCKET_LIBS)
AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
pkglib_LTLIBRARIES = liblyxcore.la pkglib_LTLIBRARIES = liblyxcore.la
noinst_PROGRAMS = $(FRONTENDS_PROGS) noinst_PROGRAMS = $(FRONTENDS_PROGS)
EXTRA_PROGRAMS = lyx-qt4 EXTRA_PROGRAMS = lyx-qt4
@ -224,6 +226,8 @@ liblyxcore_la_SOURCES = \
SpellBase.h \ SpellBase.h \
TexRow.cpp \ TexRow.cpp \
TexRow.h \ TexRow.h \
TexStream.cpp \
TexStream.h \
Text.h \ Text.h \
Text.cpp \ Text.cpp \
Text2.cpp \ Text2.cpp \
@ -457,8 +461,6 @@ EXTRA_DIST += \
insets/InsetTheorem.cpp \ insets/InsetTheorem.cpp \
insets/InsetTheorem.h insets/InsetTheorem.h
AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
liblyxinsets_la_SOURCES = \ liblyxinsets_la_SOURCES = \
insets/MailInset.cpp \ insets/MailInset.cpp \
insets/MailInset.h \ insets/MailInset.h \

View File

@ -20,7 +20,9 @@
namespace lyx { namespace lyx {
/// Represents the correspondence between paragraphs and the generated LaTeX file /// Represents the correspondence between paragraphs and the generated
//LaTeX file
class TexRow { class TexRow {
public: public:
/// ///
@ -60,24 +62,13 @@ public:
{} {}
/// paragraph id /// paragraph id
int id() const { int id() const { return id_; }
return id_;
}
/// set paragraph position /// set paragraph position
void pos(int p) { void pos(int p) { pos_ = p; }
pos_ = p;
}
/// paragraph position /// paragraph position
int pos() const { int pos() const { return pos_; }
return pos_;
}
/// row number /// row number
int rownumber() const { int rownumber() const { return rownumber_; }
return rownumber_;
}
private: private:
RowItem(); RowItem();
int id_; int id_;

View File

@ -1,4 +1,5 @@
#include "LaTeXStream.h" #include "TexStream.h"
#include "TexRow.h"
#include <iostream> #include <iostream>
#include <streambuf> #include <streambuf>
@ -7,43 +8,50 @@ namespace lyx {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// //
// LaTeXStreamBuffer // TexStreamBuffer
// //
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
class LaTeXStreamBuffer : public std::streambuf class TexStreamBuffer : public TexStreamBase
{ {
public: public:
explicit LaTeXStreamBuffer(std::streambuf * sbuf); TexStreamBuffer(TexStreamBase * sbuf, TexRow * texrow);
int line() const { return line_; } int line() const { return line_; }
int column() const { return column_; }
protected: protected:
int overflow(int); int overflow(int);
int sync(); int sync();
private: private:
std::streambuf * sbuf_; TexStreamBase * sbuf_;
TexRow * texrow_;
int column_;
int line_; int line_;
}; };
LaTeXStreamBuffer::LaTeXStreamBuffer(std::streambuf *sb) TexStreamBuffer::TexStreamBuffer(TexStreamBase *sb, TexRow * texrow)
: sbuf_(sb), line_(0) : sbuf_(sb), texrow_(texrow), line_(0)
{ {
setp(0, 0); setp(0, 0);
setg(0, 0, 0); setg(0, 0, 0);
} }
int LaTeXStreamBuffer::overflow(int c) int TexStreamBuffer::overflow(int c)
{ {
if (c == '\n') if (c == '\n') {
++line_; ++line_;
column_ = 0;
} else {
++column_;
}
return c; return c;
} }
int LaTeXStreamBuffer::sync() int TexStreamBuffer::sync()
{ {
sbuf_->pubsync(); sbuf_->pubsync();
return 0; return 0;
@ -52,22 +60,22 @@ int LaTeXStreamBuffer::sync()
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// //
// LaTeXStream // TexStream
// //
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
LaTeXStream::LaTeXStream(std::streambuf * sbuf) TexStream::TexStream(TexStreamBase * sbuf, TexRow * texrow)
: std::ostream(sbuf_ = new LaTeXStreamBuffer(sbuf)) : std::basic_ostream<char_type>(sbuf_ = new TexStreamBuffer(sbuf, texrow))
{} {}
LaTeXStream::~LaTeXStream() TexStream::~TexStream()
{ {
delete sbuf_; delete sbuf_;
} }
int LaTeXStream::line() const int TexStream::line() const
{ {
return sbuf_->line(); return sbuf_->line();
} }
@ -83,7 +91,7 @@ int LaTeXStream::line() const
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
LaTeXStream out(std::cout.rdbuf()); TexStream out(std::cout.rdbuf());
char c; char c;
while (std::cin) { while (std::cin) {
if (std::cin.get(c)) if (std::cin.get(c))

View File

@ -1,21 +1,29 @@
#ifndef LATEXSTREAM_H #ifndef LATEXSTREAM_H
#define LATEXSTREAM_H #define LATEXSTREAM_H
#include "support/docstring.h"
#include "TexRow.h"
#include <iostream> #include <iostream>
#include <streambuf> #include <streambuf>
namespace lyx { namespace lyx {
class LaTeXStreamBuffer; class TexStreamBuffer;
class TexRow;
class LaTeXStream : public std::ostream typedef std::basic_streambuf<char_type> TexStreamBase;
class TexStream : public std::basic_ostream<char_type>
{ {
public: public:
LaTeXStream(std::streambuf * sbuf); TexStream(TexStreamBase * sbuf, TexRow * texrow);
~LaTeXStream(); ~TexStream();
int line() const; int line() const;
private: private:
LaTeXStreamBuffer * sbuf_; TexStreamBuffer * sbuf_;
}; };
} // namespace lyx } // namespace lyx