Category : Files from Magazines
Archive   : PCTV3N2.ZIP
Filename : TVOUTERR.CPP

 
Output of file : TVOUTERR.CPP contained in archive : PCTV3N2.ZIP
#include

#define Uses_otstream
#define Uses_TApplication
#define Uses_TDeskTop
#define Uses_TRect
#define Uses_TTerminal
#define Uses_TWindow
#include

class TOutputWindow : public TWindow
{
TTerminal *_term;

public:

TOutputWindow(TRect bounds, const char *title,
ostream_withassign& ostr, ushort bufsize);

void attach(ostream_withassign& ostr)
{
// Attach TTerminal stream buffer to I/O stream.
ostr = _term;
}
};

class TOutErr : public TApplication
{
ostream_withassign _old_cout;
ostream_withassign _old_cerr;
ostream_withassign _old_clog;

public:

TOutErr(TRect& outbounds, ushort outbufsize, TRect& errbounds,
ushort errbufsize);

~TOutErr();

virtual void run();
};

TOutputWindow::TOutputWindow(TRect bounds, const char *title,
ostream_withassign& ostr, ushort bufsize) :
TWindowInit(&TOutputWindow::initFrame),
TWindow(bounds, title, wnNoNumber)
{
// Terminal view should cover entire window.
bounds = getExtent();
bounds.grow(-1, -1);

// Create terminal view and add to window.
_term = new TTerminal(bounds,
standardScrollBar(sbHorizontal | sbHandleKeyboard),
standardScrollBar(sbVertical | sbHandleKeyboard), bufsize);
insert(_term);

// Create TV output stream.
otstream ot(_term);

ot << "Terminal window \"" << title << "\" created." << endl;

// Copy output stream; normally attach(ostr) would be sufficient.
ostr = ot;
}

TOutErr::TOutErr(TRect& outbounds, ushort outbufsize,
TRect& errbounds, ushort errbufsize) :
TProgInit(&TOutErr::initStatusLine, &TOutErr::initMenuBar,
&TOutErr::initDeskTop)
{
// Save current I/O assignments.
_old_cout = cout;
_old_cerr = cerr;
_old_clog = clog;

TOutputWindow *tow;

// Create standard output window.
tow = new TOutputWindow(outbounds, "Standard Output", cout,
outbufsize);
deskTop->insert(tow);

// Create standard error window and attach to log stream.
tow = new TOutputWindow(errbounds, "Standard Error", cerr,
errbufsize);
tow->attach(clog);
deskTop->insert(tow);
}

TOutErr::~TOutErr()
{
// Restore old I/O assignments.
cout = _old_cout;
cerr = _old_cerr;
clog = _old_clog;
}

void TOutErr::run()
{
cout << "Testing standard output:";
for (int i = 0; i < 10; i++)
cout << ' ' << i;
cout << endl;

cerr << "Testing standard error:";
for (; i < 20; i++)
cerr << ' ' << i;
cerr << endl;

clog << "Testing log:";
for (; i < 30; i++)
clog << ' ' << i;
clog << endl;

TApplication::run();
}

int main()
{
TOutErr outerr(TRect(0, 0, 80, 15), 8192, TRect(0, 15, 80, 23),
2048);
outerr.run();
return (0);
}


  3 Responses to “Category : Files from Magazines
Archive   : PCTV3N2.ZIP
Filename : TVOUTERR.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/