GithubHelp home page GithubHelp logo

benhoyt / inih Goto Github PK

View Code? Open in Web Editor NEW
2.4K 103.0 481.0 161 KB

Simple .INI file parser in C, good for embedded systems

License: Other

C++ 23.00% C 47.70% Batchfile 3.75% Shell 7.20% Meson 18.35%
ini parser configparser embedded-systems c

inih's Introduction

inih (INI Not Invented Here)

Tests

inih (INI Not Invented Here) is a simple .INI file parser written in C. It's only a couple of pages of code, and it was designed to be small and simple, so it's good for embedded systems. It's also more or less compatible with Python's ConfigParser style of .INI files, including RFC 822-style multi-line syntax and name: value entries.

To use it, just give ini_parse() an INI file, and it will call a callback for every name=value pair parsed, giving you strings for the section, name, and value. It's done this way ("SAX style") because it works well on low-memory embedded systems, but also because it makes for a KISS implementation.

You can also call ini_parse_file() to parse directly from a FILE* object, ini_parse_string() to parse data from a string, or ini_parse_stream() to parse using a custom fgets-style reader function for custom I/O.

Download a release, browse the source, or read about how to use inih in a DRY style with X-Macros.

Compile-time options

You can control various aspects of inih using preprocessor defines:

Syntax options

  • Multi-line entries: By default, inih supports multi-line entries in the style of Python's ConfigParser. To disable, add -DINI_ALLOW_MULTILINE=0.
  • UTF-8 BOM: By default, inih allows a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of INI files. To disable, add -DINI_ALLOW_BOM=0.
  • Inline comments: By default, inih allows inline comments with the ; character. To disable, add -DINI_ALLOW_INLINE_COMMENTS=0. You can also specify which character(s) start an inline comment using INI_INLINE_COMMENT_PREFIXES.
  • Start-of-line comments: By default, inih allows both ; and # to start a comment at the beginning of a line. You can override this by changing INI_START_COMMENT_PREFIXES.
  • Allow no value: By default, inih treats a name with no value (no = or : on the line) as an error. To allow names with no values, add -DINI_ALLOW_NO_VALUE=1, and inih will call your handler function with value set to NULL.

Parsing options

  • Stop on first error: By default, inih keeps parsing the rest of the file after an error. To stop parsing on the first error, add -DINI_STOP_ON_FIRST_ERROR=1.
  • Report line numbers: By default, the ini_handler callback doesn't receive the line number as a parameter. If you need that, add -DINI_HANDLER_LINENO=1.
  • Call handler on new section: By default, inih only calls the handler on each name=value pair. To detect new sections (e.g., the INI file has multiple sections with the same name), add -DINI_CALL_HANDLER_ON_NEW_SECTION=1. Your handler function will then be called each time a new section is encountered, with section set to the new section name but name and value set to NULL.

Memory options

  • Stack vs heap: By default, inih creates a fixed-sized line buffer on the stack. To allocate on the heap using malloc instead, specify -DINI_USE_STACK=0.
  • Maximum line length: The default maximum line length (for stack or heap) is 200 bytes. To override this, add something like -DINI_MAX_LINE=1000. Note that INI_MAX_LINE must be 3 more than the longest line (due to \r, \n, and the NUL).
  • Initial malloc size: INI_INITIAL_ALLOC specifies the initial malloc size when using the heap. It defaults to 200 bytes.
  • Allow realloc: By default when using the heap (-DINI_USE_STACK=0), inih allocates a fixed-sized buffer of INI_INITIAL_ALLOC bytes. To allow this to grow to INI_MAX_LINE bytes, doubling if needed, set -DINI_ALLOW_REALLOC=1.
  • Custom allocator: By default when using the heap, the standard library's malloc, free, and realloc functions are used; to use a custom allocator, specify -DINI_CUSTOM_ALLOCATOR=1 (and -DINI_USE_STACK=0). You must define and link functions named ini_malloc, ini_free, and (if INI_ALLOW_REALLOC is set) ini_realloc, which must have the same signatures as the stdlib.h memory allocation functions.

