Scripts parsing fix

pull/129/head
Ivan Yartsev 6 months ago
parent 5222ad9c9f
commit 23c131a225

@ -1548,6 +1548,12 @@ logrotate_configure_window *yon_logrotate_window_new(char *paths, logrotate_wind
if (log_name){
char *parameters = yon_config_get_by_key(LOGROTATE(log_name));
if (parameters){
char *firstaction = "";
char *lastaction = "";
char *prerotate = "";
char *postrotate = "";
char *preremove = "";
char *current_script = NULL;
if(parameters[strlen(parameters)-1]=='\"') parameters[strlen(parameters)-1]='\0';
parameters=strstr(parameters,":");
if (parameters) parameters++;
@ -1672,32 +1678,56 @@ logrotate_configure_window *yon_logrotate_window_new(char *paths, logrotate_wind
}else if (!strcmp(parsed[i],"sharedscripts")){
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SharedScenariosCheck),1);
}else if (strstr(parsed[i],"firstaction")){
char *value = parsed[i+1];
gtk_entry_set_text(GTK_ENTRY(window->CommandBeforeOnceEntry),value);
i++;
current_script = "firstaction";
}else if (strstr(parsed[i],"lastaction")){
char *value = parsed[i+1];
gtk_entry_set_text(GTK_ENTRY(window->CommandAfterOnceEntry),value);
i++;
current_script = "lastaction";
}else if (strstr(parsed[i],"prerotate")){
char *value = parsed[i+1];
gtk_entry_set_text(GTK_ENTRY(window->CommandBeforeEntry),value);
i++;
current_script = "prerotate";
}else if (strstr(parsed[i],"postrotate")){
char *value = parsed[i+1];
gtk_entry_set_text(GTK_ENTRY(window->CommandAfterEntry),value);
i++;
current_script = "postrotate";
}else if (!strcmp(parsed[i],"preremove")){
char *value = parsed[i+1];
gtk_entry_set_text(GTK_ENTRY(window->EndworkCommandEntry),value);
i++;
current_script = "preremove";
}else if (!strcmp(parsed[i],"endscript")){
current_script = NULL;
}else if (strstr(parsed[i],"rotate")){
char *value = strstr(parsed[i]," ")+1;
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->FileAmountSpin),atol(value));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->FileAmountCheck),1);
}else if (!strcmp(parsed[i],"endscript")){
} else {
if (!yon_char_is_empty(current_script)){
if (!strcmp(current_script,"firstaction")){
char *temp = yon_char_unite(firstaction, !yon_char_is_empty(firstaction)?",":"", parsed[i],NULL);
if(!yon_char_is_empty(firstaction)) free(firstaction);
firstaction = temp;
} else if (!strcmp(current_script,"lastaction")){
char *temp = yon_char_unite(lastaction, !yon_char_is_empty(lastaction)?",":"", parsed[i],NULL);
if(!yon_char_is_empty(lastaction)) free(lastaction);
lastaction = temp;
} else if (!strcmp(current_script,"prerotate")){
char *temp = yon_char_unite(prerotate, !yon_char_is_empty(prerotate)?",":"", parsed[i],NULL);
if(!yon_char_is_empty(prerotate)) free(prerotate);
prerotate = temp;
} else if (!strcmp(current_script,"postrotate")){
char *temp = yon_char_unite(postrotate, !yon_char_is_empty(postrotate)?",":"", parsed[i],NULL);
if(!yon_char_is_empty(postrotate)) free(postrotate);
postrotate = temp;
} else if (!strcmp(current_script,"preremove")){
char *temp = yon_char_unite(preremove, !yon_char_is_empty(preremove)?",":"", parsed[i],NULL);
if(!yon_char_is_empty(preremove)) free(preremove);
preremove = temp;
}
}
}
}
if (!yon_char_is_empty(firstaction)) gtk_entry_set_text(GTK_ENTRY(window->CommandBeforeOnceEntry),firstaction);
if (!yon_char_is_empty(lastaction)) gtk_entry_set_text(GTK_ENTRY(window->CommandAfterOnceEntry),lastaction);
if (!yon_char_is_empty(prerotate)) gtk_entry_set_text(GTK_ENTRY(window->CommandBeforeEntry),prerotate);
if (!yon_char_is_empty(postrotate)) gtk_entry_set_text(GTK_ENTRY(window->CommandAfterEntry),postrotate);
if (!yon_char_is_empty(preremove)) gtk_entry_set_text(GTK_ENTRY(window->EndworkCommandEntry),preremove);
}
}
}

Loading…
Cancel
Save