1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include "scanner.ih"
// SEE ALSO THE MEMBER waitForSentinel()
void Scanner::read(std::istream &src, string const &fname)
{
ofstream target(fname.c_str());
if (!target)
d_reporter.exit() << "Can't open `" << fname << "' to write" << endl;
Util::debug() << "Scanner::read(): about to read child input" << endl;
char c;
string partialSentinel;
size_t length = 0;
while (true)
{
src.read(&c, 1); // read char by char
if (c == d_sentinel[length]) // got next sentinel char
{
length++;
if (length == d_sentinel.length()) // matched the sentinel
{
Util::debug() << "GOT Sentinel" << endl;
string tail; // get the end-chars as well
getline(src, tail);
partialSentinel += tail;
break; // so we're done.
}
partialSentinel += c; // append c to the partial Sentinel
}
else
{
if (length)
{
target.write(partialSentinel.c_str(), length);
partialSentinel.erase();
length = 0;
}
target.write(&c, 1);
}
}
testExitValue(partialSentinel);
}
|