Simple example in C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../ini.h"

typedef struct
{
    int version;
    const char* name;
    const char* email;
} configuration;

static int handler(void* user, const char* section, const char* name,
                   const char* value)
{
    configuration* pconfig = (configuration*)user;

    #define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
    if (MATCH("protocol", "version")) {
        pconfig->version = atoi(value);
    } else if (MATCH("user", "name")) {
        pconfig->name = strdup(value);
    } else if (MATCH("user", "email")) {
        pconfig->email = strdup(value);
    } else {
        return 0;  /* unknown section/name, error */
    }
    return 1;
}

int main(int argc, char* argv[])
{
    configuration config;

    if (ini_parse("test.ini", handler, &config) < 0) {
        printf("Can't load 'test.ini'\n");
        return 1;
    }
    printf("Config loaded from 'test.ini': version=%d, name=%s, email=%s\n",
        config.version, config.name, config.email);
    return 0;
}

C++ example

If you're into C++ and the STL, there is also an easy-to-use INIReader class that stores values in a map and lets you Get() them:

#include <iostream>
#include "INIReader.h"

int main()
{
    INIReader reader("../examples/test.ini");

    if (reader.ParseError() < 0) {
        std::cout << "Can't load 'test.ini'\n";
        return 1;
    }
    std::cout << "Config loaded from 'test.ini': version="
              << reader.GetInteger("protocol", "version", -1) << ", name="
              << reader.Get("user", "name", "UNKNOWN") << ", email="
              << reader.Get("user", "email", "UNKNOWN") << ", pi="
              << reader.GetReal("user", "pi", -1) << ", active="
              << reader.GetBoolean("user", "active", true) << "\n";
    return 0;
}

This simple C++ API works fine, but it's not very fully-fledged. I'm not planning to work more on the C++ API at the moment, so if you want a bit more power (for example GetSections() and GetFields() functions), see these forks:

Differences from ConfigParser

Some differences between inih and Python's ConfigParser standard library module:

  • INI name=value pairs given above any section headers are treated as valid items with no section (section name is an empty string). In ConfigParser having no section is an error.
  • Line continuations are handled with leading whitespace on continued lines (like ConfigParser). However, instead of concatenating continued lines together, they are treated as separate values for the same key (unlike ConfigParser).

Platform-specific notes

  • Windows/Win32 uses UTF-16 filenames natively, so to handle Unicode paths you need to call _wfopen() to open a file and then ini_parse_file() to parse it; inih does not include wchar_t or Unicode handling.

Meson notes

  • The meson.build file is not required to use or compile inih, its main purpose is for distributions.
  • By default Meson is set up for distro installation, but this behavior can be configured for embedded use cases:
    • with -Ddefault_library=static static libraries are built.
    • with -Ddistro_install=false libraries, headers and pkg-config files won't be installed.
    • with -Dwith_INIReader=false you can disable building the C++ library.
  • All compile-time options are implemented in Meson as well, you can take a look at meson_options.txt for their definition. These won't work if distro_install is set to true.
  • If you want to use inih for programs which may be shipped in a distro, consider linking against the shared libraries. The pkg-config entries are inih and INIReader.
  • In case you use inih as a Meson subproject, you can use the inih_dep and INIReader_dep dependency variables. You might want to set default_library=static and distro_install=false for the subproject. An official Wrap is provided on WrapDB.
  • For packagers: if you want to tag the version in the pkg-config file, you will need to do this downstream. Add version : '<version_as_int>', after the license tag in the project() function and version : meson.project_version(), after the soversion tag in both library() functions.

Using inih with tipi.build

inih can be easily used in tipi.build projects simply by adding the following entry to your .tipi/deps (replace r56 with the latest version tag):

{
    "benhoyt/inih": { "@": "r56" }
}

The required include path in your project is:

#include <ini.h>

Building from vcpkg

You can build and install inih using vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install inih

The inih port in vcpkg is kept up to date by microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Related links

inih's People

Contributors

