2005-05-19 02:23:54 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
#include "e.h"
|
|
|
|
|
|
|
|
/* local subsystem functions */
|
2006-07-10 09:37:52 -07:00
|
|
|
static int _e_prefix_share_hunt(void);
|
2005-07-30 23:22:31 -07:00
|
|
|
static int _e_prefix_fallbacks(void);
|
2005-05-19 02:23:54 -07:00
|
|
|
static int _e_prefix_try_proc(void);
|
|
|
|
static int _e_prefix_try_argv(char *argv0);
|
|
|
|
|
|
|
|
/* local subsystem globals */
|
|
|
|
static char *_exe_path = NULL;
|
|
|
|
static char *_prefix_path = NULL;
|
2005-07-30 23:22:31 -07:00
|
|
|
static char *_prefix_path_locale = NULL;
|
|
|
|
static char *_prefix_path_bin = NULL;
|
|
|
|
static char *_prefix_path_data = NULL;
|
|
|
|
static char *_prefix_path_lib = NULL;
|
2005-05-19 02:23:54 -07:00
|
|
|
|
2009-04-13 07:56:38 -07:00
|
|
|
static size_t _prefix_path_data_len = 0;
|
|
|
|
|
2006-07-10 09:37:52 -07:00
|
|
|
#define PREFIX_CACHE_FILE 1
|
|
|
|
#define SHARE_D "share/enlightenment"
|
|
|
|
#define MAGIC_FILE "AUTHORS"
|
|
|
|
#define MAGIC_DAT SHARE_D"/"MAGIC_FILE
|
|
|
|
#define LOCALE_D "share/locale"
|
|
|
|
|
2005-06-01 21:21:00 -07:00
|
|
|
/* externally accessible functions */
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI int
|
2005-05-19 02:23:54 -07:00
|
|
|
e_prefix_determine(char *argv0)
|
|
|
|
{
|
2006-07-10 09:37:52 -07:00
|
|
|
char *p, buf[4096];
|
2005-07-30 23:22:31 -07:00
|
|
|
|
2006-02-21 07:00:10 -08:00
|
|
|
e_prefix_shutdown();
|
2006-07-10 09:37:52 -07:00
|
|
|
|
|
|
|
/* if user provides E_PREFIX - then use that or also more specific sub
|
|
|
|
* dirs for bin, lib, data and locale */
|
|
|
|
if (getenv("E_PREFIX"))
|
|
|
|
{
|
|
|
|
_prefix_path = strdup(getenv("E_PREFIX"));
|
|
|
|
if (getenv("E_BIN_DIR"))
|
2009-01-02 03:19:06 -08:00
|
|
|
_prefix_path_bin = strdup(getenv("E_BIN_DIR"));
|
2006-07-10 09:37:52 -07:00
|
|
|
else
|
2009-01-02 03:19:06 -08:00
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/bin", _prefix_path);
|
|
|
|
_prefix_path_bin = strdup(buf);
|
|
|
|
e_util_env_set("E_BIN_DIR", _prefix_path_bin);
|
|
|
|
}
|
2006-07-21 08:55:54 -07:00
|
|
|
|
2006-07-10 09:37:52 -07:00
|
|
|
if (getenv("E_LIB_DIR"))
|
2009-01-02 03:19:06 -08:00
|
|
|
_prefix_path_lib = strdup(getenv("E_LIB_DIR"));
|
2006-07-10 09:37:52 -07:00
|
|
|
else
|
2009-01-02 03:19:06 -08:00
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/lib", _prefix_path);
|
|
|
|
_prefix_path_lib = strdup(buf);
|
|
|
|
e_util_env_set("E_LIB_DIR", _prefix_path_lib);
|
|
|
|
}
|
2006-07-21 08:55:54 -07:00
|
|
|
|
2006-07-10 09:37:52 -07:00
|
|
|
if (getenv("E_DATA_DIR"))
|
2009-04-13 07:56:38 -07:00
|
|
|
{
|
|
|
|
_prefix_path_data = strdup(getenv("E_DATA_DIR"));
|
|
|
|
_prefix_path_data_len = strlen(_prefix_path_data);
|
|
|
|
}
|
2006-07-10 09:37:52 -07:00
|
|
|
else
|
2009-01-02 03:19:06 -08:00
|
|
|
{
|
2009-04-13 07:56:38 -07:00
|
|
|
_prefix_path_data_len = snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path);
|
2009-01-02 03:19:06 -08:00
|
|
|
_prefix_path_data = strdup(buf);
|
|
|
|
e_util_env_set("E_DATA_DIR", _prefix_path_data);
|
|
|
|
}
|
2006-07-21 08:55:54 -07:00
|
|
|
|
2006-07-10 09:37:52 -07:00
|
|
|
if (getenv("E_LOCALE_DIR"))
|
2009-01-02 03:19:06 -08:00
|
|
|
_prefix_path_locale = strdup(getenv("E_LOCALE_DIR"));
|
2006-07-10 09:37:52 -07:00
|
|
|
else
|
2009-01-02 03:19:06 -08:00
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/"LOCALE_D, _prefix_path);
|
|
|
|
_prefix_path_locale = strdup(buf);
|
|
|
|
e_util_env_set("E_LOCALE_DIR", _prefix_path_locale);
|
|
|
|
}
|
2006-07-10 09:37:52 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* no env var - examine process and possible argv0 */
|
2005-05-19 02:23:54 -07:00
|
|
|
if (!_e_prefix_try_proc())
|
|
|
|
{
|
|
|
|
if (!_e_prefix_try_argv(argv0))
|
2005-07-30 23:22:31 -07:00
|
|
|
{
|
2006-07-13 09:35:46 -07:00
|
|
|
e_prefix_fallback();
|
2009-01-02 03:19:06 -08:00
|
|
|
e_util_env_set("E_PREFIX", _prefix_path);
|
|
|
|
e_util_env_set("E_BIN_DIR", _prefix_path_bin);
|
|
|
|
e_util_env_set("E_LIB_DIR", _prefix_path_lib);
|
|
|
|
e_util_env_set("E_DATA_DIR", _prefix_path_data);
|
2005-07-30 23:22:31 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2005-05-19 02:23:54 -07:00
|
|
|
}
|
|
|
|
/* _exe_path is now a full absolute path TO this exe - figure out rest */
|
|
|
|
/* if
|
|
|
|
* exe = /blah/whatever/bin/exe
|
|
|
|
* then
|
|
|
|
* prefix = /blah/whatever
|
|
|
|
* bin_dir = /blah/whatever/bin
|
|
|
|
* data_dir = /blah/whatever/share/enlightenment
|
|
|
|
* locale_dir = /blah/whatever/share/locale
|
|
|
|
* lib_dir = /blah/whatever/lib
|
|
|
|
*/
|
|
|
|
p = strrchr(_exe_path, '/');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p--;
|
|
|
|
while (p >= _exe_path)
|
|
|
|
{
|
|
|
|
if (*p == '/')
|
|
|
|
{
|
|
|
|
_prefix_path = malloc(p - _exe_path + 1);
|
|
|
|
if (_prefix_path)
|
|
|
|
{
|
2008-10-27 05:34:35 -07:00
|
|
|
ecore_strlcpy(_prefix_path, _exe_path, p - _exe_path + 1);
|
2006-07-10 09:37:52 -07:00
|
|
|
|
|
|
|
/* bin and lib always together */
|
|
|
|
snprintf(buf, sizeof(buf), "%s/bin", _prefix_path);
|
|
|
|
_prefix_path_bin = strdup(buf);
|
|
|
|
snprintf(buf, sizeof(buf), "%s/lib", _prefix_path);
|
|
|
|
_prefix_path_lib = strdup(buf);
|
2005-07-30 23:22:31 -07:00
|
|
|
|
2005-05-19 02:23:54 -07:00
|
|
|
printf("DYNAMIC DETERMINED PREFIX: %s\n", _prefix_path);
|
2006-07-10 09:37:52 -07:00
|
|
|
|
|
|
|
/* check if AUTHORS file is there - then our guess is right */
|
|
|
|
snprintf(buf, sizeof(buf), "%s/"MAGIC_DAT, _prefix_path);
|
|
|
|
if (ecore_file_exists(buf))
|
|
|
|
{
|
2009-04-13 07:56:38 -07:00
|
|
|
_prefix_path_data_len = snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path);
|
2006-07-10 09:37:52 -07:00
|
|
|
_prefix_path_data = strdup(buf);
|
|
|
|
snprintf(buf, sizeof(buf), "%s/"LOCALE_D, _prefix_path);
|
|
|
|
_prefix_path_locale = strdup(buf);
|
|
|
|
}
|
|
|
|
/* AUTHORS file not there. time to start hunting! */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_e_prefix_share_hunt())
|
|
|
|
{
|
|
|
|
printf("DIFFERENT DYNAMIC DETERMINED DATA DIR: %s\n", _prefix_path_data);
|
|
|
|
printf("DIFFERENT DYNAMIC DETERMINED LOCALE DIR: %s\n", _prefix_path_locale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e_prefix_fallback();
|
2009-01-02 03:19:06 -08:00
|
|
|
e_util_env_set("E_PREFIX", _prefix_path);
|
|
|
|
e_util_env_set("E_BIN_DIR", _prefix_path_bin);
|
|
|
|
e_util_env_set("E_LIB_DIR", _prefix_path_lib);
|
|
|
|
e_util_env_set("E_DATA_DIR", _prefix_path_data);
|
2006-07-10 09:37:52 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-01-02 03:19:06 -08:00
|
|
|
e_util_env_set("E_PREFIX", _prefix_path);
|
|
|
|
e_util_env_set("E_BIN_DIR", _prefix_path_bin);
|
|
|
|
e_util_env_set("E_LIB_DIR", _prefix_path_lib);
|
|
|
|
e_util_env_set("E_DATA_DIR", _prefix_path_data);
|
2005-05-19 02:23:54 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-10 09:37:52 -07:00
|
|
|
e_prefix_fallback();
|
2009-01-02 03:19:06 -08:00
|
|
|
e_util_env_set("E_PREFIX", _prefix_path);
|
|
|
|
e_util_env_set("E_BIN_DIR", _prefix_path_bin);
|
|
|
|
e_util_env_set("E_LIB_DIR", _prefix_path_lib);
|
|
|
|
e_util_env_set("E_DATA_DIR", _prefix_path_data);
|
2005-05-19 02:23:54 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 09:37:52 -07:00
|
|
|
e_prefix_fallback();
|
2009-01-02 03:19:06 -08:00
|
|
|
e_util_env_set("E_PREFIX", _prefix_path);
|
|
|
|
e_util_env_set("E_BIN_DIR", _prefix_path_bin);
|
|
|
|
e_util_env_set("E_LIB_DIR", _prefix_path_lib);
|
|
|
|
e_util_env_set("E_DATA_DIR", _prefix_path_data);
|
2005-05-19 02:23:54 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI void
|
2006-02-21 07:00:10 -08:00
|
|
|
e_prefix_shutdown(void)
|
2005-07-30 23:22:31 -07:00
|
|
|
{
|
2005-09-05 08:24:07 -07:00
|
|
|
E_FREE(_exe_path);
|
|
|
|
E_FREE(_prefix_path);
|
|
|
|
E_FREE(_prefix_path_locale);
|
|
|
|
E_FREE(_prefix_path_bin);
|
|
|
|
E_FREE(_prefix_path_data);
|
|
|
|
E_FREE(_prefix_path_lib);
|
2006-02-21 07:00:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
e_prefix_fallback(void)
|
|
|
|
{
|
|
|
|
e_prefix_shutdown();
|
2005-07-30 23:22:31 -07:00
|
|
|
_e_prefix_fallbacks();
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI const char *
|
2005-05-19 02:23:54 -07:00
|
|
|
e_prefix_get(void)
|
|
|
|
{
|
|
|
|
return _prefix_path;
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI const char *
|
2005-07-30 23:22:31 -07:00
|
|
|
e_prefix_locale_get(void)
|
|
|
|
{
|
|
|
|
return _prefix_path_locale;
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI const char *
|
2005-08-01 02:12:03 -07:00
|
|
|
e_prefix_bin_get(void)
|
2005-07-30 23:22:31 -07:00
|
|
|
{
|
|
|
|
return _prefix_path_bin;
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI const char *
|
2005-07-30 23:22:31 -07:00
|
|
|
e_prefix_data_get(void)
|
|
|
|
{
|
|
|
|
return _prefix_path_data;
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:39:46 -08:00
|
|
|
EAPI const char *
|
2005-08-01 02:12:03 -07:00
|
|
|
e_prefix_lib_get(void)
|
2005-07-30 23:22:31 -07:00
|
|
|
{
|
|
|
|
return _prefix_path_lib;
|
|
|
|
}
|
|
|
|
|
2005-05-19 02:23:54 -07:00
|
|
|
/* local subsystem functions */
|
2006-07-10 09:37:52 -07:00
|
|
|
static int
|
|
|
|
_e_prefix_share_hunt(void)
|
|
|
|
{
|
|
|
|
char buf[4096], buf2[4096], *p;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
/* 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:
|
|
|
|
*
|
|
|
|
* /blah/whatever/exec/bin/exe
|
|
|
|
* ->
|
|
|
|
* /blah/whatever/exec/bin
|
|
|
|
* /blah/whatever/common/share/enlightenment
|
|
|
|
* /blah/whatever/common/share/locale
|
|
|
|
* /blah/whatever/exec/lib
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* this is pure black magic to try and find data shares */
|
|
|
|
#ifdef PREFIX_CACHE_FILE
|
|
|
|
/* 1. check cache file - as a first attempt. this will speed up subsequent
|
|
|
|
* hunts - if needed */
|
2009-04-13 07:56:38 -07:00
|
|
|
e_user_dir_concat_static(buf, "prefix_share_cache.txt");
|
2006-07-10 09:37:52 -07:00
|
|
|
f = fopen(buf, "r");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
if (fgets(buf2, sizeof(buf2), f))
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(buf2);
|
|
|
|
if (len > 1) buf2[len - 1] = 0;
|
|
|
|
snprintf(buf, sizeof(buf), "%s/"MAGIC_FILE, buf2);
|
|
|
|
if (ecore_file_exists(buf))
|
|
|
|
{
|
|
|
|
/* path is ok - magic file found */
|
|
|
|
_prefix_path_data = strdup(buf2);
|
2009-04-13 07:56:38 -07:00
|
|
|
_prefix_path_data_len = ecore_strlcpy(buf, buf2, sizeof(buf));
|
2006-07-10 09:37:52 -07:00
|
|
|
p = strrchr(buf, '/');
|
|
|
|
if (p) *p = 0;
|
|
|
|
snprintf(buf2, sizeof(buf2), "%s/locale", buf);
|
|
|
|
_prefix_path_locale = strdup(buf2);
|
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* 2. cache file doesn't exist or is invalid - we need to search - this is
|
|
|
|
* where the real black magic begins */
|
|
|
|
|
|
|
|
/* BLACK MAGIC 1:
|
|
|
|
* /blah/whatever/dir1/bin
|
|
|
|
* /blah/whatever/dir2/share/enlightenment
|
|
|
|
*/
|
|
|
|
if (!_prefix_path_data)
|
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *files;
|
|
|
|
Eina_List *l;
|
2009-04-13 07:56:38 -07:00
|
|
|
|
|
|
|
ecore_strlcpy(buf, _prefix_path, sizeof(buf));
|
2006-07-10 09:37:52 -07:00
|
|
|
p = strrchr(buf, '/');
|
|
|
|
if (p) *p = 0;
|
|
|
|
files = ecore_file_ls(buf);
|
|
|
|
if (files)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(files, l, file)
|
2006-07-10 09:37:52 -07:00
|
|
|
{
|
|
|
|
snprintf(buf2, sizeof(buf2), "%s/%s/"MAGIC_DAT, buf, file);
|
|
|
|
if (ecore_file_exists(buf2))
|
|
|
|
{
|
2009-04-13 07:56:38 -07:00
|
|
|
_prefix_path_data_len = snprintf(buf2, sizeof(buf2), "%s/%s/"SHARE_D, buf, file);
|
2006-07-10 09:37:52 -07:00
|
|
|
_prefix_path_data = strdup(buf2);
|
|
|
|
snprintf(buf2, sizeof(buf2), "%s/%s/"LOCALE_D, buf, file);
|
|
|
|
_prefix_path_locale = strdup(buf2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-04-13 07:56:38 -07:00
|
|
|
EINA_LIST_FREE(files, p)
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
{
|
2009-04-13 07:56:38 -07:00
|
|
|
free(p);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
}
|
2006-07-10 09:37:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BLACK MAGIC 2:
|
|
|
|
* /blah/whatever/dir1/bin
|
|
|
|
* /blah/whatever/share/enlightenment
|
|
|
|
*/
|
|
|
|
if (!_prefix_path_data)
|
|
|
|
{
|
2009-04-13 07:56:38 -07:00
|
|
|
ecore_strlcpy(buf, _prefix_path, sizeof(buf));
|
2006-07-10 09:37:52 -07:00
|
|
|
p = strrchr(buf, '/');
|
|
|
|
if (p) *p = 0;
|
|
|
|
snprintf(buf2, sizeof(buf2), "%s/"MAGIC_DAT, buf);
|
|
|
|
if (ecore_file_exists(buf2))
|
|
|
|
{
|
2009-04-13 07:56:38 -07:00
|
|
|
_prefix_path_data_len = snprintf(buf2, sizeof(buf2), "%s/"SHARE_D, buf);
|
2006-07-10 09:37:52 -07:00
|
|
|
_prefix_path_data = strdup(buf2);
|
|
|
|
snprintf(buf2, sizeof(buf2), "%s/"LOCALE_D, buf);
|
|
|
|
_prefix_path_locale = strdup(buf2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add more black magic as required as we discover weridnesss - remember
|
|
|
|
* this is to save users having to set environment variables to tell
|
|
|
|
* e where it lives, so e auto-adapts. so these code snippets are just
|
|
|
|
* logic to figure that out for the user
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* done. we found it - write cache file */
|
|
|
|
if (_prefix_path_data)
|
|
|
|
{
|
|
|
|
#ifdef PREFIX_CACHE_FILE
|
2009-04-13 07:56:38 -07:00
|
|
|
ecore_file_mkpath(e_user_dir_get());
|
|
|
|
e_user_dir_concat_static(buf, "prefix_share_cache.txt");
|
2006-07-10 09:37:52 -07:00
|
|
|
f = fopen(buf, "w");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fprintf(f, "%s\n", _prefix_path_data);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* fail. everything failed */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-30 23:22:31 -07:00
|
|
|
static int
|
|
|
|
_e_prefix_fallbacks(void)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
_prefix_path = strdup(PACKAGE_BIN_DIR);
|
|
|
|
p = strrchr(_prefix_path, '/');
|
|
|
|
if (p) *p = 0;
|
|
|
|
_prefix_path_locale = strdup(LOCALE_DIR);
|
2006-07-10 09:37:52 -07:00
|
|
|
_prefix_path_bin = strdup(PACKAGE_BIN_DIR);
|
|
|
|
_prefix_path_data = strdup(PACKAGE_DATA_DIR);
|
2009-04-13 07:56:38 -07:00
|
|
|
_prefix_path_data_len = strlen(_prefix_path_data);
|
2006-07-10 09:37:52 -07:00
|
|
|
_prefix_path_lib = strdup(PACKAGE_LIB_DIR);
|
2005-07-30 23:22:31 -07:00
|
|
|
printf("WARNING: Enlightenment could not determine its installed prefix\n"
|
|
|
|
" and is falling back on the compiled in default:\n"
|
2006-07-13 09:35:46 -07:00
|
|
|
" %s\n"
|
2006-07-10 09:37:52 -07:00
|
|
|
" You might like to try setting the following environment variables:\n"
|
|
|
|
" E_PREFIX - points to the base prefix of install\n"
|
|
|
|
" E_BIN_DIR - optional in addition to E_PREFIX to provide\n"
|
|
|
|
" a more specific binary directory\n"
|
|
|
|
" E_LIB_DIR - optional in addition to E_PREFIX to provide\n"
|
|
|
|
" a more specific library dir\n"
|
|
|
|
" E_DATA_DIR - optional in addition to E_PREFIX to provide\n"
|
|
|
|
" a more specific location for shared data\n"
|
|
|
|
" E_LOCALE_DIR - optional in addition to E_PREFIX to provide\n"
|
|
|
|
" a more specific location for locale data\n"
|
|
|
|
,
|
|
|
|
_prefix_path);
|
2005-08-10 21:33:46 -07:00
|
|
|
return 1;
|
2005-07-30 23:22:31 -07:00
|
|
|
}
|
|
|
|
|
2005-05-19 02:23:54 -07:00
|
|
|
static int
|
|
|
|
_e_prefix_try_proc(void)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[4096];
|
|
|
|
void *func = NULL;
|
|
|
|
|
|
|
|
func = (void *)_e_prefix_try_proc;
|
|
|
|
f = fopen("/proc/self/maps", "r");
|
|
|
|
if (!f) return 0;
|
|
|
|
while (fgets(buf, sizeof(buf), f))
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *p, mode[5] = "";
|
|
|
|
unsigned long ptr1 = 0, ptr2 = 0;
|
|
|
|
|
|
|
|
len = strlen(buf);
|
|
|
|
if (buf[len - 1] == '\n')
|
|
|
|
{
|
|
|
|
buf[len - 1] = 0;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
if (sscanf(buf, "%lx-%lx %4s", &ptr1, &ptr2, mode) == 3)
|
|
|
|
{
|
|
|
|
if (!strcmp(mode, "r-xp"))
|
|
|
|
{
|
|
|
|
if (((void *)ptr1 <= func) && (func < (void *)ptr2))
|
|
|
|
{
|
|
|
|
p = strchr(buf, '/');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
if (len > 10)
|
|
|
|
{
|
|
|
|
if (!strcmp(buf + len - 10, " (deleted)"))
|
|
|
|
buf[len - 10] = 0;
|
|
|
|
}
|
|
|
|
_exe_path = strdup(p);
|
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_e_prefix_try_argv(char *argv0)
|
|
|
|
{
|
|
|
|
char *path, *p, *cp, *s;
|
|
|
|
int len, lenexe;
|
|
|
|
char buf[4096], buf2[4096], buf3[4096];
|
|
|
|
|
|
|
|
/* 1. is argv0 abs path? */
|
|
|
|
if (argv0[0] == '/')
|
|
|
|
{
|
|
|
|
_exe_path = strdup(argv0);
|
|
|
|
if (access(_exe_path, X_OK) == 0) return 1;
|
|
|
|
free(_exe_path);
|
|
|
|
_exe_path = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* 2. relative path */
|
|
|
|
if (strchr(argv0, '/'))
|
|
|
|
{
|
|
|
|
if (getcwd(buf3, sizeof(buf3)))
|
|
|
|
{
|
|
|
|
snprintf(buf2, sizeof(buf2), "%s/%s", buf3, argv0);
|
|
|
|
if (realpath(buf2, buf))
|
|
|
|
{
|
|
|
|
_exe_path = strdup(buf);
|
|
|
|
if (access(_exe_path, X_OK) == 0) return 1;
|
|
|
|
free(_exe_path);
|
|
|
|
_exe_path = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 3. argv0 no path - look in PATH */
|
|
|
|
path = getenv("PATH");
|
|
|
|
if (!path) return 0;
|
|
|
|
p = path;
|
|
|
|
cp = p;
|
|
|
|
lenexe = strlen(argv0);
|
2005-05-28 02:57:26 -07:00
|
|
|
while ((p = strchr(cp, ':')))
|
2005-05-19 02:23:54 -07:00
|
|
|
{
|
|
|
|
len = p - cp;
|
|
|
|
s = malloc(len + 1 + lenexe + 1);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
strncpy(s, cp, len);
|
|
|
|
s[len] = '/';
|
|
|
|
strcpy(s + len + 1, argv0);
|
|
|
|
if (realpath(s, buf))
|
|
|
|
{
|
|
|
|
if (access(buf, X_OK) == 0)
|
|
|
|
{
|
|
|
|
_exe_path = strdup(buf);
|
|
|
|
free(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
cp = p + 1;
|
|
|
|
}
|
|
|
|
len = strlen(cp);
|
|
|
|
s = malloc(len + 1 + lenexe + 1);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
strncpy(s, cp, len);
|
|
|
|
s[len] = '/';
|
|
|
|
strcpy(s + len + 1, argv0);
|
|
|
|
if (realpath(s, buf))
|
|
|
|
{
|
|
|
|
if (access(buf, X_OK) == 0)
|
|
|
|
{
|
|
|
|
_exe_path = strdup(buf);
|
|
|
|
free(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
/* 4. big problems. arg[0] != executable - weird execution */
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-13 07:56:38 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|