Fixes; Function descriptions update

pull/64/head
parent 9c3230afdc
commit c38d971000
No known key found for this signature in database
GPG Key ID: FF1D842BF4DDE92B

@ -31,15 +31,19 @@ dictionary *yon_dictionary_copy_deep(dictionary *dict){
}
int yon_dictionary_set_data(dictionary *dict, void *data){
if (!dict) return 0;
dict->data=data;
return 1;
}
int yon_dictionary_set_key(dictionary *dict, char *key){
if (!dict||yon_char_is_empty(key)) return 0;
dict->key=key;
return 1;
}
int yon_dictionary_set(dictionary *dict, char *key, void *data){
if (!dict||yon_char_is_empty(key)) return 0;
dict->key=key;
dict->data=data;
return 1;
@ -222,7 +226,7 @@ void *yon_dictionary_free(dictionary *dictionary_to_free){
}
}
void *yon_dictionary_free_all(dictionary *dictionary_to_free,void (*data_manipulation)(void*)){
void yon_dictionary_free_all(dictionary *dictionary_to_free,void (*data_manipulation)(void*)){
if (dictionary_to_free){
dictionary *dict=NULL;
for_dictionaries(dict,dictionary_to_free){
@ -232,7 +236,6 @@ void *yon_dictionary_free_all(dictionary *dictionary_to_free,void (*data_manipul
free(dict->prev);
}
free(dict);
return NULL;
}
}
@ -245,22 +248,24 @@ dictionary *yon_dictionary_append_with_data(dictionary *dict, char *key, void *d
return dct;
}
dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect)
int yon_dictionary_connect(dictionary *old, dictionary *toconnect)
{
if (!old||!toconnect) return 0;
dictionary *dict = yon_dictionary_get_last(old);
dict->next = toconnect;
toconnect->prev = dict;
toconnect->first = dict->first;
return toconnect;
return 1;
}
dictionary *yon_dictionary_merge(dictionary *dict1,dictionary *dict2){
int yon_dictionary_merge(dictionary *dict1,dictionary *dict2){
if (!dict1||!dict2) return 0;
dictionary *dct = NULL;
for_dictionaries(dct,dict2){
if (!yon_dictionary_get(&dict1,dct->key))
yon_dictionary_connect(dict1,dct);
}
return dict1;
return 1;
}
dictionary *yon_dictionary_get(dictionary **dict, char *key)

@ -16,14 +16,19 @@
#define DesktopPath "/usr/share/applications/"
/**for_dictionaries(element, stack)
* [EN]
/**
* @brief Works like for, but is used to enumerate dictionary elements.
*
* [RU]
* Работает как for, но нужен для перечисления элементов словаря типа dictioary [stack]. Каждый цикл текущий элемент попадает в [element]
*/
#define for_dictionaries(element, stack) for (element = stack->first; element != NULL; element = element->next)
* Работает как for, но нужен для перечисления элементов словаря.
*
* @param iterator Type: dictionary*
*
* dictionary element iterator.
* @param stack Type: dictinoary*
*
* dictionary pointer.
*/
#define for_dictionaries(iterator, stack) for (iterator = stack->first; iterator != NULL; iterator = iterator->next)
#define new(type) malloc(sizeof(type))
#define new_arr(type,size) malloc(sizeof(type)*size)
@ -48,15 +53,30 @@ typedef enum
struct type_name *prev;\
struct type_name *first;\
DICT_TYPE data_type;
/**
* @brief Named dictionary structure.
*
* Структура именованого списка.
* [key] - ключ элемента
* [data] - хранимое значение
* [next] - следующий элемент списка
* [prev] - предыдущий элемент списка
* [first] - первый элемент списка
* [data_type] - Тип значения в словаре
*/
* @param key dictionary element key.
*
* Ключ элемента словаря.
* @param data dictionary element value.
*
* Значение элемента словаря.
* @param next next dictionary element.
*
* Следующий элемент словаря.
* @param prev previous dictionary element.
*
* Предыдущий элемент словаря.
* @param first first dictionary element.
*
* Следующий элемент словаря.
* @param data_type value type.
*
* Тип значения.
*/
typedef struct dictionary
{
char *key;
@ -67,9 +87,6 @@ typedef struct dictionary
DICT_TYPE data_type;
} dictionary;
typedef struct apps
{
char *Name;
@ -83,226 +100,491 @@ typedef struct apps
typedef char** config_str;
/**config(key)
* Возвращает элемент конфигурации ubconfig с ключом [key] или NULL если такого нет
*/
/**
* @brief Get configuration parameter value.
*
* Получение значения параметра конфигурации.
* @param key Key of configuration parameter.
*
* Ключ параметра конфигурации.
* @return Type: char*
*
* Value of configuration parameter or NULL.
*
* Значение парамерта конфигурации или NULL.
*/
#define config(key) yon_config_get_by_key(key)
/**
* @brief Allocates or reallocates memory.
*
* Выделение или перевыделение памяти.
* @param pointer If NULL, uses malloc(), otherwise uses realloc().
*
* Если NULL, используется malloc(), иначе realloc().
* @param size Size of memory allocation.
*
* Размер выделенной памяти.
* @return Type: void*
* Newly allocated memory.
*
* Новая выделенная память.
*/
#define yon_remalloc(pointer, size) (!pointer) ? malloc(size) : realloc(pointer, size)
// dictionary functions
/**yon_dictionary_get_data(dictionary, type)
* [EN]
* Gets data from dictionary.
* [dictionary] is dictionary, from which data should be extracted;
* [type] is type of data, [dictionary] contains.
* [RU]
* Возвращает данные из словаря.
* [dictionary] - словарь из которого достаются данные.
* [type] - тип данных, хранящихся в словаре [dictionary].
*/
/**
* @brief Gets data from dictionary element.
*
* Получение значения элемента словаря.
* @param dictionary dictionary element.
*
* Элемент словаря.
* @param type type of value, dictionary element contains.
*
* Тип значения, содержащегося в элементе словаря.
* @return Type: void*
* Value, dictionary element contains.
*
* Значение, которое содержит элемент словаря.
*/
#define yon_dictionary_get_data(dictionary, type) ((type)dictionary->data)
/**yon_dictionary_add_or_create_if_exists_with_data(dict,key,data)
* [EN]
/**
* @brief Creates new or appends new element to dictionary.
*
* [RU]
* Добавляет элемент словаря в конец словаря [dict] c ключом [key] и данными [data].
* Если словарь не существует, создаёт его
*/
* Создаёт новый элемент словаря.
*
* ---
*
* @param dict dictionary*, where new element will be added to.
*
* Словарь в который будет добавлен новый элемент.
*
* ---
*
* @param key char*, new allocated element's key.
*
* Ключ нового элемента.
*
* ---
*
* @param data void*, data of any type.
*
* Данные любого типа
*
*/
#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);}
/**yon_dictionary_new():
* [EN]
* Creates and returns empty dictionary
* [RU]
* Создаёт и возвращает пустой словарь.
/**
* @brief Creates and returns empty dictionary.
*
* Создаёт и возвращает пустой словарь.
*
* ---
*
* @return A newly allocated dictionary.
*
* The caller of the method takes ownership of the returned data, and is responsible for freeing it.
*
* Новый выделенный dictionary*.
*
* Вызывающий метод берёт на себя ответственность за возвращаемые данные и отвечает за их освобождение.
*/
dictionary *yon_dictionary_new();
/**yon_dictionary_copy(dictionary *dict)
* [EN]
/**
* @brief copies dictionary.
*
* [RU]
* Создаёт и возвращает копию элемента словаря [dict]
*/
* Копирует словарь.
*
* ---
* @param dict dictionary to copy.
*
* словарь для копирования.
*
* ---
* @return A new allocated dictionary*
*
* The caller of the method takes ownership of the returned data, and is responsible for freeing it.
*
* Новый выделенный dictionary*
*
* Вызывающий метод берёт на себя ответственность за возвращаемые данные и отвечает за их освобождение.
*/
dictionary *yon_dictinoary_copy(dictionary *dict);
/**yon_dictionary_copy_deep(dictionary *dict)
* [EN]
/**
* @brief Creates a deep copy of the dictionary and returns the first element.
*
* [RU]
* Создаёт полную копию словаря [dict] и возвращает первый элемент
*/
* Создаёт полную копию словаря и возвращает первый элемент.
*
* ---
* @param dict first element of dictionary to copy.
*
* Первый элемент копируемого словаря.
*
* ---
* @return A new allocated dictionary*
*
* The caller of the method takes ownership of the returned data, and is responsible for freeing it.
*
* Новый выделенный dictionary*
*
* Вызывающий метод берёт на себя ответственность за возвращаемые данные и отвечает за их освобождение.
*/
dictionary *yon_dictionary_copy_deep(dictionary *dict);
/**int yon_dictionary_set_data(dictionary *dict, void *data)
* [EN]
/**
* @brief Set a data to dictionary element.
*
* [RU]
* Установить элементу словаря [dict] значение [data]
*/
* Установить элементу словаря значение.
*
* ---
* @param dict dictionary element to set data.
*
* Элемент словаря в который устанавливается новое значение.
* @param data new value for dictionaty
*
* Новое значение словаря.
*
* ---
* @return 0 if failed, 1 if succeeded.
*
* 0 при провале, 1 при успехе
*/
int yon_dictionary_set_data(dictionary *dict, void *data);
/**int yon_dictionary_set_key(dictionary *dict, char *key)
* [EN]
/**
* @brief Change dioctionary element's key.
*
* [RU]
* Изменяет ключ элемента словаря [dict] на [key]
*/
* Изменяет ключ элемента словаря.
*
* ---
* @param dict dictionary element for key change.
*
* Элемент словаря для изменения ключа.
* @param key
* @return 0 if failed, 1 if succeeded.
*
* 0 при провале, 1 при успехе
*/
int yon_dictionary_set_key(dictionary *dict, char *key);
/** int yon_dictionary_set(dictionary *dict, char *key, void *data)
* [EN]
/**
* @brief Sets dictionary element's key and data
*
* [RU]
* Устанавливает значение ключа элемента словаря [dict] на [key] и его данные на [data]
*/
* Устанавливает значение ключа элемента словаря и его данные
*
* ---
* @param dict dictionary element for change.
*
* Элемент словаря для изменения.
* @param key new key for dictionary element.
*
* Новый ключ для элемента словаря.
* @param data new value for dictionary element.
*
* Новое значение элемента словаря.
*
* ---
* @return 0 if failed, 1 if succeeded.
*
* 0 при провале, 1 при успехе.
*/
int yon_dictionary_set(dictionary *dict, char *key, void *data);
/**int yon_dictionary_empty(dictionary *dict)
* [EN]
/**
* @brief Cleans dictionary element.
*
* [RU]
* Очищает элемент словаря [dict] от данных
*/
* Очищает элемент словаря.
* @param dict target dictionary element.
*
* Очищаемый элемент словаря.
* @return 0 if failed, 1 if succeeded.
*
* 0 при провале, 1 при успехе.
*/
int yon_dictionary_empty(dictionary *dict);
/**yon_dictionary_switch_to_last(dictionary **dict)
* [EN]
/**
* @brief Switch dictionary to last element.
*
* [RU]
* Переключает словарь [dict] на последний элемент.
*/
* Переключает словарь на последний элемент.
*
* ---
* @param dict Dictionary to pointer.
*
* Указатель на словарь.
*/
void yon_dictionary_switch_to_last(dictionary **dict);
/**yon_dictionary_create_conneced(dictionary *targetdict)
* [EN]
/**
* @brief Appends dictionary with new element.
*
* [RU]
* Создаёт новый элемент словаря [targetdict]
*/
* Дополнить словарь новым элементом.
*
* ---
* @param targetdict dictionary to append.
*
* Словарь для дополнения.
* @return A new allocated dictionary*, element of dictionary.
*
* Новый выделенный dictionary*, элемент словаря.
*/
dictionary *yon_dictionary_append(dictionary *targetdict);
/**yon_dictionary_get_last(dictionary *dict)
* [EN]
/**
* @brief Returns the last element of the dictionary.
* Unlike yon_dictionary_switch_to_last()
* the dictionary remains at its previous element.
*
* [RU]
* Возвращает последний элемент словаря [dict].
* Возвращает последний элемент словаря.
* В отличае от yon_dictionary_switch_to_last()
* словарь [dict] остаётся на прежнем элементе.
*/
* словарь остаётся на прежнем элементе.
* @param dict The dictionary whose last element will be retrieved.
*
* Словарь, последний элемент которого будет получен.
* @return Type: dictionary*
*
* The last element of dictionary.
*/
dictionary *yon_dictionary_get_last(dictionary *dict);
/**yon_dictionary_switch_places(dictionary *dict, int aim)
* [EN]
/**
* @brief iterate dictionary element position.
*
* [RU]
* Меняет элемент словаря [dict] местами с другим элементом.
* если [aim]<0 элемент меняется местами с левым элементом;
* если [aim]>0 элемент меняется местами с правым элементом;
*/
* Меняет элемент словаря местами с другим элементом.
* @param dict The moving dictionary element.
*
* Перемещаемый элемент словаря.
* @param aim if <0, element switches with left element;
* if >0, element switches with right element;
*
* если <0 элемент меняется местами с левым элементом;
* если >0 элемент меняется местами с правым элементом;
* @return Type: dictionary*
*
* dictionary element, swapped with current.
*
* Элемент словаря с которым текущий поменялся местами.
*/
dictionary *yon_dictionary_swap(dictionary *dict, int aim);
/**yon_dictionary_make_first(dictionary *dict)
* [EN]
[[ deprecated ]];
/**
* @brief Sets the first element pointer of the dictionary
* to the current element. Do not use
*
* [RU]
* Устанавливает указатель первого элемента словаря [dict]
* на текущий элемент. Не использовать.
*/
* Устанавливает указатель первого элемента словаря
* на текущий элемент. Не использовать
* @param dict
*/
void yon_dictionary_make_first(dictionary *dict);
/**yon_dictionary_make_nth(dictionary *dict, int nth)
* [EN]
/**
* @brief Moves dictionary element to new position.
*
* [RU]
* Перемещает элемент словаря [dict] на позицию [nth].
*/
* Перемещает элемент словаря на новую позицию.
* @param dict dictionary element to move.
*
* Перемещаемый элемент словаря.
* @param nth new position for dictionary element.
*
* новоя позиция для элемента словаря.
*/
void yon_dictionary_make_nth(dictionary *dict, int nth);
/**yon_dictionary_create_with_data(char *key, void *data)
* [EN]
/**
* @brief Create new dictionary element with key and value.
*
* [RU]
* Создаёт новый словарь с ключом [key] и указателем на данные [data]
*/
* Создать новый элемент словаря с ключом и значением.
* @param key new dictionary element's key.
*
* Ключ нового элемента словаря.
* @param data new dictionary element's value.
*
* Значение нового элемента словаря.
* @return Type: dictionary*
*
* New dictionary element.
*
* Новый элемент словаря.
*/
dictionary *yon_dictionary_new_with_data(char *key, void *data);
/**yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data)
* [EN]
/**
* @brief Create and append dictionary element to dictionary with key and value.
*
* [RU]
* Создаёт новый элемент словаря, присоединяемый в конец словаря [dict]
* с ключом [key] и указателем на данные [data]
*/
* Создать новый элемент словаря, присоединяемый в конец словаря
* с ключом и значением.
* @param dict dictionary to append with new element.
*
* Словарь к которому добавляется элемент.
* @param key new dictionary element's key;
*
* Ключ нового элемента словаря.
* @param data New dictionary element's value.
*
* Значение нового элемента словаря.
* @return Type: dictionary*
*
* New allocated dictionary element.
*
* Новый выделенный элемент словаря.
*/
dictionary *yon_dictionary_append_with_data(dictionary *dict, char *key, void *data);
/**yon_dictionary_connect(dictionary *old, dictionary *toconnect)
* [EN]
/**
* @brief Connect dictionary element to the end of dictionary.
*
* [RU]
* Присоединяет словарь [toconnect] в конец словаря [old].
*/
dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect);
* Присоединение элемента словаря в конец словаря.
* @param target Dictionary to connect element.
*
* Словарь для присоединения элемента.
* @param append An appendable dictionary element.
*
* Присоединяемый элемент словаря.
* @return Type: int.
*
* 0 if failed, 1 if success.
*
* 0 при провале, 1 при успехе.
*/
int yon_dictionary_connect(dictionary *target, dictionary *append);
dictionary *yon_dictionary_merge(dictionary *dict1,dictionary *dict2);
/**
* @brief Merge second dictionary into first.
*
* Объединить два словаря в один.
* @param dict1 Dictionary which other dictionary connects to.
*
* Словарь с которым объединяется другой словарь.
* @param dict2 Dictionary to connect.
*
* Присоединяемый словарь.
* @return Type: int
*
* 0 if failed, 1 if success.
*
* 0 при провале, 1 при успехе.
*/
int yon_dictionary_merge(dictionary *dict1,dictionary *dict2);
/**yon_dictionary_get(dictionary **dict, char *key)
* [EN]
/**
* @brief Get dictionary element by key.
*
* [RU]
* Возвращает элемент словаря [dict] с ключом [key].
* Если такого элемента не было обнаружено, возвращается NULL
*/
* Возвращает элемент словаря с ключом.
* @param dict dictionary link.
*
* Ссылка на словарь.
* @param key key of requested dictionary element.
*
* Ключ запрашиваемого элемента словаря.
* @return Type: dictionary*
*
* Dictionary element with requested key or NULL.
*
* "Элемент словаря с разыскиваемым ключом или NULL."
*/
dictionary *yon_dictionary_get(dictionary **dict, char *key);
/**yon_dictionary_rip(dictionary *dict)
* [EN]
/**
* @brief Free dictionary element.
*
* [RU]
* Вырезает элемент из словаря и возвращает ближайший элемент.
*/
* Освобождает элемент словаря.
* @param dict Dictionary element to free.
* Освобождаемый элемент списка.
* @return Type: dictionary*
*
* Closest valid dictionary element.
*
* Ближайший валидный элемент словаря.
*/
dictionary *yon_dictionary_rip(dictionary *dict);
/**yon_dictionary_get_nth(dictionary *dict, int place)
* [EN]
/**
* @brief Get dictionary element of specific position.
*
* [RU]
* Возвращает [place]-й элемент словаря [dict]
*/
* Получить элемент списка на конкретной позиции.
* @param dict First dictionary element.
*
* Первый элемент словаря.
* @param place Desired dictionary element position.
*
* Желаемая позиция элемента словаря.
* @return Type: dictionary*
*
* Dictionary element on desired position or NULL.
*
* Элемент словаря на желаемой позиции или NULL.
*/
dictionary *yon_dictionary_get_nth(dictionary *dict, int place);
/** void *yon_dictionary_free_all(dictionary *dictionary,void *data_manipulation)
* [EN]
* Frees memory of dictionary [dictionary_to_free].
* [RU]
* Освобождает память элемента словаря [dictionary_to_free].
*/
/**
* @brief Frees memory of dictionary element.
*
* Освобождает память элемента словаря.
* @param dictionary_to_free
* @return Type: void*
* Value, freed dictionary element was containing.
*
* Значение, которое содержалось в освобождённом словаре.
*/
void *yon_dictionary_free(dictionary *dictionary_to_free);
/** void *yon_dictionary_free_all(dictionary *dictionary,void *data_manipulation)
* [EN]
* Frees whole [dictionary] and activates [data_manipulation] function if not NULL with [dictionary]->data argument for each dictionary.
* [RU]
* Освобождает память для всех элементов словаря [dictionary] и активирует функцию [data_manipulation], если она была передана, с аргументом [dictionary]->data на каждый элемент словаря.
*/
void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(void*));
/**
* @brief Frees whole dictionary.
*
* Освобождает память для всех элементов словаря.
* @param dictionary
* @param data_manipulation Function, activated, if not NULL, for every dictionary element in dictionary.
*
* Функция, активируемая, если не NULL, для каждого элемента словаря в словаре.
*/
void yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(void*));
[[ deprecated ]]
dictionary *yon_dictionary_sort(dictionary *dict);
// [[ deprecated ]]
// dictionary *yon_dictionary_sort(dictionary *dict);
[[__warnattr("Function is yon_dictionary_check_loops() is untested")]];
dictionary *yon_dictionary_check_loops(dictionary *target);
// char functions
/**
* @brief Macros for yon_char_divide_search function to get right part from string, freeing left part.
*
* Макросы для функции yon_char_divide_search для извлечения правой части из строки, освобождая левую часть.
* @param str string
* @param find string to find
* @param delete_divider
*/
#define yon_char_divide_search_self(str,find,delete_divider) {char *temp = str; str = yon_char_divide_search(str,find,delete_divider); free(temp);}
/**
* @brief check if string is empty.
*
* Проверить пустая ли строка.
* @param string
*/
#define yon_char_is_empty(string) !(string&&strcmp(string,""))
/**
* @brief Macros. If string is not empty, returns string, otherwise returns other string.
*
* @param string String to check. If string is empty, returns other string.
*
* @param opposite If main shring is empty, returns this string.
*
*/
#define yon_char_return_if_exist(string,opposite) string&&strcmp(string,"")?string:opposite
#define yon_char_remove_last_symbol(target,symbol) {if (target[strlen(target)-1]==symbol) target[strlen(target)-1]='\0';}
char *yon_char_conenct_if_true();

Loading…
Cancel
Save