@ -809,6 +809,7 @@ typedef struct yon_config_parameter
DICT_TYPE data_type ;
DICT_TYPE data_type ;
int flag1 ;
int flag1 ;
char * section ;
char * section ;
int ignore ;
} yon_config_parameter ;
} yon_config_parameter ;
yon_config_parameter * yon_config_parameter_new_with_data ( char * key , void * data ) {
yon_config_parameter * yon_config_parameter_new_with_data ( char * key , void * data ) {
@ -821,6 +822,7 @@ yon_config_parameter *yon_config_parameter_new_with_data(char *key, void *data){
param - > next = NULL ;
param - > next = NULL ;
param - > prev = NULL ;
param - > prev = NULL ;
param - > section = NULL ;
param - > section = NULL ;
param - > ignore = 0 ;
return param ;
return param ;
}
}
@ -834,11 +836,24 @@ 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 ;
dictionary * __yon_config_ignored = 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_dictionaries(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 ) ; }
int yon_config_set_ignore ( char * key ) {
yon_dictionary_add_or_create_if_exists_with_data ( __yon_config_ignored , key , NULL ) ;
}
int yon_config_check_ignore ( char * key ) {
dictionary * dict = yon_dictionary_get ( & __yon_config_ignored , key ) ;
if ( dict ) return 1 ;
else return 0 ;
}
int yon_config_load_register ( YON_CONFIG_TYPE config_type , char * section , char * parameter , . . . ) {
int yon_config_load_register ( YON_CONFIG_TYPE config_type , char * section , char * parameter , . . . ) {
if ( __yon__config__strings ) {
if ( __yon__config__strings ) {
__yon__config__strings = yon_dictionary_free_all ( ( dictionary * ) __yon__config__strings , NULL ) ;
__yon__config__strings = yon_dictionary_free_all ( ( dictionary * ) __yon__config__strings , NULL ) ;
@ -848,8 +863,7 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par
char * arg ;
char * arg ;
dictionary * sections = NULL ;
dictionary * sections = NULL ;
{
{
if ( sections & & yon_dictionary_get ( & sections , section ) ) sections - > data = ( void * ) yon_char_unite ( yon_dictionary_get_data ( sections , char * ) , " " , parameter , NULL ) ;
yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
else yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
}
}
while ( arg = va_arg ( args , char * ) ) {
while ( arg = va_arg ( args , char * ) ) {
char * key = va_arg ( args , char * ) ;
char * key = va_arg ( args , char * ) ;
@ -858,6 +872,29 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par
}
}
char * command = NULL ;
char * command = NULL ;
dictionary * dict ;
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 " ) ;
char * * output_strings = NULL ;
output_strings = malloc ( sizeof ( char * ) ) ;
int i = 0 ;
char str [ 4096 ] ;
memset ( str , 0 , 4096 ) ;
while ( fgets ( str , 4096 , output ) )
{
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 ) ) ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
}
}
for_dictionaries ( dict , sections ) {
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 ) ;
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 " ) ;
FILE * output = popen ( command , " r " ) ;
@ -872,7 +909,10 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par
{
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
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 ) ) ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
__yon__config__strings - > section = dict - > key ;
}
}
@ -964,6 +1004,23 @@ void *yon_config_get_all_by_key(char *key, int *size){
}
}
}
}
void * yon_config_get_all_by_key_no_ignored ( char * key , int * size ) {
check_config {
( * size ) = 0 ;
config_str ret_data = NULL ;
dictionary * dict = NULL ;
for_dictionaries ( dict , ( dictionary * ) __yon__config__strings ) {
if ( strstr ( dict - > key , key ) & & ( ( yon_config_parameter * ) dict ) - > flag1 ! = - 1 & & yon_config_check_ignore ( dict - > key ) = = 0 ) {
char * ret_string = yon_char_unite ( dict - > key , " = " , ( char * ) dict - > data , NULL ) ;
if ( ret_data ) ret_data = yon_char_parsed_append ( ret_data , size , ret_string ) ;
else ret_data = yon_char_parsed_new ( size , ret_string , NULL ) ;
}
}
return ret_data ;
}
}
config_str yon_config_get_all_keys ( int * size ) {
config_str yon_config_get_all_keys ( int * size ) {
check_config {
check_config {
* size = 0 ;
* size = 0 ;
@ -977,6 +1034,21 @@ config_str yon_config_get_all_keys(int *size){
return NULL ;
return NULL ;
}
}
config_str yon_config_get_all_keys_no_ignored ( int * size ) {
check_config {
* size = 0 ;
config_str final = NULL ;
for_config {
if ( ! yon_config_check_ignore ( temp - > key ) ) {
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 ) ;
@ -1129,6 +1201,25 @@ config_str yon_config_get_all(int *size){
} else return NULL ;
} else return NULL ;
}
}
config_str yon_config_get_all_no_ignored ( int * size ) {
check_config {
* size = 1 ;
config_str conf = NULL ;
dictionary * dict = NULL ;
for_dictionaries ( dict , ( dictionary * ) __yon__config__strings ) {
if ( yon_config_check_ignore ( dict - > key ) = = 0 ) {
conf = yon_remalloc ( conf , sizeof ( char * ) * ( * size ) ) ;
conf [ ( * size ) - 1 ] = yon_char_unite ( dict - > key , " = " , ( char * ) dict - > data , NULL ) ;
( * size ) + + ;
}
}
conf = yon_remalloc ( conf , sizeof ( char * ) * ( * size ) ) ;
conf [ * size - 1 ] = NULL ;
( * size ) = ( * size ) - 1 ;
return conf ;
} else return NULL ;
}
char * yon_config_get_parameter ( config_str parameters , int size , char * param )
char * yon_config_get_parameter ( config_str parameters , int size , char * param )
{
{
if ( param [ 0 ] = = ' ' )
if ( param [ 0 ] = = ' ' )