A config file parser written in C. Super light weight.
@brief: Load a config file
@param[in] DIR: Config file
@returns: int\ The number of loaded config options
-1\ Error
@brief: Get a value by key (string)
@param[in] key: Config key
@returns: const char *\ The pointer of the result string
NULL\ No correspond value
@brief: Check if value is true
@param[in] key: Config key
@returns: 0\ False
1\ True
-1\ No correspond value or it's not a true/false string
@brief: Print all the config options
@brief: Free the memory where the loaded config options saved
The following is an example of the config.ini file. We will use cCONFIG library to parse this file.
# Number of LEDs
led_number=12
# LED IC model
led_model=APA102
# Animations
on_idle=true
on_listen=false1. Copy the cCONFIG.h and cCONFIG.c to your project folder.
2. Include the head file from where you would use this library.
#include "cCONFIG.h"3. Call cCONFIG_Parse_Config("your_config_file") function with the config.ini file name as input.
cCONFIG_Parse_Config("config.ini.test");4. Call cCONFIG_Dump() function to check if the config options are correctly loaded.
cCONFIG_Dump();You should see the following output if you are using the example config content.
--------------------------------------
| No. | KEY | VALUE |
|-----|-----------------|------------|
| 1 | led_number | 12 |
| 2 | led_model | APA102 |
| 3 | on_idle | true |
| 4 | on_listen | false |
--------------------------------------5. [Important] Delete the config list before your program is terminated.
cCONFIG_Delete_List();(All the loaded config info is save in a dynamic link list, without calling this function, your program will cause a memory leakage)
Contributions are welcome! Not familiar with the codebase yet? No problem!
There are many ways to contribute to open source projects: reporting bugs, helping with the documentation, spreading the word and of course, adding new features and patches.
- Make sure you have a GitHub account.
- Open a new issue, assuming one does not already exist.
- Clearly describe the issue including steps to reproduce when it is a bug.
- Fork this repository.
- Create a feature branch from where you want to base your work.
- Make commits of logical units (if needed rebase your feature branch before submitting it).
- Check for unnecessary whitespace with
git diff --checkbefore committing. - Make sure your commit messages are well formatted.
- If your commit fixes an open issue, reference it in the commit message (f.e.
#15). - Run all the tests (if existing) to assure nothing else was accidentally broken.
These guidelines also apply when helping with documentation.
- Push your changes to a feature branch in your fork of the repository.
- Submit a
Pull Request. - Wait for maintainer feedback.