5 |
|
#include <ctype.h> |
6 |
|
|
7 |
|
#include "inifile.h" |
8 |
< |
|
8 |
> |
/* |
9 |
> |
char* inifile_cleanstr(char* str) |
10 |
> |
{ |
11 |
> |
while (isspace(*str)) |
12 |
> |
str++; |
13 |
> |
|
14 |
> |
int i; |
15 |
> |
for (i = 0; str[i]; i ++) |
16 |
> |
{ |
17 |
> |
if |
18 |
> |
} |
19 |
> |
|
20 |
> |
return str; |
21 |
> |
} |
22 |
> |
*/ |
23 |
|
bool inifile_read(char* filename, inifile_callback callback) |
24 |
|
{ |
25 |
|
FILE* fp = fopen(filename, "r"); |
56 |
|
|
57 |
|
if (inisection[0]) |
58 |
|
free(inisection); |
59 |
< |
inisection = strdup(readptr + 1); |
59 |
> |
inisection = strdup(readptr + 1); // Skip the first [ |
60 |
|
newsection = true; |
61 |
|
} |
62 |
|
else // It's a value. |
70 |
|
if (readptr[i - 1] == '\n') |
71 |
|
readptr[i - 1] = '\0'; // Remove the trailing newline. |
72 |
|
|
73 |
< |
if (equals) // If there's no equals, crash with error. |
73 |
> |
if (equals) |
74 |
|
{ |
75 |
|
readptr[equals] = '\0'; |
76 |
|
if (!callback(inisection, newsection, readptr, readptr + equals + 1)) // If the callback is false, exit. |
77 |
|
break; |
78 |
|
newsection = false; |
79 |
|
} |
80 |
< |
else |
80 |
> |
else // If there's no equals, crash with error. |
81 |
|
{ |
82 |
|
success = false; |
83 |
|
break; |