Files
config-parser/test.c
jonathan santis 4c2e79638d add configparser
2025-05-13 16:55:07 +02:00

73 lines
1.8 KiB
C

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "file.h"
int main(void)
{
char teststr[] = "sdafsdfsdf[12345asdfddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd]";
char *name = NULL;
char *sectionName=NULL;
int ret=0;
name = malloc(MAX_LEN_SECTIONNAME*sizeof(char));
getStrAtPos(teststr, 11, 15, &name, MAX_LEN_SECTIONNAME);
sectionName = malloc(MAX_LEN_SECTIONNAME*sizeof(char));
if((ret=checkSection(teststr,'[',']', &sectionName)) == FOUND_SECTION)
{
printf("checkSection sucessfull\nsectionName=%s\n",sectionName);
}
else
{
printf("an error occured:%d\n",ret);
}
char testpair[] = "asifdsfo=s1254124";
char *keyName=NULL;
char *keyValue=NULL;
char *content=NULL;
keyName = malloc(MAX_LEN_SECTIONNAME);
keyValue = malloc(MAX_LEN_SECTIONNAME);
if((ret=getNameValuePair(testpair,
'=',0,
&keyName,&keyValue,
MAX_LEN_SECTIONNAME,MAX_LEN_SECTIONNAME))==NO_ERROR)
{
printf("keyname:%s Value: %s\n",keyName,keyValue);
}else{
printf("error getNameValuePair: %d\n",ret);
}
long neededSize=0;
if((ret=getFile("config.cfg",NULL,0,&neededSize))==NO_ERROR)
{
printf("sucessfull retrieved size:%ld\n",neededSize);
}
else {
printf("Error on getFile:%d\n",ret);
}
content = malloc(neededSize);
if((ret=getFile("config.cfg",&content,neededSize,&neededSize))==NO_ERROR)
{
printf("Sucessfull read file into buffer:%s\n---\n",content);
}
else {
printf("Error on getFile:%d\n",ret);
}
parseConfig(content,&entry,sizeEntry);
free(keyValue);
free(keyName);
free(name);
}