File: read.cc

package info (click to toggle)
stealth 1.47.4-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 780 kB
  • ctags: 190
  • sloc: cpp: 1,710; makefile: 155; sh: 62
file content (63 lines) | stat: -rw-r--r-- 1,697 bytes parent folder | download | duplicates (2)
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
53
54
55
56
57
58
59
60
61
62
63
#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;
    off_t size = 0;

    while (true)
    {
        if (!src.read(&c, 1))               // read char by char
        {
            d_quit = true;
            d_reporter.exit() << "Incomplete read from `" << fname << "'" <<
                                                                        endl;
            return;
        }

        if (!checkSize(fname, ++size))
            return;

        if (c == d_sentinel[length])       // got next sentinel char
        {
            length++;
                                            // matched the sentinel
            if (length == d_sentinel.length())
            {
                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);
}