42 #define MAX_SECTION 50
50 static unsigned char*
rstrip(
unsigned char* s)
52 unsigned char* p = s + strlen((
char*)s);
53 while (p > s && isspace(*--p))
61 static char*
lskip(
const unsigned char* s)
63 while (*s && isspace(*s))
75 int was_whitespace = 0;
76 while (*s && *s != c && !(was_whitespace && *s ==
';')) {
77 was_whitespace = isspace(*s);
86 static char*
strncpy0(
char* dest,
const char* src,
size_t size)
88 strncpy(dest, src, size);
89 dest[size - 1] =
'\0';
95 int (*handler)(
void*,
const char*,
const char*,
const char*),
111 file = fopen(filename,
"r");
116 while (fgets(line,
sizeof(line), file) != NULL) {
120 #if INI_ALLOW_MULTILINE
121 if (*prev_name && *start && start > line) {
124 if (!handler(user, section, prev_name, start) && !error)
129 if (*start ==
';' || *start ==
'#') {
132 else if (*start ==
'[') {
137 strncpy0(section, start + 1,
sizeof(section));
145 else if (*start && *start !=
';') {
150 name = (
char*)
rstrip((
unsigned char*)start);
151 value =
lskip((
unsigned char*)end + 1);
155 rstrip((
unsigned char*)value);
158 strncpy0(prev_name, name,
sizeof(prev_name));
159 if (!handler(user, section, name, value) && !error)
static char * find_char_or_comment(const unsigned char *s, char c)
static char * lskip(const unsigned char *s)
int ini_parse(const char *filename, int(*handler)(void *, const char *, const char *, const char *), void *user)
static char * strncpy0(char *dest, const char *src, size_t size)
static unsigned char * rstrip(unsigned char *s)