diff --git a/source/libublsettings-config.c b/source/libublsettings-config.c index 40129f3..0b216fe 100644 --- a/source/libublsettings-config.c +++ b/source/libublsettings-config.c @@ -1149,8 +1149,9 @@ config_str yon_config_get_save_parameters_by_list(int *size, config_str paramete } config_str yon_config_get_save_parameters_by_key(int *size,...){ - va_list list; (*size)=0; + check_config{ + va_list list; va_start(list,size); int removed_size; config_str removed = NULL; @@ -1196,6 +1197,8 @@ config_str yon_config_get_save_parameters_by_key(int *size,...){ } final = yon_char_parsed_merge(updated,updated_size,removed,removed_size,size); return final; + } + return NULL; } config_str yon_config_find_keys(char *target, int *size){ diff --git a/source/libublsettings-hash.c b/source/libublsettings-hash.c new file mode 100644 index 0000000..68c2b5a --- /dev/null +++ b/source/libublsettings-hash.c @@ -0,0 +1,88 @@ +#include "libublsettings.h" + +yon_hash *yon_hash_new(int size, unsigned int(*hash_func)(const char *)){ + yon_hash *hash = malloc(sizeof(yon_hash)); + memset(hash,0,sizeof(yon_hash)); + hash->data = malloc(sizeof(yon_hash_element)*size); + hash->size = size; + hash->hash_func = hash_func; + return hash; +} + +yon_hash_element *yon_hash_element_new(const char *key, const char *data){ + yon_hash_element *element = malloc(sizeof(yon_hash_element)); + memset(element,0,sizeof(yon_hash_element)); + element->key = yon_char_new(key); + element->data = yon_char_new(data); + return element; +} + +int yon_hash_insert(yon_hash *target, const char *key, void *data){ + if (target&&target->hash_func&&!yon_char_is_empty(key)&&data){ + unsigned int hash = target->hash_func(key)%target->size; + if (target->data[hash]){ + yon_hash_element *element = yon_hash_element_new(key,data); + yon_hash_element *last = (yon_hash_element *)yon_dictionary_get_last((dictionary*)target->data[hash]); + last->next=(struct yon_hash_element*)element; + element->prev=(struct yon_hash_element*)last; + element->first=(struct yon_hash_element*)last->first; + return 1; + } else { + target->data = malloc(sizeof(yon_hash_element*)); + target->data[0] = yon_hash_element_new(key,data); + return 1; + } + } + return 0; +} + +int yon_hash_remove(yon_hash *target, const char *key){ + if (target&&target->hash_func&&!yon_char_is_empty(key)){ + unsigned int hash = target->hash_func(key)%target->size; + if (target->data[hash]){ + dictionary *dict = yon_dictionary_get((dictionary**)&target->data[hash],(char*)key); + target->data[hash]=(yon_hash_element*)yon_dictionary_rip(dict); + } + } + return 0; +} + +void *yon_hash_lookup(yon_hash *target, const char *key){ + if (target&&target->size>0&&!yon_char_is_empty(key)){ + unsigned int hash = target->hash_func(key)%target->size; + if (target->data[hash]){ + dictionary *dict = yon_dictionary_get((dictionary**)&target->data[hash],(char*)key); + return yon_dictionary_get_data(dict,void*); + } + } + return NULL; +} + +int yon_hash_contains(yon_hash *target, const char *key){ + if (target&&!yon_char_is_empty(key)){ + unsigned int hash = target->hash_func(key)%target->size; + if (target->data[hash]){ + if (yon_dictionary_get((dictionary**)&target->data[hash],key)) return 1; + } + } + return 0; +} + +int yon_hash_add(yon_hash *target,const char *key){ + if (target&&target->size>0&&!yon_char_is_empty(key)){ + unsigned int hash = target->hash_func(key)%target->size; + + if (target->data[hash]){ + yon_hash_element *element = yon_hash_element_new(key,NULL); + yon_hash_element *last = (yon_hash_element *)yon_dictionary_get_last((dictionary*)target->data[hash]); + last->next=(struct yon_hash_element*)element; + element->prev=(struct yon_hash_element*)last; + element->first=(struct yon_hash_element*)last->first; + return 1; + } else { + target->data = malloc(sizeof(yon_hash_element*)); + target->data[0] = yon_hash_element_new(key,NULL); + return 1; + } + } +} \ No newline at end of file diff --git a/source/libublsettings-locale.c b/source/libublsettings-locale.c new file mode 100644 index 0000000..edd5f93 --- /dev/null +++ b/source/libublsettings-locale.c @@ -0,0 +1,42 @@ +#include "libublsettings.h" + +#define locales_path "/usr/share/i18n/locales/" + +struct yon_locale { + char *code; + char *lang_ab; + char *territory; + char *language; + char *lang_name; + char *title; +}; + +struct yon_locale *yon_lang_new(){ + struct yon_locale *cur_locale = malloc(sizeof(struct yon_locale)); + memset(cur_locale,0,sizeof(struct yon_locale)); + return cur_locale; +} + +void yon_locale_set(struct yon_locale *target,char *locale_name){ + int size; + char *path = yon_char_unite(locales_path,locale_name,NULL); + config_str *locale_string = yon_file_open(path,&size); + target->code = yon_char_new(locale_name); + target->lang_ab = yon_char_parsed_check_exist_begins_with(locale_string,size,"lang_ab"); + target->territory = yon_char_parsed_check_exist_begins_with(locale_string,size,"territory"); + target->language = yon_char_parsed_check_exist_begins_with(locale_string,size,"language"); + target->lang_name = yon_char_parsed_check_exist_begins_with(locale_string,size,"lang_name"); + target->title = yon_char_parsed_check_exist_begins_with(locale_string,size,"title"); + yon_char_parsed_free(locale_string,size); + free(path); +} + +void yon_locale_init(){ + int size; + config_str *locales_list = yon_dir_get_contents(locales_path,&size); + for (int i=0;i