From 238610ef4ee54ac103ac56895f8c266c783154ec Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Thu, 25 Jan 2024 05:54:17 +1300 Subject: [PATCH 1/2] Add ini_ prefix even to static names so inih can be used as an #include Fixes #163 --- ini.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ini.c b/ini.c index 509952d..f2f9a6a 100644 --- a/ini.c +++ b/ini.c @@ -45,7 +45,7 @@ typedef struct { } ini_parse_string_ctx; /* Strip whitespace chars off end of given string, in place. Return s. */ -static char* rstrip(char* s) +static char* ini_rstrip(char* s) { char* p = s + strlen(s); while (p > s && isspace((unsigned char)(*--p))) @@ -54,7 +54,7 @@ static char* rstrip(char* s) } /* Return pointer to first non-whitespace char in given string. */ -static char* lskip(const char* s) +static char* ini_lskip(const char* s) { while (*s && isspace((unsigned char)(*s))) s++; @@ -64,7 +64,7 @@ static char* lskip(const char* s) /* Return pointer to first char (of chars) or inline comment in given string, or pointer to NUL at end of string if neither found. Inline comment must be prefixed by a whitespace character to register as a comment. */ -static char* find_chars_or_comment(const char* s, const char* chars) +static char* ini_find_chars_or_comment(const char* s, const char* chars) { #if INI_ALLOW_INLINE_COMMENTS int was_space = 0; @@ -83,7 +83,7 @@ static char* find_chars_or_comment(const char* s, const char* chars) /* Similar to strncpy, but ensures dest (size bytes) is NUL-terminated, and doesn't pad with NULs. */ -static char* strncpy0(char* dest, const char* src, size_t size) +static char* ini_strncpy0(char* dest, const char* src, size_t size) { /* Could use strncpy internally, but it causes gcc warnings (see issue #91) */ size_t i; @@ -164,7 +164,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, start += 3; } #endif - start = lskip(rstrip(start)); + start = ini_lskip(ini_rstrip(start)); if (strchr(INI_START_COMMENT_PREFIXES, *start)) { /* Start-of-line comment */ @@ -172,10 +172,10 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, #if INI_ALLOW_MULTILINE else if (*prev_name && *start && start > line) { #if INI_ALLOW_INLINE_COMMENTS - end = find_chars_or_comment(start, NULL); + end = ini_find_chars_or_comment(start, NULL); if (*end) *end = '\0'; - rstrip(start); + ini_rstrip(start); #endif /* Non-blank line with leading whitespace, treat as continuation of previous name's value (as per Python configparser). */ @@ -185,10 +185,10 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, #endif else if (*start == '[') { /* A "[section]" line */ - end = find_chars_or_comment(start + 1, "]"); + end = ini_find_chars_or_comment(start + 1, "]"); if (*end == ']') { *end = '\0'; - strncpy0(section, start + 1, sizeof(section)); + ini_strncpy0(section, start + 1, sizeof(section)); *prev_name = '\0'; #if INI_CALL_HANDLER_ON_NEW_SECTION if (!HANDLER(user, section, NULL, NULL) && !error) @@ -202,21 +202,21 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, } else if (*start) { /* Not a comment, must be a name[=:]value pair */ - end = find_chars_or_comment(start, "=:"); + end = ini_find_chars_or_comment(start, "=:"); if (*end == '=' || *end == ':') { *end = '\0'; - name = rstrip(start); + name = ini_rstrip(start); value = end + 1; #if INI_ALLOW_INLINE_COMMENTS - end = find_chars_or_comment(value, NULL); + end = ini_find_chars_or_comment(value, NULL); if (*end) *end = '\0'; #endif - value = lskip(value); - rstrip(value); + value = ini_lskip(value); + ini_rstrip(value); /* Valid name[=:]value pair found, call handler */ - strncpy0(prev_name, name, sizeof(prev_name)); + ini_strncpy0(prev_name, name, sizeof(prev_name)); if (!HANDLER(user, section, name, value) && !error) error = lineno; } @@ -224,7 +224,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, /* No '=' or ':' found on name[=:]value line */ #if INI_ALLOW_NO_VALUE *end = '\0'; - name = rstrip(start); + name = ini_rstrip(start); if (!HANDLER(user, section, name, NULL) && !error) error = lineno; #else From d032d6ff5cb2afb10bd71f0d22580d4c582afc3b Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Thu, 25 Jan 2024 05:58:14 +1300 Subject: [PATCH 2/2] Bump up version for release r58 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index e0340ff..d440cbc 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project('inih', ['c'], license : 'BSD-3-Clause', - version : '57', + version : '58', default_options : ['cpp_std=c++11'] )