diff --git a/source/libublsettings.c b/source/libublsettings.c index c0d22fd..54061b5 100644 --- a/source/libublsettings.c +++ b/source/libublsettings.c @@ -71,8 +71,9 @@ dictionary *yon_dictionary_get_last(dictionary *dict) { if (dict->next){ dictionary *dct = NULL; - for_dictionaries(dct,dict); - return dct; + for_dictionaries(dct,dict) + if (!dct->next) + return dct; } else return dict; } @@ -836,12 +837,20 @@ yon_config_parameter *yon_config_parameter_append_with_data(yon_config_parameter static yon_config_parameter *__yon__config__strings = NULL; +static yon_config_parameter *__yon__config__default__strings = NULL; dictionary *__yon_config_ignored = NULL; #define check_config if(__yon__config__strings&&__yon__config__strings->data_type==DICTIONARY_CHAR_TYPE) +#define check_default_config if(__yon__config__default__strings) #define for_config dictionary *temp = NULL; for_dictionaries(temp,(dictionary*)__yon__config__strings) -#define yon_config_parameter_add_or_create_if_exists_with_data(dict,key,data) {if (!dict) dict=yon_config_parameter_new_with_data(key,data); \ - else dict=yon_config_parameter_append_with_data(dict,key,data);} +#define for_default_config dictionary *temp = NULL; for_dictionaries(temp,(dictionary*)__yon__config__default__strings) +#define yon_config_parameter_add_or_create_if_exists_with_data(dict,key,value) {if (dict){\ + if (yon_dictionary_get((dictionary**)&dict,key))\ + dict->data=value;\ + else\ + dict=yon_config_parameter_append_with_data(dict,key,value);\ + }\ + else dict=yon_config_parameter_new_with_data(key,value);} int yon_config_set_ignore(char *key){ @@ -860,11 +869,10 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par } va_list args; va_start(args,parameter); - char *arg; dictionary *sections = NULL; - { - yon_dictionary_add_or_create_if_exists_with_data(sections,section,parameter); - } + yon_dictionary_add_or_create_if_exists_with_data(sections,section,parameter); + char *arg; + while (arg=va_arg(args,char*)){ char *key = va_arg(args,char*); if (sections&&yon_dictionary_get(§ions,arg)) sections->data=(void*)yon_char_unite(yon_dictionary_get_data(sections,char*)," ",key,NULL); @@ -875,8 +883,6 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par for_dictionaries(dict,sections){ command = yon_char_unite(ubconfig_load_command, " default get ", dict->key," ", yon_dictionary_get_data(dict,char*),NULL); FILE *output = popen(command, "r"); - char **output_strings = NULL; - output_strings = malloc(sizeof(char*)); int i = 0; char str[4096]; memset(str, 0, 4096); @@ -894,12 +900,12 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par __yon__config__strings->section=dict->key; } } + free(command); + fclose(output); } for_dictionaries(dict,sections){ command = yon_char_unite(ubconfig_load_command,config_type==YON_CONFIG_GLOBAL ? " global get " : " system get ", dict->key," ", yon_dictionary_get_data(dict,char*),NULL); FILE *output = popen(command, "r"); - char **output_strings = NULL; - output_strings = malloc(sizeof(char*)); int i = 0; char str[4096]; memset(str, 0, 4096); @@ -912,11 +918,15 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par if (!yon_dictionary_get((dictionary**)&__yon__config__strings,key)){ yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,yon_char_new(final_str)); + } else { + __yon__config__strings->data=final_str; } __yon__config__strings->data_type=DICTIONARY_CHAR_TYPE; __yon__config__strings->section=dict->key; } } + free(command); + fclose(output); } check_config return 1; @@ -1125,17 +1135,17 @@ int yon_config_save_registered(char *path){ dictionary *sections_add=NULL; dictionary *sections_remove=NULL; for_dictionaries(dct,(dictionary*)__yon__config__strings){ - if (dct->data&&strcmp(yon_dictionary_get_data(dct,char*),"")!=0){ - if (((yon_config_parameter*)dct)->flag1==1){ + if (((yon_config_parameter*)dct)->flag1==1){ + if (dct->data&&strcmp(yon_dictionary_get_data(dct,char*),"")!=0){ ((yon_config_parameter*)dct)->flag1=0; if (sections_add&&yon_dictionary_get(§ions_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL); else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section, " ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL)); - } else if (((yon_config_parameter*)dct)->flag1==-1){ - ((yon_config_parameter*)dct)->flag1=0; - if (sections_remove&&yon_dictionary_get(§ions_remove,((yon_config_parameter*)dct)->section)) sections_remove->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_remove,char*)," ",dct->key,NULL); - else yon_dictionary_add_or_create_if_exists_with_data(sections_remove,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " remove ", ((yon_config_parameter*)dct)->section, " ",dct->key,NULL)); - yon_dictionary_rip(dct); } + } else if (((yon_config_parameter*)dct)->flag1==-1){ + ((yon_config_parameter*)dct)->flag1=0; + if (sections_remove&&yon_dictionary_get(§ions_remove,((yon_config_parameter*)dct)->section)) sections_remove->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_remove,char*)," ",dct->key,NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections_remove,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " remove ", ((yon_config_parameter*)dct)->section, " ",dct->key,NULL)); + yon_dictionary_rip(dct); } } if (sections_add)