1 #include <assert.h>
2 #include <set>
3 #include "lazyP21DataSectionReader.h"
4 #include "lazyInstMgr.h"
5 
lazyP21DataSectionReader(lazyFileReader * parent,std::ifstream & file,std::streampos start,sectionID sid)6 lazyP21DataSectionReader::lazyP21DataSectionReader( lazyFileReader * parent, std::ifstream & file,
7         std::streampos start, sectionID sid ):
8     lazyDataSectionReader( parent, file, start, sid ) {
9     findSectionStart();
10     namedLazyInstance nl;
11     while( nl = nextInstance(), ( ( nl.loc.begin > 0 ) && ( nl.name != 0 ) ) ) {
12         parent->getInstMgr()->addLazyInstance( nl );
13     }
14 
15     if(  sectionReader::_error->severity() <= SEVERITY_WARNING ) {
16         sectionReader::_error->PrintContents( std::cerr );
17         if(  sectionReader::_error->severity() <= SEVERITY_INPUT_ERROR ) {
18             _error = true;
19             return;
20         }
21     }
22 
23     if( !_file.good() ) {
24         _error = true;
25         return;
26     }
27     if( nl.loc.instance == 0 ) {
28         //check for ENDSEC;
29         skipWS();
30         std::streampos pos = _file.tellg();
31         if( _file.get() == 'E' && _file.get() == 'N' && _file.get() == 'D'
32                 && _file.get() == 'S' && _file.get() == 'E' && _file.get() == 'C'
33                 && ( skipWS(), _file.get() == ';' ) ) {
34             _sectionEnd = _file.tellg();
35         } else {
36             _file.seekg( pos );
37             char found[26] = { '\0' };
38             _file.read( found, 25 );
39             std::cerr << "expected 'ENDSEC;', found " << found << std::endl;
40             _error = true;
41         }
42     }
43 }
44 
45 // part of readdata1
46 //if this changes, probably need to change sectionReader::getType()
nextInstance()47 const namedLazyInstance lazyP21DataSectionReader::nextInstance() {
48     std::streampos end = -1;
49     namedLazyInstance i;
50 
51     i.refs = 0;
52     i.loc.begin = _file.tellg();
53     i.loc.instance = readInstanceNumber();
54     if( ( _file.good() ) && ( i.loc.instance > 0 ) ) {
55         skipWS();
56         i.loc.section = _sectionID;
57         i.name = getDelimitedKeyword( ";( /\\" );
58         if( _file.good() ) {
59             end = seekInstanceEnd( & i.refs );
60         }
61     }
62     if( ( i.loc.instance == 0 ) || ( !_file.good() ) || ( end == ( std::streampos ) - 1 ) ) {
63         //invalid instance, so clear everything
64         _file.seekg( i.loc.begin );
65         i.loc.begin = -1;
66         if( i.refs ) {
67             delete i.refs;
68         }
69         i.name = 0;
70     }
71     return i;
72 }
73 
74