0x34d avatar absinthescripting avatar ametzler avatar artemshelest avatar benhoyt avatar bkuhls avatar bostjan avatar cosmy1 avatar ddeka2910 avatar downercase avatar evorw avatar fredrikblix avatar girish946 avatar ihilt avatar jinstrong avatar just6979 avatar jvanrhijn avatar mayak-dev avatar neatnit avatar niluje avatar odgalvin avatar phoebehui avatar stephanlachnit avatar tachi107 avatar thesamesam avatar thevice avatar tuxsh avatar vrresto avatar weltling avatar xkzl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inih's Issues

Strip quotes from values

Hello,

I was just trying out your library and I have noticed that returned values include quotes if quotes exist in ini file, which is a tad annoying behavior for my use case.

I understand that to existing users this behavior might be expected and preferred.

I wonder if patch that creates new -DSTRIP_VALUE_QUOTES would be accepted and merged?

Thanks for your consideration,
b.

NULL and 0 is not the same

In the code i've found the following:

file = fopen(filename, "r");
if (!file)                  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    return -1;

The problem is that NULL it's not always 0, there are other implementations 
with different values.

Original issue reported on code.google.com by [email protected] on 6 May 2011 at 3:56

Allow "]" in section name

What steps will reproduce the problem?
1. Parse an INI file with "]" in the section name
2. Witness that everything before the first "]" is parsed as section name 
instead

Example file:
[The Wicker Man [1973]]
runtime = 88

expect to see the following section name parsed: "The Wicker Man [1973]", but 
instead "The Wicker Man [1973" is parsed.

Attached is a patch file to fix this problem.  The patch changes the parser to 
use the last found "]" (before comment or end of line) when parsing a section 
name instead of using the first one found.

Original issue reported on code.google.com by [email protected] on 3 Nov 2011 at 3:51

Attachments:

Merge improvements done by O.S. Systems

We have been using inih in some code for our projects and we've been adding the 
features we felt it would have and also the need build improvements we'd like 
to get done into it.

This is available at https://github.com/OSSystems/inih

Please take a look and consider merging some of our changes into your code.

Original issue reported on code.google.com by [email protected] on 20 Jun 2011 at 11:09

Comment handling with INI_ALLOW_MULTILINE

What steps will reproduce the problem?
1. Create a test.ini 
[User]
Name = Bob Smith       ; Spaces around '=' are stripped
                                    ; This comment will show up as a value for Name
Email = [email protected]  ; And comments (like this) ignored

2. Compile the ini_dump.c example
gcc ini_dump.c ini.c -o ini_dump
3. Run 
ini_dump test.ini

What is the expected output?
[User]
Name = Bob Smith
Email = [email protected]
Active = True

 What do you see instead?
[User]
Name = Bob Smith
Name = ; This comment will show up as a value for Name
Email = [email protected]
Active = True



Please provide any additional information below.
The attached patch  would fix this. Basically, the test for comment should 
precede any other test.

Original issue reported on code.google.com by [email protected] on 29 Dec 2011 at 11:42

Attachments:

"ini_parse_file" to support FatFs

First my gratitude for you efficient and brilliant work.

This is the results of your library, ported to an ATMEL SAM4S:

Start SD card install                                                      
SD/MMC card ready                           
Mount disk (f_mount)...                         
[OK]
Create a file (f_open)...
[OK]
Write to test file (f_puts)...
[OK]
Test is successful.

Read test ini file...

Config loaded from 'Setup.ini': version=6, name=Bob Smith,
 [email protected]

Please unplug the card.

I did some, very small modifications to the function "ini_parse_file" to add support to FatFs (FAT file system module include file R0.09) in my ATMEL SAM embedded project, as you can see in the attached image:

inih ini not invented here 20151014

Plus, the addition of 'ff.h' include in the top of the file. If you can I would love to help in your project but I have no idea how to add a fork in this repository. I can, of course, upload the modified file. You tell me.

Warmest regards and again, a big THANK YOU!.

Should spaces be stripped around section name?

