2004-11-24 19:37:45 -08:00
|
|
|
#include "e.h"
|
|
|
|
|
|
|
|
/* local subsystem functions */
|
|
|
|
static void _e_path_free(E_Path *ep);
|
|
|
|
static void _e_path_cache_free(E_Path *ep);
|
2008-12-17 07:33:43 -08:00
|
|
|
static Eina_Bool _e_path_cache_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata);
|
2004-11-24 19:37:45 -08:00
|
|
|
|
|
|
|
/* externally accessible functions */
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI E_Path *
|
2004-11-24 19:37:45 -08:00
|
|
|
e_path_new(void)
|
|
|
|
{
|
|
|
|
E_Path *ep;
|
2008-12-17 07:33:43 -08:00
|
|
|
|
2005-01-21 22:58:34 -08:00
|
|
|
ep = E_OBJECT_ALLOC(E_Path, E_PATH_TYPE, _e_path_free);
|
2004-11-24 19:37:45 -08:00
|
|
|
return ep;
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2005-05-19 20:09:44 -07:00
|
|
|
e_path_default_path_append(E_Path *ep, const char *path)
|
2004-11-24 19:37:45 -08:00
|
|
|
{
|
|
|
|
E_OBJECT_CHECK(ep);
|
2005-01-21 22:58:34 -08:00
|
|
|
E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
|
2004-11-24 19:37:45 -08:00
|
|
|
if (!path) return;
|
|
|
|
if (path[0] == '~')
|
|
|
|
{
|
2005-05-19 20:09:44 -07:00
|
|
|
E_Path_Dir *epd;
|
2012-09-18 23:44:39 -07:00
|
|
|
char *new_path;
|
|
|
|
const char *home_dir;
|
|
|
|
int len1, len2;
|
|
|
|
|
|
|
|
home_dir = e_user_homedir_get();
|
|
|
|
len1 = strlen(home_dir);
|
|
|
|
len2 = strlen(path);
|
|
|
|
new_path = malloc(len1 + len2 + 1);
|
|
|
|
if (!new_path) return;
|
|
|
|
epd = malloc(sizeof(E_Path_Dir));
|
2005-05-19 20:09:44 -07:00
|
|
|
if (!epd)
|
2012-09-18 23:44:39 -07:00
|
|
|
{
|
|
|
|
free(new_path);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-19 20:09:44 -07:00
|
|
|
|
2012-09-18 23:44:39 -07:00
|
|
|
strcpy(new_path, home_dir);
|
|
|
|
strcat(new_path, path + 1);
|
2008-10-15 08:12:56 -07:00
|
|
|
epd->dir = eina_stringshare_add(new_path);
|
2012-09-18 23:44:39 -07:00
|
|
|
free(new_path);
|
|
|
|
ep->default_dir_list = eina_list_append(ep->default_dir_list, epd);
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
|
|
|
else
|
2005-05-19 20:09:44 -07:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
E_Path_Dir *epd;
|
|
|
|
epd = malloc(sizeof(E_Path_Dir));
|
|
|
|
if (!epd)
|
|
|
|
return;
|
|
|
|
epd->dir = eina_stringshare_add(path);
|
|
|
|
ep->default_dir_list = eina_list_append(ep->default_dir_list, epd);
|
2005-05-19 20:09:44 -07:00
|
|
|
}
|
2004-11-24 19:37:45 -08:00
|
|
|
_e_path_cache_free(ep);
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2008-10-22 04:49:33 -07:00
|
|
|
e_path_user_path_set(E_Path *ep, Eina_List **user_dir_list)
|
2005-05-19 20:09:44 -07:00
|
|
|
{
|
|
|
|
E_OBJECT_CHECK(ep);
|
|
|
|
E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
|
2012-06-20 23:19:43 -07:00
|
|
|
|
2005-05-19 20:09:44 -07:00
|
|
|
ep->user_dir_list = user_dir_list;
|
|
|
|
_e_path_cache_free(ep);
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2005-05-19 20:09:44 -07:00
|
|
|
e_path_user_path_append(E_Path *ep, const char *path)
|
2004-11-24 19:37:45 -08:00
|
|
|
{
|
|
|
|
E_OBJECT_CHECK(ep);
|
2005-01-21 22:58:34 -08:00
|
|
|
E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
|
2004-11-24 19:37:45 -08:00
|
|
|
if (!path) return;
|
|
|
|
if (path[0] == '~')
|
|
|
|
{
|
2005-05-19 20:09:44 -07:00
|
|
|
E_Path_Dir *epd;
|
2012-09-18 23:44:39 -07:00
|
|
|
char *new_path;
|
|
|
|
const char *home_dir;
|
|
|
|
int len1, len2;
|
|
|
|
|
|
|
|
home_dir = e_user_homedir_get();
|
|
|
|
len1 = strlen(home_dir);
|
|
|
|
len2 = strlen(path);
|
|
|
|
new_path = malloc(len1 + len2 + 1);
|
|
|
|
if (!new_path) return;
|
|
|
|
epd = malloc(sizeof(E_Path_Dir));
|
2005-05-19 20:09:44 -07:00
|
|
|
if (!epd)
|
2012-09-18 23:44:39 -07:00
|
|
|
{
|
|
|
|
free(new_path);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-19 20:09:44 -07:00
|
|
|
|
2012-09-18 23:44:39 -07:00
|
|
|
strcpy(new_path, home_dir);
|
|
|
|
strcat(new_path, path + 1);
|
2008-10-15 08:12:56 -07:00
|
|
|
epd->dir = eina_stringshare_add(new_path);
|
2012-09-18 23:44:39 -07:00
|
|
|
free(new_path);
|
|
|
|
*(ep->user_dir_list) = eina_list_append(*(ep->user_dir_list), epd);
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
|
|
|
else
|
2005-05-19 20:09:44 -07:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
E_Path_Dir *epd;
|
|
|
|
epd = malloc(sizeof(E_Path_Dir));
|
|
|
|
if (!epd)
|
|
|
|
return;
|
|
|
|
epd->dir = eina_stringshare_add(path);
|
|
|
|
*(ep->user_dir_list) = eina_list_append(*(ep->user_dir_list), epd);
|
2005-05-19 20:09:44 -07:00
|
|
|
}
|
2004-11-24 19:37:45 -08:00
|
|
|
_e_path_cache_free(ep);
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2005-05-19 20:09:44 -07:00
|
|
|
e_path_user_path_prepend(E_Path *ep, const char *path)
|
|
|
|
{
|
|
|
|
E_OBJECT_CHECK(ep);
|
|
|
|
E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
|
|
|
|
if (!path) return;
|
|
|
|
if (path[0] == '~')
|
|
|
|
{
|
|
|
|
E_Path_Dir *epd;
|
2012-09-18 23:44:39 -07:00
|
|
|
char *new_path;
|
|
|
|
const char *home_dir;
|
|
|
|
int len1, len2;
|
|
|
|
|
|
|
|
home_dir = e_user_homedir_get();
|
|
|
|
len1 = strlen(home_dir);
|
|
|
|
len2 = strlen(path);
|
|
|
|
new_path = malloc(len1 + len2 + 1);
|
|
|
|
if (!new_path) return;
|
|
|
|
epd = malloc(sizeof(E_Path_Dir));
|
2005-05-19 20:09:44 -07:00
|
|
|
if (!epd)
|
2012-09-18 23:44:39 -07:00
|
|
|
{
|
|
|
|
free(new_path);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-19 20:09:44 -07:00
|
|
|
|
2012-09-18 23:44:39 -07:00
|
|
|
strcpy(new_path, home_dir);
|
|
|
|
strcat(new_path, path + 1);
|
2008-10-15 08:12:56 -07:00
|
|
|
epd->dir = eina_stringshare_add(new_path);
|
2012-09-18 23:44:39 -07:00
|
|
|
free(new_path);
|
|
|
|
*(ep->user_dir_list) = eina_list_prepend(*(ep->user_dir_list), epd);
|
2005-05-19 20:09:44 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
E_Path_Dir *epd;
|
|
|
|
epd = malloc(sizeof(E_Path_Dir));
|
|
|
|
if (!epd)
|
|
|
|
return;
|
|
|
|
epd->dir = eina_stringshare_add(path);
|
|
|
|
*(ep->user_dir_list) = eina_list_prepend(*(ep->user_dir_list), epd);
|
2005-05-19 20:09:44 -07:00
|
|
|
}
|
|
|
|
_e_path_cache_free(ep);
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2005-05-19 20:09:44 -07:00
|
|
|
e_path_user_path_remove(E_Path *ep, const char *path)
|
2004-11-24 19:37:45 -08:00
|
|
|
{
|
2008-10-22 04:49:33 -07:00
|
|
|
Eina_List *l;
|
2009-08-21 08:08:49 -07:00
|
|
|
E_Path_Dir *epd;
|
2004-11-24 19:37:45 -08:00
|
|
|
|
|
|
|
E_OBJECT_CHECK(ep);
|
2005-01-21 22:58:34 -08:00
|
|
|
E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
|
2004-11-24 19:37:45 -08:00
|
|
|
if (!path) return;
|
|
|
|
if (path[0] == '~')
|
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
char *new_path;
|
|
|
|
const char *home_dir;
|
|
|
|
int len1, len2;
|
|
|
|
|
|
|
|
home_dir = e_user_homedir_get();
|
|
|
|
len1 = strlen(home_dir);
|
|
|
|
len2 = strlen(path);
|
|
|
|
new_path = malloc(len1 + len2 + 1);
|
|
|
|
if (!new_path) return;
|
|
|
|
strcpy(new_path, home_dir);
|
|
|
|
strcat(new_path, path + 1);
|
|
|
|
EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd)
|
|
|
|
{
|
|
|
|
if (epd->dir)
|
|
|
|
{
|
|
|
|
if (!strcmp(epd->dir, new_path))
|
|
|
|
{
|
|
|
|
*(ep->user_dir_list) = eina_list_remove_list(
|
|
|
|
*(ep->user_dir_list), l);
|
|
|
|
eina_stringshare_del(epd->dir);
|
|
|
|
free(epd);
|
|
|
|
free(new_path);
|
|
|
|
_e_path_cache_free(ep);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(new_path);
|
|
|
|
}
|
2004-11-24 19:37:45 -08:00
|
|
|
else
|
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd)
|
|
|
|
{
|
|
|
|
if (epd->dir)
|
|
|
|
{
|
|
|
|
if (!strcmp(epd->dir, path))
|
|
|
|
{
|
|
|
|
*(ep->user_dir_list) = eina_list_remove_list(
|
|
|
|
*(ep->user_dir_list), l);
|
|
|
|
eina_stringshare_del(epd->dir);
|
|
|
|
free(epd);
|
|
|
|
_e_path_cache_free(ep);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-09 04:55:18 -07:00
|
|
|
EAPI void
|
|
|
|
e_path_user_path_clear(E_Path *ep)
|
2009-08-21 08:08:49 -07:00
|
|
|
{
|
|
|
|
E_Path_Dir *epd;
|
|
|
|
EINA_LIST_FREE(*(ep->user_dir_list), epd)
|
2006-04-09 04:55:18 -07:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
eina_stringshare_del(epd->dir);
|
|
|
|
free(epd);
|
2006-04-09 04:55:18 -07:00
|
|
|
}
|
|
|
|
_e_path_cache_free(ep);
|
|
|
|
}
|
|
|
|
|
2012-12-21 01:03:30 -08:00
|
|
|
EAPI Eina_Stringshare *
|
2004-11-24 19:37:45 -08:00
|
|
|
e_path_find(E_Path *ep, const char *file)
|
|
|
|
{
|
2008-10-22 04:49:33 -07:00
|
|
|
Eina_List *l;
|
2008-12-17 07:33:43 -08:00
|
|
|
E_Path_Dir *epd;
|
2004-11-24 19:37:45 -08:00
|
|
|
char *str;
|
2012-12-21 02:01:01 -08:00
|
|
|
Eina_Stringshare *ret;
|
2005-05-25 01:08:44 -07:00
|
|
|
char buf[PATH_MAX] = "";
|
2008-12-17 07:33:43 -08:00
|
|
|
|
2004-11-24 19:37:45 -08:00
|
|
|
E_OBJECT_CHECK_RETURN(ep, NULL);
|
2005-01-21 22:58:34 -08:00
|
|
|
E_OBJECT_TYPE_CHECK_RETURN(ep, E_PATH_TYPE, NULL);
|
2005-05-19 20:09:44 -07:00
|
|
|
|
2004-11-24 19:37:45 -08:00
|
|
|
if (!file) return NULL;
|
2008-12-17 07:33:43 -08:00
|
|
|
str = eina_hash_find(ep->hash, file);
|
2012-12-21 02:01:01 -08:00
|
|
|
if (str) return eina_stringshare_ref(str);
|
2005-05-19 20:09:44 -07:00
|
|
|
/* Look in the default dir list */
|
2008-12-17 07:33:43 -08:00
|
|
|
EINA_LIST_FOREACH(ep->default_dir_list, l, epd)
|
2005-05-19 20:09:44 -07:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
if (epd->dir)
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", epd->dir, file);
|
|
|
|
if (ecore_file_exists(buf))
|
|
|
|
{
|
|
|
|
if (!ep->hash)
|
|
|
|
ep->hash = eina_hash_string_superfast_new(NULL);
|
|
|
|
if (eina_hash_population(ep->hash) >= 512)
|
|
|
|
_e_path_cache_free(ep);
|
2012-12-21 02:01:01 -08:00
|
|
|
ret = eina_stringshare_add(buf);
|
|
|
|
eina_hash_add(ep->hash, file, ret);
|
|
|
|
return eina_stringshare_ref(ret);
|
2012-09-18 23:44:39 -07:00
|
|
|
}
|
|
|
|
}
|
2005-05-19 20:09:44 -07:00
|
|
|
}
|
|
|
|
/* Look in the users dir list */
|
2009-08-21 08:08:49 -07:00
|
|
|
EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd)
|
2004-11-24 19:37:45 -08:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
if (epd->dir)
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", epd->dir, file);
|
|
|
|
if (ecore_file_exists(buf))
|
|
|
|
{
|
|
|
|
if (!ep->hash)
|
|
|
|
ep->hash = eina_hash_string_superfast_new(NULL);
|
|
|
|
if (eina_hash_population(ep->hash) >= 512)
|
|
|
|
_e_path_cache_free(ep);
|
2012-12-21 02:01:01 -08:00
|
|
|
ret = eina_stringshare_add(buf);
|
|
|
|
eina_hash_add(ep->hash, file, ret);
|
|
|
|
return eina_stringshare_ref(ret);
|
2012-09-18 23:44:39 -07:00
|
|
|
}
|
|
|
|
}
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
2005-05-25 01:08:44 -07:00
|
|
|
return NULL;
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2004-11-24 19:37:45 -08:00
|
|
|
e_path_evas_append(E_Path *ep, Evas *evas)
|
|
|
|
{
|
2008-10-22 04:49:33 -07:00
|
|
|
Eina_List *dir_list;
|
2009-08-21 08:08:49 -07:00
|
|
|
E_Path_Dir *epd;
|
2012-06-20 23:19:43 -07:00
|
|
|
|
2004-11-24 19:37:45 -08:00
|
|
|
E_OBJECT_CHECK(ep);
|
2005-01-21 22:58:34 -08:00
|
|
|
E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
|
2004-11-24 19:37:45 -08:00
|
|
|
if (!evas) return;
|
2005-05-19 20:09:44 -07:00
|
|
|
|
|
|
|
dir_list = e_path_dir_list_get(ep);
|
|
|
|
|
2009-08-21 08:08:49 -07:00
|
|
|
EINA_LIST_FREE(dir_list, epd)
|
2004-11-24 19:37:45 -08:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
if (epd->dir) evas_font_path_append(evas, epd->dir);
|
|
|
|
eina_stringshare_del(epd->dir);
|
|
|
|
free(epd);
|
2005-05-19 20:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-26 03:44:02 -08:00
|
|
|
/* combine default_list and and user_list in and easy to use list */
|
2008-10-22 04:49:33 -07:00
|
|
|
EAPI Eina_List *
|
2005-05-19 20:09:44 -07:00
|
|
|
e_path_dir_list_get(E_Path *ep)
|
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
Eina_List *dir_list;
|
|
|
|
Eina_List *l;
|
|
|
|
E_Path_Dir *new_epd;
|
|
|
|
E_Path_Dir *epd;
|
2005-05-19 20:09:44 -07:00
|
|
|
|
|
|
|
dir_list = NULL;
|
|
|
|
|
2005-06-06 03:37:15 -07:00
|
|
|
if (ep->user_dir_list)
|
2005-05-19 20:09:44 -07:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd)
|
|
|
|
{
|
|
|
|
new_epd = malloc(sizeof(E_Path_Dir));
|
|
|
|
new_epd->dir = eina_stringshare_add(epd->dir);
|
|
|
|
dir_list = eina_list_append(dir_list, new_epd);
|
|
|
|
}
|
2005-05-19 20:09:44 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 08:08:49 -07:00
|
|
|
EINA_LIST_FOREACH(ep->default_dir_list, l, epd)
|
2005-11-26 03:44:02 -08:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
new_epd = malloc(sizeof(E_Path_Dir));
|
|
|
|
new_epd->dir = eina_stringshare_add(epd->dir);
|
|
|
|
dir_list = eina_list_append(dir_list, new_epd);
|
2005-11-26 03:44:02 -08:00
|
|
|
}
|
|
|
|
|
2005-05-19 20:09:44 -07:00
|
|
|
return dir_list;
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2008-10-22 04:49:33 -07:00
|
|
|
e_path_dir_list_free(Eina_List *dir_list)
|
2005-05-19 20:09:44 -07:00
|
|
|
{
|
|
|
|
E_Path_Dir *epd;
|
|
|
|
|
2009-08-21 08:08:49 -07:00
|
|
|
EINA_LIST_FREE(dir_list, epd)
|
2005-05-19 20:09:44 -07:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
eina_stringshare_del(epd->dir);
|
|
|
|
free(epd);
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* local subsystem functions */
|
2012-06-20 23:19:43 -07:00
|
|
|
static void
|
2004-11-24 19:37:45 -08:00
|
|
|
_e_path_free(E_Path *ep)
|
|
|
|
{
|
2009-08-21 08:08:49 -07:00
|
|
|
E_Path_Dir *epd;
|
|
|
|
|
2004-11-24 19:37:45 -08:00
|
|
|
_e_path_cache_free(ep);
|
2009-08-21 08:08:49 -07:00
|
|
|
EINA_LIST_FREE(ep->default_dir_list, epd)
|
2004-11-24 19:37:45 -08:00
|
|
|
{
|
2012-09-18 23:44:39 -07:00
|
|
|
eina_stringshare_del(epd->dir);
|
|
|
|
free(epd);
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
|
|
|
free(ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_path_cache_free(E_Path *ep)
|
|
|
|
{
|
|
|
|
if (!ep->hash) return;
|
2008-12-17 07:33:43 -08:00
|
|
|
eina_hash_foreach(ep->hash, _e_path_cache_free_cb, NULL);
|
|
|
|
eina_hash_free(ep->hash);
|
2005-05-19 20:09:44 -07:00
|
|
|
ep->hash = NULL;
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
|
|
|
|
2008-12-17 07:33:43 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_e_path_cache_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__)
|
2004-11-24 19:37:45 -08:00
|
|
|
{
|
2008-10-15 08:12:56 -07:00
|
|
|
eina_stringshare_del(data);
|
2005-05-25 01:08:44 -07:00
|
|
|
return 1;
|
2004-11-24 19:37:45 -08:00
|
|
|
}
|
2012-09-18 23:44:39 -07:00
|
|
|
|