Skip to content

Commit bac11c8

Browse files
author
kanru
committed
Import tinyxml, drop scew and expat.
1 parent 3c7112b commit bac11c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+5331
-3756
lines changed

Experiments/Win32/Makefile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ LINK32_OBJS = \
1313
$(OUTDIR)\Utils.obj \
1414
$(OUTDIR)\OVStringToolKit.obj \
1515
$(OUTDIR)\OVDummyLoader.obj \
16-
$(OUTDIR)\DOVDictionary.obj
16+
$(OUTDIR)\DOVDictionary.obj \
17+
$(OUTDIR)\tinyxml.obj \
18+
$(OUTDIR)\tinyxmlerror.obj \
19+
$(OUTDIR)\tinyxmlparser.obj
1720

1821
$(OUTDIR):
1922
if not exist "$(OUTDIR)/$(NULL)" mkdir $(OUTDIR)
2023

21-
LINK_LIBS = kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib OVIME\IMM32.LIB OVIME\OVIMEUI.lib OVDummyLoader\libltdl.lib OVDummyLoader\libiconv.lib OVDummyLoader\expat\libexpat.lib scew.lib
24+
LINK_LIBS = kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib OVIME\IMM32.LIB OVIME\OVIMEUI.lib OVDummyLoader\libltdl.lib OVDummyLoader\libiconv.lib
2225

2326
dllllflags = /INCREMENTAL:NO /NOLOGO /DLL /PDB:$(OUTDIR)/vc70.pdb /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /MACHINE:IX86
2427

2528
$(OUTDIR)\$(Proj).dll: $(OUTDIR) $(LINK32_OBJS) $(OUTDIR)\$(Proj).res
2629
link $(dllllflags) \
27-
/NODEFAULTLIB:scew_.lib \
28-
/LIBPATH:OVDummyLoader\scew \
2930
$(LINK32_OBJS) $(OUTDIR)\$(Proj).res $(LINK_LIBS) \
3031
-out:$(OUTDIR)\$(Proj).ime\
3132
-def:OVIME\$(Proj).def
@@ -53,7 +54,7 @@ FILE=Utils
5354
$(OUTDIR)\$(FILE).obj: OVIME\$(FILE).cpp $(OUTDIR)
5455
$(CXX) $(cflags) /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" OVIME\$(FILE).cpp
5556

56-
cflags = /O2 /Ob1 /Oy /I "OVIME" /I "OVIMEUI\Headers" /I "../../Headers" /I "OVDummyLoader/expat" /I "OVDummyLoader/scew" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "OVIME_EXPORTS" /D "_WINDLL" /GF /EHsc /MT /GS /Gy /W3 /c /Wp64 /Zi /TP /GR
57+
cflags = /O2 /Ob1 /Oy /I "OVIME" /I "OVIMEUI\Headers" /I "../../Headers" /I "OVDummyLoader/expat" /I "OVDummyLoader/tinyxml" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "OVIME_EXPORTS" /D "_WINDLL" /GF /EHsc /MT /GS /Gy /W3 /c /Wp64 /Zi /TP /GR
5758
FILE=OVStringToolKit
5859
$(OUTDIR)\$(FILE).obj: ..\..\Source\$(FILE).cpp $(OUTDIR)
5960
$(CXX) $(cflags) /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" ..\..\Source\$(FILE).cpp
@@ -63,6 +64,16 @@ $(OUTDIR)\$(FILE).obj: OVDummyLoader\$(FILE).cpp $(OUTDIR)
6364
FILE=DOVDictionary
6465
$(OUTDIR)\$(FILE).obj: OVDummyLoader\$(FILE).cpp $(OUTDIR)
6566
$(CXX) $(cflags) /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" OVDummyLoader\$(FILE).cpp
67+
FILE=tinyxml
68+
$(OUTDIR)\$(FILE).obj: OVDummyLoader\tinyxml\$(FILE).cpp $(OUTDIR)
69+
$(CXX) $(cflags) /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" OVDummyLoader\tinyxml\$(FILE).cpp
70+
FILE=tinyxmlerror
71+
$(OUTDIR)\$(FILE).obj: OVDummyLoader\tinyxml\$(FILE).cpp $(OUTDIR)
72+
$(CXX) $(cflags) /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" OVDummyLoader\tinyxml\$(FILE).cpp
73+
FILE=tinyxmlparser
74+
$(OUTDIR)\$(FILE).obj: OVDummyLoader\tinyxml\$(FILE).cpp $(OUTDIR)
75+
$(CXX) $(cflags) /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" OVDummyLoader\tinyxml\$(FILE).cpp
76+
6677

