|
|
#ifndef UTIL_H
|
|
|
#define UTIL_H
|
|
|
#include <stdio.h>
|
|
|
#include <tuple>
|
|
|
#include <iostream>
|
|
|
#include <sstream>
|
|
|
#include <fstream>
|
|
|
#include <string>
|
|
|
#include <array>
|
|
|
#include <vector>
|
|
|
#include <linux/limits.h>
|
|
|
#include <sys/types.h>
|
|
|
#include <pwd.h>
|
|
|
#include <unistd.h>
|
|
|
#include <iostream>
|
|
|
#include <map>
|
|
|
#include <string>
|
|
|
#include <array>
|
|
|
#include <vector>
|
|
|
#include <fstream>
|
|
|
#include <filesystem>
|
|
|
#include <stdio.h>
|
|
|
#include <map>
|
|
|
#include <pwd.h>
|
|
|
#include <set>
|
|
|
#include <gtkmm.h>
|
|
|
#include <gtk/gtk.h>
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
#define get_home_dir_command yon_char_unite((char*)"getent passwd \"",yon_ubl_root_user_get(),(char*)"\" | cut -d: -f6",NULL)
|
|
|
|
|
|
template<typename Type>
|
|
|
struct Result{
|
|
|
Type response;
|
|
|
int error;
|
|
|
};
|
|
|
|
|
|
struct Passwd {
|
|
|
string user;
|
|
|
int uid;
|
|
|
};
|
|
|
|
|
|
std::array<std::vector<std::string>, 5> read_csv(const std::string& filename);
|
|
|
std::string call(std::string cmd);
|
|
|
vector<int> find_all(string &str_ntp, string substr);
|
|
|
void str_remove(std::string& source, std::string to_remove);
|
|
|
void str_replace_all(string &str_base, string str_find, string str_replace);
|
|
|
std::vector<std::string> split(std::string text, char delim);
|
|
|
vector<tuple<string, string>> read_csv_melody(const string& filename);
|
|
|
void write_file(string path_name, string data);
|
|
|
|
|
|
#define for_dictionaries(element, stack) for (element = stack->first; element != NULL; element = element->next)
|
|
|
#define yon_dictionary_get_data(dictionary, type) ((type)dictionary->data)
|
|
|
|
|
|
typedef enum
|
|
|
{
|
|
|
DICTIONARY_GTK_WIDGETS_TYPE,
|
|
|
DICTIONARY_OTHER_TYPE=0,
|
|
|
DICTIONARY_CHAR_TYPE,
|
|
|
DICTIONARY_INT_TYPE,
|
|
|
DICTIONARY_BOOL_TYPE,
|
|
|
|
|
|
} DICT_TYPE;
|
|
|
|
|
|
typedef struct dictionary
|
|
|
{
|
|
|
char *key;
|
|
|
void *data;
|
|
|
struct dictionary *next;
|
|
|
struct dictionary *prev;
|
|
|
struct dictionary *first;
|
|
|
DICT_TYPE data_type;
|
|
|
} dictionary;
|
|
|
|
|
|
typedef char** config_str;
|
|
|
|
|
|
char *yon_char_divide(char *source, int dividepos);
|
|
|
|
|
|
char *yon_char_divide_search(char *source, char *dividepos, int delete_divider);
|
|
|
|
|
|
char *yon_char_new(char *chr);
|
|
|
|
|
|
char *yon_char_append(char *source, char *append);
|
|
|
|
|
|
char *yon_char_unite(char *source, ...);
|
|
|
|
|
|
char **yon_char_parse(char *parameters, int *size, char *divider);
|
|
|
|
|
|
/**YON_TYPE
|
|
|
* [EN]
|
|
|
*
|
|
|
* [RU]
|
|
|
* Типы, поддерживаемые функциями сохранения/загрузки конфигурации утилиты
|
|
|
*/
|
|
|
enum YON_TYPE{
|
|
|
YON_TYPE_STRING,
|
|
|
YON_TYPE_STRING_LIST,
|
|
|
YON_TYPE_INT,
|
|
|
YON_TYPE_BOOLEAN,
|
|
|
YON_TYPE_OTHER};
|
|
|
|
|
|
/**yon_window_config_setup(GtkWindow *window)
|
|
|
* [EN]
|
|
|
*
|
|
|
* [RU]
|
|
|
* Устанавливает указатель на окно для отслеживания его положения и размера
|
|
|
*/
|
|
|
void yon_window_config_setup(GtkWindow *window);
|
|
|
|
|
|
/**yon_window_config_load(char *path)
|
|
|
* [EN]
|
|
|
*
|
|
|
* [RU]
|
|
|
* Загружает конфиг окна и инициализирует отслеживание его параметров
|
|
|
*/
|
|
|
int yon_window_config_load(char *path);
|
|
|
|
|
|
/**yon_window_config_get_section(char *section, gsize *size)
|
|
|
* [EN]
|
|
|
*
|
|
|
* [RU]
|
|
|
* Возвращает все параметры раздела [section] конфига утилиты и записывает в [size] количество считанных параметров.
|
|
|
*/
|
|
|
config_str yon_window_config_get_section(char *section, gsize *size);
|
|
|
|
|
|
|
|
|
char *yon_ubl_user_get_home_directory();
|
|
|
|
|
|
char *yon_ubl_root_user_get();
|
|
|
|
|
|
|
|
|
int yon_ubl_check_root();
|
|
|
}
|
|
|
#endif |