3 * PROJECT: System regression tool for ReactOS
4 * LICENSE: GPL - See COPYING in the top level directory
5 * FILE: tools/sysreg/conf_parser.h
6 * PURPOSE: file reading support
7 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
10 #include "file_reader.h"
14 //---------------------------------------------------------------------------------------
15 FileReader::FileReader() : DataSource(), m_File(NULL
)
18 //---------------------------------------------------------------------------------------
19 FileReader::~FileReader()
22 //---------------------------------------------------------------------------------------
23 bool FileReader::openSource(const string
& filename
)
25 m_File
= fopen((char*)filename
.c_str(), (char*)"rb");
36 //---------------------------------------------------------------------------------------
37 bool FileReader::closeSource()
52 //---------------------------------------------------------------------------------------
53 bool FileReader::readSource(vector
<string
> & lines
)
61 size_t total_length
= 0;
62 size_t line_count
= lines
.size();
67 if (m_BufferedLines
.length())
69 strcpy(szBuffer
, m_BufferedLines
.c_str());
70 readoffset
= m_BufferedLines
.length();
75 if (total_length
< num
)
77 memmove(szBuffer
, &szBuffer
[total_length
], num
- total_length
);
78 readoffset
= num
- total_length
;
81 num
= fread(&szBuffer
[readoffset
],
82 sizeof(char), sizeof(szBuffer
)/sizeof(char) - (readoffset
+1) * sizeof(char),
85 szBuffer
[num
] = L
'\0';
89 if (line_count
== lines
.size ())
96 char * offset
= szBuffer
;
99 while((ptr
= strstr(offset
, "\x0D\x0A")) != NULL
)
101 long length
= ((long )ptr
- (long)offset
);
102 length
/= sizeof(char);
104 offset
[length
] = '\0';
106 string line
= offset
;
107 lines
.push_back (line
);
109 offset
+= length
+ 2;
110 total_length
+= length
+ 2;
112 if (total_length
== num
)
119 if (total_length
< num
)
121 m_BufferedLines
= &szBuffer
[total_length
];
127 } // end of namespace System_