At the moment spaces won't be stripped around section names, so:

[ section ]
name = value

with call handler with " section " as the section string. Is this good, or
should spaces be stripped around section names?


Original issue reported on code.google.com by [email protected] on 21 Aug 2009 at 2:48

values with spaces are read incorrectly

I've got an .INI file with multi-word strings in quotes

name = "my multiline string"

I think that ConfigParser's (i.e. expected) behaviour in this case is to return 
whole right side of the equal sign until the EOL, trimmed.  

That is '"my multiline string"' should be read by parser.

But inih stops at the first whitespace and returns '"my'.

Original issue reported on code.google.com by [email protected] on 25 Sep 2010 at 7:47

':' to separate 'name' and 'value'

Using some ini files not created by me I found that inih doesn't support ':' to 
separate 'name' and 'value'. I've read it's no standard but some 
implementations allow it (like ConfigParser).

I send you the patch. In patch file i've called ini.c.old the original file and 
ini.c the new one.

Thank you for that project and for your time.

Original issue reported on code.google.com by [email protected] on 7 Mar 2011 at 6:36

Attachments:

Array of items

Hi, is it able to support array of items, like this

[list_of_files]
item.txt
item1.txt
item2.txt

inih C++ wrapper won't read multi-line entries correctly

What steps will reproduce the problem?
1. Prepare a ini file with at least a multi-line entry
2. Create a c++ program that read and print that entry

What is the expected output? What do you see instead?
I expected to see the whole multi-line entry and instead I only see the last 
line of it

What version of the product are you using? On what operating system?
inih r14 on a C++ project, both on windows and macosx

Please provide any additional information below.

I've been trying to use your inih library (version r14) for a C++
project of mine and I've been hitting a snag as it seemed that
(contrary to what the instructions were saying) it couldn't read
multilines entries.
After some tries, I've found out that there was an error in the C++
interface class: when the handler received a new line with the same
key as a previously memorized one, it  overwrote the old value with
the new one (instead of appending it).

I'm attaching a new version of the method that works for me (it adds a
newline between different values with the same key):

int INIReader::ValueHandler(void* user, const char* section, const char* name, 
const char* value)
{
   INIReader* reader = (INIReader*)user;
   string k = MakeKey(section, name);
   if(reader->_values[k].size()>0) reader->_values[k] += "\n";
   reader->_values[k] += value;
   return 1;
}

Feel free to take it, modify it or publish it as you prefer.

Original issue reported on code.google.com by [email protected] on 6 Mar 2012 at 8:39

inih does not build with -Wcast-qual

Simply building with:

gcc -c -Wcast-qual ini.c

Output:

ini.c: In function ‘lskip’:
ini.c:42:12: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
     return (char*)s;
            ^
ini.c: In function ‘find_char_or_comment’:
ini.c:55:12: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
     return (char*)s;
            ^

Tested with GCC 4.4 and 4.9 on Debian and Ubuntu.

Can i use this with Raspberry ?

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 27 Jan 2014 at 9:49

Typo in INIReader.cpp?

When I tried to compile INIReader.cpp, I got the error

g++ -c -o INIReader.o INIReader.cpp -std=c++11
INIReader.cpp:65:68: error: non-member function ‘bool HasValue(const string&, const string&)’ cannot have cv-qualifier
 ol HasValue(const std::string& section, const std::string& name) const
                                                                  ^~~~~
INIReader.cpp: In function ‘bool HasValue(const string&, const string&)’:
INIReader.cpp:67:39: error: ‘MakeKey’ was not declared in this scope
     string key = MakeKey(section, name);
                                       ^
INIReader.cpp:68:12: error: ‘_values’ was not declared in this scope
     return _values.count(key);

I could fix this by replacing line 65 of INIReader.cpp with

bool INIReader::HasValue(const std::string& section, const std::string& name) const

The INIReader:: was missing. Is this a typo or was I doing something wrong to get the error in the first place?

Indentation breaks parsing

Reproduce with:

#include <stdio.h>
#include "inih/ini.h"

