update doc

This commit is contained in:
jonathan santis
2025-05-21 09:46:06 +02:00
parent 094a9801cf
commit a05c9ce786
9 changed files with 306 additions and 96 deletions

132
config.c
View File

@@ -5,21 +5,21 @@
#include<errno.h>
/**
* @brief 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
*
* @brief Input:
* @param char **str: the string to check
* @param char delimiterLeft: the left delimiter to check for
* @param char delimiterRight: the right delimiter to check for
*
* @brief Output:
* @param char **sectionName: if found the section Name of the section
*
* @brief Return:
* @param int status_code: one of the following values:
*
@brief 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
@brief Input:
@param char **str: the string to check
@param char delimiterLeft: the left delimiter to check for
@param char delimiterRight: the right delimiter to check for
@brief Output:
@param char **sectionName: if found the section Name of the section
@brief Return:
@param int status_code: one of the following values:
*/
int checkSection(char *str,char delimiterLeft,char delimiterRight,char **sectionName)
{
@@ -84,16 +84,16 @@ int checkSection(char *str,char delimiterLeft,char delimiterRight,char **section
}
/**
* 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
@brief Here we get / cut from fromPos to toPos and write it to an address
@brief Input:
@param char *str: the string to cut
@param int fromPos: from which position we want to copy, the pos is included and zero indexed
@param int toPos: to which position we want to copy, the pos is included and zero indexed
@brief Output:
@param char **name: here we will write the section name to
@brief Input:
@param int sizeName: the size of the user allocated buffer at **name
*/
int getStrAtPos(char *str,int fromPos,int toPos,char **name,int sizeName)
{
@@ -120,33 +120,33 @@ int getStrAtPos(char *str,int fromPos,int toPos,char **name,int sizeName)
}
/**
*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 '('
*
* Input:
* 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:
* will return NO_ERROR (0) if successfull.
* If not it will return the error of the subroutine
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: \n
ex1: \n
NAME=VALUE \n
____^_____^ \n
____|_____Here we have no delimiter this means rightDelimiterPos must be NULL \n
____This is the left delimiter \n
ex2: \n
name(value) \n
____^_____^ \n
____|_____This is the rightDelimiterPos and must be ')' \n
____This is leftDelimiterPos which must be '(' \n
@brief Input:
@param char *str: the line in the form of a string where a key value pair is stored
@param char leftDelimiterPos: the left delimiter for example '='
@param 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
@brief Output:
@param char **name: The address where we store the name of the Key
@param char **value: The address where we store the key value
@param int sizeName: for size checking against memory allocated at **name
@param int sizeValue: for size checking against memory allocated at **value
@brief Return:
@return will return NO_ERROR (0) if successfull.
If not it will return the error of the subroutine
*/
int getNameValuePair(char *str,char leftDelimiterPos,char rightDelimiterPos,char **name,char **value,int sizeName,int sizeValue)
{
@@ -197,20 +197,20 @@ int getNameValuePair(char *str,char leftDelimiterPos,char rightDelimiterPos,char
}
/**
* 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.
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.
*/
int parseConfig(char *originalBuffer,struct configEntry **entry,int configSizeCount,int *returnedCount)
{