6778
FILE=OVIME
6879
$(OUTDIR)\$(FILE).res: OVIME\$(FILE).rc $(OUTDIR)

Experiments/Win32/OVDummyLoader/DOVDictionary.cpp

Lines changed: 44 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,52 @@ DummyDictionary::DummyDictionary(const char *f, const char *dict)
66
{
77
file = f;
88
file += "config.xml";
9-
parser = scew_parser_create();
10-
scew_parser_ignore_whitespaces(parser, 1);
11-
if(!scew_parser_load_file(parser, file.c_str())) {
12-
createNewConfig(file.c_str());
13-
scew_parser_load_file(parser, file.c_str());
9+
if(!doc.LoadFile(file)) {
10+
createNewConfig(file);
11+
doc.LoadFile();
1412
}
15-
tree = scew_parser_tree(parser);
16-
root = scew_tree_root(tree);
17-
scew_element* i = scew_element_next(root, NULL);
18-
while(i) {
19-
if(!strcmp(scew_element_name(i), "dict")) {
20-
scew_attribute* at = scew_attribute_by_name(i, "name");
21-
if(at && !strcmp(scew_attribute_value(at), dict))
22-
break;
23-
}
24-
i = scew_element_next(root, i);
25-
}
26-
module = i;
13+
14+
module = findChild(doc.RootElement(), "dict", dict);
2715
name = dict;
2816
}
2917

30-
bool DummyDictionary::createNewConfig(const char *f)
18+
bool DummyDictionary::createNewConfig(std::string file)
3119
{
32-
scew_tree *t = NULL;
33-
scew_element *r = NULL;
34-
t = scew_tree_create();
35-
r = scew_tree_add_root(t, "OpenVanilla");
36-
scew_writer_tree_file(t, f);
37-
scew_tree_free(t);
20+
TiXmlDocument tmp(file);
21+
tmp.Parse("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><OpenVanilla></OpenVanilla>");
22+
tmp.SaveFile();
3823
return true;
3924
}
4025

4126
void DummyDictionary::newDict()
4227
{
43-
module = scew_element_add(root, "dict");
44-
scew_element_add_attr_pair(module, "name", name.c_str());
45-
scew_writer_tree_file(tree, file.c_str());
28+
TiXmlElement tmp("dict");
29+
tmp.SetAttribute("name", name.c_str());
30+
module = doc.RootElement()->InsertEndChild(tmp);
31+
doc.SaveFile();
32+
}
33+
34+
TiXmlNode *DummyDictionary::findChild(TiXmlNode *parent, const char *node, const char *name)
35+
{
36+
TiXmlNode *child = 0;
37+
while( child = parent->ToElement()->IterateChildren( child ) ) {
38+
if(!strcmp(child->Value(), node))
39+
if(!strcmp(child->ToElement()->Attribute("name"), name))
40+
break;
41+
}
42+
return child;
4643
}
4744

4845
DummyDictionary::~DummyDictionary()
4946
{
50-
scew_parser_free(parser);
5147
}
5248

5349
int DummyDictionary::keyExist(const char *key)
5450
{
55-
unsigned int count;
56-
int retval = 0;
57-
if(!module) return retval;
58-
scew_element** list = scew_element_list(module, "key", &count);
59-
for(int i = 0; i < count; i++) {
60-
scew_attribute* at = scew_attribute_by_name(list[i], "name");
61-
if(at && !strcmp(scew_attribute_value(at), key)) {
62-
retval = 1;
63-
break;
64-
}
65-
}
66-
scew_element_list_free(list);
67-
return retval;
51+
if(module && findChild(module, "key", key))
52+
return 1;
53+
else
54+
return 0;
6855
}
6956

7057
int DummyDictionary::getInteger(const char *key)
@@ -82,61 +69,43 @@ int DummyDictionary::setInteger(const char *key, int value)
8269

8370
const char* DummyDictionary::getString(const char *key)
8471
{
85-
int i;
86-
unsigned int count;
8772
if(!module) return "";
88-
scew_element** list = scew_element_list(module, "key", &count);
89-
for(i = 0; i < count; i++) {
90-
scew_attribute* at = scew_attribute_by_name(list[i], "name");
91-
if(at && !strcmp(scew_attribute_value(at), key))
92-
break;
93-
}
94-
if(i == count) {
95-
scew_element_list_free(list);
96-
return "";
97-
}
98-
scew_attribute* at = scew_attribute_by_name(list[i], "value");
99-
const XML_Char *value = at ? scew_attribute_value(at) : NULL;
100-
scew_element_list_free(list);
101-
if(value)
102-
return value;
73+
TiXmlNode *child = findChild(module, "key", key);
74+
if(child)
75+
return child->ToElement()->Attribute("value");
10376
else
10477
return "";
10578
}
10679

10780
const char* DummyDictionary::setString(const char *key, const char *value)
10881
{
109-
int i;
110-
unsigned int count;
111-
scew_element *cur;
11282
if(!module)
11383
newDict();
114-
scew_element** list = scew_element_list(module, "key", &count);
115-
for(i = 0; i < count; i++) {
116-
scew_attribute* at = scew_attribute_by_name(list[i], "name");
117-
if(at && !strcmp(scew_attribute_value(at), key))
118-
break;
84+
TiXmlNode *child;
85+
child = findChild(module, "key", key);
86+
if(!child) {
87+
TiXmlElement tmp("key");
88+
tmp.SetAttribute("name", key);
89+
child = module->ToElement()->InsertEndChild(tmp);
11990
}
120-
if(i == count)
121-
cur = scew_element_add(module, "key");
122-
else
123-
cur = list[i];
124-
scew_element_add_attr_pair(cur, "name", key);
125-
scew_element_add_attr_pair(cur, "value", value);
126-
scew_writer_tree_file(tree, file.c_str());
127-
scew_element_list_free(list);
91+
child->ToElement()->SetAttribute("value", value);
92+
doc.SaveFile();
12893
return value;
12994
}
13095

13196
/*
13297
int main()
13398
{
134-
DummyDictionary d("F:\\windows\\openvanilla\\", "Orz");
99+
DummyDictionary d(".\\", "Orz");
100+
if(d.keyExist("ccc"))
101+
std::cout << "Ya!" << d.getString("ccc") << std::endl;
135102
d.setInteger("ccc", 456);
103+
d.setString("bbb", "hahaha");
136104
if(d.keyExist("ccc"))
137105
{
138106
printf("orz/aaa: %d\n", d.getInteger("aaa"));
139107
printf("orz/aaa: %s\n", d.getString("ccc"));
108+
printf("orz/bbb: %s\n", d.getString("bbb"));
140109
}
141110
return 0;
142111
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include <string>
22
#include "OpenVanilla.h"
3-
extern "C" {
4-
#include "scew/scew.h"
5-
}
3+
#include "tinyxml.h"
64

75
class DummyDictionary : public OVDictionary {
86
public:
@@ -13,13 +11,12 @@ class DummyDictionary : public OVDictionary {
1311
virtual int setInteger(const char *key, int value);
1412
virtual const char* getString(const char *key);
1513
virtual const char* setString(const char *key, const char *value);
16-
bool createNewConfig(const char *path);
14+
bool createNewConfig(std::string path);
1715
private:
1816
std::string name;
1917
std::string file;
2018
void newDict();
21-
scew_parser* parser;
22-
scew_tree* tree;
23-
scew_element* root;
24-
scew_element* module;
19+
TiXmlNode *findChild(TiXmlNode *parent, const char *node, const char *name);
20+
TiXmlDocument doc;
21+
TiXmlNode *module;
2522
};

Experiments/Win32/OVDummyLoader/expat/ascii.h

Lines changed: 0 additions & 85 deletions
This file was deleted.

Experiments/Win32/OVDummyLoader/expat/asciitab.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)