@ -213,6 +213,15 @@ dictionary *yon_dictionary_new_with_data(char *key, void *data)
return dct ;
}
void * yon_dictionary_free ( dictionary * dictionary_to_free ) {
if ( dictionary_to_free ) {
free ( dictionary_to_free - > data ) ;
free ( dictionary_to_free - > key ) ;
free ( dictionary_to_free ) ;
return NULL ;
}
}
void * yon_dictionary_free_all ( dictionary * dictionary_to_free , void ( * data_manipulation ) ( void * ) ) {
if ( dictionary_to_free ) {
dictionary * dict = NULL ;
@ -891,7 +900,24 @@ dictionary *__yon_config_ignored = NULL;
int yon_config_set_ignore ( char * key ) {
yon_dictionary_add_or_create_if_exists_with_data ( __yon_config_ignored , key , NULL ) ;
if ( ! yon_dictionary_get ( & __yon_config_ignored , key ) ) {
yon_dictionary_add_or_create_if_exists_with_data ( __yon_config_ignored , key , NULL ) ;
}
}
int yon_config_remove_ignore ( char * key ) {
dictionary * dict = yon_dictionary_get ( & __yon_config_ignored , key ) ;
if ( dict ) {
yon_dictionary_free ( yon_dictionary_rip ( dict ) ) ;
}
}
int yon_config_get_status ( char * key ) {
dictionary * dict ;
if ( yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
return ( ( yon_config_parameter * ) dict ) - > flag1 ;
}
else return 0 ;
}
int yon_config_check_ignore ( char * key ) {
@ -900,83 +926,114 @@ int yon_config_check_ignore(char *key){
else return 0 ;
}
int yon_config_load_register ( YON_CONFIG_TYPE config_type , char * section , char * parameter , . . . ) {
if ( __yon__config__strings ) {
__yon__config__strings = yon_dictionary_free_all ( ( dictionary * ) __yon__config__strings , NULL ) ;
}
va_list args ;
va_start ( args , parameter ) ;
dictionary * sections = NULL ;
yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
char * arg ;
while ( arg = va_arg ( args , char * ) ) {
char * key = va_arg ( args , char * ) ;
if ( sections & & yon_dictionary_get ( & sections , arg ) ) sections - > data = ( void * ) yon_char_unite ( yon_dictionary_get_data ( sections , char * ) , " " , key , NULL ) ;
else yon_dictionary_add_or_create_if_exists_with_data ( sections , arg , key ) ;
}
char * command = NULL ;
dictionary * dict ;
for_dictionaries ( dict , sections ) {
command = yon_char_unite ( ubconfig_load_command , " default get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
FILE * output = popen ( command , " r " ) ;
int i = 0 ;
char str [ 4096 ] ;
memset ( str , 0 , 4096 ) ;
while ( fgets ( str , 4096 , output ) )
{
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 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 ;
va_start ( args , parameter ) ;
dictionary * sections = NULL ;
yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
char * arg ;
while ( arg = va_arg ( args , char * ) ) {
char * key = va_arg ( args , char * ) ;
if ( sections & & yon_dictionary_get ( & sections , arg ) ) sections - > data = ( void * ) yon_char_unite ( yon_dictionary_get_data ( sections , char * ) , " " , key , NULL ) ;
else yon_dictionary_add_or_create_if_exists_with_data ( sections , arg , key ) ;
}
char * command = NULL ;
dictionary * dict ;
for_dictionaries ( dict , sections ) {
command = yon_char_unite ( ubconfig_load_command , config_type = = YON_CONFIG_GLOBAL ? " global get " : config_type = = YON_CONFIG_LOCAL ? " system get " : " default get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
FILE * output = popen ( command , " r " ) ;
int i = 0 ;
char str [ 4096 ] ;
memset ( str , 0 , 4096 ) ;
while ( fgets ( str , 4096 , output ) )
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 0 )
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
} else {
__yon__config__strings - > data = final_str ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
free ( command ) ;
fclose ( output ) ;
}
free ( command ) ;
fclose ( output ) ;
}
for_dictionaries ( dict , sections ) {
command = yon_char_unite ( ubconfig_load_command , config_type = = YON_CONFIG_GLOBAL ? " global get " : " system get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
FILE * output = popen ( command , " r " ) ;
int i = 0 ;
char str [ 4096 ] ;
memset ( str , 0 , 4096 ) ;
while ( fgets ( str , 4096 , output ) )
{
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 0 )
check_config
return 1 ;
else return 0 ;
} else return - 1 ;
}
int yon_config_load_register ( YON_CONFIG_TYPE config_type , char * section , char * parameter , . . . ) {
if ( config_type ! = YON_CONFIG_BOTH ) {
if ( __yon__config__strings ) {
__yon__config__strings = yon_dictionary_free_all ( ( dictionary * ) __yon__config__strings , NULL ) ;
}
va_list args ;
va_start ( args , parameter ) ;
dictionary * sections = NULL ;
yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
char * arg ;
while ( arg = va_arg ( args , char * ) ) {
char * key = va_arg ( args , char * ) ;
if ( sections & & yon_dictionary_get ( & sections , arg ) ) sections - > data = ( void * ) yon_char_unite ( yon_dictionary_get_data ( sections , char * ) , " " , key , NULL ) ;
else yon_dictionary_add_or_create_if_exists_with_data ( sections , arg , key ) ;
}
char * command = NULL ;
dictionary * dict ;
for_dictionaries ( dict , sections ) {
command = yon_char_unite ( ubconfig_load_command , config_type = = YON_CONFIG_GLOBAL ? " global get " : config_type = = YON_CONFIG_LOCAL ? " system get " : " default get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
FILE * output = popen ( command , " r " ) ;
int i = 0 ;
char str [ 4096 ] ;
memset ( str , 0 , 4096 ) ;
while ( fgets ( str , 4096 , output ) )
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
} else {
__yon__config__strings - > data = final_str ;
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 0 )
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
} else {
__yon__config__strings - > data = final_str ;
}
if ( config_type = = YON_CONFIG_DEFAULT ) {
__yon__config__strings - > flag1 = - 2 ;
yon_config_set_ignore ( key ) ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
free ( command ) ;
fclose ( output ) ;
}
free ( command ) ;
fclose ( output ) ;
}
check_config
return 1 ;
else return 0 ;
check_config
return 1 ;
else return 0 ;
} else return - 1 ;
}
int yon_config_remove_by_key ( char * key ) {
check_config {
dictionary * dict = yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
if ( dict ) {
( ( yon_config_parameter * ) dict ) - > flag1 = - 1 ;
dict - > data = " " ;
return 1 ;
if ( ! yon_dictionary_get ( & __yon_config_ignored , dict - > key ) ) {
( ( yon_config_parameter * ) dict ) - > flag1 = - 1 ;
dict - > data = " " ;
return 1 ;
} else return 0 ;
} else return 0 ;
}
return 0 ;
@ -1117,6 +1174,11 @@ int yon_config_set(char *key, void *data){
yon_config_parameter * dict = ( yon_config_parameter * ) yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
dict - > data = data ;
dict - > flag1 = 1 ;
printf ( " %s has been changed \n " , dict - > key ) ;
if ( yon_dictionary_get ( & __yon_config_ignored , dict - > key ) ) {
__yon_config_ignored = yon_dictionary_rip ( __yon_config_ignored ) ;
printf ( " %s removed from ignored \n " , dict - > key ) ;
}
return 1 ;
} else return 0 ;
}
@ -1142,13 +1204,17 @@ 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_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( 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 - > data = yon_char_new ( data ) ;
__yon__config__strings - > flag1 = 1 ;
if ( yon_dictionary_get ( & __yon_config_ignored , __yon__config__strings - > key ) ) {
__yon_config_ignored = yon_dictionary_rip ( __yon_config_ignored ) ;
printf ( " %s removed from ignored \n " , __yon__config__strings - > key ) ;
}
}
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;