Skip to content

Commit

Permalink
Merge pull request #4 from SamHerts/main
Browse files Browse the repository at this point in the history
Fix character pointer bug
  • Loading branch information
MichaelBrim authored Oct 22, 2024
2 parents 24af616 + ab86f18 commit de6c466
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
11 changes: 8 additions & 3 deletions configurator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ target_include_directories(nanojsonc_lib PUBLIC ${nanojsonc_SOURCE_DIR}/include)
# Combine third party libraries for easier access
set(NEEDED_LIBS inih_lib tinyexpr_lib nanojsonc_lib)

add_library(configurator STATIC ${configurator_sources})
target_link_libraries(configurator PRIVATE ${NEEDED_LIBS})

# Configurator_cpp target
add_executable(Configurator_cpp ${configurator_sources} testpp.cpp)
target_link_libraries(Configurator_cpp PRIVATE ${NEEDED_LIBS})
add_executable(Configurator_cpp testpp.cpp)
target_include_directories(Configurator_cpp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(Configurator_cpp PRIVATE configurator ${NEEDED_LIBS})

# Configurator_c target
add_executable(Configurator_c ${configurator_sources} test.c)
target_link_libraries(Configurator_c PRIVATE ${NEEDED_LIBS} m)
target_include_directories(Configurator_c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(Configurator_c PRIVATE configurator ${NEEDED_LIBS} m)
42 changes: 40 additions & 2 deletions configurator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ the order of precedence is: (higher numbers have greater priority)
## CMake
CMake can be used to download and install the necessary libraries as well

## Usage
## Setup

The following macros are used to define configuration options:
* `PREFIX_CFG( section, key, type, default-value, description)`
Expand All @@ -50,7 +50,45 @@ In the macros, `type` is one of: `BOOL | FLOAT | INT | STRING`
- `FLOAT` values: scalars convertible to C double, or compatible tinyexpr expression
- `INT` values: scalars convertible to C long, or compatible tinyexpr expression

### Configuration files
## Usage
### configurator.h:
```c++
...
#define PREFIX_CONFIGS \
PREFIX_CFG_CLI(prefix, my_config_option, INT, NULL, "My INT Config Option", int, 'i', "Add an Integer to the configuration") \
...
```
### main.cpp:
```c++
#include <configurator.h>
int main(int argc, char* argv[])
{
int rc;
long l;
prefix_cfg_t my_config;
if( argc == 1 ) {
prefix_config_cli_usage(argv[0]);
return 1;
}
if( prefix_config_init(&mycfg, argc, argv)) {
fprintf(stderr, "prefix_config_init() failed - rc=%d (%s)\n", rc, strerror(rc));
return 1;
}
prefix_config_print(&my_config, stdout);
if( 0 == configurator_int_val(my_config.prefix_my_config_option, &l))
printf("My Config Option = %ld\n", l);
prefix_config_fini(&my_config);
return 0;
}
```

## Configuration files
Configuration files have .ini section-key-value format:
```
# whole-line comment
Expand Down
8 changes: 6 additions & 2 deletions configurator/configurator.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,15 @@ void json_config_handler(enum NanoJSONCError error, const char *const key, const

if(simple_section)
{
simple_section++;
simple_section[strlen(simple_section)-1] = '\0';
inih_config_handler(object, simple_section + sizeof(char), key, value);

}
else
{
inih_config_handler(object, NULL, key, value);
}

inih_config_handler(object, simple_section, key, value);
free(simple_section);
}

Expand Down

0 comments on commit de6c466

Please sign in to comment.