Added various functions: for dictionary, for configuration, for string arrays, etc

pull/2/head
parent 5e95dea494
commit 56b396a870

@ -26,8 +26,6 @@ if(WEBKIT_LIBRARIES_FOUND)
endif() endif()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -lm")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \
-O2 -pipe -fno-plt -fexceptions \ -O2 -pipe -fno-plt -fexceptions \
-Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \

@ -242,17 +242,26 @@ dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect)
return toconnect; return toconnect;
} }
dictionary *yon_dictionary_merge(dictionary *dict1,dictionary *dict2){
dictionary *dct = NULL;
for_dictionaries(dct,dict2){
if (!yon_dictionary_get(&dict1,dct->key))
yon_dictionary_connect(dict1,dct);
}
return dict1;
}
dictionary *yon_dictionary_get(dictionary **dict, char *key) dictionary *yon_dictionary_get(dictionary **dict, char *key)
{ {
dictionary *dct = *dict; dictionary *dct = *dict;
for (dictionary *pointer = dct->first; pointer != NULL; pointer = pointer->next) if (dct){
{ for (dictionary *pointer = dct->first; pointer != NULL; pointer = pointer->next){
if (strcmp(pointer->key, key) == 0) if (pointer->key&&strcmp(pointer->key, key) == 0){
{
*dict = pointer; *dict = pointer;
return pointer; return pointer;
} }
} }
}
return NULL; return NULL;
} }
@ -395,7 +404,6 @@ int yon_char_find_count(char *source, char *find){
if(strstr(rtn[j],find)) if(strstr(rtn[j],find))
i++; i++;
} }
printf("%d\n",i);
return i; return i;
} }
@ -579,14 +587,14 @@ void yon_char_parsed_free(config_str source, int size){
free(source); free(source);
} }
void yon_char_parsed_copy(config_str *source, config_str *to_copy){ config_str yon_char_parsed_copy(config_str to_copy, int size){
if (source&&!*source&&to_copy){ if (to_copy&&(*to_copy)&&size>0){
int size=0; int final_size=0;
config_str new_char = yon_char_parsed_new(&size,(*to_copy)[0]); config_str final = yon_char_parsed_new(&final_size,to_copy[0],NULL);
for (int i=0;(*to_copy)[i];i++){ for (int i=1;i<size;i++){
new_char = yon_char_parsed_append(new_char,&size,yon_char_new((*to_copy)[i])); final = yon_char_parsed_append(final,&final_size,to_copy[i]);
} }
if (new_char) *source = new_char; return final;
} }
} }
@ -597,6 +605,88 @@ config_str yon_char_parsed_append(config_str parsed, int *size, char *string){
return new_parsed; return new_parsed;
} }
config_str yon_char_parsed_merge(config_str array1, int size1, config_str array2, int size2, int *final_size){
if (array1&&array2&&size1>0&&size2>0){
*final_size=0;
config_str parsed_final = yon_char_parsed_new(final_size,array1[0],NULL);
for (int i=1;i<size1;i++){
int new_size=0;
parsed_final = yon_char_parsed_append(parsed_final,&new_size,array1[i]);
}
for (int i=0;i<size2;i++){
parsed_final = yon_char_parsed_append(parsed_final,final_size,array2[i]);
}
return parsed_final;
}
}
config_str yon_char_parsed_merge_no_repeats(config_str array1, int size1, config_str array2, int size2, int *final_size){
if (array1&&array2&&size1>0&&size2>0){
*final_size=0;
int new_size=0;
config_str parsed_final = yon_char_parsed_new(final_size,array1[0],NULL);
for (int i=1;i<size1;i++){
parsed_final = yon_char_parsed_append(parsed_final,final_size,array1[i]);
}
for (int i=0;i<size2;i++){
int found=0;
for (int j=0;j<size1;j++){
if (!strcmp(array1[j],array2[i])){
found=1;
break;
}
}
if (!found)
parsed_final= yon_char_parsed_append(parsed_final,final_size,array2[i]);
}
return parsed_final;
}
}
int yon_char_parsed_divide_full(config_str parsed,int size,int divide_pos){
if(parsed&&size>0){
for (int i=0;i<size;i++){
char *parsed_temp = yon_char_divide(parsed[i],divide_pos);
free(parsed[i]);
parsed[i]=parsed_temp;
}
return 1;
} return 0;
}
int yon_char_parsed_divide_search_full(config_str parsed,int size,char *divide_pos, int delete_divider){
if(parsed&&size>0){
for (int i=0;i<size;i++){
char *parsed_temp = yon_char_divide_search(parsed[i],divide_pos,delete_divider);
free(parsed[i]);
parsed[i]=parsed_temp;
}
return 1;
} return 0;
}
dictionary *yon_char_parsed_convert_to_dictionary(config_str parsed, int size){
if (parsed&&size>0){
dictionary *dict = NULL;
for (int i=0;i<size;i++){
yon_dictionary_add_or_create_if_exists_with_data(dict,NULL,parsed[i]);
}
return dict;
}
return NULL;
}
dictionary *yon_char_parsed_convert_copy_to_dictionary(config_str parsed, int size){
if (parsed&&size>0){
dictionary *dict = NULL;
for (int i=0;i<size;i++){
yon_dictionary_add_or_create_if_exists_with_data(dict,NULL,yon_char_new(parsed[i]));
}
return dict;
}
return NULL;
}
int yon_ubl_check_root(){ int yon_ubl_check_root(){
if (getuid()==0) return 1; if (getuid()==0) return 1;
else return 0; else return 0;
@ -825,7 +915,7 @@ 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__strings = NULL;
#define check_config if(__yon__config__strings&&__yon__config__strings->data_type==DICTIONARY_CHAR_TYPE) #define check_config if(__yon__config__strings&&__yon__config__strings->data_type==DICTIONARY_CHAR_TYPE)
#define for_config dictionary temp = NULL; for_dictionary(temp,(dictionary*)__yon__config__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); \ #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);} else dict=yon_config_parameter_append_with_data(dict,key,data);}
@ -905,6 +995,14 @@ int yon_config_remove_element(char *key, char *deleted){
} else return 0; } else return 0;
} }
void yon_config_set_status(int status){
check_config{
for_config{
((yon_config_parameter*)temp)->flag1=status;
}
}
}
void *yon_config_get_by_key(char *key){ void *yon_config_get_by_key(char *key){
check_config{ check_config{
dictionary *dict = NULL; dictionary *dict = NULL;
@ -917,6 +1015,18 @@ void *yon_config_get_by_key(char *key){
return NULL; return NULL;
} }
char *yon_config_get_section_for_key(char *key){
check_config{
for_config{
if (!yon_char_is_empty(temp->key)){
if (!strcmp(temp->key,key)){
return yon_char_new(((yon_config_parameter*)temp)->section);
}
}
}
}
}
void *yon_config_get_all_by_key(char *key, int *size){ void *yon_config_get_all_by_key(char *key, int *size){
check_config{ check_config{
config_str ret_data=NULL; config_str ret_data=NULL;
@ -932,6 +1042,19 @@ void *yon_config_get_all_by_key(char *key, int *size){
} }
} }
config_str yon_config_get_all_keys(int *size){
check_config{
*size=0;
config_str final = NULL;
for_config{
if (!final) final = yon_char_parsed_new(size,temp->key,NULL);
else final = yon_char_parsed_append(final,size,temp->key);
}
return final;
}
return NULL;
}
int yon_config_set(char *key, void *data){ int yon_config_set(char *key, void *data){
check_config{ check_config{
yon_config_parameter *dict = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key); yon_config_parameter *dict = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key);
@ -963,10 +1086,15 @@ int yon_config_clean(){
void yon_config_register(char *key, char *config_section, void *data){ void yon_config_register(char *key, char *config_section, void *data){
if (!__yon__config__strings||!yon_dictionary_get((dictionary**)&__yon__config__strings,key)){ if (!__yon__config__strings||!yon_dictionary_get((dictionary**)&__yon__config__strings,key)){
yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,data); yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,data);
__yon__config__strings->flag1=1;
} }
else if (yon_dictionary_get((dictionary**)&__yon__config__strings,key)) __yon__config__strings->data=data; else if (yon_dictionary_get((dictionary**)&__yon__config__strings,key)){
__yon__config__strings->data_type=DICTIONARY_CHAR_TYPE; if (data!=__yon__config__strings->data&&strcmp(__yon__config__strings->data,data)){
__yon__config__strings->data=data;
__yon__config__strings->flag1=1; __yon__config__strings->flag1=1;
}
}
__yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
__yon__config__strings->section=yon_char_new(config_section); __yon__config__strings->section=yon_char_new(config_section);
} }

@ -238,6 +238,8 @@ dictionary *yon_dictionary_append_with_data(dictionary *dict, char *key, void *d
*/ */
dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect); dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect);
dictionary *yon_dictionary_merge(dictionary *dict1,dictionary *dict2);
/**yon_dictionary_get(dictionary **dict, char *key) /**yon_dictionary_get(dictionary **dict, char *key)
* [EN] * [EN]
* *
@ -378,6 +380,9 @@ char *yon_char_replace(char *source, char *find, char*replace);
*/ */
char **yon_char_parse(char *parameters, int *size, char *divider); char **yon_char_parse(char *parameters, int *size, char *divider);
#define yon_char_parsed_add_or_create_if_exists(parsed,size,data) {if (!parsed) parsed = yon_char_parsed_new(size,data,NULL);\
else parsed = yon_char_parsed_append(parsed,size,data);}
/**yon_char_parsed_rip(char **char_string, int *size, int item_to_delete) /**yon_char_parsed_rip(char **char_string, int *size, int item_to_delete)
* [EN] * [EN]
* *
@ -435,13 +440,13 @@ config_str yon_char_parsed_new (int *size, ...);
void yon_char_parsed_free(config_str source, int size); void yon_char_parsed_free(config_str source, int size);
/**yon_char_parsed_copy(config_str *source, config_str *to_copy) /**config_str yon_char_parsed_copy(config_str to_copy, int size)
* [EN] * [EN]
* *
* [RU] * [RU]
* Копирует массив строк [to_copy] в [source] * Возвращает копию массива строк [to_copy] размера [size]
*/ */
void yon_char_parsed_copy(config_str *source, config_str *to_copy); config_str yon_char_parsed_copy(config_str to_copy, int size);
/**config_str yon_char_parsed_append(config_str parsed, int *size, char *string) /**config_str yon_char_parsed_append(config_str parsed, int *size, char *string)
* [EN] * [EN]
@ -451,6 +456,36 @@ void yon_char_parsed_copy(config_str *source, config_str *to_copy);
*/ */
config_str yon_char_parsed_append(config_str parsed, int *size, char *string); config_str yon_char_parsed_append(config_str parsed, int *size, char *string);
/**yon_char_parsed_merge(config_str array1, int size1, config_str array2, int size2, int *final_size)
* [EN]
*
* [RU]
* Объединяет два массива строк в один.
* [array1] - первый массив строк размера [size1]
* [array2] - второй массив строк размера [size2]
* [final_size] - указатель на целочисленную переменную в которую должен вернуться размер нового массива
*/
config_str yon_char_parsed_merge(config_str array1, int size1, config_str array2, int size2, int *final_size);
/**yon_char_parsed_merge_no_repeats(config_str array1, int size1, config_str array2, int size2, int *final_size)
* [EN]
*
* [RU]
* Объединяет два массива строк в один с предотвращением дублей.
* [array1] - первый массив строк размера [size1]
* [array2] - второй массив строк размера [size2]
* [final_size] - указатель на целочисленную переменную в которую должен вернуться размер нового массива
*/
config_str yon_char_parsed_merge_no_repeats(config_str array1, int size1, config_str array2, int size2, int *final_size);
int yon_char_parsed_divide_full(config_str parsed,int size,int divide_pos);
int yon_char_parsed_divide_search_full(config_str parsed,int size,char *divide_pos, int delete_divider);
dictionary *yon_char_parsed_convert_to_dictionary(config_str parsed, int size);
dictionary *yon_char_parsed_convert_copy_to_dictionary(config_str parsed, int size);
/**yon_ubl_check_root() /**yon_ubl_check_root()
* [EN] * [EN]
* *
@ -610,6 +645,8 @@ int yon_config_remove_by_key(char *key);
*/ */
int yon_config_remove_element(char *key, char *deleted); int yon_config_remove_element(char *key, char *deleted);
void yon_config_set_status(int status);
/**yon_config_get_key_by_key(char *data) /**yon_config_get_key_by_key(char *data)
* [EN] * [EN]
* *
@ -619,6 +656,8 @@ int yon_config_remove_element(char *key, char *deleted);
*/ */
void *yon_config_get_by_key(char *key); void *yon_config_get_by_key(char *key);
char *yon_config_get_section_for_key(char *key);
/**yon_config_get_all_by_key(char *data) /**yon_config_get_all_by_key(char *data)
* [EN] * [EN]
* *
@ -628,6 +667,14 @@ void *yon_config_get_by_key(char *key);
*/ */
void *yon_config_get_all_by_key(char *key, int *size); void *yon_config_get_all_by_key(char *key, int *size);
/**yon_config_get_all_keys(int *size)
* [EN]
*
* [RU]
* Возвращает массив с ключами всех параметров внутреннего конфига
*/
config_str yon_config_get_all_keys(int *size);
/**yon_config_set(char *key, void *data) /**yon_config_set(char *key, void *data)
* [EN] * [EN]
* *
@ -683,7 +730,7 @@ int yon_config_force_save_registered(char *path);
* Возвращает массив со всеми параметрами конфига, оканчивающаяся NULL * Возвращает массив со всеми параметрами конфига, оканчивающаяся NULL
* [size] - указатель, в который выгружается длина массива * [size] - указатель, в который выгружается длина массива
*/ */
config_str yon_config_get_all(); config_str yon_config_get_all(int *size);
// terminal-using functions // terminal-using functions

Loading…
Cancel
Save