72 lines
1.8 KiB
C
72 lines
1.8 KiB
C
#include"config.h"
|
|
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
|
|
int loadConfig(char *str_file, char **str_entry,int size)
|
|
{
|
|
int i=0;
|
|
FILE *f_config;
|
|
char temp_str[256];
|
|
|
|
printf("\nopening config file\n");
|
|
f_config = fopen(str_file,"r");
|
|
if(f_config != NULL)
|
|
{
|
|
while(fgets(temp_str,256,f_config)!=NULL)
|
|
{
|
|
temp_str[strcspn(temp_str,"\n")]=0;
|
|
printf("while\n");
|
|
if(strcmp(temp_str,"[Host]")==0)
|
|
{
|
|
if(fgets(temp_str,256,f_config)!=NULL)
|
|
{
|
|
char host[256];
|
|
char *ptr_host = strrchr(temp_str,'=')+1;
|
|
strncpy(host,ptr_host,256);
|
|
printf("my host is:%s\n",host);
|
|
}
|
|
}
|
|
else if(strcmp(temp_str,"[Services]")==0)
|
|
{
|
|
for(i=0;i<size;i++)
|
|
{
|
|
printf("for loop:%d\n",i);
|
|
if(fgets(temp_str,256,f_config)!=NULL)
|
|
{
|
|
if(strchr(temp_str,'[')==NULL)
|
|
{
|
|
temp_str[strcspn(temp_str,"\n")]=0;
|
|
str_entry[i]=strdup(temp_str);
|
|
printf("module path:%s",str_entry[i]);
|
|
}else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
fclose(f_config);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr,"error opening file[%s]\n",str_file);
|
|
}
|
|
return 0;
|
|
}
|
|
/*int parseConfig(File *file, char *str_entry)
|
|
{
|
|
char sub_str[256];
|
|
if(strcmp(str_entry,"[Host]")==0)//section
|
|
{
|
|
fgets(sub_str,256,file);
|
|
|
|
//do sub parsing
|
|
}
|
|
}*/
|