pax_global_header00006660000000000000000000000064147721055660014527gustar00rootroot0000000000000052 comment=23acf2dd5af5287b0f170908c607560ab3995dae inih-r59/000077500000000000000000000000001477210556600124375ustar00rootroot00000000000000inih-r59/.github/000077500000000000000000000000001477210556600137775ustar00rootroot00000000000000inih-r59/.github/FUNDING.yml000066400000000000000000000000201477210556600156040ustar00rootroot00000000000000github: benhoyt inih-r59/.github/workflows/000077500000000000000000000000001477210556600160345ustar00rootroot00000000000000inih-r59/.github/workflows/tests.yml000066400000000000000000000010611477210556600177170ustar00rootroot00000000000000name: Tests on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build-linux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run Diff Tests run: | cd tests ./unittest.sh cd ../examples ./cpptest.sh git diff --exit-code build-meson: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - uses: BSFishy/meson-build@v1.0.3 with: action: test meson-version: 1.4.1 inih-r59/.gitignore000066400000000000000000000000421477210556600144230ustar00rootroot00000000000000fuzzing/findings fuzzing/inihfuzz inih-r59/LICENSE.txt000066400000000000000000000027461477210556600142730ustar00rootroot00000000000000 The "inih" library is distributed under the New BSD license: Copyright (c) 2009, Ben Hoyt All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Ben Hoyt nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY BEN HOYT ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEN HOYT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. inih-r59/README.md000066400000000000000000000232521477210556600137220ustar00rootroot00000000000000# inih (INI Not Invented Here) [![Tests](https://github.com/benhoyt/inih/actions/workflows/tests.yml/badge.svg)](https://github.com/benhoyt/inih/actions/workflows/tests.yml) **inih (INI Not Invented Here)** is a simple [.INI file](http://en.wikipedia.org/wiki/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](http://docs.python.org/library/configparser.html) 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](http://blog.brush.co.nz/2009/08/xmacros/) 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 ## ```c #include #include #include #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](https://github.com/benhoyt/inih/blob/master/cpp/INIReader.h) that stores values in a `map` and lets you `Get()` them: ```cpp #include #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: * https://github.com/Blandinium/inih * https://github.com/OSSystems/inih ## Differences from ConfigParser ## Some differences between inih and Python's [ConfigParser](http://docs.python.org/library/configparser.html) 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](https://github.com/benhoyt/inih/blob/master/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](https://wrapdb.mesonbuild.com/inih). * For packagers: if you want to tag the version in the pkg-config file, you will need to do this downstream. Add `version : '',` 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](https://tipi.build) projects simply by adding the following entry to your `.tipi/deps` (replace `r56` with the latest version tag): ```json { "benhoyt/inih": { "@": "r56" } } ``` The required include path in your project is: ```c #include ``` ## Building from vcpkg ## You can build and install inih using [vcpkg](https://github.com/microsoft/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](https://github.com/Microsoft/vcpkg) on the vcpkg repository. ## Related links ## * [Conan package for inih](https://github.com/mohamedghita/conan-inih) (Conan is a C/C++ package manager) inih-r59/cpp/000077500000000000000000000000001477210556600132215ustar00rootroot00000000000000inih-r59/cpp/INIReader.cpp000066400000000000000000000131761477210556600154770ustar00rootroot00000000000000// Read an INI file into easy-to-access name/value pairs. // SPDX-License-Identifier: BSD-3-Clause // Copyright (C) 2009-2020, Ben Hoyt // inih and INIReader are released under the New BSD license (see LICENSE.txt). // Go to the project home page for more info: // // https://github.com/benhoyt/inih #include #include #include #include "../ini.h" #include "INIReader.h" using std::string; INIReader::INIReader(const string& filename) { _error = ini_parse(filename.c_str(), ValueHandler, this); } INIReader::INIReader(const char *buffer, size_t buffer_size) { string content(buffer, buffer_size); _error = ini_parse_string(content.c_str(), ValueHandler, this); } int INIReader::ParseError() const { return _error; } string INIReader::Get(const string& section, const string& name, const string& default_value) const { string key = MakeKey(section, name); // Use _values.find() here instead of _values.at() to support pre C++11 compilers return _values.count(key) ? _values.find(key)->second : default_value; } string INIReader::GetString(const string& section, const string& name, const string& default_value) const { const string str = Get(section, name, ""); return str.empty() ? default_value : str; } long INIReader::GetInteger(const string& section, const string& name, long default_value) const { string valstr = Get(section, name, ""); const char* value = valstr.c_str(); char* end; // This parses "1234" (decimal) and also "0x4D2" (hex) long n = strtol(value, &end, 0); return end > value ? n : default_value; } INI_API int64_t INIReader::GetInteger64(const string& section, const string& name, int64_t default_value) const { string valstr = Get(section, name, ""); const char* value = valstr.c_str(); char* end; // This parses "1234" (decimal) and also "0x4D2" (hex) int64_t n = strtoll(value, &end, 0); return end > value ? n : default_value; } unsigned long INIReader::GetUnsigned(const string& section, const string& name, unsigned long default_value) const { string valstr = Get(section, name, ""); const char* value = valstr.c_str(); char* end; // This parses "1234" (decimal) and also "0x4D2" (hex) unsigned long n = strtoul(value, &end, 0); return end > value ? n : default_value; } INI_API uint64_t INIReader::GetUnsigned64(const string& section, const string& name, uint64_t default_value) const { string valstr = Get(section, name, ""); const char* value = valstr.c_str(); char* end; // This parses "1234" (decimal) and also "0x4D2" (hex) uint64_t n = strtoull(value, &end, 0); return end > value ? n : default_value; } double INIReader::GetReal(const string& section, const string& name, double default_value) const { string valstr = Get(section, name, ""); const char* value = valstr.c_str(); char* end; double n = strtod(value, &end); return end > value ? n : default_value; } bool INIReader::GetBoolean(const string& section, const string& name, bool default_value) const { string valstr = Get(section, name, ""); // Convert to lower case to make string comparisons case-insensitive std::transform(valstr.begin(), valstr.end(), valstr.begin(), [](const unsigned char& ch) { return static_cast(::tolower(ch)); }); if (valstr == "true" || valstr == "yes" || valstr == "on" || valstr == "1") return true; else if (valstr == "false" || valstr == "no" || valstr == "off" || valstr == "0") return false; else return default_value; } std::vector INIReader::Sections() const { std::set sectionSet; for (std::map::const_iterator it = _values.begin(); it != _values.end(); ++it) { size_t pos = it->first.find('='); if (pos != string::npos) { sectionSet.insert(it->first.substr(0, pos)); } } return std::vector(sectionSet.begin(), sectionSet.end()); } std::vector INIReader::Keys(const string& section) const { std::vector keys; string keyPrefix = MakeKey(section, ""); for (std::map::const_iterator it = _values.begin(); it != _values.end(); ++it) { if (it->first.compare(0, keyPrefix.length(), keyPrefix) == 0) { keys.push_back(it->first.substr(keyPrefix.length())); } } return keys; } bool INIReader::HasSection(const string& section) const { const string key = MakeKey(section, ""); std::map::const_iterator pos = _values.lower_bound(key); if (pos == _values.end()) return false; // Does the key at the lower_bound pos start with "section"? return pos->first.compare(0, key.length(), key) == 0; } bool INIReader::HasValue(const string& section, const string& name) const { string key = MakeKey(section, name); return _values.count(key); } string INIReader::MakeKey(const string& section, const string& name) { string key = section + "=" + name; // Convert to lower case to make section/name lookups case-insensitive std::transform(key.begin(), key.end(), key.begin(), [](const unsigned char& ch) { return static_cast(::tolower(ch)); }); return key; } int INIReader::ValueHandler(void* user, const char* section, const char* name, const char* value) { if (!name) // Happens when INI_CALL_HANDLER_ON_NEW_SECTION enabled return 1; INIReader* reader = static_cast(user); string key = MakeKey(section, name); if (reader->_values[key].size() > 0) reader->_values[key] += "\n"; reader->_values[key] += value ? value : ""; return 1; } inih-r59/cpp/INIReader.h000066400000000000000000000113341477210556600151360ustar00rootroot00000000000000// Read an INI file into easy-to-access name/value pairs. // SPDX-License-Identifier: BSD-3-Clause // Copyright (C) 2009-2020, Ben Hoyt // inih and INIReader are released under the New BSD license (see LICENSE.txt). // Go to the project home page for more info: // // https://github.com/benhoyt/inih #ifndef INIREADER_H #define INIREADER_H #include #include #include #include #include // Visibility symbols, required for Windows DLLs #ifndef INI_API #if defined _WIN32 || defined __CYGWIN__ # ifdef INI_SHARED_LIB # ifdef INI_SHARED_LIB_BUILDING # define INI_API __declspec(dllexport) # else # define INI_API __declspec(dllimport) # endif # else # define INI_API # endif #else # if defined(__GNUC__) && __GNUC__ >= 4 # define INI_API __attribute__ ((visibility ("default"))) # else # define INI_API # endif #endif #endif // Read an INI file into easy-to-access name/value pairs. (Note that I've gone // for simplicity here rather than speed, but it should be pretty decent.) class INIReader { public: // Construct INIReader and parse given filename. See ini.h for more info // about the parsing. INI_API explicit INIReader(const std::string& filename); // Construct INIReader and parse given buffer. See ini.h for more info // about the parsing. INI_API explicit INIReader(const char *buffer, size_t buffer_size); // Return the result of ini_parse(), i.e., 0 on success, line number of // first error on parse error, or -1 on file open error. INI_API int ParseError() const; // Get a string value from INI file, returning default_value if not found. INI_API std::string Get(const std::string& section, const std::string& name, const std::string& default_value) const; // Get a string value from INI file, returning default_value if not found, // empty, or contains only whitespace. INI_API std::string GetString(const std::string& section, const std::string& name, const std::string& default_value) const; // Get an integer (long) value from INI file, returning default_value if // not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2"). INI_API long GetInteger(const std::string& section, const std::string& name, long default_value) const; // Get a 64-bit integer (int64_t) value from INI file, returning default_value if // not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2"). INI_API int64_t GetInteger64(const std::string& section, const std::string& name, int64_t default_value) const; // Get an unsigned integer (unsigned long) value from INI file, returning default_value if // not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2"). INI_API unsigned long GetUnsigned(const std::string& section, const std::string& name, unsigned long default_value) const; // Get an unsigned 64-bit integer (uint64_t) value from INI file, returning default_value if // not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2"). INI_API uint64_t GetUnsigned64(const std::string& section, const std::string& name, uint64_t default_value) const; // Get a real (floating point double) value from INI file, returning // default_value if not found or not a valid floating point value // according to strtod(). INI_API double GetReal(const std::string& section, const std::string& name, double default_value) const; // Get a boolean value from INI file, returning default_value if not found or if // not a valid true/false value. Valid true values are "true", "yes", "on", "1", // and valid false values are "false", "no", "off", "0" (not case sensitive). INI_API bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const; // Return a newly-allocated vector of all section names, in alphabetical order. INI_API std::vector Sections() const; // Return a newly-allocated vector of keys in the given section, in alphabetical order. INI_API std::vector Keys(const std::string& section) const; // Return true if the given section exists (section must contain at least // one name=value pair). INI_API bool HasSection(const std::string& section) const; // Return true if a value exists with the given section and field names. INI_API bool HasValue(const std::string& section, const std::string& name) const; protected: int _error; std::map _values; static std::string MakeKey(const std::string& section, const std::string& name); static int ValueHandler(void* user, const char* section, const char* name, const char* value); }; #endif // INIREADER_H inih-r59/examples/000077500000000000000000000000001477210556600142555ustar00rootroot00000000000000inih-r59/examples/INIReaderExample.cpp000066400000000000000000000035261477210556600200450ustar00rootroot00000000000000// Example that shows simple usage of the INIReader class #include #include "../cpp/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) << ", unsigned version=" << reader.GetUnsigned("protocol", "version", -1) << ", trillion=" << reader.GetInteger64("user", "trillion", -1) << ", unsigned trillion=" << reader.GetUnsigned64("user", "trillion", -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"; std::cout << "Has values: user.name=" << reader.HasValue("user", "name") << ", user.nose=" << reader.HasValue("user", "nose") << "\n"; std::cout << "Has sections: user=" << reader.HasSection("user") << ", fizz=" << reader.HasSection("fizz") << "\n"; std::cout << "Sections:\n"; std::vector sections = reader.Sections(); for (std::vector::const_iterator it = sections.begin(); it != sections.end(); ++it) { std::cout << "- " << *it << "\n"; } for (std::vector::const_iterator it = sections.begin(); it != sections.end(); ++it) { std::cout << "Keys in section [" << *it << "]:\n"; std::vector keys = reader.Keys(*it); for (std::vector::const_iterator kit = keys.begin(); kit != keys.end(); ++kit) { std::cout << "- " << *kit << "\n"; } } return 0; } inih-r59/examples/config.def000066400000000000000000000002201477210556600161740ustar00rootroot00000000000000// CFG(section, name, default) CFG(protocol, version, "0") CFG(user, name, "Fatty Lumpkin") CFG(user, email, "fatty@lumpkin.com") #undef CFG inih-r59/examples/cpptest.sh000077500000000000000000000002331477210556600162740ustar00rootroot00000000000000#!/usr/bin/env bash g++ -Wall INIReaderExample.cpp ../cpp/INIReader.cpp ../ini.c -o INIReaderExample ./INIReaderExample > cpptest.txt rm INIReaderExample inih-r59/examples/cpptest.txt000066400000000000000000000005651477210556600165060ustar00rootroot00000000000000Config loaded from 'test.ini': version=6, unsigned version=6, trillion=1000000000000, unsigned trillion=1000000000000, name=Bob Smith, email=bob@smith.com, pi=3.14159, active=1 Has values: user.name=1, user.nose=0 Has sections: user=1, fizz=0 Sections: - protocol - user Keys in section [protocol]: - version Keys in section [user]: - active - email - name - pi - trillion inih-r59/examples/ini_dump.c000066400000000000000000000017241477210556600162310ustar00rootroot00000000000000/* ini.h example that simply dumps an INI file without comments */ #include #include #include "../ini.h" static int dumper(void* user, const char* section, const char* name, const char* value) { static char prev_section[50] = ""; if (strcmp(section, prev_section)) { printf("%s[%s]\n", (prev_section[0] ? "\n" : ""), section); strncpy(prev_section, section, sizeof(prev_section)); prev_section[sizeof(prev_section) - 1] = '\0'; } printf("%s = %s\n", name, value); return 1; } int main(int argc, char* argv[]) { int error; if (argc <= 1) { printf("Usage: ini_dump filename.ini\n"); return 1; } error = ini_parse(argv[1], dumper, NULL); if (error < 0) { printf("Can't read '%s'!\n", argv[1]); return 2; } else if (error) { printf("Bad config file (first error on line %d)!\n", error); return 3; } return 0; } inih-r59/examples/ini_example.c000066400000000000000000000024561477210556600167220ustar00rootroot00000000000000/* Example: parse a simple configuration file */ #include #include #include #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; config.version = 0; /* set defaults */ config.name = NULL; config.email = NULL; 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); if (config.name) free((void*)config.name); if (config.email) free((void*)config.email); return 0; } inih-r59/examples/ini_xmacros.c000066400000000000000000000022251477210556600167350ustar00rootroot00000000000000/* Parse a configuration file into a struct using X-Macros */ #include #include #include "../ini.h" /* define the config struct type */ typedef struct { #define CFG(s, n, default) char *s##_##n; #include "config.def" } config; /* create one and fill in its default values */ config Config = { #define CFG(s, n, default) default, #include "config.def" }; /* process a line of the INI file, storing valid values into config struct */ int handler(void *user, const char *section, const char *name, const char *value) { config *cfg = (config *)user; if (0) ; #define CFG(s, n, default) else if (strcmp(section, #s)==0 && \ strcmp(name, #n)==0) cfg->s##_##n = strdup(value); #include "config.def" return 1; } /* print all the variables in the config, one per line */ void dump_config(config *cfg) { #define CFG(s, n, default) printf("%s_%s = %s\n", #s, #n, cfg->s##_##n); #include "config.def" } int main(int argc, char* argv[]) { if (ini_parse("test.ini", handler, &Config) < 0) printf("Can't load 'test.ini', using defaults\n"); dump_config(&Config); return 0; } inih-r59/examples/meson.build000066400000000000000000000006231477210556600164200ustar00rootroot00000000000000runtest = files(join_paths(meson.project_source_root(), 'tests', 'runtest.sh')) tests = { 'INIReaderExample': { 'args': [] }, } foreach name, properties : tests exe = executable('unittest_' + name, src_inih, src_INIReader, 'INIReaderExample.cpp', cpp_args : ['-Wall', properties['args']]) test('test_' + name, runtest, depends : [exe], args : [files('cpptest.txt'), exe.full_path()]) endforeach inih-r59/examples/test.ini000066400000000000000000000006361477210556600157420ustar00rootroot00000000000000; Test config file for ini_example.c and INIReaderTest.cpp [protocol] ; Protocol configuration version=6 ; IPv6 [user] name = Bob Smith ; Spaces around '=' are stripped email = bob@smith.com ; And comments (like this) ignored active = true ; Test a boolean pi = 3.14159 ; Test a floating point number trillion = 1000000000000 ; Test 64-bit integers inih-r59/fuzzing/000077500000000000000000000000001477210556600141335ustar00rootroot00000000000000inih-r59/fuzzing/build.sh000077500000000000000000000001141477210556600155650ustar00rootroot00000000000000#!/usr/bin/env bash ../../afl-2.52b/afl-gcc inihfuzz.c ../ini.c -o inihfuzz inih-r59/fuzzing/fuzz.sh000077500000000000000000000001271477210556600154700ustar00rootroot00000000000000#!/usr/bin/env bash ../../afl-2.52b/afl-fuzz -i testcases -o findings -- ./inihfuzz @@ inih-r59/fuzzing/inihfuzz.c000066400000000000000000000022531477210556600161470ustar00rootroot00000000000000/* This is a slightly tweaked copy of tests/unittest.c for fuzzing */ #include #include #include #include "../ini.h" int User; char Prev_section[50]; int dumper(void* user, const char* section, const char* name, const char* value) { User = *((int*)user); if (!name || strcmp(section, Prev_section)) { printf("... [%s]\n", section); strncpy(Prev_section, section, sizeof(Prev_section)); Prev_section[sizeof(Prev_section) - 1] = '\0'; } if (!name) { return 1; } printf("... %s%s%s;\n", name, value ? "=" : "", value ? value : ""); if (!value) { // Happens when INI_ALLOW_NO_VALUE=1 and line has no value (no '=' or ':') return 1; } return strcmp(name, "user")==0 && strcmp(value, "parse_error")==0 ? 0 : 1; } void parse(const char* fname) { static int u = 100; int e; *Prev_section = '\0'; e = ini_parse(fname, dumper, &u); printf("%s: e=%d user=%d\n", fname, e, User); u++; } int main(int argc, char **argv) { if (argc < 2) { printf("usage: inihfuzz file.ini\n"); return 1; } parse(argv[1]); return 0; } inih-r59/fuzzing/testcases/000077500000000000000000000000001477210556600161315ustar00rootroot00000000000000inih-r59/fuzzing/testcases/case1.ini000066400000000000000000000001101477210556600176160ustar00rootroot00000000000000; comment [foo] ; section bar=1 ; name=value [bar] name = Bob age: 42 inih-r59/ini.c000066400000000000000000000213261477210556600133660ustar00rootroot00000000000000/* inih -- simple .INI file parser SPDX-License-Identifier: BSD-3-Clause Copyright (C) 2009-2020, Ben Hoyt inih is released under the New BSD license (see LICENSE.txt). Go to the project home page for more info: https://github.com/benhoyt/inih */ #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS #endif #include #include #include #include "ini.h" #if !INI_USE_STACK #if INI_CUSTOM_ALLOCATOR #include void* ini_malloc(size_t size); void ini_free(void* ptr); void* ini_realloc(void* ptr, size_t size); #else #include #define ini_malloc malloc #define ini_free free #define ini_realloc realloc #endif #endif #define MAX_SECTION 50 #define MAX_NAME 50 /* Used by ini_parse_string() to keep track of string parsing state. */ typedef struct { const char* ptr; size_t num_left; } ini_parse_string_ctx; /* Strip whitespace chars off end of given string, in place. Return s. */ static char* ini_rstrip(char* s) { char* p = s + strlen(s); while (p > s && isspace((unsigned char)(*--p))) *p = '\0'; return s; } /* Return pointer to first non-whitespace char in given string. */ static char* ini_lskip(const char* s) { while (*s && isspace((unsigned char)(*s))) s++; return (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* ini_find_chars_or_comment(const char* s, const char* chars) { #if INI_ALLOW_INLINE_COMMENTS int was_space = 0; while (*s && (!chars || !strchr(chars, *s)) && !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { was_space = isspace((unsigned char)(*s)); s++; } #else while (*s && (!chars || !strchr(chars, *s))) { s++; } #endif return (char*)s; } /* Similar to strncpy, but ensures dest (size bytes) is NUL-terminated, and doesn't pad with NULs. */ 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; for (i = 0; i < size - 1 && src[i]; i++) dest[i] = src[i]; dest[i] = '\0'; return dest; } /* See documentation in header file. */ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, void* user) { /* Uses a fair bit of stack (use heap instead if you need to) */ #if INI_USE_STACK char line[INI_MAX_LINE]; size_t max_line = INI_MAX_LINE; #else char* line; size_t max_line = INI_INITIAL_ALLOC; #endif #if INI_ALLOW_REALLOC && !INI_USE_STACK char* new_line; #endif char section[MAX_SECTION] = ""; #if INI_ALLOW_MULTILINE char prev_name[MAX_NAME] = ""; #endif size_t offset; char* start; char* end; char* name; char* value; int lineno = 0; int error = 0; char abyss[16]; /* Used to consume input when a line is too long. */ #if !INI_USE_STACK line = (char*)ini_malloc(INI_INITIAL_ALLOC); if (!line) { return -2; } #endif #if INI_HANDLER_LINENO #define HANDLER(u, s, n, v) handler(u, s, n, v, lineno) #else #define HANDLER(u, s, n, v) handler(u, s, n, v) #endif /* Scan through stream line by line */ while (reader(line, (int)max_line, stream) != NULL) { offset = strlen(line); #if INI_ALLOW_REALLOC && !INI_USE_STACK while (offset == max_line - 1 && line[offset - 1] != '\n') { max_line *= 2; if (max_line > INI_MAX_LINE) max_line = INI_MAX_LINE; new_line = ini_realloc(line, max_line); if (!new_line) { ini_free(line); return -2; } line = new_line; if (reader(line + offset, (int)(max_line - offset), stream) == NULL) break; offset += strlen(line + offset); if (max_line >= INI_MAX_LINE) break; } #endif lineno++; /* If line exceeded INI_MAX_LINE bytes, discard till end of line. */ if (offset == max_line - 1 && line[offset - 1] != '\n') { while (reader(abyss, sizeof(abyss), stream) != NULL) { if (!error) error = lineno; if (abyss[strlen(abyss) - 1] == '\n') break; } } start = line; #if INI_ALLOW_BOM if (lineno == 1 && (unsigned char)start[0] == 0xEF && (unsigned char)start[1] == 0xBB && (unsigned char)start[2] == 0xBF) { start += 3; } #endif start = ini_rstrip(ini_lskip(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 = ini_find_chars_or_comment(start, NULL); if (*end) *end = '\0'; ini_rstrip(start); #endif /* Non-blank line with leading whitespace, treat as continuation of previous name's value (as per Python configparser). */ if (!HANDLER(user, section, prev_name, start) && !error) error = lineno; } #endif else if (*start == '[') { /* A "[section]" line */ end = ini_find_chars_or_comment(start + 1, "]"); if (*end == ']') { *end = '\0'; ini_strncpy0(section, start + 1, sizeof(section)); #if INI_ALLOW_MULTILINE *prev_name = '\0'; #endif #if INI_CALL_HANDLER_ON_NEW_SECTION if (!HANDLER(user, section, NULL, NULL) && !error) error = lineno; #endif } else if (!error) { /* No ']' found on section line */ error = lineno; } } else if (*start) { /* Not a comment, must be a name[=:]value pair */ end = ini_find_chars_or_comment(start, "=:"); if (*end == '=' || *end == ':') { *end = '\0'; name = ini_rstrip(start); value = end + 1; #if INI_ALLOW_INLINE_COMMENTS end = ini_find_chars_or_comment(value, NULL); if (*end) *end = '\0'; #endif value = ini_lskip(value); ini_rstrip(value); #if INI_ALLOW_MULTILINE ini_strncpy0(prev_name, name, sizeof(prev_name)); #endif /* Valid name[=:]value pair found, call handler */ 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 = ini_rstrip(start); if (!HANDLER(user, section, name, NULL) && !error) error = lineno; #else error = lineno; #endif } } #if INI_STOP_ON_FIRST_ERROR if (error) break; #endif } #if !INI_USE_STACK ini_free(line); #endif return error; } /* See documentation in header file. */ int ini_parse_file(FILE* file, ini_handler handler, void* user) { return ini_parse_stream((ini_reader)fgets, file, handler, user); } /* See documentation in header file. */ int ini_parse(const char* filename, ini_handler handler, void* user) { FILE* file; int error; file = fopen(filename, "r"); if (!file) return -1; error = ini_parse_file(file, handler, user); fclose(file); return error; } /* An ini_reader function to read the next line from a string buffer. This is the fgets() equivalent used by ini_parse_string(). */ static char* ini_reader_string(char* str, int num, void* stream) { ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream; const char* ctx_ptr = ctx->ptr; size_t ctx_num_left = ctx->num_left; char* strp = str; char c; if (ctx_num_left == 0 || num < 2) return NULL; while (num > 1 && ctx_num_left != 0) { c = *ctx_ptr++; ctx_num_left--; *strp++ = c; if (c == '\n') break; num--; } *strp = '\0'; ctx->ptr = ctx_ptr; ctx->num_left = ctx_num_left; return str; } /* See documentation in header file. */ int ini_parse_string(const char* string, ini_handler handler, void* user) { ini_parse_string_ctx ctx; ctx.ptr = string; ctx.num_left = strlen(string); return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler, user); } inih-r59/ini.h000066400000000000000000000137071477210556600133770ustar00rootroot00000000000000/* inih -- simple .INI file parser SPDX-License-Identifier: BSD-3-Clause Copyright (C) 2009-2020, Ben Hoyt inih is released under the New BSD license (see LICENSE.txt). Go to the project home page for more info: https://github.com/benhoyt/inih */ #ifndef INI_H #define INI_H /* Make this header file easier to include in C++ code */ #ifdef __cplusplus extern "C" { #endif #include /* Nonzero if ini_handler callback should accept lineno parameter. */ #ifndef INI_HANDLER_LINENO #define INI_HANDLER_LINENO 0 #endif /* Visibility symbols, required for Windows DLLs */ #ifndef INI_API #if defined _WIN32 || defined __CYGWIN__ # ifdef INI_SHARED_LIB # ifdef INI_SHARED_LIB_BUILDING # define INI_API __declspec(dllexport) # else # define INI_API __declspec(dllimport) # endif # else # define INI_API # endif #else # if defined(__GNUC__) && __GNUC__ >= 4 # define INI_API __attribute__ ((visibility ("default"))) # else # define INI_API # endif #endif #endif /* Typedef for prototype of handler function. Note that even though the value parameter has type "const char*", the user may cast to "char*" and modify its content, as the value is not used again after the call to ini_handler. This is not true of section and name -- those must not be modified. */ #if INI_HANDLER_LINENO typedef int (*ini_handler)(void* user, const char* section, const char* name, const char* value, int lineno); #else typedef int (*ini_handler)(void* user, const char* section, const char* name, const char* value); #endif /* Typedef for prototype of fgets-style reader function. */ typedef char* (*ini_reader)(char* str, int num, void* stream); /* Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped), and comments starting with ';' (semicolon). Section is "" if name=value pair parsed before any section heading. name:value pairs are also supported as a concession to Python's configparser. For each name=value pair parsed, call handler function with given user pointer as well as section, name, and value (data only valid for duration of handler call). Handler should return nonzero on success, zero on error. Returns 0 on success, line number of first error on parse error (doesn't stop on first error), -1 on file open error, or -2 on memory allocation error (only when INI_USE_STACK is zero). */ INI_API int ini_parse(const char* filename, ini_handler handler, void* user); /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't close the file when it's finished -- the caller must do that. */ INI_API int ini_parse_file(FILE* file, ini_handler handler, void* user); /* Same as ini_parse(), but takes an ini_reader function pointer instead of filename. Used for implementing custom or string-based I/O (see also ini_parse_string). */ INI_API int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, void* user); /* Same as ini_parse(), but takes a zero-terminated string with the INI data instead of a file. Useful for parsing INI data from a network socket or already in memory. */ INI_API int ini_parse_string(const char* string, ini_handler handler, void* user); /* Nonzero to allow multi-line value parsing, in the style of Python's configparser. If allowed, ini_parse() will call the handler with the same name for each subsequent line parsed. */ #ifndef INI_ALLOW_MULTILINE #define INI_ALLOW_MULTILINE 1 #endif /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of the file. See https://github.com/benhoyt/inih/issues/21 */ #ifndef INI_ALLOW_BOM #define INI_ALLOW_BOM 1 #endif /* Chars that begin a start-of-line comment. Per Python configparser, allow both ; and # comments at the start of a line by default. */ #ifndef INI_START_COMMENT_PREFIXES #define INI_START_COMMENT_PREFIXES ";#" #endif /* Nonzero to allow inline comments (with valid inline comment characters specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match Python 3.2+ configparser behaviour. */ #ifndef INI_ALLOW_INLINE_COMMENTS #define INI_ALLOW_INLINE_COMMENTS 1 #endif #ifndef INI_INLINE_COMMENT_PREFIXES #define INI_INLINE_COMMENT_PREFIXES ";" #endif /* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */ #ifndef INI_USE_STACK #define INI_USE_STACK 1 #endif /* Maximum line length for any line in INI file (stack or heap). Note that this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */ #ifndef INI_MAX_LINE #define INI_MAX_LINE 200 #endif /* Nonzero to allow heap line buffer to grow via realloc(), zero for a fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is zero. */ #ifndef INI_ALLOW_REALLOC #define INI_ALLOW_REALLOC 0 #endif /* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK is zero. */ #ifndef INI_INITIAL_ALLOC #define INI_INITIAL_ALLOC 200 #endif /* Stop parsing on first error (default is to keep parsing). */ #ifndef INI_STOP_ON_FIRST_ERROR #define INI_STOP_ON_FIRST_ERROR 0 #endif /* Nonzero to call the handler at the start of each new section (with name and value NULL). Default is to only call the handler on each name=value pair. */ #ifndef INI_CALL_HANDLER_ON_NEW_SECTION #define INI_CALL_HANDLER_ON_NEW_SECTION 0 #endif /* Nonzero to allow a name without a value (no '=' or ':' on the line) and call the handler with value NULL in this case. Default is to treat no-value lines as an error. */ #ifndef INI_ALLOW_NO_VALUE #define INI_ALLOW_NO_VALUE 0 #endif /* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory allocation functions (INI_USE_STACK must also be 0). These functions must have the same signatures as malloc/free/realloc and behave in a similar way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */ #ifndef INI_CUSTOM_ALLOCATOR #define INI_CUSTOM_ALLOCATOR 0 #endif #ifdef __cplusplus } #endif #endif /* INI_H */ inih-r59/meson.build000066400000000000000000000073661477210556600146150ustar00rootroot00000000000000project('inih', ['c'], license : 'BSD-3-Clause', version : '58', default_options : ['cpp_std=c++11'], meson_version: '>=0.56.0' ) #### options #### arg_static = [] distro_install = get_option('distro_install') extra_args = [] if distro_install pkg = import('pkgconfig') else if not get_option('multi-line_entries') arg_static += ['-DINI_ALLOW_MULTILINE=0'] endif if not get_option('utf-8_bom') arg_static += ['-DINI_ALLOW_BOM=0'] endif if not get_option('inline_comments') arg_static += ['-DINI_ALLOW_INLINE_COMMENTS=0'] endif inline_comment_prefix = get_option('inline_comment_prefix') if inline_comment_prefix != ';' arg_static += ['-DINI_INLINE_COMMENT_PREFIXES="' + inline_comment_prefix + '"'] endif sol_comment_prefix = get_option('start-of-line_comment_prefix') if sol_comment_prefix != ';#' arg_static += ['-DINI_START_COMMENT_PREFIXES="' + sol_comment_prefix + '"'] endif if get_option('allow_no_value') arg_static += ['-DINI_ALLOW_NO_VALUE=1'] endif if get_option('stop_on_first_error') arg_static += ['-DINI_STOP_ON_FIRST_ERROR=1'] endif if get_option('report_line_numbers') arg_static += ['-DINI_HANDLER_LINENO=1'] endif if get_option('call_handler_on_new_section') arg_static += ['-DINI_CALL_HANDLER_ON_NEW_SECTION=1'] endif if get_option('use_heap') arg_static += ['-DINI_USE_STACK=0'] endif max_line_length = get_option('max_line_length') if max_line_length != 200 arg_static += ['-DINI_MAX_LINE=' + max_line_length.to_string()] endif initial_malloc_size = get_option('initial_malloc_size') if initial_malloc_size != 200 arg_static += ['-DINI_INITIAL_ALLOC=' + initial_malloc_size.to_string()] endif if get_option('allow_realloc') arg_static += ['-DINI_ALLOW_REALLOC=1'] endif endif if host_machine.system() == 'windows' lib = get_option('default_library') if lib == 'both' error('default_library=both is not supported on Windows') elif lib == 'shared' extra_args += '-DINI_SHARED_LIB' add_project_arguments('-DINI_SHARED_LIB_BUILDING', language: ['c', 'cpp']) endif endif #### inih #### inc_inih = include_directories('.') src_inih = files('ini.c') lib_inih = library('inih', [src_inih], include_directories : inc_inih, c_args : [arg_static, extra_args], install : distro_install, soversion : '0', gnu_symbol_visibility: 'hidden' ) if distro_install install_headers('ini.h') pkg.generate(lib_inih, name : 'inih', description : 'simple .INI file parser', extra_cflags : extra_args, ) endif inih_dep = declare_dependency( link_with : lib_inih, compile_args : arg_static + extra_args, include_directories : inc_inih ) subdir('tests') #### INIReader #### if get_option('with_INIReader') add_languages('cpp') inc_INIReader = include_directories('cpp') src_INIReader = files(join_paths('cpp', 'INIReader.cpp')) lib_INIReader = library('INIReader', src_INIReader, cpp_args : extra_args, include_directories : inc_INIReader, dependencies : inih_dep, install : distro_install, soversion : '0', gnu_symbol_visibility: 'hidden' ) if distro_install install_headers('cpp/INIReader.h') pkg.generate(lib_INIReader, name : 'INIReader', description : 'simple .INI file parser for C++', extra_cflags : extra_args, ) endif INIReader_dep = declare_dependency( link_with : lib_INIReader, include_directories : inc_INIReader, compile_args : extra_args ) subdir('examples') endif inih-r59/meson_options.txt000066400000000000000000000040201477210556600160700ustar00rootroot00000000000000option('distro_install', type : 'boolean', value : true, description : 'install shared libs, headers and pkg-config entries' ) option('with_INIReader', type : 'boolean', value : true, description : 'compile and (if selected) install INIReader' ) option('multi-line_entries', type : 'boolean', value : true, description : 'support for multi-line entries in the style of Python\'s ConfigParser' ) option('utf-8_bom', type : 'boolean', value : true, description : 'allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of INI files' ) option('inline_comments', type : 'boolean', value : true, description : 'allow inline comments with the comment prefix character' ) option('inline_comment_prefix', type : 'string', value : ';', description : 'character(s) to start an inline comment (if enabled)' ) option('start-of-line_comment_prefix', type : 'string', value : ';#', description : 'character(s) to start a comment at the beginning of a line' ) option('allow_no_value', type : 'boolean', value : false, description : 'allow name with no value' ) option('stop_on_first_error', type : 'boolean', value : false, description : 'stop parsing after an error' ) option('report_line_numbers', type : 'boolean', value : false, description : 'report line number on ini_handler callback' ) option('call_handler_on_new_section', type : 'boolean', value : false, description : 'call the handler each time a new section is encountered' ) option('use_heap', type : 'boolean', value : false, description : 'allocate memory on the heap using malloc instead using a fixed-sized line buffer on the stack' ) option('max_line_length', type : 'integer', value : 200, description : 'maximum line length in bytes' ) option('initial_malloc_size', type : 'integer', value : 200, description : 'initial malloc size in bytes (when using the heap)' ) option('allow_realloc', type : 'boolean', value : false, description : 'allow initial malloc size to grow to max line length (when using the heap)' ) inih-r59/tests/000077500000000000000000000000001477210556600136015ustar00rootroot00000000000000inih-r59/tests/bad_comment.ini000066400000000000000000000000211477210556600165430ustar00rootroot00000000000000This is an error inih-r59/tests/bad_multi.ini000066400000000000000000000000131477210556600162340ustar00rootroot00000000000000 indented inih-r59/tests/bad_section.ini000066400000000000000000000001071477210556600165520ustar00rootroot00000000000000[section1] name1=value1 [section2 [section3 ; comment ] name2=value2 inih-r59/tests/baseline_alloc.txt000066400000000000000000000001441477210556600172750ustar00rootroot00000000000000ini_malloc(12) ... [section] ... foo=bar; ini_realloc(24) ... bazz=buzz quxx; ini_free() basic: e=0 inih-r59/tests/baseline_allow_no_value.txt000066400000000000000000000027731477210556600212230ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 ... This is an error; bad_comment.ini: e=0 user=103 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line value; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=0 user=105 ... indented; bad_multi.ini: e=0 user=106 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section_list] ... section0; ... section1; ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=0 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_call_handler_on_new_section.txt000066400000000000000000000027261477210556600237140ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [empty] ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line value; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=0 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... [section1] ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section_list] ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_disallow_inline_comments.txt000066400000000000000000000032111477210556600232620ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test ; name=value comment; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3 ; only this will be a comment; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345 ; key should be "test;3"; ... test4=4#5#6 ; '#' only starts a comment at start of line; ... test7=; blank value, except if inline comments disabled; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; ... [section3 ; comment ] ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line value; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith ; comment line 1; ... foo=bar ;c1; ... foo=Hi World ;c2; multi_line.ini: e=0 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_handler_lineno.txt000066400000000000000000000034331477210556600211700ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; line 3 ... two=1234; line 4 ... [ section 2 ] ... happy=4; line 8 ... sad=; line 9 ... [comment_test] ... test1=1;2;3; line 15 ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; line 16 ... test;3=345; line 17 ... test4=4#5#6; line 18 ... test7=; line 21 ... test8=; not a comment, needs whitespace before ';'; line 22 ... [colon_tests] ... Content-Type=text/html; line 25 ... foo=bar; line 26 ... adams=42; line 27 ... funny1=with = equals; line 28 ... funny2=with : colons; line 29 ... funny3=two = equals; line 30 ... funny4=two : colons; line 31 normal.ini: e=0 user=101 ... [section1] ... name1=value1; line 2 ... name2=value2; line 5 bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; line 2 ... user=parse_error; line 3 ... c=d; line 4 user_error.ini: e=3 user=104 ... [section1] ... single1=abc; line 2 ... multi=this is a; line 3 ... multi=multi-line value; line 4 ... single2=xyz; line 5 ... [section2] ... multi=a; line 7 ... multi=b; line 8 ... multi=c; line 9 ... [section3] ... single=ghi; line 11 ... multi=the quick; line 12 ... multi=brown fox; line 13 ... name=bob smith; line 14 ... foo=bar; line 16 ... foo=Hi World; line 17 multi_line.ini: e=0 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; line 2 ... key“=value“; line 3 bom.ini: e=0 user=107 ... [section1] ... single1=abc; line 2 ... single2=xyz; line 3 ... single1=def; line 5 ... single2=qrs; line 6 duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; line 6 ... [section1] ... key1=val1; line 9 no_value.ini: e=2 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; line 3 long_section.ini: e=0 user=110 inih-r59/tests/baseline_heap.txt000066400000000000000000000026501477210556600171240ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line value; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=0 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_heap_max_line.txt000066400000000000000000000024141477210556600207760ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comm; ... [colon_tests] ... Content-Type=text/; ... foo=bar; ... adams=42; ... funny1=with = equ; ... funny2=with : col; ... funny3=two = equa; ... funny4=two : colo; normal.ini: e=1 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=4 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... name=value; long_section.ini: e=1 user=110 inih-r59/tests/baseline_heap_realloc.txt000066400000000000000000000026501477210556600206250ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line value; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=0 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_heap_realloc_max_line.txt000066400000000000000000000024141477210556600224770ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comm; ... [colon_tests] ... Content-Type=text/; ... foo=bar; ... adams=42; ... funny1=with = equ; ... funny2=with : col; ... funny3=two = equa; ... funny4=two : colo; normal.ini: e=1 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=4 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... name=value; long_section.ini: e=1 user=110 inih-r59/tests/baseline_heap_string.txt000066400000000000000000000005231477210556600205070ustar00rootroot00000000000000empty string: e=0 user=0 ... [section] ... foo=bar; ... bazz=buzz quxx; basic: e=0 user=101 ... [section] ... hello=world; ... forty_two=42; crlf: e=0 user=102 ... [sec] ... foo=0123456789012; ... bar=4321; long line: e=2 user=103 ... [sec] ... foo=0123456789012; long continued: e=2 user=104 ... [s] ... a=1; ... c=3; error: e=3 user=105 inih-r59/tests/baseline_multi.txt000066400000000000000000000026501477210556600173410ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line value; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=0 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_multi_max_line.txt000066400000000000000000000024141477210556600212130ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comm; ... [colon_tests] ... Content-Type=text/; ... foo=bar; ... adams=42; ... funny1=with = equ; ... funny2=with : col; ... funny3=two = equa; ... funny4=two : colo; normal.ini: e=1 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=4 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... name=value; long_section.ini: e=1 user=110 inih-r59/tests/baseline_single.txt000066400000000000000000000025131477210556600174660ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; ... name2=value2; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; ... c=d; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... single2=xyz; ... [section2] ... multi=a; ... [section3] ... single=ghi; ... multi=the quick; ... name=bob smith; ... foo=bar; multi_line.ini: e=4 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 ... [section0] ... key0=val0; ... [section1] ... key1=val1; no_value.ini: e=2 user=109 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_stop_on_first_error.txt000066400000000000000000000025211477210556600223050ustar00rootroot00000000000000no_file.ini: e=-1 user=0 ... [section1] ... one=This is a test; ... two=1234; ... [ section 2 ] ... happy=4; ... sad=; ... [comment_test] ... test1=1;2;3; ... test2=2;3;4;this won't be a comment, needs whitespace before ';'; ... test;3=345; ... test4=4#5#6; ... test7=; ... test8=; not a comment, needs whitespace before ';'; ... [colon_tests] ... Content-Type=text/html; ... foo=bar; ... adams=42; ... funny1=with = equals; ... funny2=with : colons; ... funny3=two = equals; ... funny4=two : colons; normal.ini: e=0 user=101 ... [section1] ... name1=value1; bad_section.ini: e=3 user=102 bad_comment.ini: e=1 user=102 ... [section] ... a=b; ... user=parse_error; user_error.ini: e=3 user=104 ... [section1] ... single1=abc; ... multi=this is a; ... multi=multi-line value; ... single2=xyz; ... [section2] ... multi=a; ... multi=b; ... multi=c; ... [section3] ... single=ghi; ... multi=the quick; ... multi=brown fox; ... name=bob smith; ... foo=bar; ... foo=Hi World; multi_line.ini: e=0 user=105 bad_multi.ini: e=1 user=105 ... [bom_section] ... bom_name=bom_value; ... key“=value“; bom.ini: e=0 user=107 ... [section1] ... single1=abc; ... single2=xyz; ... single1=def; ... single2=qrs; duplicate_sections.ini: e=0 user=108 no_value.ini: e=2 user=108 ... [_123456789_123456789_123456789_123456789_12345678] ... name=value; long_section.ini: e=0 user=110 inih-r59/tests/baseline_string.txt000066400000000000000000000005231477210556600175120ustar00rootroot00000000000000empty string: e=0 user=0 ... [section] ... foo=bar; ... bazz=buzz quxx; basic: e=0 user=101 ... [section] ... hello=world; ... forty_two=42; crlf: e=0 user=102 ... [sec] ... foo=0123456789012; ... bar=4321; long line: e=2 user=103 ... [sec] ... foo=0123456789012; long continued: e=2 user=104 ... [s] ... a=1; ... c=3; error: e=3 user=105 inih-r59/tests/bom.ini000066400000000000000000000000661477210556600150610ustar00rootroot00000000000000[bom_section] bom_name=bom_value key“ = value“ inih-r59/tests/duplicate_sections.ini000066400000000000000000000001151477210556600201600ustar00rootroot00000000000000[section1] single1 = abc single2 = xyz [section1] single1 = def single2 = qrsinih-r59/tests/long_section.ini000066400000000000000000000001561477210556600167670ustar00rootroot00000000000000# check that section is truncated [_123456789_123456789_123456789_123456789_123456789_123456789] name = value inih-r59/tests/meson.build000066400000000000000000000031471477210556600157500ustar00rootroot00000000000000runtest = files(join_paths(meson.project_source_root(), 'tests', 'runtest.sh')) tests = { 'multi': { 'args': [] }, 'multi_max_line': { 'args': ['-DINI_MAX_LINE=20'] }, 'single': { 'args': ['-DINI_ALLOW_MULTILINE=0'] }, 'disallow_inline_comments': { 'args': ['-DINI_ALLOW_INLINE_COMMENTS=0'] }, 'stop_on_first_error': { 'args': ['-DINI_STOP_ON_FIRST_ERROR=1'] }, 'handler_lineno': { 'args': ['-DINI_HANDLER_LINENO=1'] }, 'string': { 'src': 'unittest_string.c', 'args': ['-DINI_MAX_LINE=20'] }, 'heap': { 'args': ['-DINI_USE_STACK=0'] }, 'heap_max_line': { 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20'] }, 'heap_realloc': { 'args': ['-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5'] }, 'heap_realloc_max_line': { 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5'] }, 'heap_string': { 'src': 'unittest_string.c', 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20'] }, 'call_handler_on_new_section': { 'args': ['-DINI_CALL_HANDLER_ON_NEW_SECTION=1'] }, 'allow_no_value': { 'args': ['-DINI_ALLOW_NO_VALUE=1'] }, 'alloc': { 'src': 'unittest_alloc.c', 'args': ['-DINI_CUSTOM_ALLOCATOR=1', '-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=12'] } } foreach name, properties : tests test_src = 'src' in properties ? properties['src'] : 'unittest.c' exe = executable('unittest_' + name, src_inih, test_src, c_args : ['-Wall', properties['args']]) test('test_' + name, runtest, depends : [exe], args : [files('baseline_' + name + '.txt'), exe.full_path()]) endforeach inih-r59/tests/multi_line.ini000066400000000000000000000004331477210556600164430ustar00rootroot00000000000000[section1] single1 = abc multi = this is a multi-line value single2 = xyz [section2] multi = a b c [section3] single: ghi multi: the quick brown fox name = bob smith ; comment line 1 ; comment line 2 foo = bar ;c1 Hi World ;c2 inih-r59/tests/no_value.ini000066400000000000000000000001261477210556600161110ustar00rootroot00000000000000[section_list] section0 section1 [section0] key0=val0 [section1] key1=val1 inih-r59/tests/normal.ini000066400000000000000000000013551477210556600155760ustar00rootroot00000000000000; This is an INI file [section1] ; section comment one=This is a test ; name=value comment two = 1234 ; x=y [ section 2 ] happy = 4 sad = [empty] ; do nothing [comment_test] test1 = 1;2;3 ; only this will be a comment test2 = 2;3;4;this won't be a comment, needs whitespace before ';' test;3 = 345 ; key should be "test;3" test4 = 4#5#6 ; '#' only starts a comment at start of line #test5 = 567 ; entire line commented # test6 = 678 ; entire line commented, except in MULTILINE mode test7 = ; blank value, except if inline comments disabled test8 =; not a comment, needs whitespace before ';' [colon_tests] Content-Type: text/html foo:bar adams : 42 funny1 : with = equals funny2 = with : colons funny3 = two = equals funny4 : two : colons inih-r59/tests/runtest.sh000077500000000000000000000001251477210556600156420ustar00rootroot00000000000000#!/usr/bin/env bash set -euo pipefail cd "$(dirname "${1}")" diff "${1}" <("${2}") inih-r59/tests/unittest.bat000066400000000000000000000030051477210556600161460ustar00rootroot00000000000000@call tcc ..\ini.c -I..\ -run unittest.c > baseline_multi.txt @call tcc ..\ini.c -I..\ -DINI_MAX_LINE=20 -run unittest.c > baseline_multi_max_line.txt @call tcc ..\ini.c -I..\ -DINI_ALLOW_MULTILINE=0 -run unittest.c > baseline_single.txt @call tcc ..\ini.c -I..\ -DINI_ALLOW_INLINE_COMMENTS=0 -run unittest.c > baseline_disallow_inline_comments.txt @call tcc ..\ini.c -I..\ -DINI_STOP_ON_FIRST_ERROR=1 -run unittest.c > baseline_stop_on_first_error.txt @call tcc ..\ini.c -I..\ -DINI_HANDLER_LINENO=1 -run unittest.c > baseline_handler_lineno.txt @call tcc ..\ini.c -I..\ -DINI_USE_STACK=0 -run unittest.c > baseline_heap.txt @call tcc ..\ini.c -I..\ -DINI_USE_STACK=0 -DINI_MAX_LINE=20 -DINI_INITIAL_ALLOC=20 -run unittest.c > baseline_heap_max_line.txt @call tcc ..\ini.c -I..\ -DINI_USE_STACK=0 -DINI_ALLOW_REALLOC=1 -DINI_INITIAL_ALLOC=5 -run unittest.c > baseline_heap_realloc.txt @call tcc ..\ini.c -I..\ -DINI_USE_STACK=0 -DINI_MAX_LINE=20 -DINI_ALLOW_REALLOC=1 -DINI_INITIAL_ALLOC=5 -run unittest.c > baseline_heap_realloc_max_line.txt @call tcc ..\ini.c -I..\ -DINI_USE_STACK=0 -DINI_MAX_LINE=20 -DINI_INITIAL_ALLOC=20 -run unittest.c > baseline_heap_string.txt @call tcc ..\ini.c -I..\ -DINI_CALL_HANDLER_ON_NEW_SECTION=1 -run unittest.c > baseline_call_handler_on_new_section.txt @call tcc ..\ini.c -I..\ -DINI_ALLOW_NO_VALUE=1 -run unittest.c > baseline_allow_no_value.txt @call tcc ..\ini.c -I..\ -DINI_CUSTOM_ALLOCATOR=1 -DINI_USE_STACK=0 -DINI_ALLOW_REALLOC=1 -DINI_INITIAL_ALLOC=12 -run unittest_alloc.c > baseline_alloc.txt inih-r59/tests/unittest.c000066400000000000000000000036771477210556600156410ustar00rootroot00000000000000/* inih -- tests This works simply by dumping a bunch of info to standard output, which is redirected to an output file (baseline_*.txt) and checked into the Git repository. This baseline file is the test output, so the idea is to check it once, and if it changes -- look at the diff and see which tests failed. See unittest.bat and unittest.sh for how to run this (with tcc and gcc, respectively). */ #include #include #include #include "../ini.h" int User; char Prev_section[50]; #if INI_HANDLER_LINENO int dumper(void* user, const char* section, const char* name, const char* value, int lineno) #else int dumper(void* user, const char* section, const char* name, const char* value) #endif { User = *((int*)user); if (!name || strcmp(section, Prev_section)) { printf("... [%s]\n", section); strncpy(Prev_section, section, sizeof(Prev_section)); Prev_section[sizeof(Prev_section) - 1] = '\0'; } if (!name) { return 1; } #if INI_HANDLER_LINENO printf("... %s%s%s; line %d\n", name, value ? "=" : "", value ? value : "", lineno); #else printf("... %s%s%s;\n", name, value ? "=" : "", value ? value : ""); #endif if (!value) { // Happens when INI_ALLOW_NO_VALUE=1 and line has no value (no '=' or ':') return 1; } return strcmp(name, "user")==0 && strcmp(value, "parse_error")==0 ? 0 : 1; } void parse(const char* fname) { static int u = 100; int e; *Prev_section = '\0'; e = ini_parse(fname, dumper, &u); printf("%s: e=%d user=%d\n", fname, e, User); u++; } int main(void) { parse("no_file.ini"); parse("normal.ini"); parse("bad_section.ini"); parse("bad_comment.ini"); parse("user_error.ini"); parse("multi_line.ini"); parse("bad_multi.ini"); parse("bom.ini"); parse("duplicate_sections.ini"); parse("no_value.ini"); parse("long_section.ini"); return 0; } inih-r59/tests/unittest.sh000077500000000000000000000051171477210556600160230ustar00rootroot00000000000000#!/usr/bin/env bash CC="${CC:-gcc} -Wall" $CC ../ini.c unittest.c -o unittest_multi ./unittest_multi > baseline_multi.txt rm -f unittest_multi $CC ../ini.c -DINI_MAX_LINE=20 unittest.c -o unittest_multi_max_line ./unittest_multi_max_line > baseline_multi_max_line.txt rm -f unittest_multi_max_line $CC ../ini.c -DINI_ALLOW_MULTILINE=0 unittest.c -o unittest_single ./unittest_single > baseline_single.txt rm -f unittest_single $CC ../ini.c -DINI_ALLOW_INLINE_COMMENTS=0 unittest.c -o unittest_disallow_inline_comments ./unittest_disallow_inline_comments > baseline_disallow_inline_comments.txt rm -f unittest_disallow_inline_comments $CC ../ini.c -DINI_STOP_ON_FIRST_ERROR=1 unittest.c -o unittest_stop_on_first_error ./unittest_stop_on_first_error > baseline_stop_on_first_error.txt rm -f unittest_stop_on_first_error $CC ../ini.c -DINI_HANDLER_LINENO=1 unittest.c -o unittest_handler_lineno ./unittest_handler_lineno > baseline_handler_lineno.txt rm -f unittest_handler_lineno $CC ../ini.c -DINI_MAX_LINE=20 unittest_string.c -o unittest_string ./unittest_string > baseline_string.txt rm -f unittest_string $CC ../ini.c -DINI_USE_STACK=0 unittest.c -o unittest_heap ./unittest_heap > baseline_heap.txt rm -f unittest_heap $CC ../ini.c -DINI_USE_STACK=0 -DINI_MAX_LINE=20 -DINI_INITIAL_ALLOC=20 unittest.c -o unittest_heap_max_line ./unittest_heap_max_line > baseline_heap_max_line.txt rm -f unittest_heap_max_line $CC ../ini.c -DINI_USE_STACK=0 -DINI_ALLOW_REALLOC=1 -DINI_INITIAL_ALLOC=5 unittest.c -o unittest_heap_realloc ./unittest_heap_realloc > baseline_heap_realloc.txt rm -f unittest_heap_realloc $CC ../ini.c -DINI_USE_STACK=0 -DINI_MAX_LINE=20 -DINI_ALLOW_REALLOC=1 -DINI_INITIAL_ALLOC=5 unittest.c -o unittest_heap_realloc_max_line ./unittest_heap_realloc_max_line > baseline_heap_realloc_max_line.txt rm -f unittest_heap_realloc_max_line $CC ../ini.c -DINI_USE_STACK=0 -DINI_MAX_LINE=20 -DINI_INITIAL_ALLOC=20 unittest_string.c -o unittest_heap_string ./unittest_heap_string > baseline_heap_string.txt rm -f unittest_heap_string $CC ../ini.c -DINI_CALL_HANDLER_ON_NEW_SECTION=1 unittest.c -o unittest_call_handler_on_new_section ./unittest_call_handler_on_new_section > baseline_call_handler_on_new_section.txt rm -f unittest_call_handler_on_new_section $CC ../ini.c -DINI_ALLOW_NO_VALUE=1 unittest.c -o unittest_allow_no_value ./unittest_allow_no_value > baseline_allow_no_value.txt rm -f unittest_allow_no_value $CC -DINI_CUSTOM_ALLOCATOR=1 -DINI_USE_STACK=0 -DINI_ALLOW_REALLOC=1 -DINI_INITIAL_ALLOC=12 ../ini.c unittest_alloc.c -o unittest_alloc ./unittest_alloc > baseline_alloc.txt rm -f unittest_alloc inih-r59/tests/unittest_alloc.c000066400000000000000000000020651477210556600170010ustar00rootroot00000000000000/* inih -- tests with custom memory allocator */ #include #include #include #include "../ini.h" void* ini_malloc(size_t size) { printf("ini_malloc(%d)\n", (int)size); return malloc(size); } void ini_free(void* ptr) { printf("ini_free()\n"); free(ptr); } void* ini_realloc(void* ptr, size_t size) { printf("ini_realloc(%d)\n", (int)size); return realloc(ptr, size); } char Prev_section[50]; int dumper(void* user, const char* section, const char* name, const char* value) { if (strcmp(section, Prev_section)) { printf("... [%s]\n", section); strncpy(Prev_section, section, sizeof(Prev_section)); Prev_section[sizeof(Prev_section) - 1] = '\0'; } printf("... %s=%s;\n", name, value); return 1; } void parse(const char* name, const char* string) { int e; *Prev_section = '\0'; e = ini_parse_string(string, dumper, NULL); printf("%s: e=%d\n", name, e); } int main(void) { parse("basic", "[section]\nfoo = bar\nbazz = buzz quxx"); return 0; } inih-r59/tests/unittest_string.c000066400000000000000000000021621477210556600172130ustar00rootroot00000000000000/* inih -- tests for ini_parse_string() */ #include #include #include #include "../ini.h" int User; char Prev_section[50]; int dumper(void* user, const char* section, const char* name, const char* value) { User = *((int*)user); if (strcmp(section, Prev_section)) { printf("... [%s]\n", section); strncpy(Prev_section, section, sizeof(Prev_section)); Prev_section[sizeof(Prev_section) - 1] = '\0'; } printf("... %s=%s;\n", name, value); return 1; } void parse(const char* name, const char* string) { static int u = 100; int e; *Prev_section = '\0'; e = ini_parse_string(string, dumper, &u); printf("%s: e=%d user=%d\n", name, e, User); u++; } int main(void) { parse("empty string", ""); parse("basic", "[section]\nfoo = bar\nbazz = buzz quxx"); parse("crlf", "[section]\r\nhello = world\r\nforty_two = 42\r\n"); parse("long line", "[sec]\nfoo = 01234567890123456789\nbar=4321\n"); parse("long continued", "[sec]\nfoo = 0123456789012bix=1234\n"); parse("error", "[s]\na=1\nb\nc=3"); return 0; } inih-r59/tests/user_error.ini000066400000000000000000000000511477210556600164650ustar00rootroot00000000000000[section] a = b user = parse_error c = d