Пример #1
0
//读取配置文件
void parseconf_load_file(const char *path)
{
	FILE *fp = fopen(path, "r");
	if (fp == NULL)
		ERR_EXIT("fopen");

	char setting_line[1024] = {0};
	while (fgets(setting_line, sizeof(setting_line), fp) != NULL)
	{
        //去掉空行、全是空格的、以#号开头的注释行
		if (strlen(setting_line) == 0
			|| setting_line[0] == '#'
			|| str_all_space(setting_line))
			continue;

        //去掉后面的/r/n
		str_trim_crlf(setting_line);

        //解析配置信息
		parseconf_load_setting(setting_line);
		memset(setting_line, 0, sizeof(setting_line));
	}

	fclose(fp);
}
Пример #2
0
void parseconf_load_file(const char *path){
	FILE *fp = fopen(path, "r");
	if(fp == NULL) ERR_EXIT("fopen");
	
	char setting_line[MAX_SETTING_LINE] = {0};
	while(fgets(setting_line, sizeof(setting_line), fp) != NULL){
		if(strlen(setting_line) == 0 
			|| setting_line[0] == '#'
			|| str_all_space(setting_line))
			continue;
		str_trim_crlf(setting_line);
		parseconf_load_setting(setting_line);
		memset(setting_line, 0, sizeof setting_line);
	}
	fclose(fp);

}
Пример #3
0
/*
* parseconf_load_file -- 加载配置文件配置
* 参数:
    @path: 配置文件路径
*/
void parseconf_load_file(const char *path)
{
    FILE *fp = fopen(path, "r");
    if(fp == NULL)
        handle_error("fopen");
    char setting_line[1024] = {0};

    while(fgets(setting_line, sizeof(setting_line), fp) != NULL)
    {
        if((strlen(setting_line) == 0) ||
            (setting_line[0] == '#') ||
            str_all_space(setting_line))
            {
                memset(setting_line, 0, sizeof(setting_line));
                continue;
            }
        //将得到的有效字符串去除\r\n
        str_trim_crlf(setting_line);
        //解析配置行,将信息保存在对应的变量中
        parseconf_load_setting(setting_line);
        memset(setting_line, 0, sizeof(setting_line));
    }
    fclose(fp);
}