//读取配置文件的内容
//获取配置文件的参数信息
bool read_configfile(
char* configfile, stCFG &ostCFG)
{
FILE* f;
char line[256];
char* p=(char*)NULL;
int iFinish = 0;
if ((f = fopen(configfile, "r")) == (FILE*)NULL)
{
printf("can not open file %s ", configfile);
return false;
}
while (fgets(line, 256, f)!=(char*)NULL)
{
if (line[0]=='#')
continue;
if ((p = strstr(line, "username")))
{
trim_whitespace(line);
strcpy(ostCFG.mysql_username, line+strlen("username"));
trim_whitespace(ostCFG.mysql_username);
iFinish++;
}
else if ((p = strstr(line, "password")))
{
trim_whitespace(line);
strcpy(ostCFG.mysql_password, line+strlen("password"));
trim_whitespace(ostCFG.mysql_password);
iFinish++;
}
else if ((p = strstr(line, "dbname")))
{
trim_whitespace(line);
strcpy(ostCFG.mysql_dbname, line+strlen("dbname"));
trim_whitespace(ostCFG.mysql_dbname);
iFinish++;
}
}
fclose(f);
//配置文件是不是正确得到了配置
if (NUM_PARA_IN_CFG != iFinish)
{
return false;
}
return true;
}