|
|
|
|
@ -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&÷pos){
|
|
|
|
|
@ -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)
|
|
|
|
|
|