|
|
|
|
@ -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;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,109 @@ void yon_config_set_last_command(char *command){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int yon_config_load_config(YON_CONFIG_TYPE config_type, ...){
|
|
|
|
|
if (config_type!=YON_CONFIG_BOTH){
|
|
|
|
|
if (config_type == YON_CONFIG_BOTH) return 0;
|
|
|
|
|
|
|
|
|
|
char *current;
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args,config_type);
|
|
|
|
|
char *current = NULL;
|
|
|
|
|
int command_size=0;
|
|
|
|
|
config_str command=NULL;
|
|
|
|
|
|
|
|
|
|
int commands_size;
|
|
|
|
|
config_str commands = NULL;
|
|
|
|
|
while ((current=va_arg(args,char*))){
|
|
|
|
|
yon_config_command_prepare(&command,&command_size,current);
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(commands,&commands_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);
|
|
|
|
|
|
|
|
|
|
char *final_command = yon_config_command_get_full(commands,commands_size);
|
|
|
|
|
|
|
|
|
|
int parameters_size;
|
|
|
|
|
printf("%s\n",final_command);
|
|
|
|
|
config_str parameters = yon_config_load(final_command,¶meters_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);
|
|
|
|
|
char *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_set_ignore(key);
|
|
|
|
|
yon_config_set_status(key,-2);
|
|
|
|
|
} else {
|
|
|
|
|
yon_config_default_remove(key);
|
|
|
|
|
yon_config_set_status(key,0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
yon_config_register_default(parameter, get_command,NULL);
|
|
|
|
|
}
|
|
|
|
|
yon_char_parsed_free(parsed,parsed_size);
|
|
|
|
|
if ((cur_ignore&&value)||(!cur_ignore)){
|
|
|
|
|
yon_config_register(parameter,get_command,value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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){
|
|
|
|
|
|