formats/ini/m_ini_reader.c
/* M_ini_reader_determine_type should be used to determine if this is a section before calling this function.
 * This function does not check that the input conforms to the type. */
M_ini_reader_determine_type should be used to determine if this is a section before calling this function.
This function does not check that the input conforms to the type.
M_ini_reader_determine_type should be used to determine if this is a section before calling this function . This function does not check that the input conforms to the type .
static M_bool M_ini_reader_parse_section(const char *line, const M_ini_settings_t *info, M_ini_element_t *elem)
{
	char          *s;
	char          *temp;
	size_t         len;
	size_t         i;
	unsigned char  comment_char = M_ini_settings_get_comment_char(info);
	M_bool         have_name    = M_FALSE;
	M_bool         have_comment = M_FALSE;
	(void)info;
	s = M_strdup(line);
	len = M_str_len(s);
	M_mem_move(s, s+1, len);
	s[len-1] = '\0';
	len--;
	for (i=0; i<len; i++) {
		if (s[i] == comment_char) {
			M_free(s);
			return M_FALSE;
		} else if (s[i] == ']') {
			have_name = M_TRUE;
			break;
		}
	}
	if (!have_name) {
		M_free(s);
		return M_FALSE;
	}
	temp = M_strdup_max(s, i);
	M_str_trim(temp);
	M_ini_element_section_set_name(elem, temp);
	M_free(temp);
	for (; i<len; i++) {
		if (s[i] == comment_char) {
			have_comment = M_TRUE;
			break;
		}
	}
	if (have_comment) {
		temp = M_strdup(s+i+1);
		M_str_trim(temp);
		M_ini_element_section_set_comment(elem, temp);
		M_free(temp);
	}
	M_free(s);
	return M_TRUE;
}
static M_bool M_ini_reader_parse_section ( const char * line , const M_ini_settings_t * info , M_ini_element_t * elem ) { char * s ; char * temp ; size_t len ; size_t i ; unsigned char comment_char = M_ini_settings_get_comment_char ( info ) ; M_bool have_name = M_FALSE ; M_bool have_comment = M_FALSE ; ( void ) info ; s = M_strdup ( line ) ; len = M_str_len ( s ) ; M_mem_move ( s , s + 1 , len ) ; s [ len - 1 ] = ' \0 ' ; len -- ; for ( i = 0 ; i < len ; i ++ ) { if ( s [ i ] == comment_char ) { M_free ( s ) ; return M_FALSE ; } else if ( s [ i ] == ' ' ) { have_name = M_TRUE ; break ; } } if ( ! have_name ) { M_free ( s ) ; return M_FALSE ; } temp = M_strdup_max ( s , i ) ; M_str_trim ( temp ) ; M_ini_element_section_set_name ( elem , temp ) ; M_free ( temp ) ; for ( ; i < len ; i ++ ) { if ( s [ i ] == comment_char ) { have_comment = M_TRUE ; break ; } } if ( have_comment ) { temp = M_strdup ( s + i + 1 ) ; M_str_trim ( temp ) ; M_ini_element_section_set_comment ( elem , temp ) ; M_free ( temp ) ; } M_free ( s ) ; return M_TRUE ; }
M_ini_reader_determine_type should be used to determine if this is a section before calling this function.
M_ini_reader_determine_type should be used to determine if this is a section before calling this function .
/* Remove the start framing ([) character. */ /* Find the end framing character (]). */ /* Section name can't include the comment character. */ /* Verify we actually have an end. */ /* Copy off the name. */ /* Look for comment. */