34 #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
35 #define _CRT_SECURE_NO_WARNINGS
48 #define MAX_SECTION 50
60 char* p = s + strlen(s);
61 while (p > s && isspace((
unsigned char)(*--p)))
67 static char*
lskip(
const char* s)
69 while (*s && isspace((
unsigned char)(*s)))
79 #if INI_ALLOW_INLINE_COMMENTS
81 while (*s && (!chars || !strchr(chars, *s)) &&
83 was_space = isspace((
unsigned char)(*s));
87 while (*s && (!chars || !strchr(chars, *s))) {
95 static char*
strncpy0(
char* dest,
const char* src,
size_t size)
97 strncpy(dest, src, size - 1);
98 dest[size - 1] =
'\0';
114 #if INI_ALLOW_REALLOC && !INI_USE_STACK
135 #if INI_HANDLER_LINENO
136 #define HANDLER(u, s, n, v) handler(u, s, n, v, lineno)
138 #define HANDLER(u, s, n, v) handler(u, s, n, v)
142 while (reader(line, max_line, stream) != NULL) {
143 #if INI_ALLOW_REALLOC && !INI_USE_STACK
144 offset = strlen(line);
145 while (offset == max_line - 1 && line[offset - 1] !=
'\n') {
149 new_line = realloc(line, max_line);
155 if (reader(line + offset, max_line - offset, stream) == NULL)
159 offset += strlen(line + offset);
167 if (lineno == 1 && (
unsigned char)start[0] == 0xEF &&
168 (
unsigned char)start[1] == 0xBB &&
169 (
unsigned char)start[2] == 0xBF) {
178 #if INI_ALLOW_MULTILINE
179 else if (*prev_name && *start && start > line) {
182 if (!
HANDLER(user, section, prev_name, start) && !error)
186 else if (*start ==
'[') {
191 strncpy0(section, start + 1,
sizeof(section));
202 if (*end ==
'=' || *end ==
':') {
206 #if INI_ALLOW_INLINE_COMMENTS
211 value =
lskip(value);
215 strncpy0(prev_name, name,
sizeof(prev_name));
216 if (!
HANDLER(user, section, name, value) && !error)
225 #if INI_STOP_ON_FIRST_ERROR
250 file = fopen(filename,
"r");
262 const char* ctx_ptr = ctx->
ptr;
263 size_t ctx_num_left = ctx->
num_left;
267 if (ctx_num_left == 0 || num < 2)
270 while (num > 1 && ctx_num_left != 0) {
static char * lskip(const char *s)
static char * strncpy0(char *dest, const char *src, size_t size)
int ini_parse(const char *filename, ini_handler handler, void *user)
#define HANDLER(u, s, n, v)
int ini_parse_file(FILE *file, ini_handler handler, void *user)
static char * find_chars_or_comment(const char *s, const char *chars)
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, void *user)
static char * rstrip(char *s)
int ini_parse_string(const char *string, ini_handler handler, void *user)
static char * ini_reader_string(char *str, int num, void *stream)
#define INI_INLINE_COMMENT_PREFIXES
char *(* ini_reader)(char *str, int num, void *stream)
int(* ini_handler)(void *user, const char *section, const char *name, const char *value)
#define INI_START_COMMENT_PREFIXES
#define INI_INITIAL_ALLOC