From 31d782b82088ffedd60057fd3061d7258512d81a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sun, 12 Aug 2007 14:54:54 +0000 Subject: [PATCH] shuffle (la)texstream around a bit git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19460 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 3 +++ src/Makefile.am | 6 ++++-- src/TexRow.h | 23 +++++++---------------- src/TexStream.cpp | 40 ++++++++++++++++++++++++---------------- src/TexStream.h | 18 +++++++++++++----- 5 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index bc61f08d8e..c9c3b07e53 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -47,6 +47,7 @@ #include "ParIterator.h" #include "sgml.h" #include "TexRow.h" +#include "TexStream.h" #include "TocBackend.h" #include "Undo.h" #include "version.h" @@ -920,6 +921,8 @@ bool Buffer::makeLaTeXFile(FileName const & fname, if (!openFileWrite(ofs, fname)) return false; + //TexStream ts(ofs.rdbuf(), &texrow()); + bool failed_export = false; try { writeLaTeXSource(ofs, original_path, diff --git a/src/Makefile.am b/src/Makefile.am index a19047db8e..431ebc0e69 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,6 +25,8 @@ LYX_POST_LIBS = frontends/controllers/liblyxcontrollers.la \ OTHERLIBS = $(BOOST_LIBS) $(INTLLIBS) $(AIKSAURUS_LIBS) @LIBS@ $(SOCKET_LIBS) +AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES) + pkglib_LTLIBRARIES = liblyxcore.la noinst_PROGRAMS = $(FRONTENDS_PROGS) EXTRA_PROGRAMS = lyx-qt4 @@ -224,6 +226,8 @@ liblyxcore_la_SOURCES = \ SpellBase.h \ TexRow.cpp \ TexRow.h \ + TexStream.cpp \ + TexStream.h \ Text.h \ Text.cpp \ Text2.cpp \ @@ -457,8 +461,6 @@ EXTRA_DIST += \ insets/InsetTheorem.cpp \ insets/InsetTheorem.h -AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES) - liblyxinsets_la_SOURCES = \ insets/MailInset.cpp \ insets/MailInset.h \ diff --git a/src/TexRow.h b/src/TexRow.h index 24a61c0730..0dea3d158d 100644 --- a/src/TexRow.h +++ b/src/TexRow.h @@ -20,7 +20,9 @@ namespace lyx { -/// Represents the correspondence between paragraphs and the generated LaTeX file +/// Represents the correspondence between paragraphs and the generated +//LaTeX file + class TexRow { public: /// @@ -60,24 +62,13 @@ public: {} /// paragraph id - int id() const { - return id_; - } - + int id() const { return id_; } /// set paragraph position - void pos(int p) { - pos_ = p; - } - + void pos(int p) { pos_ = p; } /// paragraph position - int pos() const { - return pos_; - } - + int pos() const { return pos_; } /// row number - int rownumber() const { - return rownumber_; - } + int rownumber() const { return rownumber_; } private: RowItem(); int id_; diff --git a/src/TexStream.cpp b/src/TexStream.cpp index b3d9f50362..557833dabe 100644 --- a/src/TexStream.cpp +++ b/src/TexStream.cpp @@ -1,4 +1,5 @@ -#include "LaTeXStream.h" +#include "TexStream.h" +#include "TexRow.h" #include #include @@ -7,43 +8,50 @@ namespace lyx { //////////////////////////////////////////////////////////////// // -// LaTeXStreamBuffer +// TexStreamBuffer // //////////////////////////////////////////////////////////////// -class LaTeXStreamBuffer : public std::streambuf +class TexStreamBuffer : public TexStreamBase { public: - explicit LaTeXStreamBuffer(std::streambuf * sbuf); + TexStreamBuffer(TexStreamBase * sbuf, TexRow * texrow); int line() const { return line_; } + int column() const { return column_; } protected: int overflow(int); int sync(); private: - std::streambuf * sbuf_; + TexStreamBase * sbuf_; + TexRow * texrow_; + int column_; int line_; }; -LaTeXStreamBuffer::LaTeXStreamBuffer(std::streambuf *sb) - : sbuf_(sb), line_(0) +TexStreamBuffer::TexStreamBuffer(TexStreamBase *sb, TexRow * texrow) + : sbuf_(sb), texrow_(texrow), line_(0) { setp(0, 0); setg(0, 0, 0); } -int LaTeXStreamBuffer::overflow(int c) +int TexStreamBuffer::overflow(int c) { - if (c == '\n') + if (c == '\n') { ++line_; + column_ = 0; + } else { + ++column_; + } return c; } -int LaTeXStreamBuffer::sync() +int TexStreamBuffer::sync() { sbuf_->pubsync(); return 0; @@ -52,22 +60,22 @@ int LaTeXStreamBuffer::sync() //////////////////////////////////////////////////////////////// // -// LaTeXStream +// TexStream // //////////////////////////////////////////////////////////////// -LaTeXStream::LaTeXStream(std::streambuf * sbuf) - : std::ostream(sbuf_ = new LaTeXStreamBuffer(sbuf)) +TexStream::TexStream(TexStreamBase * sbuf, TexRow * texrow) + : std::basic_ostream(sbuf_ = new TexStreamBuffer(sbuf, texrow)) {} -LaTeXStream::~LaTeXStream() +TexStream::~TexStream() { delete sbuf_; } -int LaTeXStream::line() const +int TexStream::line() const { return sbuf_->line(); } @@ -83,7 +91,7 @@ int LaTeXStream::line() const int main(int argc, char *argv[]) { - LaTeXStream out(std::cout.rdbuf()); + TexStream out(std::cout.rdbuf()); char c; while (std::cin) { if (std::cin.get(c)) diff --git a/src/TexStream.h b/src/TexStream.h index bdd32fc877..9ae20222a6 100644 --- a/src/TexStream.h +++ b/src/TexStream.h @@ -1,21 +1,29 @@ #ifndef LATEXSTREAM_H #define LATEXSTREAM_H +#include "support/docstring.h" + +#include "TexRow.h" + #include #include namespace lyx { -class LaTeXStreamBuffer; +class TexStreamBuffer; +class TexRow; -class LaTeXStream : public std::ostream +typedef std::basic_streambuf TexStreamBase; + +class TexStream : public std::basic_ostream { public: - LaTeXStream(std::streambuf * sbuf); - ~LaTeXStream(); + TexStream(TexStreamBase * sbuf, TexRow * texrow); + ~TexStream(); int line() const; + private: - LaTeXStreamBuffer * sbuf_; + TexStreamBuffer * sbuf_; }; } // namespace lyx -- 2.39.2