| 1 |
#include <stdio.h> |
| 2 |
|
| 3 |
#define INI_MAX_LINE 200 |
| 4 |
|
| 5 |
typedef char* (*ini_reader)(char* str, int num, void* stream); |
| 6 |
|
| 7 |
int ini_parse(const char* filename); |
| 8 |
|
| 9 |
static int ini_parse_stream(ini_reader reader, void* stream) |
| 10 |
{ |
| 11 |
char line[INI_MAX_LINE]; |
| 12 |
int max_line = INI_MAX_LINE; |
| 13 |
while (reader(line, max_line, stream) != NULL) |
| 14 |
; |
| 15 |
return 0; |
| 16 |
} |
| 17 |
|
| 18 |
static int ini_parse_file(FILE* file) |
| 19 |
{ |
| 20 |
return ini_parse_stream((ini_reader)fgets, file); |
| 21 |
} |
| 22 |
|
| 23 |
int ini_parse(const char* filename) |
| 24 |
{ |
| 25 |
FILE* file; |
| 26 |
int error; |
| 27 |
|
| 28 |
file = fopen(filename, "r"); |
| 29 |
if (!file) |
| 30 |
return -1; |
| 31 |
error = ini_parse_file(file); |
| 32 |
fclose(file); |
| 33 |
return error; |
| 34 |
} |