int handler(void *user, const char *s, const char *k, const char *v)
{
    printf("%s : %s\n", k, v);
    return 0;
}

int main(int argc, char *argv[])
{
    if (argc > 1)
        ini_parse(argv[1], handler, NULL);
}

Input file (lines 2 and 4 are indented with a space):

key1=value1
 key2=value2
key3=value3
 key4=value4

Output:

key1 : value1
key1 : key2=value2
key3 : value3
key3 : key4=value4

This was discovered while attempting to parse .gitconfig which uses tabs for indentation.

Makefile for building inih as static library

Hello,

I am packaging dunst software into Fedora and our rules does not allow 
embedding libraries. Would you accept this Makefile so linux distributions 
could make static packages of your library?

It does not have to be called "Makefile", I would be fine with 
"Makefile.static" or "Makefile.dist". It would be also possible to include the 
file in the extra/ directory (but some paths would need to be changed).

More details here: https://fedorahosted.org/fpc/ticket/216

Thank you in advance. This is the Makefile (attaching it as well because of 
TABs):

# 
# Simple makefile to build inih as static library.
#

SRC = ini.c
OBJ = $(SRC:.c=.o)
OUT = libinih.a
INCLUDES = -I.
CCFLAGS = -g -O2
CCC = g++
LDFLAGS = -g

.SUFFIXES: .cpp

default: $(OUT)

.cpp.o:
    $(CCC) $(INCLUDES) $(CCFLAGS) $(EXTRACCFLAGS) -c $< -o $@

$(OUT): $(OBJ)
    ar rcs $(OUT) $(OBJ)

clean:
    rm -f $(OBJ) $(OUT)

Original issue reported on code.google.com by [email protected] on 8 Oct 2012 at 2:38

Attachments:

Empty value with following comment

Hi there!
Currently the library doesn't support an empty value with a following comment.
For example:

A_KEY = ;This is a comment

Is it possible to support this possibility?

Thank you!

strncpy error in VS2013

This library seems promising, with tests and all.

When I tried your example in Visual Studio 2013, I got this error

Error   1   error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.    c:\users\sturaroa\downloads\inih-r30\ini.c  56  1   IniParserTest

I'd rather not use have to set permissive flags just for this bit.

CMake and pkgconfig support

We have been using this library for a while (since 2011) and we made a few changes on it. We'd like to contribute them back if you think it makes sense.

  • CMake
  • pkgconfig

Please let me know if a PR is desired. I can rebase our changes and prepare it.

ini_parse_file() does not behave as advertised

ini_parse_file() supposed to return 0 on success or the line number of the line 
with error.

However, it always return 2 on a well-formatted config file because of the code 
on line 123:

