summaryrefslogtreecommitdiff
path: root/src/xmlfilereader.cpp
blob: 216c08aaefbb6c767d83f4d4959100c911b2fb38 (plain)
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 "xmlfilereader.h"
#include <string.h>

XmlFileReader::XmlFileReader( const char *sFile, bool bStrip )
	: XmlReader( bStrip )
{
	fh = fopen( sFile, "rt" );

	if( fh == NULL )
	{
		reportError("Couldn't open file.");
		//nError = 1;
	}
	else
	{
		char buf[50];
		fgets( buf, 50, fh );

		if( !strcmp( buf, "<?xml version=\"1.0\"?>\n" ) )
		{
			buildDoc();
		}
	}
}

XmlFileReader::~XmlFileReader()
{
}

char XmlFileReader::getChar( int nIndex )
{
	// Make sure we always have a little data left in the buffer
	if( fbDataIn.getLength() <= nIndex+1 && fh )
	{
		int nBytes = fbDataIn.getCapacity()-1;
		char *buf = new char[nBytes];
		int nRead = fread( buf, 1, nBytes, fh );
		fbDataIn.appendData( buf, nRead );
		delete[] buf;

		if( nRead < nBytes )
		{
			fclose( fh );
			fh = NULL;
		}
	}
	if( fbDataIn.getLength() >= nIndex+1 )
	{
		return fbDataIn.getData()[nIndex];
	}
	else
	{
		return '\0';
	}
}

void XmlFileReader::usedChar()
{
	if( fbDataIn.getLength() > 0 )
	{
		fbDataIn.usedData( 1 );
	}
}