From 066e42494820ccf9ff15deba88f8cdf99d8302e1 Mon Sep 17 00:00:00 2001 From: Li Bo Date: Tue, 20 Jun 2023 13:35:52 +0800 Subject: [PATCH] 0.0.1: release to esp-registry --- .github/workflows/upload_component.yml | 20 ++++ CHANGELOG.md | 6 ++ README.md | 131 +++---------------------- idf_component.yml | 8 ++ ini_config.h | 4 +- tests/unittest.c | 2 +- 6 files changed, 49 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/upload_component.yml create mode 100644 CHANGELOG.md create mode 100644 idf_component.yml diff --git a/.github/workflows/upload_component.yml b/.github/workflows/upload_component.yml new file mode 100644 index 0000000..52394f7 --- /dev/null +++ b/.github/workflows/upload_component.yml @@ -0,0 +1,20 @@ +name: Push components to Espressif Component Service + +on: + push: + branches: + - master + +jobs: + upload_components: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + with: + submodules: 'recursive' + - name: Upload components to component service + uses: espressif/upload-components-ci-action@v1 + with: + name: "esp-inih" + namespace: "leeebo" + api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..38653ca --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# ChangeLog + +## v0.0.1 - 2023-06-20 + +* Initial version (base version [d6e9d1](https://github.com/benhoyt/inih/commit/d6e9d1ba68148060d5614145eb566b94fc0d532f)), test pass on ESP32S3 +* Add Kconfig support \ No newline at end of file diff --git a/README.md b/README.md index 4e6e536..8aeecb3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -# inih (INI Not Invented Here) +# esp-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) +[![Tests](https://github.com/leeebo/esp-inih/actions/workflows/tests.yml/badge.svg)](https://github.com/leeebo/esp-inih/actions/workflows/tests.yml) + +**This is a ESP-IDF component warpped version of [inih](https://github.com/benhoyt/inih), which can be directly used in ESP-IDF projects.** **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. @@ -8,42 +10,17 @@ To use it, just give `ini_parse()` an INI file, and it will call a callback for 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. +## Compile-time options -### Parsing options ### +You can using `idf.py menuconfig` to configure all the compile-time options. the options are is decribed in [compile-time-options](https://github.com/benhoyt/inih#compile-time-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 ## +## Simple example in C ```c #include #include #include -#include "../ini.h" +#include "ini.h" typedef struct { @@ -70,7 +47,7 @@ static int handler(void* user, const char* section, const char* name, return 1; } -int main(int argc, char* argv[]) +void app_main(void) { configuration config; @@ -84,92 +61,6 @@ int main(int argc, char* argv[]) } ``` +## Related links -## 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 (INI Not Invented Here)](https://github.com/benhoyt/inih) diff --git a/idf_component.yml b/idf_component.yml new file mode 100644 index 0000000..45d10f1 --- /dev/null +++ b/idf_component.yml @@ -0,0 +1,8 @@ +version: "0.0.1" +description: Simple .INI file parser written in C, portting for ESP-IDF +url: https://github.com/leeebo/esp-inih +repository: https://github.com/leeebo/esp-inih.git +documentation: https://github.com/leeebo/esp-inih +issues: https://github.com/leeebo/esp-inih/issues +dependencies: + idf: ">=4.4" \ No newline at end of file diff --git a/ini_config.h b/ini_config.h index d30d915..db2c95c 100644 --- a/ini_config.h +++ b/ini_config.h @@ -5,6 +5,7 @@ */ #pragma once +#ifdef CONFIG_IDF_TARGET #include "sdkconfig.h" /* Nonzero if ini_handler callback should accept lineno parameter. */ @@ -62,4 +63,5 @@ 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. */ -#define INI_CUSTOM_ALLOCATOR CONFIG_INI_CUSTOM_ALLOCATOR \ No newline at end of file +#define INI_CUSTOM_ALLOCATOR CONFIG_INI_CUSTOM_ALLOCATOR +#endif \ No newline at end of file diff --git a/tests/unittest.c b/tests/unittest.c index e455efa..c0dd0f7 100644 --- a/tests/unittest.c +++ b/tests/unittest.c @@ -101,7 +101,7 @@ void spiffs_init(void) { void app_main(void) #else -#define BASE_PATH +#define BASE_PATH "." int main(void) #endif {