Skip to content

Commit

Permalink
Merge pull request #164 from benhoyt/ini-prefix
Browse files Browse the repository at this point in the history
Add ini_ prefix even to static names so inih can be used as an #include
  • Loading branch information
benhoyt authored Jan 24, 2024
2 parents 4e618f7 + d032d6f commit 5cc5e2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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++;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -164,18 +164,18 @@ 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 */
}
#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). */
Expand All @@ -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)
Expand All @@ -202,29 +202,29 @@ 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;
}
else if (!error) {
/* 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
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project('inih',
['c'],
license : 'BSD-3-Clause',
version : '57',
version : '58',
default_options : ['cpp_std=c++11']
)

Expand Down

0 comments on commit 5cc5e2c

Please sign in to comment.