1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "INIImporter.h"
23 #include "Interface.h"
33 if (str
&& autoFree
) {
36 for (unsigned int i
= 0; i
< tags
.size(); i
++)
40 bool INIImp::Open(DataStream
* stream
, bool autoFree
)
45 if (str
&& this->autoFree
) {
49 this->autoFree
= autoFree
;
51 char* strbuf
= ( char* ) malloc( 4097 );
52 INITag
* lastTag
= NULL
;
54 cnt
= str
->ReadLine( strbuf
, 4096 );
59 if (strbuf
[0] == ';') //Rem
61 if (strbuf
[0] == '[') {
63 char* sbptr
= strbuf
+ 1;
64 char* TagName
= sbptr
;
65 while (*sbptr
!= '\0') {
72 INITag
* it
= new INITag( TagName
);
79 if (lastTag
->AddLine( strbuf
)) {
80 printMessage("INIImporter","", LIGHT_RED
);
81 printf("Bad Line in file: %s, Section: [%s], Entry: '%s'\n", stream
->filename
, lastTag
->GetTagName(), strbuf
);
89 int INIImp::GetKeysCount(const char* Tag
)
91 for (unsigned int i
= 0; i
< tags
.size(); i
++) {
92 const char* TagName
= tags
[i
]->GetTagName();
93 if (stricmp( TagName
, Tag
) == 0) {
94 return tags
[i
]->GetKeyCount();
100 const char* INIImp::GetKeyNameByIndex(const char* Tag
, int index
)
102 for (unsigned int i
= 0; i
< tags
.size(); i
++) {
103 const char* TagName
= tags
[i
]->GetTagName();
104 if (stricmp( TagName
, Tag
) == 0) {
105 return tags
[i
]->GetKeyNameByIndex(index
);
111 const char* INIImp::GetKeyAsString(const char* Tag
, const char* Key
,
114 for (unsigned int i
= 0; i
< tags
.size(); i
++) {
115 const char* TagName
= tags
[i
]->GetTagName();
116 if (stricmp( TagName
, Tag
) == 0) {
117 return tags
[i
]->GetKeyAsString( Key
, Default
);
123 int INIImp::GetKeyAsInt(const char* Tag
, const char* Key
,
126 for (unsigned int i
= 0; i
< tags
.size(); i
++) {
127 const char* TagName
= tags
[i
]->GetTagName();
128 if (stricmp( TagName
, Tag
) == 0) {
129 return tags
[i
]->GetKeyAsInt( Key
, Default
);
135 float INIImp::GetKeyAsFloat(const char* Tag
, const char* Key
,
138 for (unsigned int i
= 0; i
< tags
.size(); i
++) {
139 const char* TagName
= tags
[i
]->GetTagName();
140 if (stricmp( TagName
, Tag
) == 0) {
141 return tags
[i
]->GetKeyAsFloat( Key
, Default
);
147 bool INIImp::GetKeyAsBool(const char* Tag
, const char* Key
,
150 for (unsigned int i
= 0; i
< tags
.size(); i
++) {
151 const char* TagName
= tags
[i
]->GetTagName();
152 if (stricmp( TagName
, Tag
) == 0) {
153 return tags
[i
]->GetKeyAsBool( Key
, Default
);
159 #include "plugindef.h"
161 GEMRB_PLUGIN(0xB62F6D7, "INI File Importer")
162 PLUGIN_CLASS(IE_INI_CLASS_ID
, INIImp
)