aboutsummaryrefslogtreecommitdiff
path: root/src/xmlfilereader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlfilereader.cpp')
-rw-r--r--src/xmlfilereader.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/xmlfilereader.cpp b/src/xmlfilereader.cpp
new file mode 100644
index 0000000..216c08a
--- /dev/null
+++ b/src/xmlfilereader.cpp
@@ -0,0 +1,63 @@
1#include "xmlfilereader.h"
2#include <string.h>
3
4XmlFileReader::XmlFileReader( const char *sFile, bool bStrip )
5 : XmlReader( bStrip )
6{
7 fh = fopen( sFile, "rt" );
8
9 if( fh == NULL )
10 {
11 reportError("Couldn't open file.");
12 //nError = 1;
13 }
14 else
15 {
16 char buf[50];
17 fgets( buf, 50, fh );
18
19 if( !strcmp( buf, "<?xml version=\"1.0\"?>\n" ) )
20 {
21 buildDoc();
22 }
23 }
24}
25
26XmlFileReader::~XmlFileReader()
27{
28}
29
30char XmlFileReader::getChar( int nIndex )
31{
32 // Make sure we always have a little data left in the buffer
33 if( fbDataIn.getLength() <= nIndex+1 && fh )
34 {
35 int nBytes = fbDataIn.getCapacity()-1;
36 char *buf = new char[nBytes];
37 int nRead = fread( buf, 1, nBytes, fh );
38 fbDataIn.appendData( buf, nRead );
39 delete[] buf;
40
41 if( nRead < nBytes )
42 {
43 fclose( fh );
44 fh = NULL;
45 }
46 }
47 if( fbDataIn.getLength() >= nIndex+1 )
48 {
49 return fbDataIn.getData()[nIndex];
50 }
51 else
52 {
53 return '\0';
54 }
55}
56
57void XmlFileReader::usedChar()
58{
59 if( fbDataIn.getLength() > 0 )
60 {
61 fbDataIn.usedData( 1 );
62 }
63}