Go to the source code of this file.
Functions | |
| int | checkSection (char *str, char delimiterLeft, char delimiterRight, char **sectionName) |
| Here we check if the given string contains a section for example [SECTIONName] here delimiterLeft is [ and delimiterRight is ] if a section is found, the section name will be written to sectionName. | |
| int | getStrAtPos (char *str, int fromPos, int toPos, char **name, int sizeName) |
| Here we get / cut from fromPos to toPos and write it to an address. | |
| int | getNameValuePair (char *str, char leftDelimiterPos, char rightDelimiterPos, char **name, char **value, int sizeName, int sizeValue) |
| Input: | |
| int | parseConfig (char *originalBuffer, struct configEntry **entry, int configSizeCount, int *returnedCount) |
| int checkSection | ( | char * | str, |
| char | delimiterLeft, | ||
| char | delimiterRight, | ||
| char ** | sectionName ) |
Here we check if the given string contains a section for example [SECTIONName] here delimiterLeft is [ and delimiterRight is ] if a section is found, the section name will be written to sectionName.
Input:
| char | **str: the string to check |
| char | delimiterLeft: the left delimiter to check for |
| char | delimiterRight: the right delimiter to check for |
Output:
| char | **sectionName: if found the section Name of the section |
Return:
| int | status_code: one of the following values: |
| int getNameValuePair | ( | char * | str, |
| char | leftDelimiterPos, | ||
| char | rightDelimiterPos, | ||
| char ** | name, | ||
| char ** | value, | ||
| int | sizeName, | ||
| int | sizeValue ) |
Input:
Here we get a "pair" of data, parsed from *str, witch consists of a keyname and a keyvalue. These are written to the pointers at char **name and char **value. These pair can be in the form of:
ex1:
NAME=VALUE
____^_____^
____|_____Here we have no delimiter this means rightDelimiterPos must be NULL
____This is the left delimiter
ex2:
name(value)
____^_____^
____|_____This is the rightDelimiterPos and must be ')'
____This is leftDelimiterPos which must be '('
| char | *str: the line in the form of a string where a key value pair is stored |
| char | leftDelimiterPos: the left delimiter for example '=' |
| char | rightDelimiterPos: the right delimiter can be NULL in most cases, if NULL we assume that there is only one delimiter, which is in this case the leftDelimiterPos |
Output:
| char | **name: The address where we store the name of the Key |
| char | **value: The address where we store the key value |
| int | sizeName: for size checking against memory allocated at **name |
| int | sizeValue: for size checking against memory allocated at **value |
Return:
| int getStrAtPos | ( | char * | str, |
| int | fromPos, | ||
| int | toPos, | ||
| char ** | name, | ||
| int | sizeName ) |
Here we get / cut from fromPos to toPos and write it to an address.
Input:
| char | *str: the string to cut |
| int | fromPos: from which position we want to copy, the pos is included and zero indexed |
| int | toPos: to which position we want to copy, the pos is included and zero indexed |
Output:
| char | **name: here we will write the section name to |
Input:
| int | sizeName: the size of the user allocated buffer at **name |
| int parseConfig | ( | char * | originalBuffer, |
| struct configEntry ** | entry, | ||
| int | configSizeCount, | ||
| int * | returnedCount ) |
Given a null terminated buffer of content(ex. from a file) an parse it with a default syntax of: Sections -> [SECTIONNAME] name / value -> name=value
Input: char *originalBuffer: the buffer which holds the string for parsing. struct configEntry **entry: a user allocated buffer to which we write the parsed config data. int configSizeCount: the user allocated size of **entry. Output: int *returnedCount: to this variable the function writes the count of struct, which will be required to store all alavaible data.
Note: The funtion returns the maximum allowed data structures, determined by configSizeCount. All data which exceeds will be dropped. To get the whole data we run the funtion a second time with the realloced configSizeCount in the size of [returnedCount] structures.