Added preloading of default configuration

pull/6/head
parent 328e670f5f
commit 010ec59ac3

@ -836,7 +836,9 @@ 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 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); \
@ -862,8 +864,7 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par
char *arg;
dictionary *sections = NULL;
{
if (sections&&yon_dictionary_get(&sections,section)) sections->data=(void*)yon_char_unite(yon_dictionary_get_data(sections,char*)," ",parameter,NULL);
else yon_dictionary_add_or_create_if_exists_with_data(sections,section,parameter);
yon_dictionary_add_or_create_if_exists_with_data(sections,section,parameter);
}
while (arg=va_arg(args,char*)){
char *key = va_arg(args,char*);
@ -872,6 +873,29 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par
}
char *command=NULL;
dictionary *dict;
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);
while (fgets(str, 4096, output))
{
if (strcmp(str, "") != 0&& strcmp(str,"(null)\n")!=0)
{
char *key = yon_char_divide_search(str,"=",-1);
char *final_str=yon_char_divide_search(str,"\n",-1);
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));
}
__yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
__yon__config__strings->section=dict->key;
}
}
}
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");
@ -886,7 +910,10 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par
{
char *key = yon_char_divide_search(str,"=",-1);
char *final_str=yon_char_divide_search(str,"\n",-1);
yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,yon_char_new(final_str));
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));
}
__yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
__yon__config__strings->section=dict->key;
}

Loading…
Cancel
Save