project_files/frontlib/util/inihelper.c
changeset 7467 a9ab8067a2d1
parent 7316 f7b49b2c5d84
child 10017 de822cd3df3a
equal deleted inserted replaced
7464:859ab6859854 7467:a9ab8067a2d1
   121 		free(ini->currentSection);
   121 		free(ini->currentSection);
   122 		ini->currentSection = NULL;
   122 		ini->currentSection = NULL;
   123 	}
   123 	}
   124 	if(!log_badargs_if2(ini==NULL, section==NULL)) {
   124 	if(!log_badargs_if2(ini==NULL, section==NULL)) {
   125 		if(!iniparser_find_entry(ini->inidict, section)) {
   125 		if(!iniparser_find_entry(ini->inidict, section)) {
       
   126 			flib_log_d("Ini section %s not found", section);
   126 			result = INI_ERROR_NOTFOUND;
   127 			result = INI_ERROR_NOTFOUND;
   127 		} else {
   128 		} else {
   128 			ini->currentSection = flib_strdupnull(section);
   129 			ini->currentSection = flib_strdupnull(section);
   129 			if(ini->currentSection) {
   130 			if(ini->currentSection) {
   130 				// Usually iniparser ignores case, but some section-handling functions don't,
   131 				// Usually iniparser ignores case, but some section-handling functions don't,
   141 	int result = INI_ERROR_OTHER;
   142 	int result = INI_ERROR_OTHER;
   142 	if(!log_badargs_if2(ini==NULL, section==NULL)) {
   143 	if(!log_badargs_if2(ini==NULL, section==NULL)) {
   143 		result = flib_ini_enter_section(ini, section);
   144 		result = flib_ini_enter_section(ini, section);
   144 		if(result == INI_ERROR_NOTFOUND) {
   145 		if(result == INI_ERROR_NOTFOUND) {
   145 			if(iniparser_set(ini->inidict, section, NULL)) {
   146 			if(iniparser_set(ini->inidict, section, NULL)) {
       
   147 				flib_log_e("Error creating ini section %s", section);
   146 				result = INI_ERROR_OTHER;
   148 				result = INI_ERROR_OTHER;
   147 			} else {
   149 			} else {
   148 				result = flib_ini_enter_section(ini, section);
   150 				result = flib_ini_enter_section(ini, section);
   149 			}
   151 			}
   150 		}
   152 		}
   254 	return result;
   256 	return result;
   255 }
   257 }
   256 
   258 
   257 int flib_ini_set_str(flib_ini *ini, const char *key, const char *value) {
   259 int flib_ini_set_str(flib_ini *ini, const char *key, const char *value) {
   258 	int result = INI_ERROR_OTHER;
   260 	int result = INI_ERROR_OTHER;
   259 	if(log_badargs_if4(ini==NULL, ini->currentSection==NULL, key==NULL, value==NULL)) {
   261 	if(!log_badargs_if4(ini==NULL, ini->currentSection==NULL, key==NULL, value==NULL)) {
   260 		char *dictKey = createDictKey(ini->currentSection, key);
   262 		char *dictKey = createDictKey(ini->currentSection, key);
   261 		if(dictKey) {
   263 		if(dictKey) {
   262 			result = iniparser_set(ini->inidict, dictKey, value);
   264 			result = iniparser_set(ini->inidict, dictKey, value);
       
   265 			if(result) {
       
   266 				flib_log_e("Error setting ini entry %s to %s", dictKey, value);
       
   267 			}
   263 		}
   268 		}
   264 		free(dictKey);
   269 		free(dictKey);
   265 	}
   270 	}
   266 	return result;
   271 	return result;
   267 }
   272 }