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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
Miranda Scripting Plugin for Miranda-IM
Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _XML_DOC_H_
#define _XML_DOC_H_
#include <memory.h>
/*/////////////////////
//CXmlDoc::Structures
/////////////////////*/
#define xmlmin(a,b) (((a) < (b)) ? (a) : (b))
struct sXmlProperty
{
const char* name;
const char* value;
sXmlProperty* next;
public:
sXmlProperty(){
name = value = NULL;
next = NULL;
}
void Free()
{
if(name){
free((void*)name);
}
if(value){
free((void*)value);
}
}
int type(){
return 0;
}
};
struct sXmlBinProperty : public sXmlProperty
{
public:
void Free(){
value = NULL;
sXmlProperty::Free();
}
int type(){return 1;}
};
struct sXmlNode
{
const char* name;
const char* value;
long type;
long num_children;
sXmlProperty* f_prop;
sXmlProperty* l_prop;
sXmlNode* parent;
sXmlNode* f_child;/*first child*/
sXmlNode* l_child;/*last child*/
sXmlNode* next;
public:
sXmlNode(){memset(this,0,sizeof(sXmlNode));}
void Free()
{
sXmlNode* f = this->f_child;
sXmlProperty* p = this->f_prop;
while(f)
{
sXmlNode* tmp = f->next;
f->Free();
free((void*)f);
f = tmp;
}
while(p)
{
sXmlProperty* tmp = p->next;
p->Free();
free((void*)p);
p = tmp;
}
if(this->name)free((void*)this->name);
if(this->value)free((void*)this->value);
memset(this,0,sizeof(sXmlNode));
}
};
class cXmlDoc
{
public:
enum {NODE_NONE = 0,NODE_DOC_TYPE,NODE_SPECIAL,NODE_COMMAND,NODE_ROOT,NODE_PARENT,NODE_DATA,NODE_COMMENT};
const static long PARSE_NOT_REQUIRE_DEF = 0x01;
const static long PARSE_COMMENTS = 0x02;
const static long PARSE_IGNORE_WHITESPACES = 0x04;
const static long PARSE_MULTIPLE_ROOTS = 0x08;
const static long PARSE_SPECIAL = 0x10;
const static long PARSE_COMMANDS = 0x20;
const static long PARSE_IGNORE_BAD_PROPERTIES = 0x40;
public:
cXmlDoc();
~cXmlDoc();
public:
long ParseFile(const char* file,long flags);
long ParseString(char* string, long flags);
long SaveToFile(const char* file);
void Free();
public:
const char* GetProperty(sXmlNode* node,const char* name);
sXmlNode* GetRootNode(){return &m_root;}
sXmlNode* GetNode(const char* path,sXmlNode* parent = NULL);
sXmlNode* AddNewNode(const char* name,const char* value,sXmlNode* parent = NULL);
long SetValue(sXmlNode* node,const char* value);
protected:
long SaveNode(FILE* f,sXmlNode* node);
char* ParseNode(char* start,sXmlNode* parent);
long ParseProperties(char* start,sXmlNode* node);
long JoinParent(sXmlNode* parent,sXmlNode* child);
long AddProperty(sXmlProperty* prop,sXmlNode* node);
long AddBinProperty(sXmlBinProperty* prop,sXmlNode* node);
long AddNewBinProperty(sXmlNode* node,const char* name,void* value);
long SetBinPropertyValue(sXmlNode* node,const char* name,void* value);
void* GetBinPropertyValue(sXmlNode* node,const char* name,long* success);
protected:
sXmlNode m_root;
long m_flags;
long m_parse_flags;
long m_level;
};
#endif //_XML_DOC_H_
|