Memory management

SVN revision: 29114
This commit is contained in:
Sebastian Dransfeld 2007-03-25 13:10:09 +00:00
parent 2f086b0e73
commit fe0fbd4189
3 changed files with 21 additions and 18 deletions

View File

@ -6,23 +6,20 @@ int
ef_cb_utils(void)
{
Efreet_Desktop *desktop;
char *tmp;
char *tmp1;
const char *tmp2;
printf("\n");
tmp = efreet_util_path_in_default("applications",
tmp1 = efreet_util_path_in_default("applications",
"/usr/share/applications/test.desktop");
if (tmp)
if (tmp1)
{
printf("%s\n", tmp);
free(tmp);
printf("%s\n", tmp1);
free(tmp1);
}
tmp = efreet_util_path_to_file_id("/usr/share/applications/this/tmp/test.desktop");
if (tmp)
{
printf("%s\n", tmp);
free(tmp);
}
tmp2 = efreet_util_path_to_file_id("/usr/share/applications/this/tmp/test.desktop");
if (tmp2) printf("%s\n", tmp2);
desktop = efreet_util_desktop_file_id_find("kde-kresources.desktop");
printf("kde-kresources.desktop: %p\n", desktop);

View File

@ -36,7 +36,10 @@ efreet_util_init(void)
desktop_by_file_id = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_set_free_key(desktop_by_file_id, ECORE_FREE_CB(ecore_string_release));
desktop_by_exec = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_set_free_key(desktop_by_exec, ECORE_FREE_CB(ecore_string_release));
file_id_by_desktop_path = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_set_free_key(file_id_by_desktop_path, ECORE_FREE_CB(ecore_string_release));
ecore_hash_set_free_value(file_id_by_desktop_path, ECORE_FREE_CB(ecore_string_release));
fill = NEW(Efreet_Cache_Fill, 1);
fill->dirs = ecore_list_new();
@ -105,12 +108,13 @@ efreet_util_path_in_default(const char *section, const char *path)
return ret;
}
char *
const char *
efreet_util_path_to_file_id(const char *path)
{
size_t len;
char *file_id, *p;
char *tmp, *p;
char *base;
const char *file_id = NULL;
if (!path) return NULL;
file_id = ecore_hash_get(file_id_by_desktop_path, path);
@ -131,16 +135,18 @@ efreet_util_path_to_file_id(const char *path)
return NULL;
}
file_id = strdup(path + len + 1);
p = file_id;
tmp = strdup(path + len + 1);
p = tmp;
while (*p)
{
if (*p == '/') *p = '-';
p++;
}
free(base);
if (file_id) ecore_hash_set(file_id_by_desktop_path, (void *)ecore_string_instance(path),
(void *)ecore_string_instance(file_id));
file_id = ecore_string_instance(tmp);
free(tmp);
ecore_hash_set(file_id_by_desktop_path, (void *)ecore_string_instance(path),
(void *)file_id);
return file_id;
}

View File

@ -3,7 +3,7 @@
#define EFREET_UTILS_H
char *efreet_util_path_in_default(const char *section, const char *path);
char *efreet_util_path_to_file_id(const char *path);
const char *efreet_util_path_to_file_id(const char *path);
Efreet_Desktop *efreet_util_desktop_file_id_find(const char *file_id);
Efreet_Desktop *efreet_util_desktop_exec_find(const char *exec);