major cleanup of path creation to $DATADIR and $HOME/.e/e

This cleanup replaces snprintf() usage with specific calls, they have
the benefit of being cleaner (so easier to grep), typing less and also
marginal speed up compared to the other (specially concat_static),
although those are rarely used in critical paths.

I'm testing it for some time and seems to not break anything, but let
me know of any problem. If you can review the patch and try to spot
incorrect names, please do.




SVN revision: 40014
devs/princeamd/enlightenment-0.17-elive
Gustavo Sverzut Barbieri 14 years ago
parent 64f80081aa
commit e0040cefb9
  1. 2
      src/bin/e_about.c
  2. 117
      src/bin/e_config.c
  3. 12
      src/bin/e_fm.c
  4. 14
      src/bin/e_fm_custom.c
  5. 33
      src/bin/e_fm_hal.c
  6. 55
      src/bin/e_fm_mime.c
  7. 19
      src/bin/e_int_border_menu.c
  8. 6
      src/bin/e_int_menus.c
  9. 4
      src/bin/e_intl.c
  10. 49
      src/bin/e_main.c
  11. 76
      src/bin/e_prefix.c
  12. 12
      src/bin/e_prefix.h
  13. 16
      src/bin/e_startup.c
  14. 5
      src/bin/e_thumb_main.c
  15. 151
      src/bin/e_user.c
  16. 21
      src/bin/e_user.h
  17. 31
      src/bin/e_widget_fsel.c
  18. 12
      src/modules/conf_applications/e_int_config_apps.c
  19. 48
      src/modules/conf_desklock/e_int_config_desklock.c
  20. 16
      src/modules/conf_profiles/e_int_config_profiles.c
  21. 48
      src/modules/conf_startup/e_int_config_startup.c
  22. 50
      src/modules/conf_theme/e_int_config_theme.c
  23. 5
      src/modules/conf_theme/e_int_config_theme_import.c
  24. 2
      src/modules/conf_theme/e_int_config_theme_web.c
  25. 33
      src/modules/conf_wallpaper/e_int_config_wallpaper.c
  26. 9
      src/modules/conf_wallpaper/e_int_config_wallpaper_gradient.c
  27. 22
      src/modules/conf_wallpaper/e_int_config_wallpaper_import.c
  28. 2
      src/modules/conf_wallpaper/e_int_config_wallpaper_web.c
  29. 4
      src/modules/conf_wallpaper2/e_int_config_wallpaper.c
  30. 27
      src/modules/gadman/e_mod_config.c
  31. 56
      src/modules/ibar/e_mod_config.c
  32. 10
      src/modules/ibar/e_mod_main.c
  33. 5
      src/modules/illume/e_kbd.c
  34. 42
      src/modules/illume/e_kbd_buf.c
  35. 70
      src/modules/illume/e_kbd_int.c
  36. 30
      src/modules/illume/e_mod_win.c
  37. 6
      src/modules/wizard/page_010.c
  38. 16
      src/modules/wizard/page_020.c
  39. 8
      src/modules/wizard/page_080.c
  40. 22
      src/modules/wizard/page_200.c

