-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml.cpp
More file actions
138 lines (130 loc) · 3.79 KB
/
xml.cpp
File metadata and controls
138 lines (130 loc) · 3.79 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "xml.h"
xml::xml(wxString filepath, wxString codepath, int lang_sel) {
std::string path = std::string(filepath.mb_str());
std::ifstream file(path, std::ios::in);
std::string line;
int flag; // whether inside opening tag, data or closing tag
int flagout = -1; // whether inside the <node> tag or outside
node* x = nullptr;
int r = -1, d = -1, l = -1; // whether right tag, down tag or/and loop tag present
// Read the xml file line by line
while (!file.eof()) {
getline(file, line);
std::string line1 = "";
// Fix errors arising due to /r and /n
for(int i = 0; line[i] != '\0'; i++){
if(line[i] != '\r' && line[i] != '\n'){
line1 += line[i];
}
}
line = line1;
if (line == "<node>") {
flagout = 0;
x = new node;
continue;
}
else if (line == "</node>") {
flagout = -1;
if (start1 == NULL) {
start1 = x;
}
else {
if (d != -1) {
node* temp = traverse1(start1, d);
temp->down = x;
}
if (r != -1) {
node* temp = traverse1(start1, r);
temp->right = x;
}
if (l != -1) {
node* temp = traverse1(start1, l);
x->loop = temp;
}
d = -1, r = -1, l = -1;
}
x = NULL;
continue;
}
if (flagout == -1) {
continue;
}
flag = -1;
std::string tag = "";
std::string text = "";
for (int i = 0; line[i] != '\0'; i++) {
if (line[i] == '<') {
if (flag == -1) {
flag = 0;
}
else if (flag == 1) {
if (line[i + 1] == '/') {
flag = 2;
}
else {
text += line[i];
}
}
continue;
}
if (line[i] == '>' && flag == 0) {
flag = 1;
continue;
}
if (flag == 0) {
tag += line[i];
}
else if (flag == 1) {
text += line[i];
}
}
if (tag == "type") {
if (text == "connector") {
x->type = 3;
}
else if (text == "process") {
x->type = 4;
}
else if (text == "decision") {
x->type = 5;
}
else if (text == "data") {
x->type = 6;
}
else if (text == "terminator") {
x->type = 7;
}
}
else if (tag == "id") {
x->id = stoi(text);
}
else if (tag == "text") {
x->text = text;
}
else if (tag == "right") {
r = stoi(text);
}
else if (tag == "down") {
d = stoi(text);
}
else if (tag == "loop") {
l = stoi(text);
}
}
file.close();
generate = new CodeGenerate(codepath, start1, lang_sel);
}
// Function to traverse the data structure created
struct node* xml::traverse1(struct node* temp, int id1) {
if (temp->id == id1) {
return temp;
}
node* x = NULL;
if (temp->right != NULL) {
x = traverse1(temp->right, id1);
}
if (temp->down != NULL && x == NULL) {
x = traverse1(temp->down, id1);
}
return x;
}