LINE_TYPE line_type_get(char *p_line) { p_line = ini_skip_spaces(p_line); if(!p_line || !(*p_line)) return(LINE_NONE); if(p_line[0] == SECTION_NAME_START) { return(LINE_SECTION_START); } else if(p_line[0] == SECTION_NAME_STOP) { return(LINE_SECTION_STOP); } else if(p_line[0] == SECTION_NAME_COMMENT2) { return(LINE_COMMENT); } else if(p_line[0] == SECTION_NAME_COMMENT[0]) { if(p_line[1] != '\0') { if(p_line[1] == SECTION_NAME_COMMENT[1]) return(LINE_COMMENT); if(p_line[1] == SECTION_NAME_COMMENT_START[1]) return(LINE_COMMENT_START); } } else if(p_line[0] == SECTION_NAME_COMMENT_STOP[0]) { if(p_line[1] != '\0' && p_line[1] == SECTION_NAME_COMMENT_STOP[1]) return(LINE_COMMENT_STOP); } else if(p_line[0] == SECTION_NAME_INCLUDE[0] && !strncasecmp(p_line, SECTION_NAME_INCLUDE, strlen(SECTION_NAME_INCLUDE))) { return(LINE_SECTION_INCLUDE); } return(LINE_SECTION_ITEM); }
/* Check if the given string is a section (a string between []) */ int is_section(const char *p_line) { char *p_start = ini_skip_spaces((char *)p_line); if(p_start[0] != '[') return(FALSE); return(strchr(p_start+1,']') != NULL); }
char *ini_skip_separator(char *p_line, char separator) { char *p_tmp = strchr(p_line, separator); if (p_tmp) { return (ini_skip_spaces(p_tmp + 1)); } else { return (NULL); } }
char *ini_read_param(char *p_line, char *p_param, int max_len) { char *p_start = p_param; int i = 0; p_line = ini_skip_spaces(p_line); while (*p_line && i < max_len - 1 && !ini_is_space(*p_line) && !ini_is_separator(*p_line)) { *p_param++ = *p_line++; i++; } *p_param = '\0'; return (p_start); }
/* Reading section (between []) from file */ char * read_section(char *p_line, char *p_section, int max_len) { char *p_start = ini_skip_spaces(p_line); char *p_end; if(p_start[0] != '[') return(NULL); p_start++; if(!(p_end = strchr(p_start,']'))) return(NULL); int len = p_end - p_start; if(len+1 >= max_len) return(NULL); strncpy(p_section, p_start, len); p_section[len] = '\0'; return(p_section); }
bool is_empty(const char *p_line) { char *p_start = ini_skip_spaces((char *)p_line); return(!p_start[0]); }