My Project
 
Loading...
Searching...
No Matches
config.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

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)
 
int getNameValuePair (char *str, char leftDelimiterPos, char rightDelimiterPos, char **name, char **value, int sizeName, int sizeValue)
 
int parseConfig (char *originalBuffer, struct configEntry **entry, int configSizeCount, int *returnedCount)
 

Function Documentation

◆ checkSection()

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:

Parameters
char**str: the string to check
chardelimiterLeft: the left delimiter to check for
chardelimiterRight: the right delimiter to check for

Output:

Parameters
char**sectionName: if found the section Name of the section

Return:

Parameters
intstatus_code: one of the following values:

Definition at line 24 of file config.c.

◆ getNameValuePair()

int getNameValuePair ( char * str,
char leftDelimiterPos,
char rightDelimiterPos,
char ** name,
char ** value,
int sizeName,
int sizeValue )

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

Definition at line 151 of file config.c.

◆ getStrAtPos()

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

Definition at line 98 of file config.c.

◆ parseConfig()

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.

Definition at line 215 of file config.c.