|
|
|
|
@ -242,15 +242,24 @@ dictionary *yon_dictionary_connect(dictionary *old, dictionary *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 *dct = *dict;
|
|
|
|
|
for (dictionary *pointer = dct->first; pointer != NULL; pointer = pointer->next)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(pointer->key, key) == 0)
|
|
|
|
|
{
|
|
|
|
|
*dict = pointer;
|
|
|
|
|
return pointer;
|
|
|
|
|
if (dct){
|
|
|
|
|
for (dictionary *pointer = dct->first; pointer != NULL; pointer = pointer->next){
|
|
|
|
|
if (pointer->key&&strcmp(pointer->key, key) == 0){
|
|
|
|
|
*dict = pointer;
|
|
|
|
|
return pointer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
@ -395,7 +404,6 @@ int yon_char_find_count(char *source, char *find){
|
|
|
|
|
if(strstr(rtn[j],find))
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
printf("%d\n",i);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -579,14 +587,14 @@ void yon_char_parsed_free(config_str source, int size){
|
|
|
|
|
free(source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yon_char_parsed_copy(config_str *source, config_str *to_copy){
|
|
|
|
|
if (source&&!*source&&to_copy){
|
|
|
|
|
int size=0;
|
|
|
|
|
config_str new_char = yon_char_parsed_new(&size,(*to_copy)[0]);
|
|
|
|
|
for (int i=0;(*to_copy)[i];i++){
|
|
|
|
|
new_char = yon_char_parsed_append(new_char,&size,yon_char_new((*to_copy)[i]));
|
|
|
|
|
config_str yon_char_parsed_copy(config_str to_copy, int size){
|
|
|
|
|
if (to_copy&&(*to_copy)&&size>0){
|
|
|
|
|
int final_size=0;
|
|
|
|
|
config_str final = yon_char_parsed_new(&final_size,to_copy[0],NULL);
|
|
|
|
|
for (int i=1;i<size;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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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(){
|
|
|
|
|
if (getuid()==0) return 1;
|
|
|
|
|
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;
|
|
|
|
|
#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); \
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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){
|
|
|
|
|
check_config{
|
|
|
|
|
dictionary *dict = NULL;
|
|
|
|
|
@ -917,6 +1015,18 @@ void *yon_config_get_by_key(char *key){
|
|
|
|
|
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){
|
|
|
|
|
check_config{
|
|
|
|
|
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){
|
|
|
|
|
check_config{
|
|
|
|
|
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){
|
|
|
|
|
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__strings->flag1=1;
|
|
|
|
|
}
|
|
|
|
|
else if (yon_dictionary_get((dictionary**)&__yon__config__strings,key)){
|
|
|
|
|
if (data!=__yon__config__strings->data&&strcmp(__yon__config__strings->data,data)){
|
|
|
|
|
__yon__config__strings->data=data;
|
|
|
|
|
__yon__config__strings->flag1=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (yon_dictionary_get((dictionary**)&__yon__config__strings,key)) __yon__config__strings->data=data;
|
|
|
|
|
__yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
|
|
|
|
|
__yon__config__strings->flag1=1;
|
|
|
|
|
__yon__config__strings->section=yon_char_new(config_section);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|