|
|
|
|
@ -261,7 +261,7 @@ char *yon_config_replace_parameter(char *command, char *parameter, int place){
|
|
|
|
|
if (!yon_char_is_empty(command));
|
|
|
|
|
int size=0;
|
|
|
|
|
config_str parsed = yon_char_parse(command,&size," ");
|
|
|
|
|
int firstparameter = yon_config_command_get_section_pos(parsed,size)+1;
|
|
|
|
|
int firstparameter = yon_config_command_get_section_pos(command)+1;
|
|
|
|
|
if (firstparameter+place<size){
|
|
|
|
|
free(parsed[firstparameter+place]);
|
|
|
|
|
parsed[firstparameter+place]=yon_char_new(parameter);
|
|
|
|
|
@ -271,13 +271,14 @@ char *yon_config_replace_parameter(char *command, char *parameter, int place){
|
|
|
|
|
return final;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Парсит команду на отдельные команды для каждого параметра*/
|
|
|
|
|
int yon_config_command_prepare(config_str *commands, int *commands_size,char *command){
|
|
|
|
|
if (!yon_char_is_empty(command)){
|
|
|
|
|
int parsed_size;
|
|
|
|
|
int done=0;
|
|
|
|
|
config_str parsed = yon_char_parse(command,&parsed_size," ");
|
|
|
|
|
int get_place = yon_char_parsed_check_exist(parsed,parsed_size,"get");
|
|
|
|
|
if (get_place){
|
|
|
|
|
int get_place = yon_config_command_get_section_pos(command)-1;
|
|
|
|
|
if (get_place>-1){
|
|
|
|
|
if (parsed_size>get_place+2){
|
|
|
|
|
for (int j=get_place+2;j<parsed_size;j++){
|
|
|
|
|
int new_size=get_place+2;
|
|
|
|
|
@ -293,25 +294,98 @@ int yon_config_command_prepare(config_str *commands, int *commands_size,char *co
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int yon_config_command_get_section_pos(config_str parsed, int size){
|
|
|
|
|
/** */
|
|
|
|
|
char *yon_config_command_get_full(config_str command, int command_size){
|
|
|
|
|
if (command && command_size>0){
|
|
|
|
|
int final_size;
|
|
|
|
|
config_str final = NULL;
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(final,&final_size,command[0]);
|
|
|
|
|
for (int i=1;i<command_size;i++){
|
|
|
|
|
int parsed_size;
|
|
|
|
|
config_str parsed = yon_char_parse(command[i],&parsed_size," ");
|
|
|
|
|
int pos = yon_config_command_get_section_pos(command[i]);
|
|
|
|
|
if (pos>-1){
|
|
|
|
|
char *cur_string = "";
|
|
|
|
|
for (int j=pos;j<parsed_size;j++){
|
|
|
|
|
char *temp = yon_char_unite(cur_string," ",parsed[j],NULL);
|
|
|
|
|
if (!yon_char_is_empty(cur_string)) free(cur_string);
|
|
|
|
|
cur_string = temp;
|
|
|
|
|
}
|
|
|
|
|
if (!yon_char_is_empty(cur_string)){
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(final,&final_size,cur_string);
|
|
|
|
|
free(cur_string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
yon_char_parsed_free(parsed,parsed_size);
|
|
|
|
|
}
|
|
|
|
|
if (final_size>0){
|
|
|
|
|
char *final_command = yon_char_parsed_to_string(final,final_size," -- get ");
|
|
|
|
|
yon_char_parsed_free(final,final_size);
|
|
|
|
|
return final_command;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config_str yon_config_command_get_parameters(const char *command, int *size){
|
|
|
|
|
(*size)=0;
|
|
|
|
|
if (yon_char_is_empty(command)) return NULL;
|
|
|
|
|
|
|
|
|
|
int parsed_size;
|
|
|
|
|
config_str parsed = yon_char_parse(command,&parsed_size," ");
|
|
|
|
|
int pos = yon_config_command_get_section_pos(command);
|
|
|
|
|
if (pos>-1){
|
|
|
|
|
for (int i=0;i<pos+1;i++){
|
|
|
|
|
parsed = yon_char_parsed_rip(parsed,&parsed_size,0);
|
|
|
|
|
}
|
|
|
|
|
if (parsed_size>0){
|
|
|
|
|
(*size)=parsed_size;
|
|
|
|
|
return parsed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int yon_config_command_check_parameter(const char *command,const char *parameter){
|
|
|
|
|
int size;
|
|
|
|
|
config_str parameters = yon_config_command_get_parameters(command,&size);
|
|
|
|
|
for (int i=0;i<size;i++){
|
|
|
|
|
if (!strcmp(parameters[i],parameter)){
|
|
|
|
|
yon_char_parsed_free(parameters,size);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yon_char_parsed_free(parameters,size);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Возвращает позицию раздела в команде */
|
|
|
|
|
int yon_config_command_get_section_pos(const char *command){
|
|
|
|
|
int size;
|
|
|
|
|
config_str parsed = yon_char_parse(command,&size," ");
|
|
|
|
|
int pos = -1;
|
|
|
|
|
for (int i=0;i<size-1;i++){
|
|
|
|
|
if (!strcmp(parsed[i],"get")||!strcmp(parsed[i],"set")||!strcmp(parsed[i],"remove")){
|
|
|
|
|
return i+1;
|
|
|
|
|
pos = i+1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
yon_char_parsed_free(parsed,size);
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Возвращает раздел в команде */
|
|
|
|
|
char *yon_config_command_get_section(const char *command){
|
|
|
|
|
int size;
|
|
|
|
|
config_str parsed = yon_char_parse((char*)command,&size," ");
|
|
|
|
|
int section_pos = yon_config_command_get_section_pos(parsed,size);
|
|
|
|
|
int section_pos = yon_config_command_get_section_pos(command);
|
|
|
|
|
if (section_pos==-1) return NULL;
|
|
|
|
|
char *section = yon_char_new(parsed[section_pos]);
|
|
|
|
|
yon_char_parsed_free(parsed,size);
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Возвращает позицию пути в команде */
|
|
|
|
|
int yon_config_command_get_path_pos(config_str parsed, int size){
|
|
|
|
|
for (int i=0;i<size-1;i++){
|
|
|
|
|
if (!strcmp(parsed[i],"--source")||!strcmp(parsed[i],"--target")){
|
|
|
|
|
@ -321,6 +395,7 @@ int yon_config_command_get_path_pos(config_str parsed, int size){
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Возвращает путь из команды */
|
|
|
|
|
char *yon_config_command_get_path(const char *command){
|
|
|
|
|
int size;
|
|
|
|
|
config_str parsed = yon_char_parse((char*)command,&size," ");
|
|
|
|
|
@ -341,56 +416,116 @@ void yon_config_set_last_command(char *command){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int yon_config_load_config(YON_CONFIG_TYPE config_type, ...){
|
|
|
|
|
if (config_type!=YON_CONFIG_BOTH){
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args,config_type);
|
|
|
|
|
char *current = NULL;
|
|
|
|
|
int command_size=0;
|
|
|
|
|
config_str command=NULL;
|
|
|
|
|
while ((current=va_arg(args,char*))){
|
|
|
|
|
yon_config_command_prepare(&command,&command_size,current);
|
|
|
|
|
if (config_type == YON_CONFIG_BOTH) return 0;
|
|
|
|
|
|
|
|
|
|
char *current;
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args,config_type);
|
|
|
|
|
|
|
|
|
|
int commands_size;
|
|
|
|
|
config_str commands = NULL;
|
|
|
|
|
while ((current=va_arg(args,char*))){
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(commands,&commands_size,current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *final_command = yon_config_command_get_full(commands,commands_size);
|
|
|
|
|
yon_config_set_last_command(final_command);
|
|
|
|
|
if (yon_char_is_empty(final_command)) return 0;
|
|
|
|
|
int parameters_size;
|
|
|
|
|
config_str parameters = yon_config_load(final_command,¶meters_size);
|
|
|
|
|
char *section = NULL;
|
|
|
|
|
if (!strstr(final_command," -ea ")){
|
|
|
|
|
section = yon_config_command_get_section(final_command);
|
|
|
|
|
}
|
|
|
|
|
yon_config_set_last_command(yon_char_parsed_to_string(command,command_size,";"));
|
|
|
|
|
for (int i=0;i<command_size;i++){
|
|
|
|
|
int parsed_size;
|
|
|
|
|
config_str parsed = yon_config_load(command[i],&parsed_size);
|
|
|
|
|
int command_parsed_size=0;
|
|
|
|
|
config_str command_parsed = yon_char_parse(command[i],&command_parsed_size," ");
|
|
|
|
|
if (config_type==YON_CONFIG_DEFAULT&&!strstr(command_parsed[5],"[*]")){
|
|
|
|
|
if (config_type==YON_CONFIG_DEFAULT)
|
|
|
|
|
yon_config_register_default(command_parsed[5], command[i],NULL);
|
|
|
|
|
}
|
|
|
|
|
yon_char_parsed_free(command_parsed,command_parsed_size);
|
|
|
|
|
if (parsed_size>0){
|
|
|
|
|
for (int j=0;j<parsed_size;j++){
|
|
|
|
|
if (!yon_char_is_empty(parsed[j])&&strcmp(parsed[j],"(null)\n")){
|
|
|
|
|
if (parsed[j][strlen(parsed[j])-1]=='\n') parsed[j][strlen(parsed[j])-1]='\0';
|
|
|
|
|
char *current_value = yon_char_new(parsed[j]);
|
|
|
|
|
char *key = yon_char_divide_search(current_value,"=",-1);
|
|
|
|
|
yon_char_remove_brackets(current_value);
|
|
|
|
|
char *current_command = yon_char_new(command[i]);
|
|
|
|
|
current_command = yon_config_replace_parameter(current_command,key,0);
|
|
|
|
|
char *cur_data = config(key);
|
|
|
|
|
int cur_ignore = yon_config_check_ignore(key);
|
|
|
|
|
if ((cur_ignore&¤t_value)||(!cur_ignore))
|
|
|
|
|
yon_config_register(key,current_command,current_value);
|
|
|
|
|
if (config_type==YON_CONFIG_DEFAULT){
|
|
|
|
|
yon_config_set_ignore(key);
|
|
|
|
|
yon_config_set_status(key,-2);
|
|
|
|
|
} else {
|
|
|
|
|
yon_config_default_remove(key);
|
|
|
|
|
yon_config_set_status(key,0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
yon_char_parsed_free(parsed,parsed_size);
|
|
|
|
|
for (int i=0;i<parameters_size;i++){
|
|
|
|
|
if (!strcmp(parameters[i],"(null)\n")) continue;
|
|
|
|
|
yon_char_remove_last_symbol(parameters[i],'\n');
|
|
|
|
|
char *value = yon_char_new(parameters[i]);
|
|
|
|
|
char *parameter = yon_char_divide_search(value,"=",-1);
|
|
|
|
|
if (parameter[0]=='['){
|
|
|
|
|
section = yon_char_divide_search(parameter," ",-1);
|
|
|
|
|
free(yon_char_divide(section,yon_char_find_last(section,'/')));
|
|
|
|
|
yon_char_remove_last_symbol(section,']');
|
|
|
|
|
}
|
|
|
|
|
yon_char_remove_brackets(value);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
char *get_parameter = yon_char_unite("[",section,"]"," ", value,NULL);
|
|
|
|
|
char *get_command = ubconfig_load_command_full("system",get_parameter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *cur_data = config(parameter);
|
|
|
|
|
int cur_ignore = yon_config_check_ignore(parameter);
|
|
|
|
|
|
|
|
|
|
if (config_type==YON_CONFIG_DEFAULT){
|
|
|
|
|
yon_config_register_default(parameter, get_command,NULL);
|
|
|
|
|
}
|
|
|
|
|
if ((cur_ignore&&value)||(!cur_ignore)){
|
|
|
|
|
yon_config_register(parameter,get_command,value);
|
|
|
|
|
// yon_config_set_section(parameter,section);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config_type==YON_CONFIG_DEFAULT){
|
|
|
|
|
yon_config_set_ignore(parameter);
|
|
|
|
|
yon_config_set_status(parameter,-2);
|
|
|
|
|
} else {
|
|
|
|
|
yon_config_default_remove(parameter);
|
|
|
|
|
yon_config_set_status(parameter,0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// int yon_config_load_config(YON_CONFIG_TYPE config_type, ...){
|
|
|
|
|
// if (config_type!=YON_CONFIG_BOTH){
|
|
|
|
|
// va_list args;
|
|
|
|
|
// va_start(args,config_type);
|
|
|
|
|
// char *current = NULL;
|
|
|
|
|
// int command_size=0;
|
|
|
|
|
// config_str command=NULL;
|
|
|
|
|
// while ((current=va_arg(args,char*))){
|
|
|
|
|
// yon_config_command_prepare(&command,&command_size,current);
|
|
|
|
|
// }
|
|
|
|
|
// yon_config_set_last_command(yon_char_parsed_to_string(command,command_size,";"));
|
|
|
|
|
// for (int i=0;i<command_size;i++){
|
|
|
|
|
// int parsed_size;
|
|
|
|
|
// config_str parsed = yon_config_load(command[i],&parsed_size);
|
|
|
|
|
// int command_parsed_size=0;
|
|
|
|
|
// config_str command_parsed = yon_char_parse(command[i],&command_parsed_size," ");
|
|
|
|
|
// if (config_type==YON_CONFIG_DEFAULT&&!strstr(command_parsed[5],"[*]")){
|
|
|
|
|
// if (config_type==YON_CONFIG_DEFAULT)
|
|
|
|
|
// yon_config_register_default(command_parsed[5], command[i],NULL);
|
|
|
|
|
// }
|
|
|
|
|
// yon_char_parsed_free(command_parsed,command_parsed_size);
|
|
|
|
|
// if (parsed_size>0){
|
|
|
|
|
// for (int j=0;j<parsed_size;j++){
|
|
|
|
|
// if (!yon_char_is_empty(parsed[j])&&strcmp(parsed[j],"(null)\n")){
|
|
|
|
|
// if (parsed[j][strlen(parsed[j])-1]=='\n') parsed[j][strlen(parsed[j])-1]='\0';
|
|
|
|
|
// char *current_value = yon_char_new(parsed[j]);
|
|
|
|
|
// char *key = yon_char_divide_search(current_value,"=",-1);
|
|
|
|
|
// yon_char_remove_brackets(current_value);
|
|
|
|
|
// char *current_command = yon_char_new(command[i]);
|
|
|
|
|
// current_command = yon_config_replace_parameter(current_command,key,0);
|
|
|
|
|
// char *cur_data = config(key);
|
|
|
|
|
// int cur_ignore = yon_config_check_ignore(key);
|
|
|
|
|
// if ((cur_ignore&¤t_value)||(!cur_ignore))
|
|
|
|
|
// yon_config_register(key,current_command,current_value);
|
|
|
|
|
// if (config_type==YON_CONFIG_DEFAULT){
|
|
|
|
|
// yon_config_set_ignore(key);
|
|
|
|
|
// yon_config_set_status(key,-2);
|
|
|
|
|
// } else {
|
|
|
|
|
// yon_config_default_remove(key);
|
|
|
|
|
// yon_config_set_status(key,0);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// yon_char_parsed_free(parsed,parsed_size);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *parameter, ...){
|
|
|
|
|
if (config_type!=YON_CONFIG_BOTH){
|
|
|
|
|
if (__yon__config__strings){
|
|
|
|
|
@ -682,7 +817,8 @@ config_str yon_config_get_all_keys_no_ignored(int *size){
|
|
|
|
|
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);
|
|
|
|
|
dict->data=data;
|
|
|
|
|
if (!dict) return 0;
|
|
|
|
|
dict->data=yon_char_new(data);
|
|
|
|
|
dict->flag1=1;
|
|
|
|
|
if (yon_dictionary_get(&__yon_config_ignored, dict->key)){
|
|
|
|
|
__yon_config_ignored = yon_dictionary_rip(__yon_config_ignored);
|
|
|
|
|
@ -723,6 +859,28 @@ int yon_config_default_remove(char *key){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// @brief Получение всех параметров отдельного раздела конфигурации
|
|
|
|
|
/// @param section_name Название раздела конфигурации
|
|
|
|
|
/// @param size размер финального массива
|
|
|
|
|
/// @return массив строк со всеми параметрами для запрашиваемого раздела
|
|
|
|
|
config_str yon_config_get_parameters_for_section(const char *section_name, int *size){
|
|
|
|
|
(*size)=0;
|
|
|
|
|
check_config{
|
|
|
|
|
int parameters_size;
|
|
|
|
|
config_str parameters = NULL;
|
|
|
|
|
|
|
|
|
|
yon_config_parameter *parameter;
|
|
|
|
|
for_dictionaries(parameter,__yon__config__strings){
|
|
|
|
|
if (!strcmp(parameter->section,section_name)){
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(parameters,¶meters_size,parameter->key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
(*size)=parameters_size;
|
|
|
|
|
return parameters;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum YON_CONFIG_SAVED_TYPE yon_config_register(char *key,char *config_load, char *data){
|
|
|
|
|
if (yon_char_is_empty(key)||yon_char_is_empty(config_load)) return YON_CONFIG_SAVED_ERROR;
|
|
|
|
|
|
|
|
|
|
@ -1130,8 +1288,11 @@ char *yon_config_parameter_prepare_command(char *command, char *path, char *sect
|
|
|
|
|
}
|
|
|
|
|
if (parameter){
|
|
|
|
|
if (size>=get_pos+2){
|
|
|
|
|
free(parsed[get_pos+2]);
|
|
|
|
|
parsed[get_pos+2] = yon_char_new(parameter);
|
|
|
|
|
config_str temp = yon_char_parsed_copy(parsed,get_pos+1);
|
|
|
|
|
yon_char_parsed_free(parsed,size);
|
|
|
|
|
parsed = temp;
|
|
|
|
|
size=get_pos+1;
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(parsed,&size,parameter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
char *final = yon_char_parsed_to_string(parsed,size," ");
|
|
|
|
|
@ -1306,8 +1467,10 @@ int yon_config_change_key(char *target, char *key){
|
|
|
|
|
|
|
|
|
|
char *yon_config_parameter_get_key(char *parameter_string){
|
|
|
|
|
char *key = yon_char_new(parameter_string);
|
|
|
|
|
if (strstr(key,"[")&&strstr(key,"]")){
|
|
|
|
|
free(yon_char_divide_search(key,"[",-1));
|
|
|
|
|
char *cut_text = strstr(key,"[");
|
|
|
|
|
if (cut_text&&strstr(key,"]")){
|
|
|
|
|
memcpy(key,key+(strlen(key)-strlen(cut_text))+1,strlen(cut_text));
|
|
|
|
|
// free(yon_char_divide_search(key,"[",-1));
|
|
|
|
|
yon_char_remove_last_symbol(key,']');
|
|
|
|
|
}
|
|
|
|
|
return key;
|
|
|
|
|
|