char *ini_read_string_section(FFILE f, const char *p_section, const char *p_template, char *p_out, int max_len, const char *p_default) { char line[MAX_TOKEN_LEN]; char section[MAX_TOKEN_LEN]; bool section_found = FALSE; fseek(f, 0, SEEK_SET); while (fgets(line, MAX_TOKEN_LEN, f)) { if(!section_found) { section_found = (bool)read_section(line, section, MAX_TOKEN_LEN); if(section_found) { section_found = !strncasecmp(p_section, section, MAX_TOKEN_LEN); } if(section_found) continue; } if(section_found && is_section(line)) { // we hit next section - so it's not found break; } if(section_found) { int len = is_token(line, p_template); char *p_rest; if (len && (p_rest = ini_skip_separator(line + len))) { return (ini_read_param(p_rest, p_out, max_len)); } } } return p_default ? (strcpy(p_out, p_default)) : NULL; }
float ini_read_float(FFILE f, const char *p_template, float dflt) { char line[MAX_TOKEN_LEN]; fseek(f, SEEK_SET, 0); while (fgets(line, MAX_TOKEN_LEN, f)) { int len = is_token(line, p_template); char *p_rest; if (len && (p_rest = ini_skip_separator(line + len))) { return (atof(ini_remove_end_of_line(p_rest))); } } return (dflt); }
char *ini_read_string(FFILE f, const char *p_template, char *p_out, int max_len, const char *p_default) { char line[MAX_TOKEN_LEN]; fseek(f, 0, SEEK_SET); while (fgets(line, MAX_TOKEN_LEN, f)) { int len = is_token(line, p_template); char *p_rest; if (len && (p_rest = ini_skip_separator(line + len))) { return (ini_read_param(p_rest, p_out, max_len)); } } return p_default ? (strcpy(p_out, p_default)) : NULL; }
bool tokenize_line_param(char *p_line, char *p_token, char *p_value) { if(p_token) { ini_read_param(p_line, p_token, MAX_TOKEN_LEN); } p_line = ini_skip_separator(p_line); if(!p_line) { return(FALSE); } if(p_value) { ini_read_param(p_line, p_value, MAX_TOKEN_LEN); } return((p_token == NULL || p_token[0]) && (p_value == NULL || p_value[0])); }
float ini_read_float(const char *p_file, const char *p_template, int dflt) { char line[MAX_TOKEN_LEN]; FFILE f(NULL, p_file, "r", FALSE); if (!f) return (dflt); while (fgets(line, MAX_TOKEN_LEN, f)) { int len = is_token(line, p_template); char *p_rest; if (len && (p_rest = ini_skip_separator(line + len))) { fclose(f); return (atof(ini_remove_end_of_line(p_rest))); } } fclose(f); return (dflt); }
char *ini_read_string(const char *p_file, const char *p_template, char *p_out, int max_len, const char *p_default) { char line[MAX_TOKEN_LEN]; FFILE f(NULL, p_file, "r", FALSE); if (!f) return (strcpy(p_out, p_default)); while (fgets(line, MAX_TOKEN_LEN, f)) { int len = is_token(line, p_template); char *p_rest; if (len && (p_rest = ini_skip_separator(line + len))) { fclose(f); return (ini_read_param(p_rest, p_out, max_len)); } } fclose(f); return (strcpy(p_out, p_default)); }