From f1399da08f0cec803ced94d5d99f5ed7c2a1eb22 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Tue, 30 May 2023 14:55:49 +0600 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=83=20=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B7=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8?= =?UTF-8?q?=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ubl-settings-resourcequota.c | 105 +++++++++++++++++++++++----- source/ubl-settings-resourcequota.h | 3 +- 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index 7cea41b..32eb766 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -260,6 +260,7 @@ void load_global_cfg() { void template_cfg(char* cmd) { int size = 0; + int index = 0; char** cfg = yon_config_load(cmd, &size); for (int index = 0; index < size; index++) { char* str_key_value = yon_char_new(cfg[index]); @@ -270,45 +271,113 @@ void template_cfg(char* cmd) { size_t length = strlen(str_key_value); str_key_value = yon_char_divide(str_key_value, length-2); } - str_split_value(str_key_value); + str_split_value(str_key_value, index); + index++; } - } } -void str_split_value(char* values) { +void str_split_value(char* values, int index) { char* new_value = yon_char_new(values); int size = 0; + char* key = NULL; + char* value = NULL; char** arr_values = philos_str_split(new_value, &size, ","); if (arr_values == NULL) { return; } - char* key = NULL; - char* value = NULL; - for (int index = 0; index < size; index++) { - value = arr_values[index]; + char* value_i = NULL; + for (int index_1 = 0; index_1 < size; index_1++) { + value = arr_values[index_1]; key = yon_char_divide_search(value, "=", -1); if (yon_char_find_count(key, "MemoryHigh") != 0) { - + set_pow_size(value, main_config.soft_raw_limit_size, main_config.soft_raw_limit, index); + } + else { + set_pow_size("-", main_config.soft_raw_limit_size, main_config.soft_raw_limit, index); + } + if (yon_char_find_count(key, "MemoryMax") != 0) { + set_pow_size(value, main_config.hard_raw_limit_size, main_config.hard_raw_limit, index); + } + else { + set_pow_size("-", main_config.hard_raw_limit_size, main_config.hard_raw_limit, index); } - else if (yon_char_find_count(key, "MemoryMax") != 0) { - + if (yon_char_find_count(key, "MemorySwapMax") != 0) { + set_pow_size(value, main_config.swap_size, main_config.swap, index); } - else if (yon_char_find_count(key, "MemorySwapMax") != 0) { - + else { + set_pow_size("-", main_config.swap_size, main_config.swap, index); } - else if (yon_char_find_count(key, "CPUQuota") != 0) { - + if (yon_char_find_count(key, "CPUQuota") != 0) { + set_pow_size(value, main_config.cpu_limit_size, main_config.cpu_limit, index); } - else if (yon_char_find_count(key, "IOReadBandwidthMax") != 0) { - + else { + set_pow_size("-", main_config.cpu_limit_size, main_config.cpu_limit, index); } - else if (yon_char_find_count(key, "IOWriteBandwidthMax") != 0) { - + if (yon_char_find_count(key, "IOReadBandwidthMax") != 0) { + set_pow_size(value, main_config.i_o_limit_read_size, main_config.i_o_limit_read, index); + } + else { + set_pow_size("-", main_config.i_o_limit_read_size, main_config.i_o_limit_read, index); + } + if (yon_char_find_count(key, "IOWriteBandwidthMax") != 0) { + set_pow_size(value, main_config.i_o_limit_write_size, main_config.i_o_limit_write, index); + } + else { + set_pow_size("-", main_config.i_o_limit_write_size, main_config.i_o_limit_write, index); } } } +void set_pow_size(char* str_find, int* array_size, char** array_data , int index) { + if (strstr(str_find,"K") != NULL) { + array_size = philos_int_append(array_size, &index, 0); + index--; + } + else if (strstr(str_find,"M") != NULL) { + array_size = philos_int_append(array_size, &index, 1); + index--; + } + else if (strstr(str_find,"G") != NULL) { + array_size = philos_int_append(array_size, &index, 2); + index--; + } + else if (strstr(str_find,"T") != NULL) { + array_size = philos_int_append(array_size, &index, 3); + index--; + } + else if (strstr(str_find,"\%") != NULL) { + array_size = philos_int_append(array_size, &index, -1); + index--; + } + else if (strstr(str_find,"\"") != NULL) { + + } + else if (strstr(str_find,"-") != NULL) { + array_size = philos_int_append(array_size, &index, -1); + index--; + } + if (strstr(str_find,"-") == NULL) { + size_t length = strlen(str_find); + str_find = yon_char_divide(str_find, length-2); + array_data = yon_char_parsed_append(array_data, &index, str_find); + } + else { + array_data = yon_char_parsed_append(array_data, &index, "-"); + } + GtkTreeIter iter; + gtk_list_store_append(main_config.list,&iter); + gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index], + 1,main_config.quota_volume[index], + 2,main_config.soft_raw_limit[index], + 3,main_config.hard_raw_limit[index], + 4,main_config.swap[index], + 5,main_config.cpu_limit[index], + 6,main_config.i_o_limit_read[index], + 7,main_config.i_o_limit_write[index],-1); +} + + void main_cbx_2_event() { int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtMainInfo)); char* cmd_text_param = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtMainInfo)); diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h index 8daf5b3..f9e6314 100755 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -180,4 +180,5 @@ void main_fill_tree_view_after_remove(); void load_system_cfg(); void load_global_cfg(); void template_cfg(char* cmd); -void str_split_value(char* values); \ No newline at end of file +void str_split_value(char* values, int index); +void set_pow_size(char* str_find, int* array_size, char** array_data, int index); \ No newline at end of file