if (!handler(user, section, name, value) && !error) {

I have attached a propose fixed for this by defining HANDLER_SUCCESS in the 
ini.h file and changed line 123 to:

if (handler(user, section, name, value) != HANDLER_SUCCESS && !error) {

Thank you very much for the library.

Original issue reported on code.google.com by [email protected] on 4 Nov 2011 at 10:19

Attachments:

Add support for TIR files

TIR files for tire data configuration look like INI files, except that they have additional line comments starting with ! or $ (as far as I can tell from sample.tir). Could ypu please add support for TIR files.

This works for me, but it would be more useful to configure the line comments at run-time (not at compile-time).

-        if (*start == ';' || *start == '#') {
+        if (*start == ';' || *start == '#' || *start == '!' || *start == '$') {
             /* Per Python configparser, allow both ; and # comments at the
                start of a line */
         } 

support ini parse from cstring

I get config from a config server, which is char*, and i don't want to save it to file. so i need an API like:

int ini_parse_str(const char* str, ini_handler handler, void* user);  

so, how about support parse from cstring?

Error compiling the C++ version, says ini_parse is undefined

I placed the download of inih in a clean directory, and executed a build
command on the cpp files:

gcc -O0 -g3 -Wall -c -fmessage-length=0 -oini.o ..\ini.c
g++ -O0 -g3 -Wall -c -fmessage-length=0 -ocpp\INIReader.o ..\cpp\INIReader.cpp
..\cpp\INIReader.cpp: In member function 'long int
INIReader::GetInteger(std::string, std::string, long int)':
..\cpp\INIReader.cpp:30: error: 'strtol' was not declared in this scope
..\cpp\INIReader.cpp: In static member function 'static std::string
INIReader::MakeKey(std::string, std::string)':
..\cpp\INIReader.cpp:38: warning: comparison between signed and unsigned
integer expressions
Build error occurred, build is stopped
Time consumed: 671  ms.  

To remedy the strtol problem i place '#include <stdlib.h>' at the start of
'INIreader.cpp'

I then execute another build command

g++ -O0 -g3 -Wall -c -fmessage-length=0 -ocpp\INIReaderTest.o
..\cpp\INIReaderTest.cpp
g++ -O0 -g3 -Wall -c -fmessage-length=0 -ocpp\INIReader.o ..\cpp\INIReader.cpp
..\cpp\INIReader.cpp: In static member function 'static std::string
INIReader::MakeKey(std::string, std::string)':
..\cpp\INIReader.cpp:39: warning: comparison between signed and unsigned
integer expressions
g++ -oParser.exe ini.o cpp\INIReaderTest.o cpp\INIReader.o
cpp\INIReader.o: In function `INIReader':
C:\Users\Andrew\Documents\code\Parser\Debug/../cpp/INIReader.cpp:12:
undefined reference to `ini_parse(char const*, int (*)(void*, char const*,
char const*, char const*), void*)'
C:\Users\Andrew\Documents\code\Parser\Debug/../cpp/INIReader.cpp:12:
undefined reference to `ini_parse(char const*, int (*)(void*, char const*,
char const*, char const*), void*)'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1388  ms.  

The result is that it ini_parse is not defined, even though it is in the
ini.h file, which is #include in the 'INIreader.cpp' file

Original issue reported on code.google.com by [email protected] on 21 Aug 2009 at 1:10

bug in C++ wrapper INIReader

I'm used MS C\C++ compiler ( included in MSVS 2008 ).

What steps will reproduce the problem?
1. create instance of INIReader class - 
INIReader reader("settings.ini");

2. try to read some int value - 
int port = reader.GetInteger( "network", "port", -1 );

It always return default_value, because of following wrong code - 
const char* value = Get(section, name, "").c_str();

Original issue reported on code.google.com by [email protected] on 28 Sep 2009 at 4:43

Error during compilation: ld: symbol(s) not found for architecture x86_64

I'm on a MAC OSX 64 bit machine, and when compiling the library I get that 
error. 

I tried running the following:

$gcc -c -std=c99 -o ini.o ini.c
$g++ -c -o INIReader.o INIReader.cpp
$g++ -o INIReader INIReader.o ../ini.o

And it fails on the third command. Any ideas about how to compile would be 
appreciated. 


Original issue reported on code.google.com by [email protected] on 14 Apr 2013 at 1:40

Unix-style (#) comments in lines seems not to be supported

I don't even know if this is a real issue (I don't have a test case to, well, test), however looking at the source code (that is really clean, this is why I noticed it) it seems you can have #, or Unix-style, comments in blank lines, however not as a line comment (in this case, only ; seems to be supported).

Why? Because of this line: https://github.com/benhoyt/inih/blob/master/ini.c#L50. You only compare the current char with ; and not #, different from this line https://github.com/benhoyt/inih/blob/master/ini.c#L106.

"Undefined reference to ini_parse" during compilation

ini_dump.c:(.text+0xc5): undefined reference toini_parse'`

Was having this issue trying to compile a different project that used ini.h and ini.c. Decided to do some digging:

I put ini.c, ini.h, ini_dump.c, and test.ini into a folder on my machine. Updated the #include statement for ini.h in ini_dump.c to be "#include "ini.h"" instead of "#include "../ini.h"".

Ran "gcc ini_dump.c" and got the "Undefinited reference to ini_parse" again. I've checked that it's reading the file and that I have the right permissions.

I'm running Ubuntu 16.04, gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.1).

stricmp should be replaced for strcasecmp

Dear developer, 

I just integrated inih in my CGI application and bumped to the examples where 
using stricmp which is non-POSIX or ANSI. Please replace it with strcasecmp.

See stackoverflow:
http://stackoverflow.com/questions/1784767/g-error-stricmp-was-not-declared-in-t
his-scope-but-ok-for-strcmp

Kind regards,
Jerry

Original issue reported on code.google.com by [email protected] on 25 Aug 2012 at 12:47

C example won't be compiled successfully by gcc

The C example in the Project Home uses "stricmp" function, which is not ANSI C 
function, and it only exists in some C libraries. Glibc does not include this 
function. Instead, it uses "strcasecmp". I recommend to remove the use of this 
function.

Original issue reported on code.google.com by xuhdev on 28 Mar 2012 at 12:46

BOM support

Seems that ini files with BOM header is not currently supported. Could you 
support this, please?


Thanks!

Original issue reported on code.google.com by xuhdev on 14 Jun 2012 at 9:24

ini_parse_string() crash on non-NULL terminated strings

ini_parse_string() will crash if string is not NULL terminated. While I guess it is ok to expect NULL terminated strings maybe it would be better to add a check or strdup like function to avoid it?

A quick fuzzer run didn't found any other bugs :-)

Build failure with r12

Current r12 fails to buind if the source doesn't include <stdio.h> byself. We 
fixed it on our fork:

https://github.com/OSSystems/inih/commit/7ab5f69cde1e921f58d0ef00fa8039d8ea31122
6

Cheers,

Original issue reported on code.google.com by [email protected] on 27 Jun 2011 at 7:11

utf-8 string is not handled

What steps will reproduce the problem?
1. Take ini file with sonme keyname or value contains utf-8 charcater
2. ini parse throws excpetion in funciton find_char_or_comment(), when 
encounters utf-8 character.


What is the expected output? What do you see instead?
value should be stored in utf-8 format. whereas program got crashed.

What version of the product are you using? On what operating system?
r26 on windows7, 64 bit sytem. 

Please provide any additional information below.
System locale is chinese (simplified). and value contains chinese charcter as 
Stock淨值查詢

Original issue reported on code.google.com by [email protected] on 4 Jan 2013 at 11:25

Should spaces be stripped around section name?

At the moment spaces won't be stripped around section names, so:

[ section ]
name = value

with call handler with " section " as the section string. Is this good, or
should spaces be stripped around section names?


Original issue reported on code.google.com by [email protected] on 21 Aug 2009 at 2:48

Section-less options do not raise an error

Adding an option outside of any section works with inih but does not work with 
Python's ConfigParser.  ConfigParser raises a MissingSectionHeader error 
<https://github.com/python-git/python/blob/b9ffb07e2e54805c052e08b60da25191e97e4
a32/Lib/ConfigParser.py#L481>.

Example INI file here:
https://github.com/editorconfig/editorconfig-vim/blob/083c977d7af181cd213578bcb2
798c7ab4ba059c/.editorconfig

Original issue reported on code.google.com by [email protected] on 3 Mar 2012 at 5:23

(not a defect) C++ template callback extension

Hello,

I've made a little C++ template extension to better integrate the C interface 
of inih in C++ code.

I have the need to use in C++ code directly the C interface of inih because of 
repeated keys in my INI file, which are not accessible by the INIReader class 
but fully supported by the C callback-based interface.

Obviously my interface is not needed at all, because that interface is pretty 
usable in C++ too, but C++ programmers tend to use class-like constructs pretty 
extensively then I think that should be far common that they want a class to be 
the receiver of parser callbacks, in such cases my extension allow to write 
code like the following with no/very-little overhead:

#include "ini.hpp"

class MyConf
{
public:
    void store(const char* section, const char* name, const char* value) {
        // do something with values
    }
    int load(const char* inifile) {
        return inihpp::iniParse(inifile, makeCallback(this, &MyConf::store));
    }
}

Feel free to include my extension in your code, in any form you like.

PS: I know... the comments are not as detailed as they should... :(

Thank-you for your work,
Paolo Bernini

*flies away ;)





Original issue reported on code.google.com by [email protected] on 16 Sep 2014 at 1:34

Attachments:

INIReader: Use '=' as separator between section and name

Take this ini file as an example:
[a.b]
c = abc
[a]
b.c = def

INIReader::MakeKey will merge a.b and c to a.b.c and it will also do the same 
for a and b.c. Thus when trying to get the value of one of these keys the 
result is "abc\ndef" and not "abc" or "def".

Using '=' as separator will fix the problem, as the name string can't contain 
an '='.

Original issue reported on code.google.com by [email protected] on 19 Aug 2014 at 3:43

callback is called after it returned error

If I return error from my callback, it gets called on the next name-value pair 
anyway.

This is strange and at least should be explicitly documented.

Motivation:

1. I may want to stop iteration since I've read all the data I need.

2. It is not so comfortable to write error handling for simpler cases — I 
need to accumulate a list of errors instead of a single one.

If you don't want to fix this behaviour, at least, please, add an option to 
stop on first error.

Original issue reported on code.google.com by [email protected] on 25 Sep 2010 at 12:00

Outdated links

The headers of source files still point to http://code.google.com/p/inih/

// Read an INI file into easy-to-access name/value pairs.
// inih and INIReader are released under the New BSD license (see LICENSE.txt).
// Go to the project home page for more info:
//
// http://code.google.com/p/inih/

The C++ example has a link that points to Google Code as well.

INIReader.cpp does not have a license header.

BTW are you the original author? The original repository is gone without explanation. You may want to put at least a redirect there.

Possible bug: ambiguous handling of continuations

What steps will reproduce the problem?
1. Compile examples/ini_dump.c program (gcc examples/ini_dump.c ini.c
2. Run output program with the INI file below (./a.out test.in)

Sample INI file:

    [testing]
    key = value
              plus a continuation
    key2 = value2

Expected output:

    [testing]
    key = value
    plus a continuation
    key2 = value2

Actual output:

    [testing]
    key = value
    key = plus a continuation
    key2 = value2

Python's ConfigParser handles line continuations by appending the continuation 
string onto the option value (prefixed with a newline).

inih's method of handling continuations makes these two files equivalent (I 
don't think they should be):

File 1:

    [testing]
    key = value
          plus a continuation

File 2:

    [testing]
    key = value
    key = plus a continuation

Original issue reported on code.google.com by [email protected] on 11 Mar 2012 at 11:33

Feature request - Read ini data from memory

Sorry, but I can't found any other way to write my request.

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 13 Mar 2011 at 10:32

New 'GetSections' method

Hello,

We've made a new method, which we use in our applications which link with inih 
library, to list the sections of the ini file.

Please see it at:

https://github.com/OSSystems/inih/commit/182f1e19eb99e188bf2f7e71fdb7ee8f4318610
2

and if possible merge it so it easy us to keep our CMake addition easy to 
maintain :D

Original issue reported on code.google.com by [email protected] on 5 Jul 2014 at 1:27

Multi-line support doesn't match ConfigParser spec

1st off, thanks a lot for such a tiny ini parser, it is really helpful!

I initially ran into some issues with multi-line enabled.
I have a section that looks like this:
[section1]
  key1=value1
  key2=value2

When I use inih with multiline, the handler gets called as follows:
1) section=section1, name=key1, value=value1
2) section=section1, name=key1, value='key2=value2'

the ConfigParser Spec says 
(http://docs.python.org/dev/library/configparser.html):
Values can also span multiple lines, as long as they are indented deeper than 
the first line of the value
But my 2 values are at the same indent level, so they shouldn't be treated as 
multi-line

Turning off multi-line is an option for me, but I thought I'd let you know.

Original issue reported on code.google.com by [email protected] on 8 Jul 2012 at 2:58

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.