2007-08-14 12:13:55 +00:00
|
|
|
/**
|
|
|
|
* \file TexStream.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2007-08-22 23:53:24 +00:00
|
|
|
*
|
|
|
|
* Inspired by Dietmar Kuehl's prefix iostreams found on
|
|
|
|
* http://www.inf.uni-konstanz.de/~kuehl/
|
2007-08-14 12:13:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2007-08-13 15:36:29 +00:00
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
#include "TexStream.h"
|
|
|
|
#include "TexRow.h"
|
2007-08-12 08:57:17 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <streambuf>
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-12 14:54:54 +00:00
|
|
|
// TexStreamBuffer
|
2007-08-12 08:57:17 +00:00
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
class TexStreamBuffer : public TexStreamBase
|
2007-08-12 08:57:17 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-08-15 06:53:25 +00:00
|
|
|
TexStreamBuffer(TexStreamBase * sbuf, TexRow * texrow);
|
2007-08-12 08:57:17 +00:00
|
|
|
int line() const { return line_; }
|
2007-08-12 14:54:54 +00:00
|
|
|
int column() const { return column_; }
|
2007-08-12 08:57:17 +00:00
|
|
|
|
|
|
|
protected:
|
2007-08-15 06:53:25 +00:00
|
|
|
int overflow(int);
|
|
|
|
int sync();
|
2007-08-12 08:57:17 +00:00
|
|
|
|
|
|
|
private:
|
2007-08-15 06:53:25 +00:00
|
|
|
TexStreamBase * sbuf_;
|
2007-08-12 14:54:54 +00:00
|
|
|
TexRow * texrow_;
|
|
|
|
int column_;
|
2007-08-12 08:57:17 +00:00
|
|
|
int line_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
TexStreamBuffer::TexStreamBuffer(TexStreamBase *sb, TexRow * texrow)
|
|
|
|
: sbuf_(sb), texrow_(texrow), line_(0)
|
2007-08-12 08:57:17 +00:00
|
|
|
{
|
2007-08-15 06:53:25 +00:00
|
|
|
setp(0, 0);
|
|
|
|
setg(0, 0, 0);
|
2007-08-12 08:57:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
int TexStreamBuffer::overflow(int c)
|
2007-08-12 08:57:17 +00:00
|
|
|
{
|
2007-08-12 14:54:54 +00:00
|
|
|
if (c == '\n') {
|
2007-08-12 08:57:17 +00:00
|
|
|
++line_;
|
2007-08-12 14:54:54 +00:00
|
|
|
column_ = 0;
|
|
|
|
} else {
|
|
|
|
++column_;
|
|
|
|
}
|
2007-08-12 08:57:17 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
int TexStreamBuffer::sync()
|
2007-08-12 08:57:17 +00:00
|
|
|
{
|
2007-08-15 06:53:25 +00:00
|
|
|
sbuf_->pubsync();
|
|
|
|
return 0;
|
2007-08-12 08:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-12 14:54:54 +00:00
|
|
|
// TexStream
|
2007-08-12 08:57:17 +00:00
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
TexStream::TexStream(TexStreamBase * sbuf, TexRow * texrow)
|
2007-12-12 20:21:09 +00:00
|
|
|
: std::basic_ostream<char_type>(sbuf_ = new TexStreamBuffer(sbuf, texrow))
|
2007-08-12 08:57:17 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
TexStream::~TexStream()
|
2007-08-12 08:57:17 +00:00
|
|
|
{
|
|
|
|
delete sbuf_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
int TexStream::line() const
|
2007-08-12 08:57:17 +00:00
|
|
|
{
|
|
|
|
return sbuf_->line();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Test
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
TexStream out(cout.rdbuf());
|
2007-08-12 08:57:17 +00:00
|
|
|
char c;
|
2007-12-12 19:28:07 +00:00
|
|
|
while (cin) {
|
|
|
|
if (cin.get(c))
|
2007-08-12 08:57:17 +00:00
|
|
|
out.put(c);
|
|
|
|
}
|
2007-12-12 19:28:07 +00:00
|
|
|
cout << "line count: " << out.line() << endl;
|
2007-08-12 08:57:17 +00:00
|
|
|
|
2007-08-15 06:53:25 +00:00
|
|
|
return 0;
|
2007-08-12 08:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
2007-08-13 15:36:29 +00:00
|
|
|
|