@ -43,7 +43,7 @@ e_about_new(E_Container *con)
FILE *f;
char buf[4096], buf2[4096], *tbuf;
snprintf(buf, sizeof(buf), "%s/AUTHORS", e_prefix_data_get());
e_prefix_data_concat_static(buf, "AUTHORS");
f = fopen(buf, "r");
if (f)
{

@ -60,18 +60,14 @@ e_config_init(void)
{
Eet_File *ef;
char buf[4096];
const char *homedir;
/* try user profile config */
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/config/profile.cfg",
homedir);
e_user_dir_concat_static(buf, "config/profile.cfg");
ef = eet_open(buf, EET_FILE_MODE_READ);
if (!ef)
{
/* use system if no user profile config */
snprintf(buf, sizeof(buf), "%s/data/config/profile.cfg",
e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/config/profile.cfg");
ef = eet_open(buf, EET_FILE_MODE_READ);
}
if (ef)
@ -99,8 +95,7 @@ e_config_init(void)
char *link = NULL;
/* check symlink - if default is a symlink to another dir */
snprintf(buf, sizeof(buf), "%s/data/config/default",
e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/config/default");
link = ecore_file_readlink(buf);
/* if so use just the filename as the priofle - must be a local link */
if (link)
@ -1079,14 +1074,10 @@ EAPI char *
e_config_profile_dir_get(const char *prof)
{
char buf[PATH_MAX];
const char *homedir;
const char *dir;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof);
e_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
if (ecore_file_is_dir(buf)) return strdup(buf);
dir = e_prefix_data_get();
snprintf(buf, sizeof(buf), "%s/data/config/%s", dir, prof);
e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", prof);
if (ecore_file_is_dir(buf)) return strdup(buf);
return NULL;
}
@ -1101,19 +1092,20 @@ e_config_profile_list(void)
{
Eina_List *files;
char buf[PATH_MAX], *p;
const char *homedir;
const char *dir;
Eina_List *flist = NULL;
int len;
size_t len;
homedir = e_user_homedir_get();
len = snprintf(buf, sizeof(buf), "%s/.e/e/config/", homedir);
if (len >= (int)sizeof(buf))
len = e_user_dir_concat_static(buf, "config");
if (len + 1 >= (int)sizeof(buf))
return NULL;
files = ecore_file_ls(buf);
buf[len] = '/';
len++;
p = buf + len;
len = sizeof(buf) - len;
files = ecore_file_ls(buf);
if (files)
{
char *file;
@ -1132,14 +1124,17 @@ e_config_profile_list(void)
free(file);
}
}
dir = e_prefix_data_get();
len = snprintf(buf, sizeof(buf), "%s/data/config/", dir);
if (len >= (int)sizeof(buf))
len = e_prefix_data_concat_static(buf, "data/config");
if (len >= sizeof(buf))
return NULL;
files = ecore_file_ls(buf);
buf[len] = '/';
len++;
p = buf + len;
len = sizeof(buf) - len;
files = ecore_file_ls(buf);
if (files)
{
char *file;
@ -1172,37 +1167,18 @@ EAPI void
e_config_profile_add(const char *prof)
{
char buf[4096];
const char *homedir;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof);
if (e_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof) >= sizeof(buf))
return;
ecore_file_mkdir(buf);
}
EAPI void
e_config_profile_del(const char *prof)
{
Eina_List *files;
char buf[4096];
const char *homedir;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof);
files = ecore_file_ls(buf);
if (files)
{
char *file;
EINA_LIST_FREE(files, file)
{
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s/%s",
homedir, prof, file);
ecore_file_unlink(buf);
free(file);
}
}
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof);
ecore_file_rmdir(buf);
if (e_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof) >= sizeof(buf))
return;
ecore_file_recursive_rm(buf);
}
EAPI Eina_List *
@ -1243,12 +1219,10 @@ e_config_domain_load(const char *domain, E_Config_DD *edd)
{
Eet_File *ef;
char buf[4096];
const char *homedir;
void *data = NULL;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s/%s.cfg",
homedir, _e_config_profile, domain);
e_user_dir_snprintf(buf, sizeof(buf), "config/%s/%s.cfg",
_e_config_profile, domain);
ef = eet_open(buf, EET_FILE_MODE_READ);
if (ef)
{
@ -1266,8 +1240,8 @@ e_config_domain_system_load(const char *domain, E_Config_DD *edd)
char buf[4096];
void *data = NULL;
snprintf(buf, sizeof(buf), "%s/data/config/%s/%s.cfg",
e_prefix_data_get(), _e_config_profile, domain);
e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/%s.cfg",
_e_config_profile, domain);
ef = eet_open(buf, EET_FILE_MODE_READ);
if (ef)
{
@ -1284,13 +1258,11 @@ e_config_profile_save(void)
{
Eet_File *ef;
char buf[4096], buf2[4096];
const char *homedir;
int ok = 0;
/* FIXME: check for other sessions fo E running */
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/config/profile.cfg", homedir);
snprintf(buf2, sizeof(buf2), "%s.tmp", buf);
e_user_dir_concat_static(buf, "config/profile.cfg");
e_user_dir_concat_static(buf2, "config/profile.cfg.tmp");
ef = eet_open(buf2, EET_FILE_MODE_WRITE);
if (ef)
@ -1317,18 +1289,31 @@ e_config_domain_save(const char *domain, E_Config_DD *edd, const void *data)
{
Eet_File *ef;
char buf[4096], buf2[4096];
const char *homedir;
int ok = 0, ret;
size_t len, len2;
if (_e_config_save_block) return 0;
/* FIXME: check for other sessions fo E running */
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s",
homedir, _e_config_profile);
len = e_user_dir_snprintf(buf, sizeof(buf), "config/%s", _e_config_profile);
if (len + 1 >= sizeof(buf)) return 0;
ecore_file_mkdir(buf);
snprintf(buf, sizeof(buf), "%s/.e/e/config/%s/%s.cfg",
homedir, _e_config_profile, domain);
snprintf(buf2, sizeof(buf2), "%s.tmp", buf);
buf[len] = '/';
len++;
len2 = ecore_strlcpy(buf + len, domain, sizeof(buf) - len);
if (len2 + sizeof(".cfg") >= sizeof(buf) - len) return 0;
len += len2;
memcpy(buf + len, ".cfg", sizeof(".cfg"));
len += sizeof(".cfg") - 1;
if (len + sizeof(".tmp") >= sizeof(buf)) return 0;
memcpy(buf2, buf, len);
memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
ef = eet_open(buf2, EET_FILE_MODE_WRITE);
if (ef)
{

@ -651,14 +651,12 @@ static Ecore_Event_Handler *_e_fm2_op_registry_entry_changed_handler = NULL;
EAPI int
e_fm2_init(void)
{
const char *homedir;
char path[PATH_MAX];
eina_stringshare_init();
ecore_job_init();
_e_storage_volume_edd_init();
homedir = e_user_homedir_get();
snprintf(path, sizeof(path), "%s/.e/e/fileman/metadata", homedir);
e_user_dir_concat_static(path, "fileman/metadata");
ecore_file_mkpath(path);
_e_fm2_meta_path = strdup(path);
@ -3037,8 +3035,7 @@ _e_fm2_dev_path_map(const char *dev, const char *path)
.desktop files or symlinks (in fact anything
* you like
*/
s = (char *)e_user_homedir_get();
if (PRT("%s/.e/e/fileman/favorites", s) >= sizeof(buf))
if (e_user_dir_concat_static(buf, "fileman/favorites") >= sizeof(buf))
return NULL;
}
else if (strcmp(dev, "desktop") == 0)
@ -3048,15 +3045,14 @@ _e_fm2_dev_path_map(const char *dev, const char *path)
.desktop files or symlinks (in fact anything
* you like
*/
s = (char *)e_user_homedir_get();
if (strcmp(path, "/") == 0)
{
if (PRT("%s/Desktop", s) >= sizeof(buf))
if (e_user_homedir_concat_static(buf, "Desktop") >= sizeof(buf))
return NULL;
}
else
{
if (PRT("%s/Desktop-%s", s, path) >= sizeof(buf))
if (e_user_homedir_snprintf(buf, sizeof(buf), "Desktop-%s", path) >= sizeof(buf))
return NULL;
}
ecore_file_mkpath(buf);

@ -359,8 +359,7 @@ _e_fm2_custom_file_info_load(void)
if (_e_fm2_custom_file) return;
_e_fm2_custom_writes = 0;
snprintf(buf, sizeof(buf), "%s/.e/e/fileman/custom.cfg",
e_user_homedir_get());
e_user_dir_concat_static(buf, "fileman/custom.cfg");
_e_fm2_custom_file = eet_open(buf, EET_FILE_MODE_READ);
if (!_e_fm2_custom_file)
_e_fm2_custom_file = eet_open(buf, EET_FILE_MODE_WRITE);
@ -390,19 +389,22 @@ _e_fm2_custom_file_info_save(void)
{
Eet_File *ef;
char buf[PATH_MAX], buf2[PATH_MAX];
size_t len;
int ret;
if (!_e_fm2_custom_file) return;
if (!_e_fm2_custom_writes) return;
snprintf(buf, sizeof(buf), "%s/.e/e/fileman/custom.cfg.tmp",
e_user_homedir_get());
len = e_user_dir_concat_static(buf, "fileman/custom.cfg.tmp");
if (len >= sizeof(buf)) return;
ef = eet_open(buf, EET_FILE_MODE_WRITE);
if (!ef) return;
eina_hash_foreach(_e_fm2_custom_hash,
_e_fm2_custom_file_hash_foreach_save, ef);
eet_close(ef);
snprintf(buf2, sizeof(buf2), "%s/.e/e/fileman/custom.cfg",
e_user_homedir_get());
memcpy(buf2, buf, len - sizeof(".tmp") - 1);
buf2[len - sizeof(".tmp") - 1] = '\0';
eet_close(_e_fm2_custom_file);
_e_fm2_custom_file = NULL;
ret = rename(buf, buf2);

@ -286,8 +286,8 @@ _e_fm2_volume_write(E_Volume *v)
if (!v->storage) return;
id = ecore_file_file_get(v->storage->udi);
// printf("vol write %s\n", id);
snprintf(buf, sizeof(buf) - 1, "%s/.e/e/fileman/favorites/|%s_%d.desktop",
e_user_homedir_get(), id, v->partition_number);
e_user_dir_snprintf(buf, sizeof(buf), "fileman/favorites/|%s_%d.desktop",
id, v->partition_number);
f = fopen(buf, "w");
if (f)
@ -313,8 +313,9 @@ _e_fm2_volume_write(E_Volume *v)
if (e_config->hal_desktop)
{
snprintf(buf2, sizeof(buf2) - 1, "%s/Desktop/|%s_%d.desktop",
e_user_homedir_get(), id, v->partition_number);
e_user_homedir_snprintf(buf2, sizeof(buf2),
"Desktop/|%s_%d.desktop",
id, v->partition_number);
ecore_file_symlink(buf, buf2);
}
@ -337,15 +338,16 @@ _e_fm2_volume_erase(E_Volume *v)
if (!v->storage) return;
id = ecore_file_file_get(v->storage->udi);
snprintf(buf, sizeof(buf) - 1, "%s/Desktop/|%s_%d.desktop",
e_user_homedir_get(), id, v->partition_number);
e_user_homedir_snprintf(buf, sizeof(buf), "Desktop/|%s_%d.desktop",
id, v->partition_number);
ecore_file_unlink(buf);
_e_fm2_file_force_update(buf);
if (e_config->hal_desktop)
{
snprintf(buf, sizeof(buf) - 1, "%s/.e/e/fileman/favorites/|%s_%d.desktop",
e_user_homedir_get(), id, v->partition_number);
e_user_dir_snprintf(buf, sizeof(buf),
"fileman/favorites/|%s_%d.desktop",
id, v->partition_number);
ecore_file_unlink(buf);
_e_fm2_file_force_update(buf);
}
@ -530,11 +532,13 @@ e_fm2_hal_show_desktop_icons(void)
id = ecore_file_file_get(v->storage->udi);
snprintf(buf, sizeof(buf) - 1, "%s/.e/e/fileman/favorites/|%s_%d.desktop",
e_user_homedir_get(), id, v->partition_number);
e_user_dir_snprintf(buf, sizeof(buf),
"fileman/favorites/|%s_%d.desktop",
id, v->partition_number);
snprintf(buf2, sizeof(buf2) - 1, "%s/Desktop/|%s_%d.desktop",
e_user_homedir_get(), id, v->partition_number);
e_user_homedir_snprintf(buf2, sizeof(buf2),
"Desktop/|%s_%d.desktop",
id, v->partition_number);
if (ecore_file_exists(buf) && !ecore_file_exists(buf2))
{
@ -561,8 +565,9 @@ e_fm2_hal_hide_desktop_icons(void)
id = ecore_file_file_get(v->storage->udi);
snprintf(buf, sizeof(buf) - 1, "%s/Desktop/|%s_%d.desktop",
e_user_homedir_get(), id, v->partition_number);
e_user_homedir_snprintf(buf, sizeof(buf),
"Desktop/|%s_%d.desktop",
id, v->partition_number);
if (ecore_file_exists(buf))
{

@ -37,9 +37,9 @@ EAPI const char *
e_fm_mime_icon_get(const char *mime)
{
char buf[4096], buf2[4096], *val;
const char *homedir = NULL;
Eina_List *l = NULL;
E_Config_Mime_Icon *mi;
size_t len;
/* 0.0 clean out hash cache once it has mroe than 512 entries in it */
if (eina_hash_population(icon_map) > 512) e_fm_mime_icon_cache_flush();
@ -64,41 +64,60 @@ e_fm_mime_icon_get(const char *mime)
}
/* 2. look up in ~/.e/e/icons */
homedir = e_user_homedir_get();
len = e_user_dir_snprintf(buf, sizeof(buf), "icons/%s.edj", mime);
if (len >= sizeof(buf))
goto try_e_icon_generic;
snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.edj", homedir, mime);
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.svg", homedir, mime);
memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg"));
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.png", homedir, mime);
memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png"));
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.edj", homedir, buf2);
try_e_icon_generic:
len = e_user_dir_snprintf(buf, sizeof(buf), "icons/%s.edj", buf2);
if (len >= sizeof(buf))
goto try_theme;
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.svg", homedir, buf2);
memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg"));
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.png", homedir, buf2);
memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png"));
if (ecore_file_exists(buf)) goto ok;
/* 3. look up icon in theme */
snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", mime);
try_theme:
memcpy(buf, "e/icons/fileman/mime/", sizeof("e/icons/fileman/mime/") - 1);
ecore_strlcpy(buf + sizeof("e/icons/fileman/mime/") - 1, mime,
sizeof(buf) - sizeof("e/icons/fileman/mime/") - 1);
val = (char *)e_theme_edje_file_get("base/theme/fileman", buf);
if ((val) && (e_util_edje_collection_exists(val, buf))) goto ok;
snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", buf2);
ecore_strlcpy(buf + sizeof("e/icons/fileman/mime/") - 1, buf2,
sizeof(buf) - sizeof("e/icons/fileman/mime/") - 1);
val = (char *)e_theme_edje_file_get("base/theme/fileman", buf);
if ((val) && (e_util_edje_collection_exists(val, buf))) goto ok;
/* 4. look up icon in PREFIX/share/enlightent/data/icons */
snprintf(buf, sizeof(buf), "%s/data/icons/%s.edj", e_prefix_data_get(), mime);
len = e_prefix_data_snprintf(buf, sizeof(buf), "data/icons/%s.edj", mime);
if (len >= sizeof(buf))
goto try_efreet_icon_generic;
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/data/icons/%s.svg", e_prefix_data_get(), mime);
memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg"));
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/data/icons/%s.png", e_prefix_data_get(), mime);
memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png"));
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/data/icons/%s.edj", e_prefix_data_get(), buf2);
try_efreet_icon_generic:
len = e_prefix_data_snprintf(buf, sizeof(buf), "data/icons/%s.edj", buf2);
if (len >= sizeof(buf))
goto try_efreet_icon_generic;
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/data/icons/%s.svg", e_prefix_data_get(), buf2);
memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg"));
if (ecore_file_exists(buf)) goto ok;
snprintf(buf, sizeof(buf), "%s/data/icons/%s.png", e_prefix_data_get(), buf2);
memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png"));
if (ecore_file_exists(buf)) goto ok;
return NULL;

@ -1065,8 +1065,7 @@ _e_border_menu_cb_fav_add(void *data, E_Menu *m, E_Menu_Item *mi)
char buf[4096];
if (!(bd = data)) return;
snprintf(buf, sizeof(buf), "%s/.e/e/applications/menu/favorite.menu",
e_user_homedir_get());
e_user_dir_concat_static(buf, "applications/menu/favorite.menu");
menu = efreet_menu_parse(buf);
if (!menu) return;
efreet_menu_desktop_insert(menu, bd->desktop, -1);
@ -1095,21 +1094,25 @@ _e_border_menu_cb_ibar_add_pre(void *data, E_Menu *m, E_Menu_Item *mi)
Eina_List *dirs;
Eina_List *l;
char buf[4096], *file;
const char *homedir;
size_t len;
if (!(bd = data)) return;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar", homedir);
len = e_user_dir_concat_static(buf, "applications/bar");
if (len + 1 >= sizeof(buf)) return;
dirs = ecore_file_ls(buf);
if (!dirs) return;
buf[len] = '/';
len++;
sm = e_menu_new();
EINA_LIST_FOREACH(dirs, l, file)
{
E_Menu_Item *smi;
if (file[0] == '.') continue;
snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s", homedir, file);
ecore_strlcpy(buf + len, file, sizeof(buf) - len);
if (ecore_file_is_dir(buf))
{
smi = e_menu_item_new(sm);
@ -1131,8 +1134,8 @@ _e_border_menu_cb_ibar_add(void *data, E_Menu *m, E_Menu_Item *mi)
bd = e_object_data_get(E_OBJECT(m));
if ((!bd) || (!bd->desktop)) return;
snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order",
e_user_homedir_get(), (char *)data);
e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s/.order",
(const char *)data);
od = e_order_new(buf);
if (!od) return;
e_order_append(od, bd->desktop);

@ -281,12 +281,8 @@ e_int_menus_favorite_apps_new(void)
{
E_Menu *m = NULL;
char buf[PATH_MAX];
const char *homedir;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf),
"%s/.e/e/applications/menu/favorite.menu", homedir);
e_user_dir_concat_static(buf, "applications/menu/favorite.menu");
if (ecore_file_exists(buf)) m = e_int_menus_apps_new(buf);
return m;
}

@ -397,7 +397,7 @@ e_intl_imc_personal_path_get(void)
{
char buf[4096];
snprintf(buf, sizeof(buf), "%s/.e/e/input_methods", e_user_homedir_get());
e_user_dir_concat_static(buf, "input_methods");
_e_intl_imc_personal_path = eina_stringshare_add(buf);
}
return _e_intl_imc_personal_path;
@ -410,7 +410,7 @@ e_intl_imc_system_path_get(void)
{
char buf[4096];
snprintf(buf, sizeof(buf), "%s/data/input_methods", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/input_methods");
_e_intl_imc_system_path = eina_stringshare_add(buf);
}
return _e_intl_imc_system_path;

@ -217,9 +217,8 @@ main(int argc, char **argv)
{
/* do some extra tests to see if the prefix really is right */
char buf[4096];
snprintf(buf, sizeof(buf), "%s/data/themes/default.edj",
e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/themes/default.edj");
if (!ecore_file_exists(buf))
{
printf("WARNING: Prefix guess was wrong. Guessed:\n"
@ -378,10 +377,7 @@ main(int argc, char **argv)
TS("arg parse done");
/* fixes for FOOLS that keep cp'ing default.edj into ~/.e/e/themes */
{
const char *homedir;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/themes/default.edj", homedir);
e_user_dir_concat_static(buf, "themes/default.edj");
if (ecore_file_exists(buf))
ecore_file_unlink(buf);
}
@ -693,7 +689,7 @@ main(int argc, char **argv)
e_canvas_add(ee);
im = evas_object_image_add(ecore_evas_get(ee));
snprintf(buf, sizeof(buf), "%s/data/images/test.png", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/images/test.png");
evas_object_image_file_set(im, buf, NULL);
if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
{
@ -702,7 +698,7 @@ main(int argc, char **argv)
_e_main_shutdown(-1);
}
snprintf(buf, sizeof(buf), "%s/data/images/test.jpg", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/images/test.jpg");
evas_object_image_file_set(im, buf, NULL);
if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
{
@ -711,7 +707,7 @@ main(int argc, char **argv)
_e_main_shutdown(-1);
}
snprintf(buf, sizeof(buf), "%s/data/images/test.edj", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/images/test.edj");
evas_object_image_file_set(im, buf, "images/0");
if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
{
@ -782,9 +778,9 @@ main(int argc, char **argv)
list = efreet_icon_extra_list_get();
if (list)
{
snprintf(buf, sizeof(buf), "%s/.e/e/icons", e_user_homedir_get());
e_user_dir_concat_static(buf, "icons");
*list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf));
snprintf(buf, sizeof(buf), "%s/data/icons", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/icons");
*list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf));
}
}
@ -1169,8 +1165,7 @@ _e_main_x_shutdown(void)
static int
_e_main_dirs_init(void)
{
const char *homedir;
char buf[PATH_MAX];
const char *base;
const char *dirs[] = {
"images",
"fonts",
@ -1192,20 +1187,12 @@ _e_main_dirs_init(void)
"input_methods",
NULL
};
int baselen;
homedir = e_user_homedir_get();
baselen = snprintf(buf, sizeof(buf), "%s/.e/e", homedir);
if (baselen >= (int)sizeof(buf))
{
e_error_message_show("Error could not join:\n'%s'\nand\n'/.e/e",
homedir);
return 0;
}
if (ecore_file_mksubdirs(buf, dirs) != sizeof(dirs)/sizeof(dirs[0]) - 1)
base = e_user_dir_get();
if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs)/sizeof(dirs[0]) - 1)
{
e_error_message_show
("Could not create one of the required subdirectories of '%s'", buf);
("Could not create one of the required subdirectories of '%s'", base);
return 0;
}
@ -1334,7 +1321,7 @@ _e_main_path_init(void)
e_error_message_show("Cannot allocate path for path_data\n");
return 0;
}
snprintf(buf, sizeof(buf), "%s/data", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data");
e_path_default_path_append(path_data, buf);
e_path_user_path_set(path_data, &(e_config->path_append_data));
@ -1346,7 +1333,7 @@ _e_main_path_init(void)
return 0;
}
e_path_default_path_append(path_images, "~/.e/e/images");
snprintf(buf, sizeof(buf), "%s/data/images", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/images");
e_path_default_path_append(path_images, buf);
e_path_user_path_set(path_images, &(e_config->path_append_images));
@ -1358,7 +1345,7 @@ _e_main_path_init(void)
return 0;
}
e_path_default_path_append(path_fonts, "~/.e/e/fonts");
snprintf(buf, sizeof(buf), "%s/data/fonts", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/fonts");
e_path_default_path_append(path_fonts, buf);
e_path_user_path_set(path_fonts, &(e_config->path_append_fonts));
@ -1370,7 +1357,7 @@ _e_main_path_init(void)
return 0;
}
e_path_default_path_append(path_themes, "~/.e/e/themes");
snprintf(buf, sizeof(buf), "%s/data/themes", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/themes");
e_path_default_path_append(path_themes, buf);
e_path_user_path_set(path_themes, &(e_config->path_append_themes));
@ -1382,7 +1369,7 @@ _e_main_path_init(void)
return 0;
}
e_path_default_path_append(path_icons, "~/.e/e/icons");
snprintf(buf, sizeof(buf), "%s/data/icons", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/icons");
e_path_default_path_append(path_icons, buf);
e_path_user_path_set(path_icons, &(e_config->path_append_icons));
@ -1412,7 +1399,7 @@ _e_main_path_init(void)
return 0;
}
e_path_default_path_append(path_backgrounds, "~/.e/e/backgrounds");
snprintf(buf, sizeof(buf), "%s/data/backgrounds", e_prefix_data_get());
e_prefix_data_concat_static(buf, "data/backgrounds");
e_path_default_path_append(path_backgrounds, buf);
e_path_user_path_set(path_backgrounds, &(e_config->path_append_backgrounds));

@ -17,6 +17,8 @@ static char *_prefix_path_bin = NULL;
static char *_prefix_path_data = NULL;
static char *_prefix_path_lib = NULL;
static size_t _prefix_path_data_len = 0;
#define PREFIX_CACHE_FILE 1
#define SHARE_D "share/enlightenment"
#define MAGIC_FILE "AUTHORS"
@ -56,10 +58,13 @@ e_prefix_determine(char *argv0)
}
if (getenv("E_DATA_DIR"))
_prefix_path_data = strdup(getenv("E_DATA_DIR"));
{
_prefix_path_data = strdup(getenv("E_DATA_DIR"));
_prefix_path_data_len = strlen(_prefix_path_data);
}
else
{
snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path);
_prefix_path_data_len = snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path);
_prefix_path_data = strdup(buf);
e_util_env_set("E_DATA_DIR", _prefix_path_data);
}
@ -122,7 +127,7 @@ e_prefix_determine(char *argv0)
snprintf(buf, sizeof(buf), "%s/"MAGIC_DAT, _prefix_path);
if (ecore_file_exists(buf))
{
snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path);
_prefix_path_data_len = snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path);
_prefix_path_data = strdup(buf);
snprintf(buf, sizeof(buf), "%s/"LOCALE_D, _prefix_path);
_prefix_path_locale = strdup(buf);
@ -226,9 +231,6 @@ _e_prefix_share_hunt(void)
{
char buf[4096], buf2[4096], *p;
FILE *f;
#ifdef PREFIX_CACHE_FILE
const char *home;
#endif
/* sometimes this isnt the case - so we need to do a more exhaustive search
* through more parent and subdirs. hre is an example i have seen:
@ -245,9 +247,7 @@ _e_prefix_share_hunt(void)
#ifdef PREFIX_CACHE_FILE
/* 1. check cache file - as a first attempt. this will speed up subsequent
* hunts - if needed */
home = e_user_homedir_get();
snprintf(buf, sizeof(buf), "%s/.e/e/prefix_share_cache.txt", home);
e_user_dir_concat_static(buf, "prefix_share_cache.txt");
f = fopen(buf, "r");
if (f)
{
@ -262,7 +262,7 @@ _e_prefix_share_hunt(void)
{
/* path is ok - magic file found */
_prefix_path_data = strdup(buf2);
snprintf(buf, sizeof(buf), "%s", buf2);
_prefix_path_data_len = ecore_strlcpy(buf, buf2, sizeof(buf));
p = strrchr(buf, '/');
if (p) *p = 0;
snprintf(buf2, sizeof(buf2), "%s/locale", buf);
@ -285,8 +285,8 @@ _e_prefix_share_hunt(void)
{
Eina_List *files;
Eina_List *l;
snprintf(buf, sizeof(buf), "%s", _prefix_path);
ecore_strlcpy(buf, _prefix_path, sizeof(buf));
p = strrchr(buf, '/');
if (p) *p = 0;
files = ecore_file_ls(buf);
@ -299,17 +299,16 @@ _e_prefix_share_hunt(void)
snprintf(buf2, sizeof(buf2), "%s/%s/"MAGIC_DAT, buf, file);
if (ecore_file_exists(buf2))
{
snprintf(buf2, sizeof(buf2), "%s/%s/"SHARE_D, buf, file);
_prefix_path_data_len = snprintf(buf2, sizeof(buf2), "%s/%s/"SHARE_D, buf, file);
_prefix_path_data = strdup(buf2);
snprintf(buf2, sizeof(buf2), "%s/%s/"LOCALE_D, buf, file);
_prefix_path_locale = strdup(buf2);
break;
}
}
while (files)
EINA_LIST_FREE(files, p)
{
free(eina_list_data_get(files));
files = eina_list_remove_list(files, files);
free(p);
}
}
}
@ -320,13 +319,13 @@ _e_prefix_share_hunt(void)
*/
if (!_prefix_path_data)
{
snprintf(buf, sizeof(buf), "%s", _prefix_path);
ecore_strlcpy(buf, _prefix_path, sizeof(buf));
p = strrchr(buf, '/');
if (p) *p = 0;
snprintf(buf2, sizeof(buf2), "%s/"MAGIC_DAT, buf);
if (ecore_file_exists(buf2))
{
snprintf(buf2, sizeof(buf2), "%s/"SHARE_D, buf);
_prefix_path_data_len = snprintf(buf2, sizeof(buf2), "%s/"SHARE_D, buf);
_prefix_path_data = strdup(buf2);
snprintf(buf2, sizeof(buf2), "%s/"LOCALE_D, buf);
_prefix_path_locale = strdup(buf2);
@ -343,9 +342,8 @@ _e_prefix_share_hunt(void)
if (_prefix_path_data)
{
#ifdef PREFIX_CACHE_FILE
snprintf(buf, sizeof(buf), "%s/.e/e", home);
ecore_file_mkpath(buf);
snprintf(buf, sizeof(buf), "%s/.e/e/prefix_share_cache.txt", home);
ecore_file_mkpath(e_user_dir_get());
e_user_dir_concat_static(buf, "prefix_share_cache.txt");
f = fopen(buf, "w");
if (f)
{
@ -370,6 +368,7 @@ _e_prefix_fallbacks(void)
_prefix_path_locale = strdup(LOCALE_DIR);
_prefix_path_bin = strdup(PACKAGE_BIN_DIR);
_prefix_path_data = strdup(PACKAGE_DATA_DIR);
_prefix_path_data_len = strlen(_prefix_path_data);
_prefix_path_lib = strdup(PACKAGE_LIB_DIR);
printf("WARNING: Enlightenment could not determine its installed prefix\n"
" and is falling back on the compiled in default:\n"
@ -519,3 +518,38 @@ _e_prefix_try_argv(char *argv0)
/* 4. big problems. arg[0] != executable - weird execution */
return 0;
}
size_t
e_prefix_data_concat_len(char *dst, size_t size, const char *path, size_t path_len)
{
return ecore_str_join_len(dst, size, '/', _prefix_path_data, _prefix_path_data_len, path, path_len);
}
size_t
e_prefix_data_snprintf(char *dst, size_t size, const char *fmt, ...)
{
size_t off, ret;
va_list ap;
va_start(ap, fmt);
off = _prefix_path_data_len + 1;
if (size < _prefix_path_data_len + 2)
{
if (size > 1)
{
memcpy(dst, _prefix_path_data, size - 1);
dst[size - 1] = '\0';
}
ret = off + vsnprintf(dst + off, size - off, fmt, ap);
va_end(ap);
return ret;
}
memcpy(dst, _prefix_path_data, _prefix_path_data_len);
dst[_prefix_path_data_len] = '/';
ret = off + vsnprintf(dst + off, size - off, fmt, ap);
va_end(ap);
return ret;
}

@ -15,6 +15,16 @@ EAPI const char *e_prefix_locale_get(void);
EAPI const char *e_prefix_bin_get(void);
EAPI const char *e_prefix_data_get(void);
EAPI const char *e_prefix_lib_get(void);
EAPI size_t e_prefix_data_concat_len(char *dst, size_t size, const char *path, size_t path_len);
EAPI size_t e_prefix_data_snprintf(char *dst, size_t size, const char *fmt, ...) EINA_PRINTF(3, 4);
static inline size_t e_prefix_data_concat(char *dst, size_t size, const char *path)
{
return e_prefix_data_concat_len(dst, size, path, strlen(path));
}
#define e_prefix_data_concat_static(dst, path) e_prefix_data_concat_len(dst, sizeof(dst), path, (sizeof(path) > 0) ? sizeof(path) - 1 : 0)
#endif
#endif

@ -20,22 +20,18 @@ static int start_app_pos = -1;
EAPI void
e_startup(E_Startup_Mode mode)
{
const char *homedir, *prefixdir;
char buf[PATH_MAX];
homedir = e_user_homedir_get();
prefixdir = e_prefix_data_get();
if (mode == E_STARTUP_START)
{
snprintf(buf, sizeof(buf), "%s/.e/e/applications/startup/.order", homedir);
if (!ecore_file_exists(buf))
snprintf(buf, sizeof(buf), "%s/data/applications/startup/.order", prefixdir);
e_user_dir_concat_static(buf, "applications/startup/.order");
if (!ecore_file_exists(buf))
e_prefix_data_concat_static(buf, "data/applications/startup/.order");
}
else if (mode == E_STARTUP_RESTART)
{
snprintf(buf, sizeof(buf), "%s/.e/e/applications/restart/.order", homedir);
if (!ecore_file_exists(buf))
snprintf(buf, sizeof(buf), "%s/data/applications/restart/.order", prefixdir);
e_user_dir_concat_static(buf, "applications/restart/.order");
if (!ecore_file_exists(buf))
e_prefix_data_concat_static(buf, "data/applications/restart/.order");
}
startup_apps = e_order_new(buf);
if (!startup_apps) return;

@ -77,10 +77,9 @@ main(int argc, char **argv)
ecore_file_init();
ecore_ipc_init();
snprintf(_thumbdir, sizeof(_thumbdir), "%s/.e/e/fileman/thumbnails",
e_user_homedir_get());
e_user_dir_concat_static(_thumbdir, "fileman/thumbnails");
ecore_file_mkpath(_thumbdir);
if (_e_ipc_init()) ecore_main_loop_begin();
if (_e_ipc_server)

@ -3,22 +3,85 @@
*/
#include "e.h"
static const char *_e_user_homedir = NULL;
static size_t _e_user_homedir_len = 0;
/* externally accessible functions */
EAPI const char *
e_user_homedir_get(void)
{
char *homedir;
int len;
char *d;
if (_e_user_homedir)
return _e_user_homedir;
_e_user_homedir = d = getenv("HOME");
if (!_e_user_homedir)
{
_e_user_homedir = "/tmp";
_e_user_homedir_len = sizeof("/tmp") - 1;
return _e_user_homedir;
}
_e_user_homedir_len = strlen(_e_user_homedir);
while ((_e_user_homedir_len > 1) &&
(d[_e_user_homedir_len - 1] == '/'))
{
_e_user_homedir_len--;
d[_e_user_homedir_len] = '\0';
}
return _e_user_homedir;
}
/**
* Concatenate '~/' and @a path.
*
* @return similar to snprintf(), this returns the number of bytes written or
* that would be required to write if greater or equal than size.
*/
EAPI size_t
e_user_homedir_concat_len(char *dst, size_t size, const char *path, size_t path_len)
{
if (!_e_user_homedir)
e_user_homedir_get();
homedir = getenv("HOME");
if (!homedir) return "/tmp";
len = strlen(homedir);
while ((len > 1) && (homedir[len - 1] == '/'))
return ecore_str_join_len(dst, size, '/', _e_user_homedir, _e_user_homedir_len, path, path_len);
}
/**
* same as snprintf("~/"fmt, ...).
*/
EAPI size_t
e_user_homedir_snprintf(char *dst, size_t size, const char *fmt, ...)
{
size_t off, ret;
va_list ap;
if (!_e_user_homedir)
e_user_homedir_get();
va_start(ap, fmt);
off = _e_user_homedir_len + 1;
if (size < _e_user_homedir_len + 2)
{
homedir[len - 1] = 0;
len--;
if (size > 1)
{
memcpy(dst, _e_user_homedir, size - 1);
dst[size - 1] = '\0';
}
ret = off + vsnprintf(dst + off, size - off, fmt, ap);
va_end(ap);
return ret;
}
return homedir;
memcpy(dst, _e_user_homedir, _e_user_homedir_len);
dst[_e_user_homedir_len] = '/';
ret = off + vsnprintf(dst + off, size - off, fmt, ap);
va_end(ap);
return ret;
}
/**
@ -52,3 +115,73 @@ e_user_icon_dir_get(void)
return dir;
}
static const char *_e_user_dir = NULL;
static size_t _e_user_dir_len = 0;
/**
* Return ~/.e/e
*/
EAPI const char *
e_user_dir_get(void)
{
static char dir[PATH_MAX] = "";
if (!dir[0])
{
_e_user_dir_len = e_user_homedir_concat(dir, sizeof(dir), ".e/e");
_e_user_dir = dir;
}
return dir;
}
/**
* Concatenate '~/.e/e' and @a path.
*
* @return similar to snprintf(), this returns the number of bytes written or
* that would be required to write if greater or equal than size.
*/
EAPI size_t
e_user_dir_concat_len(char *dst, size_t size, const char *path, size_t path_len)
{
if (!_e_user_dir)
e_user_dir_get();
return ecore_str_join_len(dst, size, '/', _e_user_dir, _e_user_dir_len, path, path_len);
}
/**
* same as snprintf("~/.e/e/"fmt, ...).
*/
EAPI size_t
e_user_dir_snprintf(char *dst, size_t size, const char *fmt, ...)
{
size_t off, ret;
va_list ap;
if (!_e_user_dir)
e_user_dir_get();
va_start(ap, fmt);
off = _e_user_dir_len + 1;
if (size < _e_user_dir_len + 2)
{
if (size > 1)
{
memcpy(dst, _e_user_dir, size - 1);
dst[size - 1] = '\0';
}
ret = off + vsnprintf(dst + off, size - off, fmt, ap);
va_end(ap);
return ret;
}
memcpy(dst, _e_user_dir, _e_user_dir_len);
dst[_e_user_dir_len] = '/';
ret = off + vsnprintf(dst + off, size - off, fmt, ap);
va_end(ap);
return ret;
}

@ -6,7 +6,28 @@
#ifndef E_USER_H
#define E_USER_H
#include <Eina.h>
EAPI const char *e_user_homedir_get(void);
EAPI size_t e_user_homedir_concat_len(char *dst, size_t size, const char *path, size_t path_len);
EAPI size_t e_user_homedir_snprintf(char *dst, size_t size, const char *fmt, ...) EINA_PRINTF(3, 4);
static inline size_t e_user_homedir_concat(char *dst, size_t size, const char *path)
{
return e_user_homedir_concat_len(dst, size, path, strlen(path));
}
#define e_user_homedir_concat_static(dst, path) e_user_homedir_concat_len(dst, sizeof(dst), path, (sizeof(path) > 0) ? sizeof(path) - 1 : 0)
EAPI const char *e_user_dir_get(void);
EAPI size_t e_user_dir_concat_len(char *dst, size_t size, const char *path, size_t path_len);
EAPI size_t e_user_dir_snprintf(char *dst, size_t size, const char *fmt, ...) EINA_PRINTF(3, 4);
static inline size_t e_user_dir_concat(char *dst, size_t size, const char *path)
{
return e_user_dir_concat_len(dst, size, path, strlen(path));
}
#define e_user_dir_concat_static(dst, path) e_user_dir_concat_len(dst, sizeof(dst), path, (sizeof(path) > 0) ? sizeof(path) - 1 : 0)
EAPI const char *e_user_desktop_dir_get(void);
EAPI const char *e_user_icon_dir_get(void);