19 #include "../../helper/string.h" 28 int level = -1, buffer1used, buffer2used;
29 size_t bufferused, i, read_buffer_used=1000,read_buffer_pos=1000, num;
30 unsigned char ch[3], *buffer = NULL;
31 unsigned char *buffer2 = NULL, *buffer1 = NULL, read_buffer[1001];
32 INI_Section *INI_info = NULL, *INI_head = NULL, *heading;
38 if (FileName == NULL) {
42 f = fopen(FileName,
"rb");
52 if (read_buffer_used == read_buffer_pos) {
53 read_buffer_used = fread(read_buffer,1,1000,f);
55 if (read_buffer_used == 0) {
62 if (read_buffer_used == read_buffer_pos) {
65 ch[0] = read_buffer[read_buffer_pos++];
69 if (read_buffer_used == read_buffer_pos) {
72 ch[1] = read_buffer[read_buffer_pos++];
76 if (ch[0] == 0xFF && ch[1] == 0xFE) FFEEUnicode =
TRUE;
81 ch[2] = ch[0]; ch[0] = ch[1]; ch[1] = ch[2];
84 if (read_buffer_used == read_buffer_pos) {
88 ch[1] = read_buffer[read_buffer_pos++];
89 if (level == -1) level = 0;
91 if ((ch[0] == 0 && ch[1] == 13) ||
92 (ch[0] == 0 && ch[1] == 10)) {
95 buffer = (
unsigned char *)realloc(buffer,bufferused+2);
100 buffer[bufferused] = ch[0];
101 buffer[bufferused+1] = ch[1];
102 bufferused = bufferused + 2;
107 if (level == 1) level = 0;
108 if (level == 3 || level == 4 || level == 5) level = 2;
111 for (i=0;i<bufferused/2;i++) {
113 ch[1] = buffer[i*2+1];
115 if (ch[0] == 0 && ch[1] ==
'[') level = 1;
116 if (ch[0] == 0 && ch[1] ==
';') {
119 if (ch[0] == 0 && ch[1] ==
'#') {
125 if (ch[0] == 0 && ch[1] ==
']') {
126 if (buffer1used == 0) {
130 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+2);
131 buffer1[buffer1used] = 0;
132 buffer1[buffer1used+1] = 0;
133 buffer1used = buffer1used + 2;
135 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+1);
136 buffer1[buffer1used] = 0x00;
137 buffer1used = buffer1used + 1;
140 if (heading == NULL) {
144 heading->SectionName = (
char *)malloc(buffer1used);
145 memcpy(heading->SectionName,buffer1,buffer1used);
146 heading->Prev = INI_info;
147 heading->
Next = NULL;
148 if (INI_info != NULL) {
149 INI_info->
Next = heading;
159 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+2);
160 buffer1[buffer1used] = ch[0];
161 buffer1[buffer1used+1] = ch[1];
162 buffer1used = buffer1used + 2;
164 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+1);
165 buffer1[buffer1used] = ch[1];
166 buffer1used = buffer1used + 1;
171 if (ch[0] == 0 && ch[1] ==
';') {
174 if (ch[0] == 0 && ch[1] ==
'#') {
177 if (ch[0] == 0 && ch[1] ==
'[') {
186 if (isspace((
int) ch[1])) {
193 if (ch[0] == 0 && ch[1] ==
'=') {
194 if (buffer1used == 0) {
202 buffer1used = buffer1used - 2;
204 if (!isspace((
int)buffer1[buffer1used-1])) {
207 buffer1used = buffer1used - 1;
214 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+2);
215 buffer1[buffer1used] = ch[0];
216 buffer1[buffer1used+1] = ch[1];
217 buffer1used = buffer1used + 2;
219 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+1);
220 buffer1[buffer1used] = ch[1];
221 buffer1used = buffer1used + 1;
230 if (isspace((
int) ch[1])) {
238 buffer2 = (
unsigned char *)realloc(buffer2,buffer2used+2);
239 buffer2[buffer2used] = ch[0];
240 buffer2[buffer2used+1] = ch[1];
241 buffer2used = buffer2used + 2;
243 buffer2 = (
unsigned char *)realloc(buffer2,buffer2used+1);
244 buffer2[buffer2used] = ch[1];
245 buffer2used = buffer2used + 1;
251 while (
myiswspace(buffer2 + buffer2used - 2) && buffer2used > 0) {
255 while (isspace(buffer2[buffer2used - 1]) && buffer2used > 0) {
259 if (buffer2used == 0) {
263 entry = (
INI_Entry *)malloc(
sizeof(*entry));
269 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+2);
270 buffer1[buffer1used] = 0;
271 buffer1[buffer1used+1] = 0;
272 buffer1used = buffer1used + 2;
273 buffer2 = (
unsigned char *)realloc(buffer2,buffer2used+2);
274 buffer2[buffer2used] = 0;
275 buffer2[buffer2used+1] = 0;
276 buffer2used = buffer2used + 2;
278 buffer1 = (
unsigned char *)realloc(buffer1,buffer1used+1);
279 buffer1[buffer1used] = 0x00;
280 buffer1used = buffer1used + 1;
281 buffer2 = (
unsigned char *)realloc(buffer2,buffer2used+1);
282 buffer2[buffer2used] = 0x00;
283 buffer2used = buffer2used + 1;
286 entry->
EntryName = (
char *)malloc(buffer1used);
291 memcpy(entry->
EntryName,buffer1,buffer1used);
293 entry->
EntryValue = (
char *)malloc(buffer2used);
298 memcpy(entry->
EntryValue,buffer2,buffer2used);
319 if (INI_head == NULL) {
370 if (cfg == NULL || section == NULL || key == NULL)
return NULL;
375 while (sec != NULL) {
379 while (ent != NULL) {
391 while (sec != NULL) {
395 while (ent != NULL) {
396 if (strcasecmp(key,ent->
EntryName) == 0) {
416 for (h = file_info; h != NULL; h = h->
Next) {
430 if (e == NULL)
return NULL;
433 while (e->
Next != NULL) e = e->
Next;
441 if (cur == NULL)
return;
442 while (cur != NULL) {
458 if (cur == NULL)
return;
459 while (cur != NULL) {
472 if (strcasecmp(value,
"true") == 0)
return TRUE;
473 if (strcasecmp(value,
"yes") == 0)
return TRUE;
474 if (strcasecmp(value,
"y") == 0)
return TRUE;
475 if (strcasecmp(value,
"t") == 0)
return TRUE;
476 if (strcasecmp(value,
"1") == 0)
return TRUE;
477 if (strcasecmp(value,
"false") == 0)
return FALSE;
478 if (strcasecmp(value,
"no") == 0)
return FALSE;
479 if (strcasecmp(value,
"f") == 0)
return FALSE;
480 if (strcasecmp(value,
"n") == 0)
return FALSE;
481 if (strcasecmp(value,
"0") == 0)
return FALSE;
gboolean GSM_StringToBool(const char *value)
int INI_GetInt(INI_Section *cfg, const unsigned char *section, const unsigned char *key, int fallback)
void INI_Free(INI_Section *head)
gboolean mywstrncasecmp(unsigned const char *a, unsigned const char *b, int num)
void INI_Free_Entries(INI_Entry *entry)
gboolean INI_GetBool(INI_Section *cfg, const unsigned char *section, const unsigned char *key, gboolean fallback)
unsigned char * EntryValue
GSM_Error INI_ReadFile(const char *FileName, gboolean Unicode, INI_Section **result)
INI_Entry * INI_FindLastSectionEntry(INI_Section *file_info, const unsigned char *section, const gboolean Unicode)
unsigned char * INI_GetValue(INI_Section *cfg, const unsigned char *section, const unsigned char *key, const gboolean Unicode)
unsigned char * SectionName
unsigned char * EntryName
gboolean myiswspace(unsigned const char *src)