New functions; function reworks; fixes

pull/44/head
parent c3e4790858
commit 5e51a0a1a3

@ -18,7 +18,7 @@ typedef struct yon_config_parameter
yon_config_parameter *yon_config_parameter_new_with_data(char *key, void *data){
yon_config_parameter *param = yon_remalloc(NULL,sizeof(yon_config_parameter));
param->data=data;
param->data=yon_char_new(data);
param->data_type=DICTIONARY_CHAR_TYPE;
param->first=param;
param->flag1=1;
@ -149,6 +149,17 @@ int yon_config_check_ignore(char *key){
else return 0;
}
int yon_config_check_default(char *key){
check_default_config{
for_default_config{
if (!strcmp(temp->key,key)){
return 1;
}
}
}
return 0;
}
int yon_config_load_register_no_cleaning(YON_CONFIG_TYPE config_type,char *section,char *parameter, ...){
if (config_type!=YON_CONFIG_BOTH){
va_list args;
@ -280,6 +291,24 @@ int yon_config_command_prepare(config_str *commands, int *commands_size,char *co
return 0;
}
int yon_config_command_get_section_pos(config_str parsed, int size){
for (int i=0;i<size-1;i++){
if (!strcmp(parsed[i],"get")||!strcmp(parsed[i],"set")||!strcmp(parsed[i],"remove")){
return i+1;
}
}
return -1;
}
char *yon_config_command_get_section(const char *command){
int size;
config_str parsed = yon_char_parse((char*)command,&size," ");
int section_pos = yon_config_command_get_section_pos(parsed,size);
char *section = yon_char_new(parsed[section_pos]);
yon_char_parsed_free(parsed,size);
return section;
}
int yon_config_load_config(YON_CONFIG_TYPE config_type, ...){
if (config_type!=YON_CONFIG_BOTH){
va_list args;
@ -412,11 +441,12 @@ int yon_config_remove_by_key(char *key){
check_config{
dictionary *dict = yon_dictionary_get((dictionary**)&__yon__config__strings,key);
if (dict){
if (!yon_dictionary_get(&__yon_config_ignored,dict->key)){
// if (!yon_dictionary_get(&__yon_config_ignored,dict->key)){
yon_config_remove_ignore(dict->key);
((yon_config_parameter*)dict)->flag1=-1;
dict->data="";
return 1;
} else return 0;
// } else return 0;
}
}
return 0;
@ -648,111 +678,44 @@ int yon_config_clean(){
else return 0;
}
void yon_config_register(char *key, char *config_load, void *data){
if (!yon_char_is_empty(key)){
key=yon_char_new(key);
config_load=yon_char_new(config_load);
yon_config_parameter *current = NULL;
if (data){
if (!__yon__config__strings||!(current=(yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key))){
{
enum YON_CONFIG_SAVED_TYPE yon_config_register(char *key,char *config_load, char *data){
if (yon_char_is_empty(key)||yon_char_is_empty(config_load)) return YON_CONFIG_SAVED_ERROR;
if (__yon__config__strings){
char *data_copy = yon_char_new(data);
yon_config_parameter* dict=NULL;
for_dictionaries(dict,__yon__config__strings){
if (!dict->next){
__yon__config__strings=dict;
}
}
__yon__config__strings=yon_config_parameter_append_with_data(__yon__config__strings,key,data_copy);
enum YON_CONFIG_SAVED_TYPE save_type = YON_CONFIG_SAVED_NEW;
yon_config_parameter *current = NULL;
check_config{
current = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key);
if (!current){
yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,data);
current = (yon_config_parameter*)yon_dictionary_get_last((dictionary *)__yon__config__strings);
} else if (!yon_char_is_empty(data)&&!strcmp((char*)current->data,(char*)data)){
save_type=YON_CONFIG_SAVED_EXIST;
return save_type;
}
else {
char *data_copy = yon_char_new(data);
__yon__config__strings=yon_config_parameter_new_with_data(key,yon_char_new(data));
}
}
__yon__config__strings = (yon_config_parameter*)yon_dictionary_get_last((dictionary*)__yon__config__strings);
__yon__config__strings->flag1=1;
__yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
__yon__config__strings->load_command=config_load;
if (yon_dictionary_get(&__yon_config_ignored, key)){
__yon_config_ignored = yon_dictionary_rip(__yon_config_ignored);
}
int size=0;
config_str section = yon_char_parse(config_load,&size," ");
__yon__config__strings->section=yon_char_new(section[yon_char_parsed_check_exist(section,size,"get")+1]);
yon_char_parsed_free(section,size);
}
else if ((current = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key))){
current->data=yon_char_new(data);
current->flag1=1;
current->data_type=DICTIONARY_CHAR_TYPE;
current->load_command=config_load;
if (yon_dictionary_get(&__yon_config_ignored, current->key)){
__yon_config_ignored = yon_dictionary_rip(__yon_config_ignored);
} else {
yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,data);
current = __yon__config__strings;
}
int size=0;
config_str section = yon_char_parse(config_load,&size," ");
current->section=yon_char_new(section[yon_char_parsed_check_exist(section,size,"get")+1]);
yon_char_parsed_free(section,size);
switch(current->flag1){
case -1: save_type = YON_CONFIG_SAVED_REMOVED;
case 1: save_type = YON_CONFIG_SAVED_CHANGED;
default: save_type = YON_CONFIG_SAVED_NEW;
}
} else if ((current = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key))) {
current->data=NULL;
current->flag1=0;
config_load = yon_char_new(config_load);
current->data_type=DICTIONARY_CHAR_TYPE;
current->load_command = config_load;
int size=0;
config_str section = yon_char_parse(config_load,&size," ");
current->section=yon_char_new(section[yon_char_parsed_check_exist(section,size,"get")+1]);
yon_char_parsed_free(section,size);
} else {
if (!__yon__config__strings||!(current=(yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key))){
{
if (__yon__config__strings){
yon_config_parameter* dict=NULL;
for_dictionaries(dict,__yon__config__strings){
if (!dict->next){
__yon__config__strings=dict;
}
}
__yon__config__strings=yon_config_parameter_append_with_data(__yon__config__strings,key,NULL);
current->section = yon_config_command_get_section(config_load);
}
else {
__yon__config__strings=yon_config_parameter_new_with_data(key,NULL);
}
}
yon_config_set_ignore(key);
__yon__config__strings = (yon_config_parameter*)yon_dictionary_get_last((dictionary*)__yon__config__strings);
__yon__config__strings->flag1=0;
__yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
__yon__config__strings->load_command=config_load;
int size=0;
config_str section = yon_char_parse(config_load,&size," ");
__yon__config__strings->section=yon_char_new(section[yon_char_parsed_check_exist(section,size,"get")+1]);
yon_char_parsed_free(section,size);
}
else if ((current = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key))){
if ((current->data&&data!=__yon__config__strings->data&&strcmp(__yon__config__strings->data,data))||!current->data){
if (data){
yon_config_remove_ignore(key);
current->flag1=1;
} else {
yon_config_set_ignore(key);
current->data=NULL;
current->flag1 = 0;
current->data_type=DICTIONARY_CHAR_TYPE;
current->load_command=config_load;
if (yon_dictionary_get(&__yon_config_ignored, current->key)){
__yon_config_ignored= yon_dictionary_rip(__yon_config_ignored);
}
int size=0;
config_str section = yon_char_parse(config_load,&size," ");
current->section=yon_char_new(section[yon_char_parsed_check_exist(section,size,"get")+1]);
yon_char_parsed_free(section,size);
}
}
}
}
return save_type;
}
void yon_config_register_default(char *key, char *config_load, void *data){

@ -841,10 +841,15 @@ int yon_config_get_status(char *key);
int yon_config_check_ignore(char *key);
int yon_config_check_default(char *key);
int yon_config_parse_parameter(char *parameter,char **key, char **value);
int yon_char_remove_brackets(char *string);
int yon_config_command_get_section_pos(config_str parsed, int size);
char *yon_config_command_get_section(const char *command);
int yon_config_load_config(YON_CONFIG_TYPE config_type, ...);
int yon_config_change_key(char *target, char *key);
@ -967,6 +972,16 @@ int yon_config_append(char *key, char *data, char *divider);
*/
int yon_config_clean();
enum YON_CONFIG_SAVED_TYPE{
YON_CONFIG_SAVED_NEW,
YON_CONFIG_SAVED_EXIST,
YON_CONFIG_SAVED_REMOVED,
YON_CONFIG_SAVED_UNCHANGED,
YON_CONFIG_SAVED_CHANGED,
YON_CONFIG_SAVED_ERROR
};
/**yon_config_register(char *key, void *data)
* [EN]
*
@ -975,7 +990,8 @@ int yon_config_clean();
* [key] - ключ параметра;
* [data] - значение параметра;
*/
void yon_config_register(char *key, char* config_section, void *data);
enum YON_CONFIG_SAVED_TYPE yon_config_register(char *key,char *config_load, char *data);
// void yon_config_register(char *key, char* config_section, void *data);
void yon_config_register_default(char *key, char *config_load, void *data);

Loading…
Cancel
Save