-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.cpp
More file actions
48 lines (37 loc) · 1021 Bytes
/
reader.cpp
File metadata and controls
48 lines (37 loc) · 1021 Bytes
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
#include "kfilter.hpp"
#define BDS_ALLOC_SIZE 1000
TiXmlDocument* get_file()
{
char buff[BUFFSIZE];
char* xml;
int xmlsize = BDS_ALLOC_SIZE;
char* ptr;
xml = (char*) calloc(1, BDS_ALLOC_SIZE);
if (xml == NULL) {
puts("Initial allocation failed.");
exit(EXIT_FAILURE);
}
xml[0] = '\0';
while ((ptr = fgets(buff, BUFFSIZE, stdin)) != NULL) {
if ((strlen(xml) + BUFFSIZE) > xmlsize) {
xmlsize += BDS_ALLOC_SIZE;
xml = (char*) realloc(xml, xmlsize);
if (xml == NULL) {
puts(" Reallocation failed.");
exit(EXIT_FAILURE);
}
}
strcat(xml, buff);
}
if (ferror(stdin) != 0) {
printf("Error reading xml file\n");
exit(EXIT_FAILURE);
}
TiXmlDocument* doc = new TiXmlDocument();
doc->Parse(xml);
if (doc->Error()) {
printf("Error in %s: %s\n", doc->Value(), doc->ErrorDesc());
exit(1);
}
return doc;
}