fix config parsing bug, where lines got overjumped
This commit is contained in:
parent
363e4fb05d
commit
272a1eaba9
7
config
7
config
@ -1,8 +1,11 @@
|
||||
[APP]
|
||||
Intervall = 5
|
||||
|
||||
[Host]
|
||||
Hostname = https://5ccppi.org:4433
|
||||
[Services]
|
||||
/org/freedesktop/systemd1/unit/NetworkManager_2dwait_2donline_2eservice
|
||||
/org/freedesktop/systemd1/unit/NetworkManager_2eservice
|
||||
/org/freedesktop/systemd1/unit/httpd_2eservice
|
||||
[APP]
|
||||
Intervall = 5
|
||||
as
|
||||
df
|
||||
|
23
config.c
23
config.c
@ -8,21 +8,24 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
|
||||
int i=0;
|
||||
FILE *f_config;
|
||||
char temp_str[256];
|
||||
char *ret = NULL;
|
||||
|
||||
printf("\nopening config file\n");
|
||||
f_config = fopen(str_file,"r");
|
||||
if(f_config != NULL)
|
||||
{
|
||||
while(fgets(temp_str,256,f_config)!=NULL)
|
||||
ret = fgets(temp_str,256,f_config);
|
||||
while(ret!=NULL)
|
||||
{
|
||||
temp_str[strcspn(temp_str,"\n")]=0;
|
||||
printf("first temp_str:%s\n",temp_str);
|
||||
if(strcmp(temp_str,"[Host]")==0)
|
||||
{
|
||||
printf("temp_str host:%s\n",temp_str);
|
||||
while(fgets(temp_str,256,f_config)!=NULL)
|
||||
while(ret!=NULL)
|
||||
{
|
||||
printf("temp_str:%s\n",temp_str);
|
||||
ret = fgets(temp_str,256,f_config);
|
||||
if(strchr(temp_str,'[')==NULL)
|
||||
{
|
||||
printf("strchr\n");
|
||||
@ -42,14 +45,16 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if(strcmp(temp_str,"[Services]")==0)
|
||||
{
|
||||
for(i=0;i<size;i++)
|
||||
{
|
||||
ret=fgets(temp_str,256,f_config);
|
||||
printf("for loop:%d\n",i);
|
||||
if(fgets(temp_str,256,f_config)!=NULL)
|
||||
if(ret!=NULL)
|
||||
{
|
||||
if(strchr(temp_str,'[')==NULL)
|
||||
{
|
||||
@ -65,18 +70,21 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if(strcmp(temp_str,"[APP]")==0)
|
||||
{
|
||||
while(fgets(temp_str,256,f_config)!=NULL)
|
||||
while(ret!=NULL)
|
||||
{
|
||||
ret = fgets(temp_str,256,f_config);
|
||||
printf("temp_str:%s\n",temp_str);
|
||||
if(strchr(temp_str,'[')==NULL)
|
||||
{
|
||||
if(strstr(temp_str,"Intervall")!=NULL)
|
||||
{
|
||||
char *ptr_intervall = strrchr(temp_str,'=')+1;//Without =
|
||||
ptr_intervall[strcspn(ptr_intervall,"p\n")]=0;
|
||||
ptr_intervall[strcspn(ptr_intervall,"\n")]=0;
|
||||
while(ptr_intervall[0]==' ')
|
||||
{
|
||||
ptr_intervall = ptr_intervall + 1;
|
||||
@ -84,12 +92,15 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
|
||||
*intervall = atoi(ptr_intervall);
|
||||
printf("intervall:%d\n",*intervall);
|
||||
}else{
|
||||
fprintf(stderr,"keyword Intervall not found in config");
|
||||
fprintf(stderr,"keyword Intervall not found in config\n");
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
ret = fgets(temp_str,256,f_config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user