master #5

Merged
asmeron merged 2 commits from YanTheKaller/libublsettings:master into master 2 years ago

@ -380,7 +380,7 @@ char *yon_cut(char *source, int size, int startpos)
char *yon_char_divide(char *source, int dividepos)
{
if (source){
if (source&&strlen(source)>=dividepos){
char *cut = malloc(dividepos + 1);
memset(cut, 0, dividepos + 1);
memcpy(cut, source, dividepos);
@ -484,9 +484,9 @@ char *yon_char_replace(char *source, char *find, char*replace){
}
char **yon_char_parse(char *parameters, int *size, char *divider){
*size=0;
if (parameters){
char **string=NULL;
*size=0;
char *paramline=yon_char_new(parameters);
char *param = strstr(paramline,divider);
for (;param;param=strstr(paramline,divider)){
@ -747,121 +747,6 @@ float yon_size_convert_automatic(int bytes, int *size){
return byte_float;
}
// apps *yon_apps_scan_and_parse_desktops(int *sizef)
// {
// int size = 0;
// struct apps *applist;
// {
// DIR *directory = opendir(DesktopPath);
// struct dirent *de;
// while ((de = readdir(directory)))
// {
// FILE *file;
// char *path = yon_char_append(DesktopPath, de->d_name);
// file = fopen(path, "r");
// if (strlen(de->d_name) > 9)
// {
// char *extension = strstr(path, ".");
// if (extension != NULL)
// {
// if (strcmp(extension, ".desktop") == 0)
// {
// apps tempapp;
// GKeyFile *gfile = g_key_file_new();
// GError *err = NULL;
// g_key_file_load_from_file(gfile, path, G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
// char *Type = g_key_file_get_string(gfile, "Desktop Entry", "Type", &err);
// if (err)
// {
// printf("%s\n", err->message);
// }
// if (strcmp(Type, "Application") == 0)
// tempapp.Type = 1;
// else if (strcmp(Type, "pyApplication") == 0)
// tempapp.Type = 2;
// else
// continue;
// tempapp.Name = g_key_file_get_locale_string(gfile, "Desktop Entry", "Name", setlocale(LC_ALL, NULL), NULL);
// if (tempapp.Name == NULL)
// continue;
// tempapp.Categories = g_key_file_get_string(gfile, "Desktop Entry", "Categories", NULL);
// if (tempapp.Categories == NULL)
// continue;
// tempapp.Exec = g_key_file_get_string(gfile, "Desktop Entry", "Exec", NULL);
// if (tempapp.Exec == NULL)
// continue;
// tempapp.Icon = g_key_file_get_string(gfile, "Desktop Entry", "Icon", NULL);
// if (tempapp.Icon == NULL)
// continue;
// tempapp.Pluggable = g_key_file_get_boolean(gfile, "Desktop Entry", "Pluggable", NULL);
// if (!tempapp.Pluggable)
// tempapp.Pluggable = g_key_file_get_boolean(gfile, "Desktop Entry", "X-XfcePluggable", NULL);
// if (tempapp.Pluggable)
// tempapp.DualPluggable = g_key_file_get_boolean(gfile, "Desktop Entry", "X-UBLPluggable", NULL);
// if (g_key_file_get_boolean(gfile, "Desktop Entry", "X-UBL-SettingsManager-Hidden", NULL) == 0)
// if (size == 0)
// {
// applist = (apps *)malloc(size + 1 * sizeof(apps));
// applist[0].Name = yon_char_new(tempapp.Name);
// applist[0].Categories = yon_char_new(tempapp.Categories);
// applist[0].Exec = yon_char_new(tempapp.Exec);
// applist[0].Icon = yon_char_new(tempapp.Icon);
// applist[0].Type = tempapp.Type;
// applist[0].Pluggable = tempapp.Pluggable;
// applist[0].DualPluggable = tempapp.DualPluggable;
// size++;
// }
// else
// {
// applist = (apps *)realloc(applist, (size + 1) * sizeof(apps));
// applist[size].Name = yon_char_new(tempapp.Name);
// applist[size].Categories = yon_char_new(tempapp.Categories);
// applist[size].Exec = yon_char_new(tempapp.Exec);
// applist[size].Icon = yon_char_new(tempapp.Icon);
// applist[size].Pluggable = tempapp.Pluggable;
// applist[size].DualPluggable = tempapp.DualPluggable;
// applist[size].Type = tempapp.Type;
// size++;
// }
// }
// }
// }
// }
// }
// *sizef = size;
// return applist;
// };
// void yon_apps_sort(apps *applist, int size)
// {
// apps tmp;
// if (size > 2)
// {
// for (int i = 1; i < size; i++)
// {
// for (int j = 1; j < size; j++)
// {
// if (strcmp(applist[j].Name, applist[j - 1].Name) < 0)
// {
// tmp = applist[j];
// applist[j] = applist[j - 1];
// applist[j - 1] = tmp;
// };
// }
// };
// }
// };
// apps *yon_apps_get_by_name(apps *applist, char *name, int size)
// {
// for (int i = 0; i < size; i++)
// {
// if (strcmp(applist[i].Name, name) == 0)
// return &applist[i];
// }
// return NULL;
// };
config_str yon_dir_get_contents(char *dir_path, int *size){
config_str dir = NULL;
*size=0;
@ -877,6 +762,41 @@ config_str yon_dir_get_contents(char *dir_path, int *size){
return dir;
}
config_str yon_dir_get_by_mask(char *path, char *mask, int *size){
(*size)=0;
if (yon_char_find_count(mask,"*")<=1){
char *lpart;
char *rpart=yon_char_new(mask);
lpart = yon_char_divide_search(rpart,"*",-1);
config_str files = NULL;
int found_size;
config_str found_files = yon_dir_get_contents(path,&found_size);
if(found_size>0){
int found = 1;
int rfound = 0;
for (int i=0;i<found_size;i++){
int c;
for (c=0;c<strlen(found_files[i]);c++){
if (found_files[i][c]!=lpart[c]){
break;
}
if (c==strlen(lpart)) break;
}
if (found){
for (int l=c;l<strlen(found_files[i]);l++){
if (found_files[i][l]==rpart[l]) rfound++;
else rfound=0;
}
if (rfound==strlen(rpart)) {
yon_char_parsed_add_or_create_if_exists(files,size,found_files[i]);
}
}
}
free(found_files);
}
}
}
//config functions
typedef struct yon_config_parameter
@ -968,6 +888,7 @@ int yon_config_remove_by_key(char *key){
dictionary *dict = yon_dictionary_get((dictionary**)&__yon__config__strings,key);
if (dict){
((yon_config_parameter*)dict)->flag1=-1;
dict->data="";
return 1;
}else return 0;
}
@ -1029,13 +950,14 @@ char *yon_config_get_section_for_key(char *key){
void *yon_config_get_all_by_key(char *key, int *size){
check_config{
(*size)=0;
config_str ret_data=NULL;
dictionary *dict = NULL;
for_dictionaries(dict, (dictionary*)__yon__config__strings){
if (strstr(dict->key,key)&&((yon_config_parameter*)dict)->flag1!=-1) {
char *ret_string = yon_char_unite(dict->key,"=",(char*)dict->data,NULL);
if (ret_data) ret_data = yon_char_parsed_append(ret_data,size,ret_string);
else ret_data = yon_char_parsed_new(size,ret_string,NULL);
else ret_data = yon_char_parsed_new(size,ret_string,NULL);
}
}
return ret_data;
@ -1300,3 +1222,97 @@ void yon_launch(char *command)
system(command);
}
// // Trash collector functions
// typedef struct yon_trash_collector_group{
// char *group_key;
// void *data;
// struct yon_trash_collector_group *next;
// struct yon_trash_collector_group *prev;
// struct yon_trash_collector_group *first;
// } yon_trash_collector_group;
// typedef struct yon_trash_collector_element{
// char *key;
// void *data;
// struct yon_trash_collector_element *next;
// struct yon_trash_collector_element *prev;
// struct yon_trash_collector_element *first;
// } yon_trash_collector_element;
// yon_trash_collector_group *__yon_trash_collector__ = NULL;
// #define check_trash if (__yon_trash_collector__)
// #define trash_group(group_key) yon_dictionary_get(&__yon_trash_collector__,group_key)
// #define for_trash_group for(yon_trash_collector_group *gr = __yon_trash_collector__->first;gr;gr=gr->next)
// #define for_trash_element(group) for (yon_trash_collector_element *gr = group->first; gr;gr=gr->next)
// yon_trash_collector_element *yon_trash_collector_element_get(void *pointer,yon_trash_collector_group *group){
// for_trash_element(group){
// if (gr->data==pointer)
// return gr;
// }
// }
// int yon_trash_collector_group_has(char *group_key, void *pointer){
// yon_trash_collector_group *group = trash_group(group_key);
// yon_trash_collector_element *element = yon_trash_collector_element_get(pointer,&group);
// if (element)
// return 1;
// }
// yon_trash_collector_group *yon_trash_collector_shell_new(char *group_key){
// yon_trash_collector_group *trash = malloc(sizeof(yon_trash_collector_group));
// trash->group_key=yon_char_new(group_key);
// trash->first=NULL;
// trash->next=NULL;
// trash->prev=NULL;
// return trash;
// }
// yon_trash_collector_group *yon_trash_collector_new(int size, char *group_key){
// yon_trash_collector_group *trash = yon_trash_collector_shell_new(group_key);
// trash->data=malloc(size);
// return trash;
// }
// int yon_trash_collector_append(void *pointer, char group_key){
// if (yon_trash_collector_group_has(group_key,pointer)){
// }
// check_trash{
// yon_trash_collector_group *trash = yon_trash_collector_shell_new(group_key);
// trash->data=pointer;
// yon_dictionary_connect((dictionary*)__yon_trash_collector__,(dictionary*)trash);
// return 1;
// } else {
// __yon_trash_collector__ = yon_trash_collector_shell_new(group_key);
// __yon_trash_collector__->data=pointer;
// return 1;
// }
// }
// int yon_trash_collector_free(char *group_key){
// }
// void *yon_malloc(int size, char *group_key){
// void * data = yon_trash_collector_new(size,group_key)->data;
// return data;
// }
// void *yon_malloc0(int size, char *group_key){
// void * data = yon_trash_collector_new(size,group_key)->data;
// memset(data,0,size);
// return data;
// }
// void *yon_realloc(void *pointer, int size, char *group_key){
// void * data = yon_trash_collector_new(size,group_key)->data;
// memset(data,0,size);
// return data;
// }

@ -751,4 +751,12 @@ int yon_launch_app_with_arguments(char *name, char *args);
* Выполнить команду [command]
*/
void yon_launch(char *command);
// // Trash collector functions
// int yon_trash_collector_append(void *pointer, char group_key);
// int yon_trash_collector_free(char *group_key);
// void *yon_malloc(int size, char *group_key);
#endif
Loading…
Cancel
Save