diff --git a/Makefile b/Makefile
index 2ec93b6..9b35b7b 100644
--- a/Makefile
+++ b/Makefile
@@ -8,10 +8,13 @@ MAKEFILE_PATH := $(dir $(MAKEFILE_FILEPATH))
CMAKE_COMMAND = cmake
CMAKE_SOURCE_DIR = $(MAKEFILE_PATH)source
CMAKE_BUILD_DIR = $(MAKEFILE_PATH)compile
+#CMAKE_SOURCE_DIR = ./source
+#CMAKE_BUILD_DIR = ./compile
DEPENDS = /bin/cmake
PREFIX ?= /usr
PKGNAME = $(MAKEFILE_DIR)
-
+#PKGNAME = ubl-settings-manager
+LATEST_TAG=
default_target: all
.PHONY: all init depend debug prepare check build uninstall install clean help
@@ -21,11 +24,11 @@ all: init build
init:
@echo "Initialize ..."; \
if [ -d ".git" ]; then \
- LATEST_TAG=$$(git describe --tags | sed 's/^v//'); \
+ LATEST_TAG=$$(git describe --tags | sed 's/^v//'|grep -oE "^[0-9]{1,}.[0-9]{1,}"); \
else \
LATEST_TAG="0.0"; \
fi; \
- sed -r "s/^(string version_application = ).*/\1\"$${LATEST_TAG}\";/" -i source/${PKGNAME}.h; \
+ sed -r "s/^(string version_application).*/\1=\"$${LATEST_TAG}\";/" -i source/${PKGNAME}.h; \
echo "-- Build path: ${CMAKE_BUILD_DIR}"
depend:
@@ -36,14 +39,16 @@ depend:
exit 1; \
fi; \
done; \
- $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B${CMAKE_BUILD_DIR} --check-build-system CMakeFiles/Makefile.cmake 1 || exit 1; \
echo "Check depends: OK"
+# $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
-debug:
- @echo "Debug ..."
+debug: init build
+ @echo "Debug ..."; \
if [ ! -d ${CMAKE_BUILD_DIR} ]; then \
$(CMAKE_COMMAND) -S${CMAKE_SOURCE_DIR} -B${CMAKE_BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="${PREFIX}"; \
fi; \
+ echo "${CMAKE_BUILD_DIR}/${PKGNAME}"; \
+ cp ${CMAKE_BUILD_DIR}/${PKGNAME} ./; \
echo "Debug: OK"
prepare:
@@ -87,7 +92,9 @@ uninstall:
@$(RM) "${DESTDIR}${PREFIX}/bin/${PKGNAME}"
@$(RM) "${DESTDIR}${PREFIX}/share/applications/${PKGNAME}.desktop"
@$(RM) "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps/com.ublinux.${PKGNAME}.svg"
- @$(RM) -rd "${DESTDIR}${PREFIX}/share/${PKGNAME}"
+ @$(RM) "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps/com.ublinux.${PKGNAME}.checked.svg"
+ @$(RM) "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps/com.ublinux.${PKGNAME}.warning.svg"
+ @$(RM) "${DESTDIR}${PREFIX}/share/polkit-1/actions/com.ublinux.${PKGNAME}.policy"
@if [ -z ${DESTDIR} ]; then \
[ -d "${DESTDIR}${PREFIX}/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}${PREFIX}/share/icons/hicolor/" &>/dev/null || true; \
update-desktop-database --quiet &>/dev/null || true; \
@@ -96,8 +103,10 @@ uninstall:
@echo "Uninstall: OK"
install: check uninstall
- @cc source/my_device.c source/my_device.h source/filters.c source/filters.h source/ubl-cmake.h source/view_edit.h source/view_edit.c source/view_add.h source/view_add.c source/ubl-utils.h source/ubl-utils.c source/ubl-strings.h source/ubl-settings-resourcequota.h source/ubl-settings-resourcequota.c -o ubl-settings-resourcequota `pkg-config --cflags --libs gtk+-3.0 vte-2.91 webkit2gtk-4.0 webkit2gtk-web-extension-4.0` -g
@echo "Install ..."
+#################################################### УДАЛИТЬ ПЕРЕД КОММИТОМ ################################################################################
+ @gcc compile/resources.c source/my_device.c source/philos_utils.c source/philos_utils.h source/my_device.h source/filters.c source/filters.h source/ubl-cmake.h source/view_edit.h source/view_edit.c source/view_add.h source/view_add.c source/ubl-utils.h source/ubl-utils.c source/ubl-strings.h source/ubl-settings-resourcequota.h source/ubl-settings-resourcequota.c -o ubl-settings-resourcequota `pkg-config --cflags --libs gtk+-3.0 vte-2.91 webkit2gtk-4.0 webkit2gtk-web-extension-4.0` -g
+#################################################### УДАЛИТЬ ПЕРЕД КОММИТОМ ################################################################################
@for FILE_PO in $(wildcard *.po); do \
LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \
install -dm755 "${DESTDIR}${PREFIX}/share/locale/$${LANG}/LC_MESSAGES"; \
@@ -112,14 +121,12 @@ install: check uninstall
done
@install -dm755 "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps"
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps/" "com.ublinux.${PKGNAME}.svg"
+ @install -dm755 "${DESTDIR}${PREFIX}/share/polkit-1/actions"
+ @install -Dm644 -t "${DESTDIR}${PREFIX}/share/polkit-1/actions/" "com.ublinux.${PKGNAME}.policy"
@install -Dm755 -t "${DESTDIR}${PREFIX}/bin/" "${CMAKE_BUILD_DIR}/${PKGNAME}"
+ @install -dm755 "${DESTDIR}/etc/xdg"
@install -dm755 "${DESTDIR}${PREFIX}/share/applications"
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/applications/" "${PKGNAME}.desktop"
- @install -dm755 "${DESTDIR}${PREFIX}/share/${PKGNAME}"/{ui,css,images}
- @install -Dm644 -t "${DESTDIR}${PREFIX}/share/${PKGNAME}/ui/" "${PKGNAME}.glade"
- @install -Dm644 -t "${DESTDIR}${PREFIX}/share/${PKGNAME}/css/" "${PKGNAME}.css"
- @install -dm755 -d "${DESTDIR}${PREFIX}/share/${PKGNAME}/images"
- @install -Dm644 -t "${DESTDIR}${PREFIX}/share/${PKGNAME}/images/" "${PKGNAME}-banner.png"
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/status/" "com.ublinux.${PKGNAME}.checked.svg"
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/status/" "com.ublinux.${PKGNAME}.warning.svg"
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/status/" "com.ublinux.${PKGNAME}.funnel.svg"
@@ -129,6 +136,7 @@ install: check uninstall
[ -d "${DESTDIR}${PREFIX}/share/applications" ] && touch "${DESTDIR}${PREFIX}/share/applications" &>/dev/null || true; \
fi
@echo "Install: OK"
+ @sed -r "s/^(string version_application=\"*\").*/string version_application;/" -i source/${PKGNAME}.h; \
clean:
@echo "Clean ..."
@@ -139,6 +147,14 @@ clean:
echo "Clean: OK"; \
fi
+up_ver:
+ @CURRENT=$$(grep 'VERSION' ${FILE_VERSION} | cut -d" " -f2); \
+ MAJOR=$$(cut -d. -f1 <<< $${CURRENT}); \
+ MINOR=$$(cut -d. -f2 <<< $${CURRENT}); \
+ VER="$${MAJOR}.$$(($${MINOR}+1))"; \
+ sed "s/VERSION *[[:digit:]]*.*/VERSION $${VER}/" -i ${FILE_VERSION}; \
+ echo "Updated version to VERSION.md: $${CURRENT} to $${VER}"
+
help:
@echo "The following are some of the valid targets for this Makefile:"; \
echo "... all (the default if no target is provided)"; \
@@ -148,4 +164,5 @@ help:
echo "... compile"; \
echo "... install"; \
echo "... uninstall"; \
- echo "... clean"
+ echo "... clean"; \
+ echo "... up_ver"
\ No newline at end of file
diff --git a/gresource.xml b/gresource.xml
new file mode 100644
index 0000000..ed4693e
--- /dev/null
+++ b/gresource.xml
@@ -0,0 +1,12 @@
+
+
+
+ ubl-settings-resourcequota.glade
+
+
+ ubl-settings-resourcequota.css
+
+
+ ubl-settings-resourcequota-banner.png
+
+
\ No newline at end of file
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index b61aca0..5202797 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -1,12 +1,12 @@
-cmake_minimum_required(VERSION 3.23)
+cmake_minimum_required(VERSION 3.7)
project(ubl-settings-resourcequota)
find_package(PkgConfig REQUIRED)
-pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
-include_directories(${GTK3_INCLUDE_DIRS})
-link_directories(${GTK3_LIBRARY_DIRS})
-add_definitions(${GTK3_CFLAGS_OTHER})
+pkg_check_modules(GTK REQUIRED gtk+-3.0)
+include_directories(${GTK_INCLUDE_DIRS})
+link_directories(${GTK_LIBRARY_DIRS})
+add_definitions(${GTK_CFLAGS_OTHER})
pkg_check_modules(VTE291 REQUIRED vte-2.91)
include_directories(${VTE291_INCLUDE_DIRS})
@@ -24,7 +24,42 @@ if(WEBKIT_LIBRARIES_FOUND)
add_definitions(${WEBKIT_CFLAGS_OTHER})
endif()
-configure_file(ubl-cmake.h.in ubl-cmake.h)
+configure_file(ubl-cmake.in ubl-cmake.h)
+
+file(COPY ${CMAKE_CURRENT_BINARY_DIR}/ubl-cmake.h DESTINATION ./)
+
+set(GRESOURCE_C resources.c)
+set(GRESOURCE_XML gresource.xml)
+
+find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED)
+add_custom_target(GLADE ubl-settings-resourcequota.glade)
+
+set(DEPENDFILES
+ ../ubl-settings-resourcequota.glade
+ ../gresource.xml
+ ../ubl-settings-resourcequota-banner.png
+ ../ubl-settings-resourcequota.css
+ )
+
+file(COPY ${DEPENDFILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+
+add_custom_command(
+ OUTPUT ${GRESOURCE_C}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMAND ${GLIB_COMPILE_RESOURCES}
+ ARGS
+ --generate-source
+ --target=${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}
+ ${GRESOURCE_XML}
+ VERBATIM
+ MAIN_DEPENDENCY ${GRESOURCE_XML}
+ DEPENDS
+ ${GLADE}
+)
+add_custom_target(
+ dummy-resource
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}
+)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -lm")
@@ -32,6 +67,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin
-O2 -pipe -fno-plt -fexceptions \
-Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \
-fstack-clash-protection -fcf-protection")
+
set(SOURCE_FILES
ubl-settings-resourcequota.c
@@ -47,15 +83,25 @@ set(SOURCE_FILES
ubl-strings.h
ubl-utils.h
ubl-utils.c
- ubl-cmake.h)
+ ubl-cmake.h
+ philos_utils.c
+ philos_utils.h
+ ${CMAKE_CURRENT_BINARY_DIR}/ubl-cmake.h
+ )
set(LIBRARIES
- ${GTK3_LIBRARIES}
+ ${GTK_LIBRARIES}
${WEBKIT_LIBRARIES}
${VTE291_LIBRARIES}
pthread)
-add_executable(${PROJECT_NAME} ${SOURCE_FILES})
+
+add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR})
-install(TARGETS ${PROJECT_NAME} DESTINATION bin)
\ No newline at end of file
+set_source_files_properties(
+ ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}
+ PROPERTIES GENERATED TRUE
+)
+install(TARGETS ${PROJECT_NAME} DESTINATION bin)
+add_dependencies(${PROJECT_NAME} dummy-resource)
\ No newline at end of file
diff --git a/source/filters.c b/source/filters.c
index c5f816e..f4397b9 100644
--- a/source/filters.c
+++ b/source/filters.c
@@ -5,7 +5,7 @@ gboolean flag_filters[8];
filters_window *filters_setup_window(char* glade_path){
if (filters_widgets == NULL) {
filters_widgets = malloc(sizeof(filters_window));
- GtkBuilder *builder = gtk_builder_new_from_file(glade_path);
+ GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
filters_widgets->Window = yon_gtk_builder_get_widget(builder,"wndFilters");
filters_widgets->chbFilterTypeQouota = yon_gtk_builder_get_widget(builder,"chbFilterTypeQouota");
filters_widgets->chbQuotaVolume = yon_gtk_builder_get_widget(builder,"chbQuotaVolume");
diff --git a/source/filters.h b/source/filters.h
index 96025df..8dd6a40 100644
--- a/source/filters.h
+++ b/source/filters.h
@@ -11,7 +11,7 @@
#include
#include
#include
-
+#include "philos_utils.h"
// Переменные
typedef struct {
diff --git a/source/my_device.h b/source/my_device.h
index 67d2211..c2ef0e6 100644
--- a/source/my_device.h
+++ b/source/my_device.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include "philos_utils.h"
typedef struct {
char** name_disk;
char** file_system;
diff --git a/source/philos_utils.c b/source/philos_utils.c
new file mode 100644
index 0000000..a3d6e4e
--- /dev/null
+++ b/source/philos_utils.c
@@ -0,0 +1,969 @@
+#include "philos_utils.h"
+
+void philos_array_string_remove_char(char*** array, char* str_remove, int size) {
+ for (int index = 0; index < size; index++) {
+ (*array)[index] = yon_char_divide_search((*array)[index], str_remove, -1);
+ }
+
+}
+
+void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char** array_size_pow) {
+ char* STR_KB = array_size_pow[0];
+ char* STR_MB = array_size_pow[1];
+ char* STR_GB = array_size_pow[2];
+ char* STR_TB = array_size_pow[3];
+ size_t length = strlen(str_find);
+ if (strstr(str_find,"K") != NULL) {
+ *array_size = philos_int_append(*array_size, &index, 0);
+ str_find = yon_char_divide(str_find, length-1);
+ str_find = yon_char_unite(str_find, " ", STR_KB, NULL);
+ index--;
+ }
+ else if (strstr(str_find,"M") != NULL) {
+ *array_size = philos_int_append(*array_size, &index, 1);
+ str_find = yon_char_divide(str_find, length-1);
+ str_find = yon_char_unite(str_find," ", STR_MB, NULL);
+ index--;
+ }
+ else if (strstr(str_find,"G") != NULL) {
+ *array_size = philos_int_append(*array_size, &index, 2);
+ str_find = yon_char_divide(str_find, length-1);
+ str_find = yon_char_unite(str_find," ", STR_GB, NULL);
+ index--;
+ }
+ else if (strstr(str_find,"T") != NULL) {
+ *array_size = philos_int_append(*array_size, &index, 3);
+ str_find = yon_char_divide(str_find, length-1);
+
+ str_find = yon_char_unite(str_find," ", STR_TB, NULL);
+ index--;
+ }
+ else if (strstr(str_find,"%%") != NULL) {
+ *array_size = philos_int_append(*array_size, &index, -1);
+ str_find = yon_char_divide(str_find, length-1);
+ index--;
+ }
+ else if (strstr(str_find,"-") != NULL) {
+ *array_size = philos_int_append(*array_size, &index, -1);
+ index--;
+ }
+
+}
+
+void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index) {
+ char* simv_del_array[10] = {"K","M","G","T","k","m","g","t"," ","%"};
+ for (size_t i = 0; i < 10; i++) {
+ if (strstr(str_find, simv_del_array[i])) {
+ str_find = yon_char_divide_search(str_find, simv_del_array[i], -1);
+ }
+ }
+ if (strstr(str_find, " ") != NULL) {
+ char* mem_s = yon_char_new(str_find);
+ yon_char_divide_search(mem_s, " ", -1);
+ *array_data = yon_char_parsed_append(*array_data, &index, mem_s);
+ }
+ if (strstr(str_find, "-") != NULL) {
+ *array_data = yon_char_parsed_append(*array_data, &index, "-");
+ }
+ else {
+ if (str_find[0] == '\"') {
+ yon_char_divide(str_find, 0);
+ size_t length = strlen(str_find);
+ str_find = yon_char_divide(str_find, length-2);
+ }
+ if (strstr(str_find, " ") == NULL) {
+ *array_data = yon_char_parsed_append(*array_data, &index, str_find);
+ }
+
+ }
+}
+
+void philos_free_string_array(char ***array, int size) {
+ if ((*array) == NULL) {
+ return;
+ }
+ for (int i = 0; i < size; i++){
+ free((*array)[i]);
+ }
+ if (size!= 0) {
+ free(*array);
+ (*array) = NULL;
+ }
+}
+
+void philos_free_string_array_n3(char ****array, int size) {
+ if ((*array) == NULL || size == 0) {
+ return;
+ }
+ int index_to_l2 = 0;
+ for (int i = 0; i < size; i++){
+ index_to_l2 = 0;
+ if ((*array)[i]!=NULL) {
+ while ((*array)[i][index_to_l2] != NULL) {
+ if ((*array)[i][index_to_l2] != NULL) {
+ free((*array)[i][index_to_l2]);
+ index_to_l2++;
+ }
+
+ }
+ }
+ free((*array)[i]);
+
+ }
+ if (size!= 0) {
+ free(*array);
+ (*array) = NULL;
+ }
+}
+
+void philos_free_int_array(int **array, int size) {
+ if (size!= 0) {
+ free(*array);
+ *array = NULL;
+ }
+}
+void philos_free_int_array_n2(int ***array, int size) {
+ if ((*array) == NULL || size == 0) {
+ return;
+ }
+ for (int i = 0; i < size; i++){
+ free((*array)[i]);
+ }
+ if (size!= 0) {
+ free(*array);
+ (*array) = NULL;
+ }
+}
+
+config_str philos_list_group(int* size) {
+ char* str_uid_min = "UID_MIN";
+ char* str_uid_max = "UID_MAX";
+ unsigned short uid_min = philos_read_uid_min_max(file_source_login_min_max, str_uid_min);
+ unsigned short uid_max = philos_read_uid_min_max(file_source_login_min_max, str_uid_max);
+ config_str str_users = malloc(1);
+ while (1) {
+ errno = 0; // so we can distinguish errors from no more entries
+ struct passwd* entry = getpwent();
+ if (!entry) {
+ if (errno) {
+ return str_users;
+ }
+ break;
+ }
+ if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
+ str_users = yon_char_parsed_append(str_users, size, entry->pw_name);
+ }
+ }
+ endpwent();
+ return str_users;
+}
+
+unsigned short philos_read_uid_min_max(char* filename, char* search) {
+ int uid = 0;
+ char* remove_tab = "\t";
+ char* remove_space = " ";
+ char* search_uid_min = "UID_MIN";
+ int buff_size = 255;
+ char* line = g_malloc0(buff_size);
+ char* search_true = yon_char_get_augumented("SYS_", search);
+ FILE *fp = fopen(filename, "r");
+ if(fp) {
+ while((fgets(line, buff_size, fp)) != NULL) {
+ try{
+ if (yon_char_find_count(line, search) != 0 && yon_char_find_count(line, search_true) == 0) {
+ line = philos_str_remove(line, search);
+ line = philos_str_remove(line, remove_space);
+ line = philos_str_remove(line, remove_tab);
+ uid = atoi(line);
+
+ }
+ }
+ catch (...) {
+ if (yon_char_find_count(search, search_uid_min) != 0){
+ uid = 1000;
+ }
+ else{
+ uid = 65534;
+ }
+ }
+ }
+ }
+ else{
+ if (yon_char_find_count(search, search_uid_min) != 0) {
+ uid = 1000;
+ }
+ else{
+ uid = 65534;
+ }
+ }
+ fclose(fp);
+ free(line);
+ free(search_true);
+ return uid;
+
+}
+
+
+config_str philos_list_user(int* size) {
+ char* str_uid_min = "UID_MIN";
+ char* str_uid_max = "UID_MAX";
+ unsigned short uid_min = philos_read_uid_min_max(file_source_login_min_max, str_uid_min);
+ unsigned short uid_max = philos_read_uid_min_max(file_source_login_min_max, str_uid_max);
+ config_str str_users = malloc(1);
+ while (1) {
+ errno = 0; // so we can distinguish errors from no more entries
+ struct passwd* entry = getpwent();
+ if (!entry) {
+ if (errno) {
+ return str_users;
+ }
+ break;
+ }
+ //if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
+ str_users = yon_char_parsed_append(str_users, size, entry->pw_name);
+ //}
+ }
+ endpwent();
+ return str_users;
+}
+
+char* philos_str_size_pow_byte(GtkWidget *combo_box_text) {
+ int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box_text));
+ if (menu_id == 0) {
+ return "K";
+ }
+ else if (menu_id == 1) {
+ return "M";
+ }
+ else if (menu_id == 2) {
+ return "G";
+ }
+ else if (menu_id == 3) {
+ return "T";
+ }
+ else {
+ return " ";
+ }
+}
+
+char* philos_str_remove(char *str, const char *sub) {
+ size_t len = strlen(sub);
+ if (len > 0) {
+ char *p = str;
+ size_t size = 0;
+ while ((p = strstr(p, sub)) != NULL) {
+ size = (size == 0) ? (p - str) + strlen(p + len) + 1 : size - len;
+ memmove(p, p + len, size - (p - str));
+ }
+ }
+ return str;
+}
+
+
+void philos_split_size_memory(char* str_value, int* size, char* pow_memory) {
+ // pow_memory = yon_char_new(str_value);
+ (*size) = atoi(yon_char_divide_search(pow_memory, " ", -1));
+}
+
+char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory) {
+ if (value == -1 || value == -3 || pow_size_memory == -3) {
+ return yon_char_new("-");
+ }
+ char* str_value = yon_char_from_int(value);
+ str_value = yon_char_divide_search(str_value, " ", -1);
+ if (pow_size_memory==0) {
+ return yon_char_unite(str_key, str_value, "K" ,NULL);
+ }
+ else if (pow_size_memory==1) {
+ return yon_char_unite(str_key, str_value, "M" ,NULL);
+ }
+ else if (pow_size_memory==2){
+ return yon_char_unite(str_key, str_value, "G" ,NULL);
+ }
+ else if (pow_size_memory== 3) {
+ return yon_char_unite(str_key, str_value, "T" ,NULL);
+ }
+ else if (pow_size_memory== -1) {
+ return yon_char_unite(str_key, str_value, "%" ,NULL);
+ }
+ else {
+ return yon_char_unite(str_key, str_value, "-" ,NULL);
+ }
+}
+
+char** philos_str_split(char *parameters, int *size, char *divider) {
+ char** array_split = NULL;
+ char* ch= NULL;
+ ch = strtok(parameters, divider);
+ if (ch != NULL) {
+ array_split = yon_char_parsed_append(array_split, size, ch);
+ while (ch != NULL) {
+ ch = strtok(NULL, divider);
+ array_split = yon_char_parsed_append(array_split, size, ch);
+ }
+ }
+ (*size) -= 1;
+ return array_split;
+}
+
+void philos_array_str_copy(char*** source, char*** copy) {
+ int index = 0;
+ if (copy == NULL || source == NULL) {
+ return;
+ }
+ while (1) {
+ if ((*copy)[index] != NULL) {
+ (*source) = yon_char_parsed_append((*source), &index, yon_char_new((*copy)[index]));
+ }
+ else {
+ break;
+ }
+ }
+}
+void philos_array_int_copy(int** source, int** copy) {
+ int * new_int = g_malloc0(sizeof(int)*2);
+ if ((*copy)[0] != -2) {
+ new_int[0] = (*copy)[0];
+ new_int[1] = -2;
+ int i = 2;
+ for (i=1;(*copy)[i]!=-2;i++) {
+ yon_int_array_append(&new_int,(*copy)[i]);
+ }
+ *source=new_int;
+ }
+ else {
+ new_int[0] = (*copy)[0];
+ *source=new_int;
+ }
+
+}
+char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data) {
+ int size = 0;
+ char** terminal_print = yon_config_load(CMD_GET_SLICE_SERVICE, &size);
+ char** array_data = NULL;
+ for (int index = 0; index < size; index++) {
+ if (strstr(terminal_print[index], str_find) != NULL) {
+ yon_char_divide_search(terminal_print[index],"─",-1);
+ terminal_print[index] = yon_char_divide_search(terminal_print[index]," ", -1);
+ yon_char_divide(terminal_print[index],1);
+ array_data = yon_char_parsed_append(array_data, size_array_data, terminal_print[index]);
+
+ }
+ }
+ return array_data;
+}
+char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size) {
+ char* split_simvol = g_malloc0(sizeof(char)*2);
+ int flag_format = 0;
+ char* cmd_old = yon_char_new(cmd);
+ if (_config->disk && _config->size && array_io && array_io_pow_size) {
+ int index_find = 0;
+ for (int index = 0; index < _config->size; index++) {
+ if (index==0) {
+ if (strlen(cmd)>1) {
+ cmd = yon_char_unite(cmd, ",", key, NULL);
+ }
+ else {
+ cmd = yon_char_unite(cmd, key, NULL);
+ }
+
+ }
+ if (array_io_pow_size[index] != -1 && array_io[index]!=-2 && array_io[index]!=-1) {
+ char* num_and_pow_size = philos_format_cfg_str_size_memory(" ", array_io[index], array_io_pow_size[index]);
+ cmd = yon_char_unite(cmd,
+ split_simvol,
+ _config->disk[index],
+ num_and_pow_size, NULL);
+ split_simvol[0] = ',';
+ split_simvol[1] = '\0';
+ flag_format = 1;
+ free(num_and_pow_size);
+ }
+ }
+ }
+ free(split_simvol);
+ if (flag_format) {
+ return cmd;
+ }
+ else {
+ return cmd_old;
+ }
+
+}
+int philos_check_activ_disk(temp_set_window *widgets, temp_config* _config) {
+ char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
+ disk = yon_char_divide_search(disk," ", -1);
+ int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
+ int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
+ if (disk == NULL || _config->size == 0) {
+ return 0;
+ }
+ return 1;
+}
+
+void philos_temp_generate_cmd(temp_set_window *widgets, temp_config* _config) {
+ char* str_cmd = "";
+ char* split_simvol = g_malloc0(sizeof(char)*2);
+ int size_bite = 0;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkSoftRestrictionTemp))) {
+ size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spiSevereRestrictionTemp));
+ str_cmd = yon_char_unite(str_cmd,
+ "MemoryHigh=",
+ yon_char_from_int(size_bite),
+ philos_str_size_pow_byte(widgets->cmSevereRestrictionTemp), NULL);
+ split_simvol[0] = ',';
+ split_simvol[1] = '\0';
+ }
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkSevereRestrictionTemp))) {
+ size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinSevereRestrictionTemp));
+ str_cmd = yon_char_unite(str_cmd, split_simvol,
+ "MemoryMax=",
+ yon_char_from_int(size_bite),
+ philos_str_size_pow_byte(widgets->cmbSevereRestrictionTemp), NULL);
+ split_simvol[0] = ',';
+ split_simvol[1] = '\0';
+ }
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkPaddingFLTemp))) {
+ size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinPaddingFLTemp));
+ str_cmd = yon_char_unite(str_cmd, split_simvol,
+ "MemorySwapMax=",
+ yon_char_from_int(size_bite),
+ philos_str_size_pow_byte(widgets->cmbPaddingFLTemp), NULL);
+ split_simvol[0] = ',';
+ split_simvol[1] = '\0';
+ }
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkCPULimitTemp))) {
+ size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinCPULimitTemp));
+ str_cmd = yon_char_unite(str_cmd, split_simvol,
+ "CPUQuota=",
+ yon_char_from_int(size_bite),
+ "%", NULL);
+ split_simvol[0] = ',';
+ split_simvol[1] = '\0';
+ }
+ if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice))!=-1) {
+ if (_config->size!=0) {
+ str_cmd = philos_pard_array_add_cmd(str_cmd, _config, "IOReadBandwidthMax=", _config->i_o_limit_read, _config->i_o_limit_read_size);
+ str_cmd = philos_pard_array_add_cmd(str_cmd, _config, "IOWriteBandwidthMax=", _config->i_o_limit_write, _config->i_o_limit_write_size);
+ }
+
+ }
+ gtk_entry_set_text(GTK_ENTRY(widgets->entryTempCmd), str_cmd);
+ free(split_simvol);
+}
+void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config) {
+ char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
+ disk = yon_char_divide_search(disk, " ", -1);
+ int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
+ int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
+ if (philos_check_activ_disk(widgets, _config) == 0) {
+ return;
+ }
+ if (_config->disk && _config->size) {
+ int index_find = -1;
+ for (int index = 0; index < _config->size; index++) {
+ char* disk_cfg = _config->disk[index];
+ if (strstr(disk_cfg, disk) != NULL) {
+ index_find = index;
+ break;
+ }
+ }
+ if ((bool_read == 0 && bool_write == 0 && index_find != -1)) {
+ _config->disk = yon_char_parsed_shrink(_config->disk,&_config->size, index_find);
+ _config->size++;
+ _config->i_o_limit_read_size = remove_element_int_array(_config->i_o_limit_read_size,&_config->size, index_find);
+ _config->size++;
+ _config->i_o_limit_write_size = remove_element_int_array(_config->i_o_limit_write_size,&_config->size, index_find);
+ _config->size++;
+ _config->i_o_limit_read = remove_element_int_array(_config->i_o_limit_read,&_config->size, index_find);
+ _config->size++;
+ _config->i_o_limit_write = remove_element_int_array(_config->i_o_limit_write,&_config->size, index_find);
+ }
+ }
+}
+
+void philos_temp_config_init(temp_config* _config) {
+ if (_config->size != 0) {
+ philos_free_string_array(&_config->disk, _config->size);
+ philos_free_int_array(&_config->i_o_limit_read, _config->size);
+ philos_free_int_array(&_config->i_o_limit_read_size, _config->size);
+ philos_free_int_array(&_config->i_o_limit_write, _config->size);
+ philos_free_int_array(&_config->i_o_limit_write_size, _config->size);
+ }
+ _config->disk = NULL;
+ _config->i_o_limit_read = NULL;
+ _config->i_o_limit_write = NULL;
+ _config->i_o_limit_read_size = NULL;
+ _config->i_o_limit_write_size = NULL;
+ _config->size = 0;
+}
+// flag_check_array = 0 READ
+// flag_check_array = 1 WRITE
+void philos_update_device_to_entry(temp_set_window *widgets, temp_config* _config, int flag_check_array) {
+ int disk_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice));
+ char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
+ disk = yon_char_divide_search(disk, " ", -1);
+ if (disk_id != -1) {
+ int index_find = -1;
+ for (int index = 0; index < _config->size; index++) {
+ char* disk_cfg = _config->disk[index];
+ if (strstr(disk_cfg, disk) != NULL) {
+ index_find = index;
+ break;
+ }
+ }
+ if (index_find != -1) {
+ if (flag_check_array==0) {
+ if (_config->i_o_limit_read[index_find]==-2 || _config->i_o_limit_read[index_find]==-1) {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
+ }
+ else {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), _config->i_o_limit_read[index_find]);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 1);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), _config->i_o_limit_read_size[index_find]);
+
+ }
+ }
+ else if (flag_check_array==1) {
+ if (_config->i_o_limit_write[index_find]==-2 || _config->i_o_limit_write[index_find]==-1) {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
+ }
+ else {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), _config->i_o_limit_write[index_find]);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 1);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), _config->i_o_limit_write_size[index_find]);
+ }
+ }
+ else {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
+ }
+ }
+ else {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
+ }
+ }
+ else {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
+ }
+}
+
+void philos_temp_add_disk(temp_set_window *widgets, temp_config* _config) {
+ char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
+ disk = yon_char_divide_search(disk, " ", -1);
+ int disk_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice));
+ int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
+ int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
+ if (disk_id >= 0 && _config->size !=0) {
+ int index_find = -1;
+ for (int index = 0; index < _config->size; index++) {
+ char* disk_cfg = _config->disk[index];
+ if (strstr(disk_cfg, disk) != NULL) {
+ index_find = index;
+ break;
+ }
+ }
+ if (index_find == -1) {
+ // Добавление
+ _config->disk = yon_char_parsed_append(_config->disk,&_config->size, disk);
+ _config->size--;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
+ _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead)));
+ _config->size--;
+ _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead)));
+ _config->size--;
+ }
+ else {
+ _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,-3);
+ _config->size--;
+ _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,-3);
+ _config->size--;
+ }
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
+ _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite)));
+ _config->size--;
+ _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite)));
+ _config->size--;
+ }
+ else {
+ _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,-3);
+ _config->size--;
+ _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,-3);
+ _config->size--;
+ }
+ _config->size++;
+
+ }
+ else {
+ // Редактирование
+ //_config->disk[index_find] = yon_char_new(disk);
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
+ _config->i_o_limit_read_size[index_find] =(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead));
+ _config->i_o_limit_read[index_find] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead));
+ }
+ else {
+ _config->i_o_limit_read_size[index_find] = -3;
+ _config->i_o_limit_read[index_find] = -3;
+ }
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
+ _config->i_o_limit_write_size[index_find] = (int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite));
+ _config->i_o_limit_write[index_find] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite));
+ }
+ else {
+ _config->i_o_limit_write_size[index_find] = -3;
+ _config->i_o_limit_write[index_find] = -3;
+ }
+
+ }
+ }
+ else {
+ if (bool_read == 1 || bool_write == 1) {
+ _config->disk = yon_char_parsed_append(_config->disk,&_config->size, disk);
+ _config->size--;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
+ _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead)));
+ _config->size--;
+ _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead)));
+ _config->size--;
+ }
+ else {
+ _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,-3);
+ _config->size--;
+ _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,-3);
+ _config->size--;
+ }
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
+ _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite)));
+ _config->size--;
+ _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite)));
+ _config->size--;
+ }
+ else {
+ _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,-3);
+ _config->size--;
+ _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,-3);
+ _config->size--;
+ }
+ _config->size++;
+ }
+ else {
+ }
+ }
+}
+int* philos_int_append(int* array, int* size, int value) {
+ array = yon_remalloc(array, (*size+1)*sizeof(int));
+ array[(*size)] = value;
+ (*size)++;
+ return array;
+
+}
+
+int* remove_element_int_array(int* array, int* size, int item_to_delete) {
+ int *new_int_parsed=NULL;
+ new_int_parsed=malloc(sizeof(int)*((*size)-1));
+ int flag = 0;
+ for (int i=0;i < (*size);i++){
+ if (i==item_to_delete) {
+ flag = 1;
+ }
+ if (flag == 0) {
+ memcpy(&(new_int_parsed[i]),&(array[i]),sizeof(int));
+ }
+ else if (flag == 1 && i!=item_to_delete) {
+ memcpy(&(new_int_parsed[i-1]),&(array[i]),sizeof(int));
+ }
+ }
+ (*size)=(*size)-1;
+ return new_int_parsed;
+}
+
+int** remove_element_int_array_n3(int** array, int* size, int item_to_delete) {
+ int **new_int_parsed=NULL;
+ new_int_parsed=malloc(sizeof(int*)*((*size)-1));
+ int flag = 0;
+ for (int i=0;i < (*size);i++){
+ if (i==item_to_delete) {
+ flag = 1;
+ }
+ if (flag == 0) {
+ philos_array_int_copy(&new_int_parsed[i],&array[i]);
+ }
+ else if (flag == 1 && i!=item_to_delete) {
+ philos_array_int_copy(&new_int_parsed[i-1],&array[i]);
+ }
+ }
+ (*size)=(*size)-1;
+ return new_int_parsed;
+}
+char* philos_get_size_bite(GtkWidget* chk_button, GtkWidget* spin, GtkWidget* combo_box_text) {
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_button))) {
+ char* size_prifics = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box_text));
+ int size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+ char* str_size_bute = yon_char_unite(yon_char_from_int(size_bite), " ", size_prifics, NULL);
+ return str_size_bute;
+ }
+ else {
+ char* str = (char*)malloc(sizeof(char*)*2);
+ str[0] = '-';
+ str[1] = '\0';
+ return str;
+ }
+}
+void philos_fill_combo_box_text(GtkWidget *cbt, config_str list_data, int size) {
+ for (int index = 0; index < size; index++) {
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cbt), list_data[index]);
+ }
+}
+// Mem Size pow
+void philos_set_spin_adjustment(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, size_t value) {
+ gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
+ guint value_spin = gtk_spin_button_get_digits(GTK_SPIN_BUTTON(spin));
+ if (active != -1) {
+ GtkAdjustment* adjustment = NULL;
+ adjustment = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(spin));
+ gtk_adjustment_set_lower(adjustment, 0.0);
+ gtk_adjustment_set_page_increment(adjustment, 1.0);
+ if (combo == NULL) {
+ gtk_adjustment_set_upper(adjustment, (gdouble)(value*100));
+ if ((value*100)0) {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),1);
+ }
+ else if (active == 0) {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
+ }
+ if (flag_cpu == 0) {
+ philos_set_spin_adjustment(check, spin, combo, resurs);
+ if (value_spin>resurs) {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), resurs);
+ }
+ }
+ else {
+ philos_set_spin_adjustment(check, spin, NULL, resurs);
+ }
+
+}
+
+size_t get_resurs_total(char* cmd) {
+ int size = 0;
+ size_t size_memory = 0;
+ char **responce = yon_config_load(cmd, &size);
+ for (int index = 0; index < size; index++ ) {
+ char* mem_size_kb = yon_char_divide_search(responce[index], "\n", -1);
+ size_memory = atoll(mem_size_kb);
+ free(mem_size_kb);
+ }
+ philos_free_string_array(&responce, size);
+ return size_memory;
+}
+
+float get_size_pow_memory(size_t size_memory, int size) {
+ float res = size_memory;
+ for (size_t index = 0; index < size; index++) {
+ res = res/1024;
+ }
+ return res;
+}
+
+void philos_set_active_widgets_device_io(GtkWidget* combo_to_l2,GtkWidget *check, GtkWidget *spin, GtkWidget *combo) {
+ int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_to_l2));
+ if (menu_id != -1) {
+ gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
+ if (active == 0) {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
+ }
+ else if (gtk_spin_button_get_digits(GTK_SPIN_BUTTON(spin))>0) {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),1);
+ }
+ gtk_widget_set_sensitive(spin, active);
+ gtk_widget_set_sensitive(combo, active);
+ }
+ else {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
+ gtk_widget_set_sensitive(spin, 0);
+ gtk_widget_set_sensitive(combo, 0);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), 0);
+ }
+ philos_set_spin_adjustment(check, spin, combo, 12582912);
+}
+char *yon_char_get_augumented(char *source, char *append)
+{
+ if (source && append)
+ {
+ int size = strlen(source) + strlen(append) + 1;
+ char *final = malloc(size);
+ memset(final, 0, size);
+ if (strstr(source, "%%"))
+ sprintf(final, source, append);
+ else
+ sprintf(final, "%s%s", source, append);
+ return final;
+ }
+ else
+ return NULL;
+}
+dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data) {
+ dictionary *dct = yon_dictionary_create_conneced(dict);
+ dct->key = yon_char_new(key);
+ dct->data = data;
+ dct->data_type = DICTIONARY_OTHER_TYPE;
+ return dct;
+}
+char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete) {
+ char **new_char_parsed=NULL;
+ new_char_parsed=malloc(sizeof(char*)*((*size)-1));
+ int flag = 0;
+ for (int i=0;i < (*size);i++){
+ if (i==item_to_delete) {
+ flag = 1;
+ }
+ if (flag == 0) {
+ new_char_parsed[i]=yon_char_new(char_string[i]);
+ }
+ else if (flag == 1 && i!=item_to_delete) {
+ new_char_parsed[i-1]=yon_char_new(char_string[i]);
+ }
+ }
+ (*size)=(*size)-1;
+ return new_char_parsed;
+}
+char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete) {
+ char ***new_char_parsed=NULL;
+ new_char_parsed=malloc(sizeof(char**)*((*size)-1));
+ int flag = 0;
+ for (int i=0;i < (*size);i++){
+ if (i==item_to_delete) {
+ flag = 1;
+ }
+ if (flag == 0) {
+ yon_char_parsed_copy(&new_char_parsed[i],&char_string[i]);
+ }
+ else if (flag == 1 && i!=item_to_delete) {
+ yon_char_parsed_copy(&new_char_parsed[i-1], &char_string[i]);
+ }
+ }
+ (*size)=(*size)-1;
+ return new_char_parsed;
+}
+dictionary *yon_dictionary_create_empty() {
+ dictionary *dict = malloc(sizeof(dictionary));
+ dict->data = NULL;
+ dict->key = NULL;
+ dict->next = NULL;
+ dict->prev = NULL;
+ dict->first = dict;
+ dict->data_type = DICTIONARY_OTHER_TYPE;
+ return dict;
+}
+void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument){
+ char **commands=new_arr(char*,2);
+ gchar **envp = g_get_environ();
+ commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL"));
+ commands[1]=NULL;
+ char **env=new_arr(char*,2);
+ env[0]="";
+ env[1]=NULL;
+ vte_terminal_set_size(VTE_TERMINAL(terminal),10,15);
+ VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL);
+ vte_terminal_set_pty(VTE_TERMINAL(terminal),pty);
+ char *install_command=yon_char_unite("tput cup 0 0 && tput ed; ",command, "; exit 0\n",NULL);
+ if(endwork_function)
+ g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument);
+ vte_terminal_spawn_async(VTE_TERMINAL(terminal),
+ VTE_PTY_DEFAULT,
+ NULL,
+ commands,
+ NULL,
+ 0,
+ NULL, NULL,
+ NULL,
+ -1,
+ NULL,
+ child_ready,
+ install_command);
+ vte_pty_spawn_async(pty,
+ NULL,
+ commands,
+ NULL,
+ 0,
+ NULL, NULL,
+ NULL,
+ -1,
+ NULL,
+ NULL,
+ NULL);
+ vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1);
+ vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE);
+ vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE);
+ gtk_widget_show_all(terminal);
+}
+dictionary *yon_dictionary_create_conneced(dictionary *targetdict)
+{
+ targetdict = yon_dictionary_get_last(targetdict);
+ targetdict->next = yon_dictionary_create_empty();
+ targetdict->next->prev = targetdict;
+ targetdict->next->first = targetdict->first;
+ targetdict->next->data_type = DICTIONARY_OTHER_TYPE;
+ return targetdict->next;
+}
+void yon_int_array_append(int **source, int append){
+ int size=0;
+ for (size=0;(*source)[size]!=-2;size++);
+ *source = realloc(*source,(size+2)*sizeof(int));
+ (*source)[size] = append;
+ (*source)[size+1] = -2;
+}
+static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data)
+{
+ if (!terminal) return;
+ if (pid == -1) printf("Error\n\n\n");
+ else vte_terminal_feed_child(VTE_TERMINAL(terminal),(char*)user_data,strlen((char*)user_data));
+}
\ No newline at end of file
diff --git a/source/philos_utils.h b/source/philos_utils.h
new file mode 100644
index 0000000..87fb987
--- /dev/null
+++ b/source/philos_utils.h
@@ -0,0 +1,111 @@
+#ifndef PHILOS_UTILS_H
+#define PHILOS_UTILS_H
+#include "ubl-utils.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define catch(x) ExitJmp:if(__HadError)
+#define throw(x) {__HadError=true;goto ExitJmp;}
+#define file_source_login_min_max "/etc/login.defs"
+static char** array_size_pow;
+typedef struct {
+ char** disk;
+ int* i_o_limit_read;
+ int* i_o_limit_write;
+ int* i_o_limit_read_size;
+ int* i_o_limit_write_size;
+ int size;
+} temp_config;
+
+typedef struct {
+
+ GtkWidget* Window;
+ GtkWidget* btnSaveTempSave;
+ GtkWidget* btnTempCancel;
+
+ GtkWidget* entryTempCmd;
+ GtkWidget* chbTempRead;
+ GtkWidget* spinTempRead;
+ GtkWidget* cbtTempRead;
+
+ GtkWidget* chbTempWrite;
+ GtkWidget* spinTempWrite;
+ GtkWidget* cbtTempWrite;
+
+ GtkWidget* chkSoftRestrictionTemp;
+ GtkWidget* spiSevereRestrictionTemp;
+ GtkWidget* cmSevereRestrictionTemp;
+
+ GtkWidget* chkSevereRestrictionTemp;
+ GtkWidget* spinSevereRestrictionTemp;
+ GtkWidget* cmbSevereRestrictionTemp;
+
+ GtkWidget* chkPaddingFLTemp;
+ GtkWidget* spinPaddingFLTemp;
+ GtkWidget* cmbPaddingFLTemp;
+
+ GtkWidget* chkCPULimitTemp;
+ GtkWidget* spinCPULimitTemp;
+ GtkWidget* lblCPULimitTemp;
+
+ GtkWidget* cbtTempDevice;
+ GtkWidget* cbxTempQuotaObj;
+ GtkWidget* cbxTempQuotaLevel2;
+ GtkWidget* boxBlockGui;
+} temp_set_window;
+void philos_array_string_remove_char(char*** array, char* str_remove, int size);
+void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char** array_size_pow);
+void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index);
+void philos_free_string_array(char ***array, int size);
+void philos_free_string_array_n3(char ****array, int size);
+void philos_free_int_array(int **array, int size);
+void philos_free_int_array_n2(int ***array, int size);
+config_str philos_list_group(int* size);
+unsigned short philos_read_uid_min_max(char* filename, char* search);
+config_str philos_list_user(int* size);
+char* philos_str_size_pow_byte(GtkWidget *combo_box_text);
+char* philos_str_remove(char *str, const char *sub);
+void philos_split_size_memory(char* str_value, int* size, char* pow_memory);
+char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory);
+char** philos_str_split(char *parameters, int *size, char *divider);
+void philos_array_str_copy(char*** source, char*** copy);
+void philos_array_int_copy(int** source, int** copy);
+char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data);
+char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size);
+int philos_check_activ_disk(temp_set_window *widgets, temp_config* _config);
+void philos_temp_generate_cmd(temp_set_window *widgets, temp_config* _config);
+void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config);
+void philos_temp_config_init(temp_config* _config);
+void philos_update_device_to_entry(temp_set_window *widgets, temp_config* _config, int flag_check_array);
+void philos_temp_add_disk(temp_set_window *widgets, temp_config* _config);
+int* philos_int_append(int* array, int* size, int value);
+int* remove_element_int_array(int* array, int* size, int item_to_delete);
+int** remove_element_int_array_n3(int** array, int* size, int item_to_delete);
+char* philos_get_size_bite(GtkWidget* chk_button, GtkWidget* spin, GtkWidget* combo_box_text);
+void philos_fill_combo_box_text(GtkWidget *cbt, config_str list_data, int size);
+void philos_set_spin_adjustment(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, size_t value);
+void philos_set_active_widgets(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, int flag_cpu, char* cmd);
+size_t get_resurs_total(char* cmd);
+float get_size_pow_memory(size_t size_memory, int size);
+void philos_set_active_widgets_device_io(GtkWidget* combo_to_l2,GtkWidget *check, GtkWidget *spin, GtkWidget *combo);
+char *yon_char_get_augumented(char *source, char *append);
+dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data);
+char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete);
+char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete);
+dictionary *yon_dictionary_create_empty();
+void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument);
+dictionary *yon_dictionary_create_conneced(dictionary *targetdict);
+void yon_int_array_append(int **source, int append);
+static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data);
+#endif
\ No newline at end of file
diff --git a/source/ubl-cmake.h.in b/source/ubl-cmake.h.in
deleted file mode 100644
index 17ba454..0000000
--- a/source/ubl-cmake.h.in
+++ /dev/null
@@ -1 +0,0 @@
-#cmakedefine WEBKIT_FOUND
\ No newline at end of file
diff --git a/source/ubl-cmake.in b/source/ubl-cmake.in
new file mode 100644
index 0000000..d4623a7
--- /dev/null
+++ b/source/ubl-cmake.in
@@ -0,0 +1 @@
+#cmakedefine WEBKIT_FOUND
diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c
index bb41243..85c1dce 100644
--- a/source/ubl-settings-resourcequota.c
+++ b/source/ubl-settings-resourcequota.c
@@ -30,7 +30,7 @@ void yon_open_browser(GtkWidget *self, char *link){
*/
void on_open_documentation_confirmation(GtkWidget *self, char *link){
if (main_config.always_open_documentation==0){
- GtkBuilder *builder = gtk_builder_new_from_file(glade_path);
+ GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
documentation_confirmation_window *widgets = malloc(sizeof(documentation_confirmation_window));
widgets->Window = yon_gtk_builder_get_widget(builder,"helpConfirmationWindow");
widgets->AcceptButton = yon_gtk_builder_get_widget(builder,"ReadHelpButton");
@@ -84,7 +84,7 @@ void on_link(GtkWidget *self, char* uri, gpointer user_data){
* Присоединять к сигналу "activate" кнопки справки типа MenuItem.
*/
void on_about(){
- GtkBuilder *builder=gtk_builder_new_from_file(glade_path);
+ GtkBuilder *builder=gtk_builder_new_from_resource(glade_path);
GtkWidget *window=yon_gtk_builder_get_widget(builder,"AboutWindow");
GtkWidget *title=yon_gtk_builder_get_widget(builder,"headerAboutTopic");
GtkWidget *hideButtonBox=yon_gtk_builder_get_widget(builder,"buttonBoxHide");
@@ -125,7 +125,7 @@ void config_init(){
main_window *setup_window(){
/* Widgets getting | Получение виджетов */
widgets = malloc(sizeof(main_window));
- GtkBuilder *builder = gtk_builder_new_from_file(glade_path);
+ GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
widgets->Window = yon_gtk_builder_get_widget(builder,"MainWindow");
widgets->btnDelQuotas = yon_gtk_builder_get_widget(builder,"btnDelQuotas");
@@ -844,10 +844,13 @@ void wrapper_edit_show() {
}
void main_edit_btn_save() {
- if (tree_view_edit(main_config.size_tree_view)) {
- edit_init_windows();
- add_on_destroy_subwindow(get_widget_edit()->Window);
+ if (get_edit_config) {
+ if (tree_view_edit(main_config.size_tree_view)) {
+ edit_init_windows();
+ add_on_destroy_subwindow(get_widget_edit()->Window);
+ }
}
+
}
void tree_view_del_line() {
@@ -1083,7 +1086,7 @@ char* template_format_str_set_save(dictionary* load_cfg, char* source_set_cmd) {
}
if (flag_save && check_save(load_cfg)== 0) {
- cmd = yon_char_unite(cmd, "\"", NULL);
+ puts(cmd);
return cmd;
}
free(cmd);
@@ -1146,7 +1149,14 @@ void main_localization(main_window *widgets) {
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->DocumentationMenuItem),DOCUMENTATION_LABEL);
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->AboutMenuItem),ABOUT_LABEL);
}
+//functions
+void yon_load_proceed(char *command){
+ if (yon_config_load_register(command))
+ yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
+ else
+ yon_ubl_status_box_render(LOAD_FAILED_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
+}
int main(int argc, char *argv[]){
local=setlocale(LC_ALL, "");
textdomain (LocaleName);
@@ -1157,7 +1167,7 @@ int main(int argc, char *argv[]){
array_size_pow = yon_char_parsed_append(array_size_pow,&size_array_size_pow, STR_GB);
array_size_pow = yon_char_parsed_append(array_size_pow,&size_array_size_pow, STR_TB);
int option_index=0;
- int show_help=0;
+ int show_help=0;
{
struct option long_options[] = {
{"help", 0, 0, 'h'},
@@ -1170,11 +1180,11 @@ int main(int argc, char *argv[]){
{"socket-id", 1, 0, 's'},
{"socket-ext-id", 1,0, 'e'},
{"socket-trd-id", 1,0, 't'},
+ {"debug", 0,0, 'd'},
{ NULL, 0, NULL, 0 }
};
-
for (int i=0;isize = 0;
- get_edit_config()->size = 0;
+
+ if (getuid()!=0){
+ main_config.lock_load_global=1;
+ main_config.lock_save_global=1;
+ main_config.lock_save_local=1;
+ }
+ gtk_init(&argc,&argv);
+
add_get_cmd_group(CMD_GET_GROUP);
add_get_systemd_cgls(CMD_GET_SLICE_SERVICE);
gtk_init(&argc,&argv);
@@ -1234,23 +1250,26 @@ int main(int argc, char *argv[]){
add_setup_window(glade_path);
main_localization(widgets);
tree_view_select(NULL, widgets);
- event_all(widgets);
- main_event(widgets);
- yon_ubl_header_setup(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path);
+ yon_ubl_header_setup_resource(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path);
- if (yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel))
- yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
+ yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel);
+ if (getuid()!=0)
+ yon_ubl_status_box_render(TITLE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
+ else
+ yon_ubl_status_box_render(TITLE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,main_config.socket_id,main_config.load_socket_id,main_config.save_socket_id);
-
+ yon_window_config_setup(GTK_WINDOW(widgets->Window));
+ yon_window_config_load(config_path);
GtkCssProvider *css=gtk_css_provider_new();
- gtk_css_provider_load_from_path(css,CssPath,NULL);
+ gtk_css_provider_load_from_resource(css,CssPath);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
- GTK_STYLE_PROVIDER(css),
- -1);
+ GTK_STYLE_PROVIDER(css),
+ -1);
load_global_cfg();
load_system_cfg();
+ event_all(widgets);
+ main_event(widgets);
gtk_main();
philos_free_string_array(&array_size_pow, size_array_size_pow);
-}
-
+}
\ No newline at end of file
diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h
old mode 100755
new mode 100644
index 85774f2..2638dd7
--- a/source/ubl-settings-resourcequota.h
+++ b/source/ubl-settings-resourcequota.h
@@ -14,19 +14,20 @@
#include "filters.h"
#include "view_edit.h"
#include "my_device.h"
+#include "philos_utils.h"
#ifdef WEBKIT_FOUND
#include
#endif
#include "ubl-strings.h"
-
+#define config_path yon_char_unite("/home/",yon_ubl_root_user_get(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define WIKI_LINK "https://wiki.ublinux.ru/ru/Программное_обеспечение/Программы_и_утилиты/Все/ubl-settings-resourcequota"
#define _(String) gettext(String)
-#define glade_path "/usr/share/ubl-settings-resourcequota/ui/ubl-settings-resourcequota.glade"
-#define banner_path "/usr/share/ubl-settings-resourcequota/images/ubl-settings-resourcequota-banner.png"
-#define CssPath "/usr/share/ubl-settings-resourcequota/css/ubl-settings-resourcequota.css"
+#define glade_path "/com/ublinux/ui/ubl-settings-resourcequota.glade"
+#define banner_path "/com/ublinux/images/ubl-settings-resourcequota-banner.png"
+#define CssPath "/com/ublinux/css/ubl-settings-resourcequota.css"
#define LocalePath "/usr/share/locale"
#define LocaleName "ubl-settings-resourcequota"
@@ -43,7 +44,7 @@
#define CMD_GET_GROUP "cut -d: -f1 /etc/group"
typedef char *string;
-string version_application = "1.2-48-g1dfc1c2";
+string version_application;
static char *local;
diff --git a/source/ubl-strings.h b/source/ubl-strings.h
index 872506e..f573c04 100644
--- a/source/ubl-strings.h
+++ b/source/ubl-strings.h
@@ -43,4 +43,6 @@
#define STR_NO_SELECT_TABLE _("Quota deleted")
#define STR_QUOTAS_ADD _("Quota deleted")
#define ALL_SAVE_SUCCESS _("Save configuration")
-#define MESS_NOTHING_SAVE _("Nothing to save!")
\ No newline at end of file
+#define MESS_NOTHING_SAVE _("Nothing to save!")
+#define LOCAL_SAVE_SUCCESS_LABEL _("Local configuration saving succseeded.")
+#define LOAD_FAILED_LABEL _("Config loading failed")
\ No newline at end of file
diff --git a/source/ubl-utils.c b/source/ubl-utils.c
index 6838589..eb06336 100644
--- a/source/ubl-utils.c
+++ b/source/ubl-utils.c
@@ -2,11 +2,13 @@
// dictionary functions
-/**[EN]
- * yon_dictionary_create_empty():
+/**yon_dictionary_create_empty():
+ * [EN]
* Creates and returns empty dictionary
+ * [RU]
+ * Создаёт и возвращает пустой словарь.
*/
-dictionary *yon_dictionary_create_empty()
+dictionary *yon_dictionary_new()
{
dictionary *dict = malloc(sizeof(dictionary));
dict->data = NULL;
@@ -17,8 +19,15 @@ dictionary *yon_dictionary_create_empty()
dict->data_type = DICTIONARY_OTHER_TYPE;
return dict;
}
-dictionary *yon_dictionary_copy(dictionary *dict){
- dictionary *dct = yon_dictionary_create_with_data(dict->key,dict->data);
+
+/**yon_dictionary_copy_deep(dictionary *dict)
+ * [EN]
+ *
+ * [RU]
+ * Создаёт и возвращает копию элемента словаря [dict]
+*/
+dictionary *yon_dictinoary_copy(dictionary *dict){
+ dictionary *dct = yon_dictionary_new_with_data(dict->key,dict->data);
dct->data_type= dict->data_type;
}
@@ -37,122 +46,79 @@ dictionary *yon_dictionary_copy_deep(dictionary *dict){
}
return newone->first;
}
-size_t yon_dict_len(dictionary *dict) {
- dictionary* ptr_dict = NULL;
- size_t size = 0;
- if (dict != NULL) {
- for_dictionaries(ptr_dict, dict) {
- size+=1;
- }
- }
- return size;
-}
-void yon_dictionary_switch_to_last(dictionary **dict)
-{
- if ((*dict)->next != NULL)
- for ((*dict) = (*dict)->first; (*dict)->next != NULL; (*dict) = (*dict)->next)
- {
- }
+int yon_dictionary_set_data(dictionary *dict, void *data){
+ dict->data=data;
}
-void philos_array_string_remove_char(char*** array, char* str_remove, int size) {
- for (int index = 0; index < size; index++) {
- (*array)[index] = yon_char_divide_search((*array)[index], str_remove, -1);
- }
+int yon_dictionary_set_key(dictionary *dict, char *key){
+ dict->key=key;
+}
+int yon_dictionary_set(dictionary *dict, char *key, void *data){
+ dict->key=key;
+ dict->data=data;
}
-void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char** array_size_pow) {
- char* STR_KB = array_size_pow[0];
- char* STR_MB = array_size_pow[1];
- char* STR_GB = array_size_pow[2];
- char* STR_TB = array_size_pow[3];
- size_t length = strlen(str_find);
- if (strstr(str_find,"K") != NULL) {
- *array_size = philos_int_append(*array_size, &index, 0);
- str_find = yon_char_divide(str_find, length-1);
- str_find = yon_char_unite(str_find, " ", STR_KB, NULL);
- index--;
- }
- else if (strstr(str_find,"M") != NULL) {
- *array_size = philos_int_append(*array_size, &index, 1);
- str_find = yon_char_divide(str_find, length-1);
- str_find = yon_char_unite(str_find," ", STR_MB, NULL);
- index--;
- }
- else if (strstr(str_find,"G") != NULL) {
- *array_size = philos_int_append(*array_size, &index, 2);
- str_find = yon_char_divide(str_find, length-1);
- str_find = yon_char_unite(str_find," ", STR_GB, NULL);
- index--;
- }
- else if (strstr(str_find,"T") != NULL) {
- *array_size = philos_int_append(*array_size, &index, 3);
- str_find = yon_char_divide(str_find, length-1);
-
- str_find = yon_char_unite(str_find," ", STR_TB, NULL);
- index--;
- }
- else if (strstr(str_find,"%%") != NULL) {
- *array_size = philos_int_append(*array_size, &index, -1);
- str_find = yon_char_divide(str_find, length-1);
- index--;
- }
- else if (strstr(str_find,"-") != NULL) {
- *array_size = philos_int_append(*array_size, &index, -1);
- index--;
- }
-
+
+int yon_dictionary_empty(dictionary *dict){
+ dict->data=NULL;
+ dict->data_type=DICTIONARY_OTHER_TYPE;
}
-void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index) {
- char* simv_del_array[10] = {"K","M","G","T","k","m","g","t"," ","%"};
- for (size_t i = 0; i < 10; i++) {
- if (strstr(str_find, simv_del_array[i])) {
- str_find = yon_char_divide_search(str_find, simv_del_array[i], -1);
- }
- }
- if (strstr(str_find, " ") != NULL) {
- char* mem_s = yon_char_new(str_find);
- yon_char_divide_search(mem_s, " ", -1);
- *array_data = yon_char_parsed_append(*array_data, &index, mem_s);
- }
- if (strstr(str_find, "-") != NULL) {
- *array_data = yon_char_parsed_append(*array_data, &index, "-");
- }
- else {
- if (str_find[0] == '\"') {
- yon_char_divide(str_find, 0);
- size_t length = strlen(str_find);
- str_find = yon_char_divide(str_find, length-2);
- }
- if (strstr(str_find, " ") == NULL) {
- *array_data = yon_char_parsed_append(*array_data, &index, str_find);
- }
-
- }
+/**yon_dictionary_switch_to_last(dictionary **dict)
+ * [EN]
+ *
+ * [RU]
+ * Переключает словарь [dict] на последний элемент.
+*/
+void yon_dictionary_switch_to_last(dictionary **dict)
+{
+ dictionary *dct=NULL, *dact=*dict;
+ for_dictionaries(dct,dact);
}
-dictionary *yon_dictionary_create_conneced(dictionary *targetdict)
+/**yon_dictionary_create_conneced(dictionary *targetdict)
+ * [EN]
+ *
+ * [RU]
+ * Создаёт новый элемент словаря [targetdict]
+*/
+dictionary *yon_dictionary_append(dictionary *targetdict)
{
targetdict = yon_dictionary_get_last(targetdict);
- targetdict->next = yon_dictionary_create_empty();
+ targetdict->next = yon_dictionary_new();
targetdict->next->prev = targetdict;
targetdict->next->first = targetdict->first;
targetdict->next->data_type = DICTIONARY_OTHER_TYPE;
return targetdict->next;
}
+/**yon_dictionary_get_last(dictionary *dict)
+ * [EN]
+ *
+ * [RU]
+ * Возвращает последний элемент словаря [dict].
+ * В отличае от yon_dictionary_switch_to_last()
+ * словарь [dict] остаётся на прежнем элементе.
+*/
dictionary *yon_dictionary_get_last(dictionary *dict)
{
- dictionary *dct = NULL;
- for (dct = dict->first; dct->next != NULL; dct = dct->next)
- {
- }
- return dct;
+ if (dict->next){
+ dictionary *dct = NULL;
+ for_dictionaries(dct,dict);
+ return dct;
+ } else return dict;
}
-dictionary *yon_dictionary_switch_places(dictionary *dict, int aim)
+/**yon_dictionary_switch_places(dictionary *dict, int aim)
+ * [EN]
+ *
+ * [RU]
+ * Меняет элемент словаря [dict] местами с другим элементом.
+ * если [aim]<0 элемент меняется местами с левым элементом;
+ * если [aim]>0 элемент меняется местами с правым элементом;
+*/
+dictionary *yon_dictionary_swap(dictionary *dict, int aim)
{
if (aim < 0)
{
@@ -253,6 +219,13 @@ dictionary *yon_dictionary_switch_places(dictionary *dict, int aim)
}
}
+/**yon_dictionary_make_first(dictionary *dict)
+ * [EN]
+ *
+ * [RU]
+ * Устанавливает указатель первого элемента словаря [dict]
+ * на текущий элемент. Не использовать.
+*/
void yon_dictionary_make_first(dictionary *dict)
{
for (dictionary *dct = dict->first; dct != NULL; dct = dct->next)
@@ -261,6 +234,12 @@ void yon_dictionary_make_first(dictionary *dict)
}
}
+/**yon_dictionary_make_nth(dictionary *dict, int nth)
+ * [EN]
+ *
+ * [RU]
+ * Перемещает элемент словаря [dict] на позицию [nth].
+*/
void yon_dictionary_make_nth(dictionary *dict, int nth)
{
dictionary *dct = dict->first;
@@ -279,9 +258,15 @@ void yon_dictionary_make_nth(dictionary *dict, int nth)
dct->prev = dict;
}
-dictionary *yon_dictionary_create_with_data(char *key, void *data)
+/**yon_dictionary_create_with_data(char *key, void *data)
+ * [EN]
+ *
+ * [RU]
+ * Создаёт новый словарь с ключом [key] и указателем на данные [data]
+*/
+dictionary *yon_dictionary_new_with_data(char *key, void *data)
{
- dictionary *dct = yon_dictionary_create_empty();
+ dictionary *dct = yon_dictionary_new();
dct->key = yon_char_new(key);
dct->data = data;
dct->data_type = DICTIONARY_OTHER_TYPE;
@@ -306,15 +291,28 @@ void *yon_dictionary_free_all(dictionary *dictionary_to_free,void (*data_manipul
return NULL;
}
-dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data)
+/**yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data)
+ * [EN]
+ *
+ * [RU]
+ * Создаёт новый элемент словаря, присоединяемый в конец словаря [dict]
+ * с ключом [key] и указателем на данные [data]
+*/
+dictionary *yon_dictionary_append_with_data(dictionary *dict, char *key, void *data)
{
- dictionary *dct = yon_dictionary_create_conneced(dict);
+ dictionary *dct = yon_dictionary_append(dict);
dct->key = yon_char_new(key);
dct->data = data;
dct->data_type = DICTIONARY_OTHER_TYPE;
return dct;
}
+/**yon_dictionary_connect(dictionary *old, dictionary *toconnect)
+ * [EN]
+ *
+ * [RU]
+ * Присоединяет словарь [toconnect] в конец словаря [old].
+*/
dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect)
{
dictionary *dict = yon_dictionary_get_last(old);
@@ -324,7 +322,14 @@ dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect)
return toconnect;
}
-dictionary *yon_dictionary_find(dictionary **dict, char *key)
+/**yon_dictionary_get(dictionary **dict, char *key)
+ * [EN]
+ *
+ * [RU]
+ * Возвращает элемент словаря [dict] с ключом [key].
+ * Если такого элемента не было обнаружено, возвращается NULL
+*/
+dictionary *yon_dictionary_get(dictionary **dict, char *key)
{
dictionary *dct = *dict;
for (dictionary *pointer = dct->first; pointer != NULL; pointer = pointer->next)
@@ -338,6 +343,12 @@ dictionary *yon_dictionary_find(dictionary **dict, char *key)
return NULL;
}
+/**yon_dictionary_rip(dictionary *dict)
+ * [EN]
+ *
+ * [RU]
+ * Вырезает элемент из словаря и возвращает вырезанный элемент.
+*/
dictionary *yon_dictionary_rip(dictionary *dict)
{
if (!dict->next&&!dict->prev) return NULL;
@@ -373,6 +384,12 @@ dictionary *yon_dictionary_rip(dictionary *dict)
}
}
+/**yon_dictionary_get_nth(dictionary *dict, int place)
+ * [EN]
+ *
+ * [RU]
+ * Возвращает [place]-й элемент словаря [dict]
+*/
dictionary *yon_dictionary_get_nth(dictionary *dict, int place)
{
if (dict){
@@ -396,7 +413,7 @@ dictionary *yon_dictionary_get_nth(dictionary *dict, int place)
*
* creates new char string by combining two char strings.
*/
-char *yon_char_get_augumented(char *source, char *append)
+char *yon_char_append(char *source, char *append)
{
if (source && append)
{
@@ -412,62 +429,7 @@ char *yon_char_get_augumented(char *source, char *append)
else
return NULL;
}
-void philos_free_string_array(char ***array, int size) {
- if ((*array) == NULL) {
- return;
- }
- for (int i = 0; i < size; i++){
- free((*array)[i]);
- }
- if (size!= 0) {
- free(*array);
- (*array) = NULL;
- }
-}
-
-void philos_free_string_array_n3(char ****array, int size) {
- if ((*array) == NULL || size == 0) {
- return;
- }
- int index_to_l2 = 0;
- for (int i = 0; i < size; i++){
- index_to_l2 = 0;
- if ((*array)[i]!=NULL) {
- while ((*array)[i][index_to_l2] != NULL) {
- if ((*array)[i][index_to_l2] != NULL) {
- free((*array)[i][index_to_l2]);
- index_to_l2++;
- }
-
- }
- }
- free((*array)[i]);
-
- }
- if (size!= 0) {
- free(*array);
- (*array) = NULL;
- }
-}
-void philos_free_int_array(int **array, int size) {
- if (size!= 0) {
- free(*array);
- *array = NULL;
- }
-}
-void philos_free_int_array_n2(int ***array, int size) {
- if ((*array) == NULL || size == 0) {
- return;
- }
- for (int i = 0; i < size; i++){
- free((*array)[i]);
- }
- if (size!= 0) {
- free(*array);
- (*array) = NULL;
- }
-}
/**[EN]
*
* creates new char string by copying another char.
@@ -493,15 +455,15 @@ char *yon_char_unite(char *source, ...){
va_start(arglist,source);
unite_char = va_arg(arglist,char*);
while(unite_char){
- new_char = yon_char_get_augumented(new_char,unite_char);
+ new_char = yon_char_append(new_char,unite_char);
unite_char = va_arg(arglist,char*);
}
va_end(arglist);
return new_char;
}
-/**[EN]
- *
+/**yon_cut(char *source, int size, int startpos)
+ * [EN]
* cuts source string by size length from startpos position.
*/
char *yon_cut(char *source, int size, int startpos)
@@ -512,8 +474,9 @@ char *yon_cut(char *source, int size, int startpos)
memcpy(cut, source + startpos, size);
return cut;
}
-/**[EN]
- *
+
+/**yon_char_divide(char *source, int dividepos)
+ * [EN]
* divides source string in dividepos position,
* returning left part of divided string and
* inserting right part to source string.
@@ -531,129 +494,6 @@ char *yon_char_divide(char *source, int dividepos)
return cut;
}
-config_str philos_list_user(int* size) {
- char* str_uid_min = "UID_MIN";
- char* str_uid_max = "UID_MAX";
- unsigned short uid_min = philos_read_uid_min_max(file_source_login_min_max, str_uid_min);
- unsigned short uid_max = philos_read_uid_min_max(file_source_login_min_max, str_uid_max);
- config_str str_users = malloc(1);
- while (1) {
- errno = 0; // so we can distinguish errors from no more entries
- struct passwd* entry = getpwent();
- if (!entry) {
- if (errno) {
- return str_users;
- }
- break;
- }
- //if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
- str_users = yon_char_parsed_append(str_users, size, entry->pw_name);
- //}
- }
- endpwent();
- return str_users;
-}
-
-char* philos_str_size_pow_byte(GtkWidget *combo_box_text) {
- int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box_text));
- if (menu_id == 0) {
- return "K";
- }
- else if (menu_id == 1) {
- return "M";
- }
- else if (menu_id == 2) {
- return "G";
- }
- else if (menu_id == 3) {
- return "T";
- }
- else {
- return " ";
- }
-}
-
-config_str philos_list_group(int* size) {
- char* str_uid_min = "UID_MIN";
- char* str_uid_max = "UID_MAX";
- unsigned short uid_min = philos_read_uid_min_max(file_source_login_min_max, str_uid_min);
- unsigned short uid_max = philos_read_uid_min_max(file_source_login_min_max, str_uid_max);
- config_str str_users = malloc(1);
- while (1) {
- errno = 0; // so we can distinguish errors from no more entries
- struct passwd* entry = getpwent();
- if (!entry) {
- if (errno) {
- return str_users;
- }
- break;
- }
- if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
- str_users = yon_char_parsed_append(str_users, size, entry->pw_name);
- }
- }
- endpwent();
- return str_users;
-}
-
-unsigned short philos_read_uid_min_max(char* filename, char* search) {
- int uid = 0;
- char* remove_tab = "\t";
- char* remove_space = " ";
- char* search_uid_min = "UID_MIN";
- int buff_size = 255;
- char* line = g_malloc0(buff_size);
- char* search_true = yon_char_get_augumented("SYS_", search);
- FILE *fp = fopen(filename, "r");
- if(fp) {
- while((fgets(line, buff_size, fp)) != NULL) {
- try{
- if (yon_char_find_count(line, search) != 0 && yon_char_find_count(line, search_true) == 0) {
- line = philos_str_remove(line, search);
- line = philos_str_remove(line, remove_space);
- line = philos_str_remove(line, remove_tab);
- uid = atoi(line);
-
- }
- }
- catch (...) {
- if (yon_char_find_count(search, search_uid_min) != 0){
- uid = 1000;
- }
- else{
- uid = 65534;
- }
- }
- }
- }
- else{
- if (yon_char_find_count(search, search_uid_min) != 0) {
- uid = 1000;
- }
- else{
- uid = 65534;
- }
- }
- fclose(fp);
- free(line);
- free(search_true);
- return uid;
-
-}
-
-char* philos_str_remove(char *str, const char *sub) {
- size_t len = strlen(sub);
- if (len > 0) {
- char *p = str;
- size_t size = 0;
- while ((p = strstr(p, sub)) != NULL) {
- size = (size == 0) ? (p - str) + strlen(p + len) + 1 : size - len;
- memmove(p, p + len, size - (p - str));
- }
- }
- return str;
-}
-
int yon_char_find_count(char *source, char *find){
char *working_string=yon_char_new(source);
int i=0;
@@ -667,7 +507,8 @@ int yon_char_find_count(char *source, char *find){
return i;
}
-/**[EN]
+/**yon_char_divide_search(char *source, char *dividepos, int delete_divider)
+ * [EN]
* char *yon_char_divide_search(char *source, char *dividepos, int delete_divider)
* searches string [dividepos] in [source] string and divides it,
* returning left part of divided string and
@@ -699,7 +540,8 @@ char *yon_char_divide_search(char *source, char *dividepos, int delete_divider)
}
}
-/**[EN]
+/**yon_char_from_int(int int_to_convert)
+ * [EN]
* char *yon_char_from_int(int int_to_convert)
* converts int to char*.
*
@@ -720,6 +562,12 @@ char *yon_char_from_int(int int_to_convert)
return ch;
}
+/**yon_char_replace(char *source, char *find, char*replace)
+ * [EN]
+ *
+ * [RU]
+ * Заменяет в строке [source] все вхождения строки [find] на [replace]
+*/
char *yon_char_replace(char *source, char *find, char*replace){
char *final=NULL;
char *temp=NULL;
@@ -728,42 +576,11 @@ char *yon_char_replace(char *source, char *find, char*replace){
temp=malloc(strlen(source)-strlen(final));
memset(temp,0,strlen(source)-strlen(final)+strlen(replace));
memcpy(temp,source,strlen(source)-strlen(final));
- temp=yon_char_get_augumented(temp,replace);
- source=yon_char_get_augumented(temp,final+1);
+ temp=yon_char_append(temp,replace);
+ source=yon_char_append(temp,final+1);
}
return source;
}
- return source;
-}
-void philos_split_size_memory(char* str_value, int* size, char* pow_memory) {
- // pow_memory = yon_char_new(str_value);
- (*size) = atoi(yon_char_divide_search(pow_memory, " ", -1));
-}
-
-char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory) {
- if (value == -1 || value == -3 || pow_size_memory == -3) {
- return yon_char_new("-");
- }
- char* str_value = yon_char_from_int(value);
- str_value = yon_char_divide_search(str_value, " ", -1);
- if (pow_size_memory==0) {
- return yon_char_unite(str_key, str_value, "K" ,NULL);
- }
- else if (pow_size_memory==1) {
- return yon_char_unite(str_key, str_value, "M" ,NULL);
- }
- else if (pow_size_memory==2){
- return yon_char_unite(str_key, str_value, "G" ,NULL);
- }
- else if (pow_size_memory== 3) {
- return yon_char_unite(str_key, str_value, "T" ,NULL);
- }
- else if (pow_size_memory== -1) {
- return yon_char_unite(str_key, str_value, "%" ,NULL);
- }
- else {
- return yon_char_unite(str_key, str_value, "-" ,NULL);
- }
}
/**[EN]
@@ -791,26 +608,16 @@ char **yon_char_parse(char *parameters, int *size, char *divider){
*size=i-1;
return string;
-
-
-}
-
-char** philos_str_split(char *parameters, int *size, char *divider) {
- char** array_split = NULL;
- char* ch= NULL;
- ch = strtok(parameters, divider);
- if (ch != NULL) {
- array_split = yon_char_parsed_append(array_split, size, ch);
- while (ch != NULL) {
- ch = strtok(NULL, divider);
- array_split = yon_char_parsed_append(array_split, size, ch);
- }
- }
- (*size) -= 1;
- return array_split;
}
-char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete){
+/**yon_char_parsed_rip(char **char_string, int *size, int item_to_delete)
+ * [EN]
+ *
+ * [RU]
+ * Удаляет элемент [item_to_delete] из массива строк [char_string], размера [size]
+ * Возвращает получившийся массив, в [size] загружается размер нового массива.
+*/
+char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete){
char **new_char_parsed=NULL;
new_char_parsed=malloc(sizeof(char*)*((*size)-1));
int flag = 0;
@@ -829,41 +636,33 @@ char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete)
return new_char_parsed;
}
-char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete){
- char ***new_char_parsed=NULL;
- new_char_parsed=malloc(sizeof(char**)*((*size)-1));
- int flag = 0;
- for (int i=0;i < (*size);i++){
- if (i==item_to_delete) {
- flag = 1;
- }
- if (flag == 0) {
- yon_char_parsed_copy(&new_char_parsed[i],&char_string[i]);
- }
- else if (flag == 1 && i!=item_to_delete) {
- yon_char_parsed_copy(&new_char_parsed[i-1], &char_string[i]);
- }
- }
- (*size)=(*size)-1;
- return new_char_parsed;
-}
-
-/**[EN]
- *
+/**yon_char_parsed_check_exist(char **parameters, int size, char *param)
+ * [EN]
* Checks if [parameters] string array of length [size]
* has [param] element;
+ * [RU]
+ * Проверяет есть ли в массиве строк [parameters], размера [size]
+ * элемент [param]
*/
int yon_char_parsed_check_exist(char **parameters, int size, char *param){
for (int i=0;id_name);
+ char *path = yon_char_append(DesktopPath, de->d_name);
file = fopen(path, "r");
if (strlen(de->d_name) > 9)
{
@@ -1086,515 +868,333 @@ apps *yon_apps_get_by_name(apps *applist, char *name, int size)
return NULL;
};
-config_str yon_config_load(char *command, int *str_len)
-{
+//config functions
+
+/**yon_config_load_register(char *command)
+ * [EN]
+ *
+ * [RU]
+ * Выполняет команду [command].
+ * Полученные данные парсятся и регистрируются в конфиг.
+*/
+int yon_config_load_register(char *command){
+ if (__yon__config__strings){
+ __yon__config__strings = yon_dictionary_free_all(__yon__config__strings,NULL);
+ }
FILE *output = popen(command, "r");
char **output_strings = NULL;
output_strings = malloc(sizeof(char));
int i = 0;
- char str[1000];
- memset(str, 0, 1000);
- while (fgets(str, 1000, output))
+ char str[4096];
+ memset(str, 0, 4096);
+ while (fgets(str, 4096, output))
{
- if (strcmp(str, "") != 0)
+ if (strcmp(str, "") != 0&& strcmp(str,"(null)\n")!=0)
{
- output_strings = realloc(output_strings, sizeof(char *) * (i + 1));
- // printf("%s\n", str);
- output_strings[i] = NULL;
- output_strings[i] = yon_char_new(str);
- memset(str, 0, 1000);
- i++;
+ char *key = yon_char_divide_search(str,"=",-1);
+ yon_dictionary_add_or_create_if_exists_with_data(__yon__config__strings,key,str);
+ __yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
}
}
- if (i>0){
- *str_len = i;
- return output_strings;
- } else{
- *str_len=-1;
- return NULL;
- }
+ check_config
+ return 0;
+ else return 1;
}
-/**[EN]
- * int yon_config_save(char *command)
- * Saves config with [command]
+/**yon_config_remove_by_key(char *key)
+ * [EN]
+ *
* [RU]
+ * Удаляет параметр конфига по ключу [key]
*/
-int yon_config_save(char *command)
-{
- FILE *output = popen(command, "r");
- return 1;
+int yon_config_remove_by_key(char *key){
+ check_config{
+ dictionary *dict = yon_dictionary_get(&__yon__config__strings,key);
+ if (dict){
+ yon_dictionary_rip(dict);
+ return 1;
+ }else return 0;
+ }
+ return 0;
}
-/**[EN]
- * char *yon_config_get_parameter(config parameters, int size, char *param)
- * Gets parameter from parameter list;
+/**yon_config_remove_by_data(void *data)
+ * [EN]
*
- * [RU]
+ * [RU]
+ * Производит поиск по конфигу на наличие параметра со значением [data] и удаляет найденное значение из конфига.
*/
-char *yon_config_get_parameter(config_str parameters, int size, char *param)
-{
- if (param[0]==' ')
- yon_char_divide_search(param," ",-1);
- param=yon_char_divide_search(yon_char_new(param)," ",-1);
-
- char *str = NULL;
- for (int j = 0; j < size; j++)
- {
- char *name = yon_char_divide_search(yon_char_new(parameters[j]), "=", 1);
- if (name)
- {
- if (strcmp(name, param) == 0)
- {
- str = yon_char_divide_search(yon_char_new(parameters[j]), "\n", 1);
- if (strcmp(str, "") != 0 && strcmp(str, "(null)") != 0)
- return str;
- else
- return NULL;
+int yon_config_remove_by_data(void *data){
+ check_config{
+ dictionary *dict = NULL;
+ for_dictionaries(dict,__yon__config__strings){
+ if (dict->data==data){
+ yon_dictionary_rip(dict);
+ return 1;
}
}
+ return 0;
}
- return NULL;
+ return 0;
}
-/**[EN]
- * Parses, modifies and connects string to use it as one of arguments,
- * sended to ubconfig.
+/**yon_config_remove_element(char *key, char *deleted)
+ * [EN]
*
* [RU]
- */
-char *yon_config_make_save_parameter_with_multiple_arguments(char *parameter_string, char *config_parameter, char *divider){
- char *final="";
- int done=0;
- char *cur=yon_char_new(parameter_string);
- yon_char_divide_search(cur,"=",1);
- char *cur_param=NULL;
- while (cur_param=yon_char_divide_search(cur,",",1)){
- if (done==0){
- final=yon_char_get_augumented(final,yon_char_get_augumented(yon_char_get_augumented(config_parameter,"="), yon_char_get_augumented(cur_param,", ")));
- done=1;
+ * Удаляет элемент [deleted] из массива параметров с ключом [key]
+*/
+int yon_config_remove_element(char *key, char *deleted){
+ check_config{
+ dictionary *dict = yon_dictionary_get(&__yon__config__strings,key);
+ char *data = (char*)dict->data;
+ char *found = strstr(data,deleted);
+ int size=strlen(data)-strlen(found)+1;
+ char *new_data = malloc(size);
+ memset(new_data,0,size);
+ if (strlen(found)!=strlen(deleted)){
+ memcpy(new_data,data,size-1);
+ new_data = yon_char_append(new_data,found+strlen(deleted)+1);
} else {
- final=yon_char_get_augumented(final,yon_char_get_augumented(yon_char_get_augumented(config_parameter,"+="), yon_char_get_augumented(cur_param,", ")));
+ memcpy(new_data,data,size-2);
+ new_data = yon_char_append(new_data,found+strlen(deleted));
}
- }
- if (cur&&strcmp(cur,"")!=0)
- if (done==0)
- final=yon_char_get_augumented(final,yon_char_get_augumented(yon_char_get_augumented(config_parameter,"="), yon_char_get_augumented(cur,", ")));
- else
- final=yon_char_get_augumented(final,yon_char_get_augumented(yon_char_get_augumented(config_parameter,"+="), yon_char_get_augumented(cur,", ")));
- return final;
+ dict->data=(void*)(new_data);
+ free(data);
+ dict->flag1=1;
+ return 1;
+ } else return 0;
}
-// terminal-using functions
-
-char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data) {
- int size = 0;
- char** terminal_print = yon_config_load(CMD_GET_SLICE_SERVICE, &size);
- char** array_data = NULL;
- for (int index = 0; index < size; index++) {
- if (strstr(terminal_print[index], str_find) != NULL) {
- yon_char_divide_search(terminal_print[index],"─",-1);
- terminal_print[index] = yon_char_divide_search(terminal_print[index]," ", -1);
- yon_char_divide(terminal_print[index],1);
- array_data = yon_char_parsed_append(array_data, size_array_data, terminal_print[index]);
-
+/**yon_config_get_by_key(char *key)
+ * [EN]
+ *
+ * [RU]
+ * Возвращает значение параметра конфига с ключом [key]
+*/
+void *yon_config_get_by_key(char *key){
+ check_config{
+ dictionary *dict = NULL;
+ for_dictionaries(dict, __yon__config__strings){
+ if (strcmp(dict->key,key)==0){
+ return dict->data;
+ }
}
}
- return array_data;
-}
-char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size) {
- char* split_simvol = g_malloc0(sizeof(char)*2);
- int flag_format = 0;
- char* cmd_old = yon_char_new(cmd);
- if (_config->disk && _config->size && array_io && array_io_pow_size) {
- int index_find = 0;
- for (int index = 0; index < _config->size; index++) {
- if (index==0) {
- if (strlen(cmd)>1) {
- cmd = yon_char_unite(cmd, ",", key, NULL);
- }
- else {
- cmd = yon_char_unite(cmd, key, NULL);
- }
-
+ return NULL;
+}
+
+/**yon_config_get_key_by_data(char *data)
+ * [EN]
+ *
+ * [RU]
+ * Возвращает ключ параметра конфига со значением [data].
+ * Если параметр с таким значением не найден, возвращается NULL
+*/
+char *yon_config_get_key_by_data(char *data){
+ check_config{
+ dictionary *dict = NULL;
+ for_dictionaries(dict, __yon__config__strings){
+ if (strcmp(((char*)dict->data),data)==0){
+ return dict->key;
}
- if (array_io_pow_size[index] != -1 && array_io[index]!=-2 && array_io[index]!=-1) {
- char* num_and_pow_size = philos_format_cfg_str_size_memory(" ", array_io[index], array_io_pow_size[index]);
- cmd = yon_char_unite(cmd,
- split_simvol,
- _config->disk[index],
- num_and_pow_size, NULL);
- split_simvol[0] = ',';
- split_simvol[1] = '\0';
- flag_format = 1;
- free(num_and_pow_size);
- }
}
}
- free(split_simvol);
- if (flag_format) {
- return cmd;
- }
- else {
- return cmd_old;
- }
-
+ return NULL;
}
-int philos_check_activ_disk(temp_set_window *widgets, temp_config* _config) {
- char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
- disk = yon_char_divide_search(disk," ", -1);
- int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
- int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
- if (disk == NULL || _config->size == 0) {
- return 0;
- }
+
+/**yon_config_set(char *key, void *data)
+ * [EN]
+ *
+ * [RU]
+ * Производит поиск по конфигу и заменяет значение параметра с ключом [key] на новое значение [data];
+*/
+int yon_config_set(char *key, void *data){
+ check_config{
+ dictionary *dict = yon_dictionary_get(&__yon__config__strings,key);
+ dict->data=data;
return 1;
+ } else return 0;
}
-void philos_temp_generate_cmd(temp_set_window *widgets, temp_config* _config) {
- char* str_cmd = "";
- char* split_simvol = g_malloc0(sizeof(char)*2);
- int size_bite = 0;
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkSoftRestrictionTemp))) {
- size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spiSevereRestrictionTemp));
- str_cmd = yon_char_unite(str_cmd,
- "MemoryHigh=",
- yon_char_from_int(size_bite),
- philos_str_size_pow_byte(widgets->cmSevereRestrictionTemp), NULL);
- split_simvol[0] = ',';
- split_simvol[1] = '\0';
- }
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkSevereRestrictionTemp))) {
- size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinSevereRestrictionTemp));
- str_cmd = yon_char_unite(str_cmd, split_simvol,
- "MemoryMax=",
- yon_char_from_int(size_bite),
- philos_str_size_pow_byte(widgets->cmbSevereRestrictionTemp), NULL);
- split_simvol[0] = ',';
- split_simvol[1] = '\0';
- }
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkPaddingFLTemp))) {
- size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinPaddingFLTemp));
- str_cmd = yon_char_unite(str_cmd, split_simvol,
- "MemorySwapMax=",
- yon_char_from_int(size_bite),
- philos_str_size_pow_byte(widgets->cmbPaddingFLTemp), NULL);
- split_simvol[0] = ',';
- split_simvol[1] = '\0';
- }
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkCPULimitTemp))) {
- size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinCPULimitTemp));
- str_cmd = yon_char_unite(str_cmd, split_simvol,
- "CPUQuota=",
- yon_char_from_int(size_bite),
- "%", NULL);
- split_simvol[0] = ',';
- split_simvol[1] = '\0';
- }
- if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice))!=-1) {
- if (_config->size!=0) {
- str_cmd = philos_pard_array_add_cmd(str_cmd, _config, "IOReadBandwidthMax=", _config->i_o_limit_read, _config->i_o_limit_read_size);
- str_cmd = philos_pard_array_add_cmd(str_cmd, _config, "IOWriteBandwidthMax=", _config->i_o_limit_write, _config->i_o_limit_write_size);
- }
-
- }
- gtk_entry_set_text(GTK_ENTRY(widgets->entryTempCmd), str_cmd);
- free(split_simvol);
-}
-void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config) {
- char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
- disk = yon_char_divide_search(disk, " ", -1);
- int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
- int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
- if (philos_check_activ_disk(widgets, _config) == 0) {
- return;
+/**yon_config_clean()
+ * [EN]
+ * Erase all parameters from config;
+ * [RU]
+ * Удаляет все параметры из конфига;
+*/
+int yon_config_clean(){
+ check_config{
+ __yon__config__strings = yon_dictionary_free_all(__yon__config__strings, NULL);
+ return 1;
}
- if (_config->disk && _config->size) {
- int index_find = -1;
- for (int index = 0; index < _config->size; index++) {
- char* disk_cfg = _config->disk[index];
- if (strstr(disk_cfg, disk) != NULL) {
- index_find = index;
- break;
- }
- }
- if ((bool_read == 0 && bool_write == 0 && index_find != -1)) {
- _config->disk = yon_char_parsed_shrink(_config->disk,&_config->size, index_find);
- _config->size++;
- _config->i_o_limit_read_size = remove_element_int_array(_config->i_o_limit_read_size,&_config->size, index_find);
- _config->size++;
- _config->i_o_limit_write_size = remove_element_int_array(_config->i_o_limit_write_size,&_config->size, index_find);
- _config->size++;
- _config->i_o_limit_read = remove_element_int_array(_config->i_o_limit_read,&_config->size, index_find);
- _config->size++;
- _config->i_o_limit_write = remove_element_int_array(_config->i_o_limit_write,&_config->size, index_find);
- }
- }
+ else return 0;
}
-void philos_temp_config_init(temp_config* _config) {
- if (_config->size != 0) {
- philos_free_string_array(&_config->disk, _config->size);
- philos_free_int_array(&_config->i_o_limit_read, _config->size);
- philos_free_int_array(&_config->i_o_limit_read_size, _config->size);
- philos_free_int_array(&_config->i_o_limit_write, _config->size);
- philos_free_int_array(&_config->i_o_limit_write_size, _config->size);
- }
- _config->disk = NULL;
- _config->i_o_limit_read = NULL;
- _config->i_o_limit_write = NULL;
- _config->i_o_limit_read_size = NULL;
- _config->i_o_limit_write_size = NULL;
- _config->size = 0;
-}
-// flag_check_array = 0 READ
-// flag_check_array = 1 WRITE
-void philos_update_device_to_entry(temp_set_window *widgets, temp_config* _config, int flag_check_array) {
- int disk_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice));
- char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
- disk = yon_char_divide_search(disk, " ", -1);
- if (disk_id != -1) {
- int index_find = -1;
- for (int index = 0; index < _config->size; index++) {
- char* disk_cfg = _config->disk[index];
- if (strstr(disk_cfg, disk) != NULL) {
- index_find = index;
- break;
- }
- }
- if (index_find != -1) {
- if (flag_check_array==0) {
- if (_config->i_o_limit_read[index_find]==-2 || _config->i_o_limit_read[index_find]==-1) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
- }
- else {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), _config->i_o_limit_read[index_find]);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 1);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), _config->i_o_limit_read_size[index_find]);
-
- }
- }
- else if (flag_check_array==1) {
- if (_config->i_o_limit_write[index_find]==-2 || _config->i_o_limit_write[index_find]==-1) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
- }
- else {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), _config->i_o_limit_write[index_find]);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 1);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), _config->i_o_limit_write_size[index_find]);
- }
- }
- else {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
- }
- }
- else {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
+/**yon_config_register(char *key, void *data)
+ * [EN]
+ *
+ * [RU]
+ * Регистрирует новый параметр конфига.
+ * [key] - ключ параметра;
+ * [data] - значение параметра;
+*/
+void yon_config_register(char *key, void *data){
+ yon_dictionary_add_or_create_if_exists_with_data(__yon__config__strings,key,data);
+ __yon__config__strings->data_type=DICTIONARY_CHAR_TYPE;
+}
+
+/**yon_config_load(char *command, int *str_len)
+ * [EN]
+ *
+ * [RU]
+ * Выполняет команду [command] и возвращает распаршеный результат выполнения команды.
+ * В [str_len] возвращается длина возвращаемого массива
+*/
+config_str yon_config_load(char *command, int *str_len){
+ 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)
+ {
+ output_strings = realloc(output_strings, sizeof(char *) * (i + 1));
+ // printf("%s\n", str);
+ output_strings[i] = NULL;
+ output_strings[i] = yon_char_new(str);
+ memset(str, 0, 4096);
+ i++;
}
}
- else {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
+ if (i>0){
+ *str_len = i;
+ return output_strings;
+ } else{
+ *str_len=-1;
+ return NULL;
}
}
-void philos_temp_add_disk(temp_set_window *widgets, temp_config* _config){
- char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
- disk = yon_char_divide_search(disk, " ", -1);
- int disk_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice));
- int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
- int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
- if (disk_id >= 0 && _config->size !=0) {
- int index_find = -1;
- for (int index = 0; index < _config->size; index++) {
- char* disk_cfg = _config->disk[index];
- if (strstr(disk_cfg, disk) != NULL) {
- index_find = index;
- break;
- }
- }
- if (index_find == -1) {
- // Добавление
- _config->disk = yon_char_parsed_append(_config->disk,&_config->size, disk);
- _config->size--;
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
- _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead)));
- _config->size--;
- _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead)));
- _config->size--;
- }
- else {
- _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,-3);
- _config->size--;
- _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,-3);
- _config->size--;
- }
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
- _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite)));
- _config->size--;
- _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite)));
- _config->size--;
- }
- else {
- _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,-3);
- _config->size--;
- _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,-3);
- _config->size--;
- }
- _config->size++;
-
- }
- else {
- // Редактирование
- //_config->disk[index_find] = yon_char_new(disk);
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
- _config->i_o_limit_read_size[index_find] =(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead));
- _config->i_o_limit_read[index_find] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead));
- }
- else {
- _config->i_o_limit_read_size[index_find] = -3;
- _config->i_o_limit_read[index_find] = -3;
- }
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
- _config->i_o_limit_write_size[index_find] = (int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite));
- _config->i_o_limit_write[index_find] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite));
- }
- else {
- _config->i_o_limit_write_size[index_find] = -3;
- _config->i_o_limit_write[index_find] = -3;
- }
-
- }
- }
- else {
- if (bool_read == 1 || bool_write == 1) {
- _config->disk = yon_char_parsed_append(_config->disk,&_config->size, disk);
- _config->size--;
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
- _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead)));
- _config->size--;
- _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead)));
- _config->size--;
- }
- else {
- _config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,-3);
- _config->size--;
- _config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,-3);
- _config->size--;
- }
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
- _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite)));
- _config->size--;
- _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite)));
- _config->size--;
- }
- else {
- _config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,-3);
- _config->size--;
- _config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,-3);
- _config->size--;
+/**int yon_config_save(char *command)
+ * [EN]
+ * Saves config with [command]
+ * [RU]
+ * Выполняет команду [command], добавляя в конец все записи конфига в таком виде:
+ * [ПАРАМЕТР1]="[значения1]" [ПАРАМЕТР2]="[значения2]"
+*/
+int yon_config_save(char *command){
+ check_config{
+ dictionary *dict = NULL;
+ for_dictionaries(dict,__yon__config__strings){
+ command = yon_char_unite(command, " ", yon_dictionary_get_data(dict,char*), NULL);
+ }
+ if (popen(command, "r")) return 1;
+ else return 0;
+ } else return 0;
+}
+
+/**yon_config_get_all(int *size)
+ * [EN]
+ *
+ * [RU]
+ * Возвращает массив со всеми параметрами конфига, оканчивающаяся NULL
+ * [size] - указатель, в который выгружается длина массива
+*/
+config_str yon_config_get_all(int *size){
+ check_config{
+ *size = 1;
+ config_str conf = NULL;
+ dictionary *dict = NULL;
+ for_dictionaries(dict,__yon__config__strings){
+ 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+1));
+ conf[*size] = NULL;
+ return conf;
+ } else return NULL;
+}
+
+/**[EN]
+ * int yon_config_save(char *command)
+ * Saves config with [command]
+ * [RU]
+ * Выполняет команду [command]
+*/
+// int yon_config_save(char *command)
+// {
+// FILE *output = popen(command, "r");
+// return 1;
+// }
+
+/**char *yon_config_get_parameter(config parameters, int size, char *param)
+ * [EN]
+ * Gets parameter [param] from parameter list [parameters] of size [size];
+ * or NULL if nothing were found
+ * [RU]
+ * Возвращает параметр [param] из массива строк [parameters] размером [size]
+ * или NULL если такой не был найден
+*/
+char *yon_config_get_parameter(config_str parameters, int size, char *param)
+{
+ if (param[0]==' ')
+ yon_char_divide_search(param," ",-1);
+ param=yon_char_divide_search(yon_char_new(param)," ",-1);
+
+ char *str = NULL;
+ for (int j = 0; j < size; j++)
+ {
+ char *name = yon_char_divide_search(yon_char_new(parameters[j]), "=", 1);
+ if (name)
+ {
+ if (strcmp(name, param) == 0)
+ {
+ str = yon_char_divide_search(yon_char_new(parameters[j]), "\n", 1);
+ if (strcmp(str, "") != 0 && strcmp(str, "(null)") != 0)
+ return str;
+ else
+ return NULL;
}
- _config->size++;
- }
- else {
}
}
+ return NULL;
}
-int yon_launch_app(char *name)
-{
- char *path = name;
- thread_output *thread = malloc(sizeof(thread_output));
- thread->command = path;
- thread->exitcode = malloc(sizeof(int));
- pthread_t thread_id;
- pthread_create(&thread_id, NULL, (void *)yon_launch, thread);
- return *thread->exitcode;
-};
+
+
+// terminal-using functions
+
+/**yon_launch_app_with_arguments(char *name, char *args)
+ * [EN]
+ * Execute [command] in separate thread;
+ * [RU]
+ * Выполнить команду [command] в отдельном потоке;
+*/
int yon_launch_app_with_arguments(char *name, char *args)
{
- char *path = yon_char_get_augumented("/usr/bin/", name);
- path = yon_char_get_augumented(path, " ");
- path = yon_char_get_augumented(path, args);
+ char *path = yon_char_unite("/usr/bin/", name, " ", args,NULL);
pthread_t thread_id;
- thread_output *thread = malloc(sizeof(thread_output));
- thread->command = path;
- thread->exitcode = malloc(sizeof(int));
- pthread_create(&thread_id, NULL, (void *)yon_launch, thread);
- return *thread->exitcode;
+ char *command = NULL;
+ command = path;
+ pthread_create(&thread_id, NULL, (void *)yon_launch, command);
};
-int yon_launch(thread_output *thread)
+/**yon_launch(char *command)
+ * [EN]
+ * Execute command [command]
+ * [RU]
+ * Выполнить команду [command]
+*/
+void yon_launch(char *command)
{
- int a = 0;
- a = system(thread->command);
- *thread->exitcode = a;
- return *thread->exitcode;
-}
-
-int* philos_int_append(int* array, int* size, int value) {
- array = yon_remalloc(array, (*size+1)*sizeof(int));
- array[(*size)] = value;
- (*size)++;
- return array;
-
+ system(command);
}
-int* remove_element_int_array(int* array, int* size, int item_to_delete) {
- int *new_int_parsed=NULL;
- new_int_parsed=malloc(sizeof(int)*((*size)-1));
- int flag = 0;
- for (int i=0;i < (*size);i++){
- if (i==item_to_delete) {
- flag = 1;
- }
- if (flag == 0) {
- memcpy(&(new_int_parsed[i]),&(array[i]),sizeof(int));
- }
- else if (flag == 1 && i!=item_to_delete) {
- memcpy(&(new_int_parsed[i-1]),&(array[i]),sizeof(int));
- }
- }
- (*size)=(*size)-1;
- return new_int_parsed;
-}
-
-int** remove_element_int_array_n3(int** array, int* size, int item_to_delete) {
- int **new_int_parsed=NULL;
- new_int_parsed=malloc(sizeof(int*)*((*size)-1));
- int flag = 0;
- for (int i=0;i < (*size);i++){
- if (i==item_to_delete) {
- flag = 1;
- }
- if (flag == 0) {
- philos_array_int_copy(&new_int_parsed[i],&array[i]);
- }
- else if (flag == 1 && i!=item_to_delete) {
- philos_array_int_copy(&new_int_parsed[i-1],&array[i]);
- }
- }
- (*size)=(*size)-1;
- return new_int_parsed;
-}
// Gtk functions
@@ -1623,7 +1223,7 @@ static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer
* терминал добавляется в контейнер [place_to_show] виджета,
* после завершения работы терминала вызывается функция [endwork_function] с аргументом [endwork_function_argument].
*/
-void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument){
+void yon_terminal_integrated_launch(GtkWidget *place_to_show, char* command, void *endwork_function, void* endwork_function_argument){
char **commands=new_arr(char*,2);
gchar **envp = g_get_environ();
commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL"));
@@ -1631,10 +1231,13 @@ void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *en
char **env=new_arr(char*,2);
env[0]="";
env[1]=NULL;
+ GtkWidget *terminal = vte_terminal_new();
vte_terminal_set_size(VTE_TERMINAL(terminal),10,15);
VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL);
vte_terminal_set_pty(VTE_TERMINAL(terminal),pty);
- char *install_command=yon_char_unite("tput cup 0 0 && tput ed; ",command, "; exit 0\n",NULL);
+ gtk_container_add(GTK_CONTAINER(place_to_show),terminal);
+ char *install_command=yon_char_unite("tput cup 0 0 && tput ed; ",command," ; sleep 5;exit 0","\n",NULL);
+ printf("%s\n",install_command);
if(endwork_function)
g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument);
vte_terminal_spawn_async(VTE_TERMINAL(terminal),
@@ -1666,28 +1269,152 @@ void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *en
gtk_widget_show_all(terminal);
}
-char* philos_get_size_bite(GtkWidget* chk_button, GtkWidget* spin, GtkWidget* combo_box_text) {
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_button))) {
- char* size_prifics = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box_text));
- int size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
- char* str_size_bute = yon_char_unite(yon_char_from_int(size_bite), " ", size_prifics, NULL);
- return str_size_bute;
+/**yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument)
+ * [EN]
+ * launches terminal with specific [command],
+ * terminal is shown in [place_to_show] container,
+ * after terminal done its work [endwork_function] is called with [endwork_function_argument] argument.
+ * [RU]
+ * Запускает терминал с командой [command],
+ * терминал добавляется в контейнер [place_to_show] виджета,
+ * после завершения работы терминала вызывается функция [endwork_function] с аргументом [endwork_function_argument].
+*/
+void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument){
+ char **commands=new_arr(char*,2);
+ gchar **envp = g_get_environ();
+ commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL"));
+ commands[1]=NULL;
+ char **env=new_arr(char*,2);
+ env[0]="";
+ env[1]=NULL;
+ vte_terminal_set_size(VTE_TERMINAL(terminal),10,15);
+ VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL);
+ vte_terminal_set_pty(VTE_TERMINAL(terminal),pty);
+ char *install_command=yon_char_unite("tput cup 0 0 && tput ed; ",command," ; sleep 5;exit 0","\n",NULL);
+ if(endwork_function)
+ g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument);
+ vte_terminal_spawn_async(VTE_TERMINAL(terminal),
+ VTE_PTY_DEFAULT,
+ NULL,
+ commands,
+ NULL,
+ 0,
+ NULL, NULL,
+ NULL,
+ -1,
+ NULL,
+ child_ready,
+ install_command);
+ vte_pty_spawn_async(pty,
+ NULL,
+ commands,
+ NULL,
+ 0,
+ NULL, NULL,
+ NULL,
+ -1,
+ NULL,
+ NULL,
+ NULL);
+ vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), 100);
+ vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE);
+ vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE);
+ gtk_widget_show_all(terminal);
}
- else {
- char* str = (char*)malloc(sizeof(char*)*2);
- str[0] = '-';
- str[1] = '\0';
- return str;
+#endif
+ // Window config functions
+ #define check_window_config_setup if(__yon_window_config_target_window)
+ struct {
+ int x;
+ int y;
+ int width;
+ int height;
+ int fullscreen;
+ } __yon_main_window_config;
+ static GtkWindow *__yon_window_config_target_window = NULL;
+ static GKeyFile *__yon_window_config_file = NULL;
+ static char *__yon_window_config_path = NULL;
+
+ void yon_window_config_save(){
+ g_key_file_set_integer(__yon_window_config_file,"window","WindowPosX",__yon_main_window_config.x);
+ g_key_file_set_integer(__yon_window_config_file,"window","WindowPosY",__yon_main_window_config.y);
+ g_key_file_set_integer(__yon_window_config_file,"window","WindowWidth",__yon_main_window_config.width);
+ g_key_file_set_integer(__yon_window_config_file,"window","WindowHeight",__yon_main_window_config.height);
+ g_key_file_set_integer(__yon_window_config_file,"window","fullscreen",__yon_main_window_config.fullscreen);
+ g_key_file_save_to_file(__yon_window_config_file,__yon_window_config_path,NULL);
}
-}
-void philos_fill_combo_box_text(GtkWidget *cbt, config_str list_data, int size) {
- for (int index = 0; index < size; index++) {
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cbt), list_data[index]);
+
+ void yon_get_is_fullscreen(){
+ gtk_window_is_maximized(__yon_window_config_target_window);
+ __yon_main_window_config.fullscreen = gtk_window_is_maximized(__yon_window_config_target_window);
}
-}
-#endif
-int yon_gtk_combo_box_fill(GtkWidget *combo, config_str parameters,int size){
+
+ void yon_on_configured_window_destroy(GtkWidget* self,GdkEvent* event){
+ check_window_config_setup{
+ yon_get_is_fullscreen();
+ yon_window_config_save();
+ }
+ gtk_main_quit();
+ }
+
+ void __yon_window_config_on_resize(){
+ int max=0;
+ max=gtk_window_is_maximized(__yon_window_config_target_window);
+ if(max==0){
+ gtk_window_get_size(__yon_window_config_target_window,&__yon_main_window_config.width,&__yon_main_window_config.height);
+ gtk_window_get_position(__yon_window_config_target_window,&__yon_main_window_config.x,&__yon_main_window_config.y);
+ }
+ }
+
+ void yon_window_config_setup(GtkWindow *window){
+ __yon_window_config_target_window = window;
+ g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(yon_on_configured_window_destroy),NULL);
+ g_signal_connect(G_OBJECT(window),"check-resize"/*"configure-event"*/,G_CALLBACK(__yon_window_config_on_resize),NULL);
+ }
+
+ void _yon_maximize(void *data){
+ g_usleep(G_USEC_PER_SEC/10);
+ if(__yon_main_window_config.fullscreen ==1) gtk_window_maximize(__yon_window_config_target_window);
+ }
+
+ int yon_window_config_load(char *path){
+ __yon_window_config_file = g_key_file_new();
+ __yon_window_config_path=yon_char_new(path);
+ if (!g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL)){
+ struct stat st;
+ int size;
+ config_str conf = yon_char_parse(yon_char_new(__yon_window_config_path),&size,"/");
+ char *path = yon_char_unite(conf[0],"/",conf[1],"/",conf[2],"/",conf[3],"/",conf[4],"/",NULL);
+ if (stat(path, &st) == -1) {
+ mkdir(path, 0777);
+ }
+ FILE *fp;
+ fp=fopen(__yon_window_config_path,"w");
+ fclose(fp);
+ g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL);
+ }
+ __yon_main_window_config.x = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosX",NULL);
+ __yon_main_window_config.y = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosY",NULL);
+ __yon_main_window_config.width = g_key_file_get_integer(__yon_window_config_file,"window","WindowWidth",NULL);
+ __yon_main_window_config.height = g_key_file_get_integer(__yon_window_config_file,"window","WindowHeight",NULL);
+ __yon_main_window_config.fullscreen = g_key_file_get_integer(__yon_window_config_file,"window","fullscreen",NULL);
+ if (__yon_main_window_config.width==0) __yon_main_window_config.width=800;
+ if (__yon_main_window_config.height==0) __yon_main_window_config.height=600;
+ gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height);
+ gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y);
+ pthread_t tid;
+ pthread_create(&tid,NULL,(void *)_yon_maximize,NULL);
+ return 1;
+ }
+
+ void yon_window_config_apply(){
+ dictionary *dict=NULL;
+ gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y);
+ gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height);
+ }
+
+int yon_gtk_combo_box_text_fill(GtkWidget *combo, config_str parameters,int size){
if (combo&¶meters){
for (int i=0;ifirst; dct != NULL; dct = dct->next)
- {
- gtk_box_pack_start(GTK_BOX(destination), (GtkWidget *)dct->data, expand, fill, padding);
- }
+/**yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...)
+ * [EN]
+ *
+ * [RU]
+ * Добвляет в [destination] все виджеты, прописанные после [padding]
+ * [expand] - расширяемость выделенного для виджетов места
+ * [fill] - заполнять ли виджетом всё ему выделенное место
+ * [padding] - отступ од других элементов
+*/
+int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){
+ va_list args;
+ va_start(args,padding);
+ GtkWidget *widget = va_arg(args,GtkWidget*);
+ while (widget){
+ gtk_box_pack_start(GTK_BOX(destination), widget, expand, fill, padding);
+ }
+ va_end(args);
return 1;
- }else return 0;
}
-int yon_dictionary_gtk_pack_end_multiple_widgets(dictionary *dict, GtkWidget *destination, gboolean expand, gboolean fill, int padding)
-{
- for (dictionary *dct = dict->first; dct != NULL; dct = dct->next)
- {
- gtk_box_pack_end(GTK_BOX(destination), (GtkWidget *)dct->data, expand, fill, padding);
- }
+int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){
+ va_list args;
+ va_start(args,padding);
+ GtkWidget *widget = va_arg(args,GtkWidget*);
+ while (widget){
+ gtk_box_pack_end(GTK_BOX(destination), widget, expand, fill, padding);
+ }
+ va_end(args);
return 1;
}
+
void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path)
{
gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head);
gtk_image_set_from_file(GTK_IMAGE(Image), image_path);
}
+void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path)
+{
+ gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head);
+ gtk_image_set_from_resource(GTK_IMAGE(Image), image_path);
+}
+
int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label)
{
if(icon&&box&&label){
@@ -1746,9 +1491,6 @@ int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label)
} else return 0;
}
-/**
- *
-*/
void _yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type)
{
render_data data = render;
@@ -1775,7 +1517,6 @@ void _yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type)
gtk_label_set_text(GTK_LABEL(data.label), text);
}
-
void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type){
_yon_ubl_status_box_render(text,type);
}
@@ -1898,109 +1639,8 @@ void yon_ubl_browser_window_open(char *link, char *browser_window_name){
if (!user)
user=getlogin();
char *command=yon_char_unite("sudo -u ",user," xdg-open ", link,NULL);
- yon_launch_app(command);
+ yon_launch(command);
}
#endif
-// Mem Size pow
-void philos_set_spin_adjustment(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, size_t value) {
- gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
- guint value_spin = gtk_spin_button_get_digits(GTK_SPIN_BUTTON(spin));
- if (active != -1) {
- GtkAdjustment* adjustment = NULL;
- adjustment = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(spin));
- gtk_adjustment_set_lower(adjustment, 0.0);
- gtk_adjustment_set_page_increment(adjustment, 1.0);
- if (combo == NULL) {
- gtk_adjustment_set_upper(adjustment, (gdouble)(value*100));
- if ((value*100)0) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),1);
- }
- else if (active == 0) {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
- }
- if (flag_cpu == 0) {
- philos_set_spin_adjustment(check, spin, combo, resurs);
- if (value_spin>resurs) {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), resurs);
- }
- }
- else {
- philos_set_spin_adjustment(check, spin, NULL, resurs);
- }
-
-}
-size_t get_resurs_total(char* cmd) {
- int size = 0;
- size_t size_memory = 0;
- char **responce = yon_config_load(cmd, &size);
- for (int index = 0; index < size; index++ ) {
- char* mem_size_kb = yon_char_divide_search(responce[index], "\n", -1);
- size_memory = atoll(mem_size_kb);
- free(mem_size_kb);
- }
- philos_free_string_array(&responce, size);
- return size_memory;
-}
-
-float get_size_pow_memory(size_t size_memory, int size) {
- float res = size_memory;
- for (size_t index = 0; index < size; index++) {
- res = res/1024;
- }
- return res;
-}
-
-void philos_set_active_widgets_device_io(GtkWidget* combo_to_l2,GtkWidget *check, GtkWidget *spin, GtkWidget *combo) {
- int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_to_l2));
- if (menu_id != -1) {
- gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
- if (active == 0) {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
- }
- else if (gtk_spin_button_get_digits(GTK_SPIN_BUTTON(spin))>0) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),1);
- }
- gtk_widget_set_sensitive(spin, active);
- gtk_widget_set_sensitive(combo, active);
- }
- else {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
- gtk_widget_set_sensitive(spin, 0);
- gtk_widget_set_sensitive(combo, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), 0);
- }
- philos_set_spin_adjustment(check, spin, combo, 12582912);
-}
#endif
\ No newline at end of file
diff --git a/source/ubl-utils.h b/source/ubl-utils.h
index 27c2baa..c16eba9 100644
--- a/source/ubl-utils.h
+++ b/source/ubl-utils.h
@@ -7,98 +7,38 @@
#include
#include
#include
+#include
+#include
#include
#include
#include
-#include
-#include
-#include
-#include "ubl-cmake.h"
+#include "ubl-cmake.h"
#ifdef WEBKIT_FOUND
#include
#endif
#define DesktopPath "/usr/share/applications/"
-#define yon_remalloc(pointer, size) (!pointer) ? malloc(size) : realloc(pointer, size)
-
#define for_dictionaries(obj, obj1) for (obj = obj1->first; obj != NULL; obj = obj->next)
-
+#define try bool __HadError=false;
+#define catch(x) ExitJmp:if(__HadError)
+#define throw(x) {__HadError=true;goto ExitJmp;}
#define new(type) malloc(sizeof(type))
#define new_arr(type,size) malloc(sizeof(type)*size)
-#define yon_ubl_set_config_save_data_pointer(command) config_commands.config_save_data = command
-
-#define yon_ubl_load_global_config(command, size_pointer) yon_config_load(command, size_pointer)
-#define yon_ubl_load_local_config(command, size_pointer) yon_config_load(command, size_pointer)
-#define yon_ubl_save_global_config(command) yon_config_save(command)
-#define yon_ubl_save_local_config(command) yon_config_save(command)
-#define try bool __HadError=false;
-#define catch(x) ExitJmp:if(__HadError)
-#define throw(x) {__HadError=true;goto ExitJmp;}
-#define file_source_login_min_max "/etc/login.defs"
-static char** array_size_pow;
typedef enum
{
#ifdef __GTK_H__
DICTIONARY_GTK_WIDGETS_TYPE,
#endif
- DICTIONARY_OTHER_TYPE
+ DICTIONARY_OTHER_TYPE=0,
+ DICTIONARY_CHAR_TYPE,
+ DICTIONARY_INT_TYPE,
+ DICTIONARY_BOOL_TYPE,
} DICT_TYPE;
-typedef struct
-{
- char *command;
- int *exitcode;
-} thread_output;
-
-typedef struct {
- char** disk;
- int* i_o_limit_read;
- int* i_o_limit_write;
- int* i_o_limit_read_size;
- int* i_o_limit_write_size;
- int size;
-} temp_config;
-
-typedef struct {
-
- GtkWidget* Window;
- GtkWidget* btnSaveTempSave;
- GtkWidget* btnTempCancel;
-
- GtkWidget* entryTempCmd;
- GtkWidget* chbTempRead;
- GtkWidget* spinTempRead;
- GtkWidget* cbtTempRead;
-
- GtkWidget* chbTempWrite;
- GtkWidget* spinTempWrite;
- GtkWidget* cbtTempWrite;
-
- GtkWidget* chkSoftRestrictionTemp;
- GtkWidget* spiSevereRestrictionTemp;
- GtkWidget* cmSevereRestrictionTemp;
-
- GtkWidget* chkSevereRestrictionTemp;
- GtkWidget* spinSevereRestrictionTemp;
- GtkWidget* cmbSevereRestrictionTemp;
-
- GtkWidget* chkPaddingFLTemp;
- GtkWidget* spinPaddingFLTemp;
- GtkWidget* cmbPaddingFLTemp;
-
- GtkWidget* chkCPULimitTemp;
- GtkWidget* spinCPULimitTemp;
- GtkWidget* lblCPULimitTemp;
-
- GtkWidget* cbtTempDevice;
- GtkWidget* cbxTempQuotaObj;
- GtkWidget* cbxTempQuotaLevel2;
- GtkWidget* boxBlockGui;
-} temp_set_window;
typedef struct dictionary
{
char *key;
@@ -107,6 +47,7 @@ typedef struct dictionary
struct dictionary *prev;
struct dictionary *first;
DICT_TYPE data_type;
+ int flag1;
} dictionary;
typedef struct apps
@@ -121,6 +62,15 @@ typedef struct apps
} apps;
typedef char** config_str;
+
+static dictionary *__yon__config__strings = NULL;
+#define check_config if(__yon__config__strings&&__yon__config__strings->data_type==DICTIONARY_CHAR_TYPE)
+
+#define config(key) yon_config_get_by_key(key)
+
+#define for_config dictionary temp = NULL; for_dictionary(temp,__yon__config__strings)
+
+#define yon_remalloc(pointer, size) (!pointer) ? malloc(size) : realloc(pointer, size)
// dictionary functions
/**yon_dictionary_get_data(dictionary, type)
@@ -134,34 +84,36 @@ typedef char** config_str;
* [type] - тип данных, хранящихся в словаре [dictionary].
*/
#define yon_dictionary_get_data(dictionary, type) ((type)dictionary->data)
-#define yon_dictionary_add_or_create_if_exists_with_data(dict,key,data) {if (!dict) dict=yon_dictionary_create_with_data(key,data); \
- else dict=yon_dictionary_create_with_data_connected(dict,key,data);}
-
-dictionary *yon_dictionary_create_empty();
-
-dictionary *yon_dictionary_copy(dictionary *dict);
-dictionary *yon_dictionary_copy_deep(dictionary *dict);
+/**yon_dictionary_add_or_create_if_exists_with_data(dict,key,data)
+ * [EN]
+ *
+ * [RU]
+ * Добавляет элемент словаря в конец словаря [dict] c ключом [key] и данными [data].
+ * Если словарь не существует, создаёт его
+*/
+#define yon_dictionary_add_or_create_if_exists_with_data(dict,key,data) {if (!dict) dict=yon_dictionary_new_with_data(key,data); \
+ else dict=yon_dictionary_append_with_data(dict,key,data);}
-size_t yon_dict_len(dictionary *dict);
+dictionary *yon_dictionary_new();
-dictionary *yon_dictionary_create_conneced(dictionary *targetdict);
+dictionary *yon_dictionary_append(dictionary *targetdict);
dictionary *yon_dictionary_get_last(dictionary *dict);
-dictionary *yon_dictionary_switch_places(dictionary *dict, int aim);
+dictionary *yon_dictionary_swap(dictionary *dict, int aim);
void yon_dictionary_make_first(dictionary *dict);
void yon_dictionary_make_nth(dictionary *dict, int nth);
-dictionary *yon_dictionary_create_with_data(char *key, void *data);
+dictionary *yon_dictionary_new_with_data(char *key, void *data);
-dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data);
+dictionary *yon_dictionary_append_with_data(dictionary *dict, char *key, void *data);
dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect);
-dictionary *yon_dictionary_find(dictionary **dict, char *key);
+dictionary *yon_dictionary_get(dictionary **dict, char *key);
dictionary *yon_dictionary_rip(dictionary *dict);
@@ -170,16 +122,8 @@ dictionary *yon_dictionary_get_nth(dictionary *dict, int place);
void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(void*));
// char functions
-char* philos_str_remove(char *str, const char *sub);
-char *yon_char_get_augumented(char *source, char *append);
-
-void philos_free_string_array(char ***array, int size);
-
-void philos_free_string_array_n3(char ****array, int size);
-
-void philos_free_int_array_n2(int ***array, int size);
-void philos_free_int_array(int **array, int size);
+char *yon_char_append(char *source, char *append);
char *yon_char_new(char *chr);
@@ -195,23 +139,9 @@ char *yon_char_from_int(int int_to_convert);
char *yon_char_replace(char *source, char *find, char*replace);
-void philos_split_size_memory(char* str_value, int* size, char* pow_memory);
-
-char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory);
-
char **yon_char_parse(char *parameters, int *size, char *divider);
-char** philos_str_split(char *parameters, int *size, char *divider);
-
-void philos_array_string_remove_char(char*** array, char* str_remove, int size);
-
-void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char** array_size_pow);
-
-void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index);
-
-char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete);
-
-char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete);
+char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete);
int yon_char_parsed_check_exist(char **parameters, int size, char *param);
@@ -220,21 +150,18 @@ int yon_char_find_count(char *source, char *find);
int yon_char_parsed_includes_char_parsed (config_str source, config_str to_check, int source_size, int check_size);
config_str yon_char_parsed_new (int *size, ...);
-config_str yon_char_parsed_append(config_str parsed, int *size, char *string);
+
void yon_char_parsed_copy(config_str *source, config_str *to_copy);
-void philos_array_str_copy(char*** source, char*** copy);
-void philos_array_int_copy(int** source, int** copy);
-void array_copy(char*** source, char*** copy);
-// parsing functions
+config_str yon_char_parsed_append(config_str parsed, int *size, char *string);
-config_str philos_list_user(int* size);
+int yon_ubl_check_root();
-char* philos_str_size_pow_byte(GtkWidget *combo_box_text);
+char *yon_ubl_root_user_get();
-config_str philos_list_group(int* size);
+// parsing functions
-unsigned short philos_read_uid_min_max(char* filename, char* search);
+config_str philos_list_user(int* size);
apps *yon_apps_scan_and_parse_desktops(int *sizef);
@@ -248,48 +175,40 @@ int yon_config_save(char *command);
char *yon_config_get_parameter(config_str parameters, int size, char *param);
-char *yon_config_make_save_parameter_with_multiple_arguments(char *parameter_string, char *config_parameter, char *divider);
+int yon_config_load_register(char *command);
-// terminal-using functions
+int yon_config_remove_by_key(char *key);
-char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data);
+int yon_config_remove_by_data(void *data);
-char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size);
+int yon_config_remove_element(char *key, char *deleted);
-int philos_check_activ_disk(temp_set_window *widgets, temp_config* _config);
+void *yon_config_get_by_key(char *key);
-void philos_temp_generate_cmd(temp_set_window *widgets, temp_config* _config);
+char *yon_config_get_key_by_data(char *data);
-void philos_update_device_to_entry(temp_set_window *widgets, temp_config* _config, int flag_check_array);
+int yon_config_set(char *key, void *data);
-void philos_temp_config_init(temp_config* _config);
+int yon_config_clean();
-void philos_temp_add_disk(temp_set_window *widgets, temp_config* _config);
+void yon_config_register(char *key, void *data);
-void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config);
+config_str yon_config_get_all();
-int yon_launch_app(char *name);
+// terminal-using functions
int yon_launch_app_with_arguments(char *name, char *args);
-int yon_launch(thread_output *thread);
-
-int* philos_int_append(int* array, int* size, int value);
+void yon_launch(char *command);
-int* remove_element_int_array(int* array, int* size, int item_to_delete);
-
-int** remove_element_int_array_n3(int** array, int* size, int item_to_delete);
// Gtk functions
#ifdef __GTK_H__
#ifdef VTE_TERMINAL
+void yon_terminal_integrated_launch(GtkWidget *place_to_show, char* command, void *endwork_function, void* endwork_function_argument);
+
+void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument);
-/**
- *
-*/
-void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument);
-char* philos_get_size_bite(GtkWidget* chk_button, GtkWidget* spin, GtkWidget* combo_box_text);
-void philos_fill_combo_box_text(GtkWidget *cbt, config_str list_data, int size);
#endif
/**yon_gtk_builder_get_widget(builder, widget_name)
@@ -308,11 +227,9 @@ typedef struct
GtkListStore *List;
} expander_icon_view;
-// GtkWidget *yon_gtk_app_chooser_apps_create();
+void yon_window_config_setup(GtkWindow *window);
-// dictionary *yon_gtk_app_chooser_create();
-
-// expander_icon_view yon_gtk_icon_view_expander_create(GtkWidget *pack, ...);
+int yon_window_config_load(char *path);
int yon_gtk_combo_box_fill(GtkWidget *combo, char **parameters,int size);
@@ -320,8 +237,9 @@ int yon_gtk_combo_box_text_find(GtkWidget *combo_box, char *text_to_find);
int yon_gtk_icon_view_hide_empty(dictionary *icon_view_segment);
-int yon_dictionary_gtk_pack_start_multiple_widgets(dictionary *dict, GtkWidget *destination, gboolean expand, gboolean fill, int padding);
-int yon_dictionary_gtk_pack_end_multiple_widgets(dictionary *dict, GtkWidget *destination, gboolean expand, gboolean fill, int padding);
+int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...);
+
+int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...);
@@ -405,10 +323,13 @@ void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type);
* [imag_path] - путь до картинки, загружаемой в [image]
*/
#define yon_ubl_header_setup(overlay, head, image, imag_path) _yon_ubl_header_setup(GTK_WIDGET(overlay), GTK_WIDGET(head), GTK_WIDGET(image), (char *)imag_path)
+#define yon_ubl_header_setup_resource(overlay, head, image, imag_path) _yon_ubl_header_setup_resource(GTK_WIDGET(overlay), GTK_WIDGET(head), GTK_WIDGET(image), (char *)imag_path)
#endif
void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path);
+void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path);
+
void yon_ubl_setup_sockets(GtkWidget *main_window, GtkWidget *left_window, GtkWidget *right_window, int socket_main_id, int socket_left_id, int socket_right_id);
#ifdef WEBKIT_FOUND
@@ -417,9 +338,4 @@ void yon_ubl_browser_window_open(char *link, char *browser_window_name);
void yon_ubl_browser_window_open(char *link, char *browser_window_name);
#endif
#endif
-void philos_set_spin_adjustment(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, size_t value);
-void philos_set_active_widgets(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, int flag_cpu, char* cmd);
-size_t get_resurs_total(char* cmd);
-float get_size_pow_memory(size_t size_memory, int size);
-void philos_set_active_widgets_device_io(GtkWidget* combo_to_l2,GtkWidget *check, GtkWidget *spin, GtkWidget *combo);
#endif
\ No newline at end of file
diff --git a/source/view_add.c b/source/view_add.c
index 00d6d32..66d5774 100644
--- a/source/view_add.c
+++ b/source/view_add.c
@@ -10,7 +10,7 @@ temp_config* get_add_config() {
temp_set_window *add_setup_window(char* glade_path) {
if (add_widgets == NULL) {
add_widgets = malloc(sizeof(temp_set_window));
- GtkBuilder *builder = gtk_builder_new_from_file(glade_path);
+ GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
add_widgets->Window = yon_gtk_builder_get_widget(builder,"wndQuotasAdding");
add_widgets->btnSaveTempSave = yon_gtk_builder_get_widget(builder,"btnSaveAddSave");
add_widgets->btnTempCancel = yon_gtk_builder_get_widget(builder,"btnAddCancel");
@@ -121,8 +121,8 @@ void add_event(temp_set_window *widgets) {
g_signal_connect(G_OBJECT(widgets->cbtTempDevice),"changed",G_CALLBACK(combo_box_device), NULL);
g_signal_connect(G_OBJECT(widgets->cbtTempRead),"changed",G_CALLBACK(event_check_io_device), NULL);
g_signal_connect(G_OBJECT(widgets->cbtTempWrite),"changed",G_CALLBACK(event_check_io_device), NULL);
- g_signal_connect(G_OBJECT(widgets->spinTempRead),"value-changed",G_CALLBACK(event_check_io_device), NULL);
- g_signal_connect(G_OBJECT(widgets->spinTempWrite),"value-changed",G_CALLBACK(event_check_io_device), NULL);
+ g_signal_connect(G_OBJECT(widgets->spinTempRead),"changed",G_CALLBACK(event_check_io_device), NULL);
+ g_signal_connect(G_OBJECT(widgets->spinTempWrite),"changed",G_CALLBACK(event_check_io_device), NULL);
g_signal_connect(G_OBJECT(widgets->chbTempRead), "toggled", G_CALLBACK(event_check_io_device), NULL);
g_signal_connect(G_OBJECT(widgets->chbTempWrite), "toggled", G_CALLBACK(event_check_io_device), NULL);
}
diff --git a/source/view_add.h b/source/view_add.h
index 2b5e06f..98ee32f 100644
--- a/source/view_add.h
+++ b/source/view_add.h
@@ -12,6 +12,7 @@
#include
#include
#include "my_device.h"
+#include "philos_utils.h"
#define CMD_CPU "lscpu | grep \"CPU(s):\" |grep -oE \"[0-9]{1,}\""
diff --git a/source/view_edit.c b/source/view_edit.c
index 889b0fc..9cd89f3 100644
--- a/source/view_edit.c
+++ b/source/view_edit.c
@@ -9,7 +9,7 @@ temp_config* get_edit_config() {
temp_set_window *edit_setup_window(char* glade_path){
if (edit_widgets == NULL) {
edit_widgets = malloc(sizeof(temp_set_window));
- GtkBuilder *builder = gtk_builder_new_from_file(glade_path);
+ GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
edit_widgets->Window = yon_gtk_builder_get_widget(builder,"wndQuotasEdit");
edit_widgets->btnTempCancel = yon_gtk_builder_get_widget(builder,"btnEditCancel");
edit_widgets->btnSaveTempSave = yon_gtk_builder_get_widget(builder,"btnSaveEditSave");
@@ -46,21 +46,7 @@ temp_set_window *edit_setup_window(char* glade_path){
}
return edit_widgets;
}
-void edit_config_init() {
- if (obj_edit_config.size != 0) {
- philos_free_string_array(&obj_edit_config.disk, obj_edit_config.size);
- philos_free_int_array(&obj_edit_config.i_o_limit_read, obj_edit_config.size);
- philos_free_int_array(&obj_edit_config.i_o_limit_write, obj_edit_config.size);
- philos_free_int_array(&obj_edit_config.i_o_limit_read_size, obj_edit_config.size);
- philos_free_int_array(&obj_edit_config.i_o_limit_write_size, obj_edit_config.size);
- }
- obj_edit_config.disk = NULL;
- obj_edit_config.i_o_limit_read = NULL;
- obj_edit_config.i_o_limit_write = NULL;
- obj_edit_config.i_o_limit_read_size = NULL;
- obj_edit_config.i_o_limit_write_size = NULL;
- obj_edit_config.size = 0;
-}
+
void edit_event(temp_set_window *widgets) {
g_signal_connect(G_OBJECT(widgets->btnTempCancel),"clicked",G_CALLBACK(edit_on_hide_subwindow),NULL);
g_signal_connect(G_OBJECT(widgets->Window), "destroy", G_CALLBACK(edit_destroy), NULL);
@@ -71,12 +57,12 @@ void edit_event(temp_set_window *widgets) {
g_signal_connect(G_OBJECT(widgets->chbTempRead), "toggled", G_CALLBACK(edit_init_windows), NULL);
g_signal_connect(G_OBJECT(widgets->chbTempWrite), "toggled", G_CALLBACK(edit_init_windows), NULL);
- g_signal_connect(G_OBJECT(widgets->spiSevereRestrictionTemp),"value-changed",G_CALLBACK(edit_init_windows), NULL);
- g_signal_connect(G_OBJECT(widgets->spinSevereRestrictionTemp),"value-changed",G_CALLBACK(edit_init_windows), NULL);
- g_signal_connect(G_OBJECT(widgets->spinPaddingFLTemp),"value-changed",G_CALLBACK(edit_init_windows), NULL);
- g_signal_connect(G_OBJECT(widgets->spinCPULimitTemp),"value-changed",G_CALLBACK(edit_init_windows), NULL);
- g_signal_connect(G_OBJECT(widgets->spinTempRead),"value-changed",G_CALLBACK(wrapper_edit_init_windows_size_memory), NULL);
- g_signal_connect(G_OBJECT(widgets->spinTempWrite),"value-changed",G_CALLBACK(wrapper_edit_init_windows_size_memory), NULL);
+ g_signal_connect(G_OBJECT(widgets->spiSevereRestrictionTemp),"changed",G_CALLBACK(edit_init_windows), NULL);
+ g_signal_connect(G_OBJECT(widgets->spinSevereRestrictionTemp),"changed",G_CALLBACK(edit_init_windows), NULL);
+ g_signal_connect(G_OBJECT(widgets->spinPaddingFLTemp),"changed",G_CALLBACK(edit_init_windows), NULL);
+ g_signal_connect(G_OBJECT(widgets->spinCPULimitTemp),"changed",G_CALLBACK(edit_init_windows), NULL);
+ g_signal_connect(G_OBJECT(widgets->spinTempRead),"changed",G_CALLBACK(wrapper_edit_init_windows_size_memory), NULL);
+ g_signal_connect(G_OBJECT(widgets->spinTempWrite),"changed",G_CALLBACK(wrapper_edit_init_windows_size_memory), NULL);
g_signal_connect(G_OBJECT(widgets->cmSevereRestrictionTemp),"changed",G_CALLBACK(wrapper_edit_init_windows_size_memory), widgets->spiSevereRestrictionTemp);
g_signal_connect(G_OBJECT(widgets->cmbSevereRestrictionTemp),"changed",G_CALLBACK(wrapper_edit_init_windows_size_memory), widgets->spinSevereRestrictionTemp);
g_signal_connect(G_OBJECT(widgets->cmbPaddingFLTemp),"changed",G_CALLBACK(wrapper_edit_init_windows_size_memory), widgets->spinPaddingFLTemp);
diff --git a/source/view_edit.h b/source/view_edit.h
index 6c09a41..c3a43da 100644
--- a/source/view_edit.h
+++ b/source/view_edit.h
@@ -12,6 +12,7 @@
#include
#include
#include "my_device.h"
+#include "philos_utils.h"
#define CMD_CPU "lscpu | grep \"CPU(s):\" |grep -oE \"[0-9]{1,}\""
#define CMD_SWAP "grep '^Swap' /proc/meminfo | grep \"SwapTotal\" |grep -oE \"[0-9]{1,}\""
diff --git a/ubl-settings-resourcequota.pot b/ubl-settings-resourcequota.pot
index 16f7dde..d8be582 100644
--- a/ubl-settings-resourcequota.pot
+++ b/ubl-settings-resourcequota.pot
@@ -17,6 +17,9 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
+msgid "Config loading failed"
+msgstr ""
+
msgid "Remove"
msgstr ""
diff --git a/ubl-settings-resourcequota_ru.po b/ubl-settings-resourcequota_ru.po
index 2c9df12..2048b2d 100644
--- a/ubl-settings-resourcequota_ru.po
+++ b/ubl-settings-resourcequota_ru.po
@@ -20,6 +20,9 @@ msgstr ""
#: source/ubl-strings.h:8
#: source/ubl-strings.h:1
+msgid "Config loading failed"
+msgstr "Не удалось загрузить конфигурацию"
+
msgid "Quota deleted"
msgstr "Квота удалена"