Merge pull request 'master' (#23) from YanTheKaller/libublsettings:master into master

Reviewed-on: #23
master v1.19
Dmitry Razumov 2 years ago
commit ebfb910a0a

@ -279,7 +279,10 @@ dictionary *yon_dictionary_get(dictionary **dict, char *key)
dictionary *yon_dictionary_rip(dictionary *dict)
{
if (!dict->next&&!dict->prev) return NULL;
if (!dict->next&&!dict->prev) {
free(dict);
return NULL;
}
else if (!dict->next)
{
dictionary *prev = dict->prev;
@ -329,6 +332,71 @@ dictionary *yon_dictionary_get_nth(dictionary *dict, int place)
} else return NULL;
}
dictionary *yon_dictionary_sort(dictionary *dict){
dictionary *first = dict->first;
dictionary *prev = first;
dictionary *current = first->next;
while (current){
if (current!=prev&&strcmp(current->key,prev->key)<0){
if (current->next)
current->next->prev=prev;
prev->next=current->next;
current->next=prev;
current->prev=prev->prev;
if (prev->prev)
prev->prev->next=current;
prev->prev=current;
if (prev==prev->first){
yon_dictionary_make_first(current);
}
dictionary *temp = prev;
prev = current;
current=temp;
}
prev=prev->next;
current = current->next;
}
return first;
}
int _yon_dictionary_check_loops(dictionary *_REG_DICT,dictionary *link){
if (_REG_DICT){
dictionary *dict;
for_dictionaries(dict,_REG_DICT){
if (dict->data==link){
return 1;
}
}
}
return 0;
}
dictionary *yon_dictionary_check_loops(dictionary *target){
dictionary *found = NULL;
dictionary *dict;
for_dictionaries(dict,target){
if (_yon_dictionary_check_loops(found,dict)){
return dict;
} else {
yon_dictionary_add_or_create_if_exists_with_data(found,NULL,dict);
}
}
yon_dictionary_free_all(found,NULL);
found = NULL;
dict=yon_dictionary_get_last(target);
for(;dict;dict=dict->prev){
if (_yon_dictionary_check_loops(found,dict)){
return dict;
} else {
yon_dictionary_add_or_create_if_exists_with_data(found,NULL,dict);
}
}
yon_dictionary_free_all(found,NULL);
return NULL;
}
// char functions
int yon_char_find_last(char *source, char find){
@ -428,6 +496,18 @@ int yon_char_find_count(char *source, char *find){
return i;
}
int yon_char_count(char *source, char *find){
char *working_string=yon_char_new(source);
int i=0;
int size=0;
char *cur=strstr(source,find);
for (i=0;cur;cur = strstr(cur,find)){
cur++;
i++;
}
return i;
}
char *yon_char_divide_search(char *source, char *dividepos, int delete_divider)
{
if (source&&dividepos){
@ -843,7 +923,7 @@ config_str yon_dir_get_contents(char *dir_path, int *size){
config_str yon_dir_get_by_mask(char *path, char *mask, int *size){
(*size)=0;
if (yon_char_find_count(mask,"*")<=1){
if (yon_char_count(mask,"*")<=1){
char *lpart;
char *rpart=yon_char_new(mask);
lpart = yon_char_divide_search(rpart,"*",-1);
@ -2003,6 +2083,70 @@ int yon_file_create_full_path(char *path, int rules){
}
}
config_str yon_file_list_dirs (char *path, int *size){
(*size)=0;
if (!yon_char_is_empty(path)&&!access(path,F_OK)){
config_str final = NULL;
DIR *current_dir = opendir(path);
struct dirent* cur_dir;
while ((cur_dir=readdir(current_dir))){
if (cur_dir->d_type==DT_DIR &&(strcmp(cur_dir->d_name, ".") && strcmp(cur_dir->d_name, ".."))){
yon_char_parsed_add_or_create_if_exists(final,size,cur_dir->d_name);
}
}
closedir(current_dir);
return final;
}
return NULL;
}
config_str yon_file_ls(char *path, int *size){
(*size)=0;
if (!yon_char_is_empty(path)&&!access(path,F_OK)){
config_str final = NULL;
DIR *current_dir = opendir(path);
struct dirent* cur_dir;
while ((cur_dir=readdir(current_dir))){
if ((strcmp(cur_dir->d_name, ".") && strcmp(cur_dir->d_name, ".."))){
yon_char_parsed_add_or_create_if_exists(final,size,cur_dir->d_name);
}
}
closedir(current_dir);
return final;
}
return NULL;
}
int yon_file_is_directory(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
return S_ISDIR(path_stat.st_mode);
}
void yon_dir_remove(const char *path){
DIR *d = opendir(path);
struct dirent *dir;
if (d) {
while ((dir = readdir(d)) != NULL) {
if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
continue;
}
char full_path[1024];
snprintf(full_path, sizeof(full_path), "%s/%s", path, dir->d_name);
if (dir->d_type == DT_DIR) {
yon_dir_remove(full_path);
} else {
unlink(full_path);
}
}
closedir(d);
rmdir(path);
}
}
// terminal-using functions
int yon_launch_app_with_arguments(char *name, char *args)

@ -290,6 +290,11 @@ void *yon_dictionary_free(dictionary *dictionary_to_free);
*/
void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(void*));
[[ deprecated ]]
dictionary *yon_dictionary_sort(dictionary *dict);
dictionary *yon_dictionary_check_loops(dictionary *target);
// char functions
#define yon_char_divide_search_self(str,find,delete_divider) {char *temp = str; str = yon_char_divide_search(str,find,delete_divider); free(temp);}
@ -300,6 +305,8 @@ void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(vo
#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();
int yon_char_find_last(char *source, char find);
/**[EN]
@ -439,8 +446,11 @@ int yon_char_parsed_check_repeats(char **parameters, int size, int *first_overla
* [RU]
* Считает количество символов [find] в строке [source]
*/
[[ deprecated("Use yon_char_count instead") ]]
int yon_char_find_count(char *source, char *find);
int yon_char_count(char *source, char *find);
/**yon_char_parsed_includes_char_parsed (config_str source, config_str to_check, int source_size, int check_size)
* [EN]
*
@ -594,6 +604,20 @@ int yon_file_create(char *path, char *name, int rules);
*/
int yon_file_create_full_path(char *path, int rules);
/**yon_file_ls (char *path, int *size)
* [EN]
*
* [RU]
* Возвращает массив названий директорий размера [size], находящихся внутри директории [path].
*/
config_str yon_file_list_dirs (char *path, int *size);
config_str yon_file_ls(char *path, int *size);
int yon_file_is_directory(const char *path);
void yon_dir_remove(const char *path);
/** yon_dir_get_contents(char *dir_path, int *size)
* [EN]
*

Loading…
Cancel
Save