diff --git a/source/libublsettings-config.c b/source/libublsettings-config.c index 964fbba..f22c612 100644 --- a/source/libublsettings-config.c +++ b/source/libublsettings-config.c @@ -14,22 +14,17 @@ typedef struct yon_config_parameter char *save_command; char *load_command; int compare_ignore; + char *regex_mask_pattern; } 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)); + memset(param,0,sizeof(yon_config_parameter)); param->data=yon_char_new(data); param->data_type=DICTIONARY_CHAR_TYPE; param->first=param; param->flag1=1; param->key=yon_char_new(key); - param->next=NULL; - param->prev=NULL; - param->section=NULL; - param->ignore=0; - param->save_command=NULL; - param->load_command=NULL; - param->compare_ignore=0; return param; } @@ -128,6 +123,30 @@ int yon_config_set_ignore(char *key){ } } +int yon_config_set_mask_pattern(const char *key, const char *mask_pattern){ + if (yon_char_is_empty(key)) return 0; + yon_config_parameter *parameter = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,(char*)key); + if (!parameter) return 0; + + if (!yon_char_is_empty(parameter->regex_mask_pattern)) + free(parameter->regex_mask_pattern); + + if (yon_char_is_empty(mask_pattern)){ + parameter->regex_mask_pattern = NULL; + } else { + parameter->regex_mask_pattern = yon_char_new(mask_pattern); + } + return 1; +} + +char *yon_config_get_mask_pattern(const char *key){ + if (yon_char_is_empty(key)) return NULL; + yon_config_parameter *parameter = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,(char*)key); + if (!parameter) return NULL; + + return yon_char_new(parameter->regex_mask_pattern); +} + int yon_config_remove_ignore(char *key){ dictionary *dict = yon_dictionary_get(&__yon_config_ignored,key); if (dict) { @@ -897,11 +916,6 @@ enum YON_CONFIG_SAVED_TYPE yon_config_register(char *key,char *config_load, char current = __yon__config__strings; } - switch(current->flag1){ - case -1: save_type = YON_CONFIG_SAVED_REMOVED; break; - case 1: save_type = YON_CONFIG_SAVED_CHANGED; break; - default: save_type = YON_CONFIG_SAVED_NEW; break; - } config_load = yon_char_new(config_load); current->data_type=DICTIONARY_CHAR_TYPE; @@ -915,6 +929,11 @@ enum YON_CONFIG_SAVED_TYPE yon_config_register(char *key,char *config_load, char yon_config_set_ignore(key); current->flag1 = 0; } + switch(current->flag1){ + case -1: save_type = YON_CONFIG_SAVED_REMOVED; break; + case 1: save_type = YON_CONFIG_SAVED_CHANGED; break; + default: save_type = YON_CONFIG_SAVED_NEW; break; + } return save_type; } diff --git a/source/libublsettings.h b/source/libublsettings.h index a0dd4a6..88cafb2 100644 --- a/source/libublsettings.h +++ b/source/libublsettings.h @@ -1397,6 +1397,18 @@ config_str yon_config_get_all_keys_no_ignored(int *size); */ int yon_config_set(char *key, void *data); + +/// @brief Set a regex pattern as a compare mask for saving window +/// @param key Parameter's key +/// @param mask_pattern regex pattern; +/// @return 1 if successful, 0 otherwise +int yon_config_set_mask_pattern(const char *key, const char *mask_pattern); + +/// @brief Get a compare mask for saving window as a regex pattern +/// @param key Parameter's key +/// @return newly allocated string of regex pattern or NULL +char *yon_config_get_mask_pattern(const char *key); + /**yon_config_clean() * [EN] * Erase all parameters from config;