Add a path for the PATH environment, then use it to fix the ugly system(which...) hack
SVN revision: 15161
This commit is contained in:
parent
d5f8d839ee
commit
ef23779c2b
|
@ -103,6 +103,7 @@ extern EAPI E_Path *path_icons;
|
|||
extern EAPI E_Path *path_init;
|
||||
extern EAPI E_Path *path_modules;
|
||||
extern EAPI E_Path *path_backgrounds;
|
||||
extern EAPI E_Path *path_bin;
|
||||
extern EAPI int restart;
|
||||
extern EAPI int good;
|
||||
extern EAPI int evil;
|
||||
|
|
|
@ -35,6 +35,7 @@ E_Path *path_init = NULL;
|
|||
E_Path *path_icons = NULL;
|
||||
E_Path *path_modules = NULL;
|
||||
E_Path *path_backgrounds = NULL;
|
||||
E_Path *path_bin = NULL;
|
||||
int restart = 0;
|
||||
int good = 0;
|
||||
int evil = 0;
|
||||
|
@ -786,6 +787,14 @@ _e_main_path_init(void)
|
|||
e_path_default_path_append(path_backgrounds, "~/.e/e/backgrounds");
|
||||
e_path_user_path_set(path_backgrounds, &(e_config->path_append_backgrounds));
|
||||
|
||||
/* setup PATH path */
|
||||
path_bin = e_path_from_env("PATH");
|
||||
if (!path_bin)
|
||||
{
|
||||
e_error_message_show("Cannot allocate path for path_bin\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,40 @@ e_path_new(void)
|
|||
return ep;
|
||||
}
|
||||
|
||||
E_Path *
|
||||
e_path_from_env(char *env)
|
||||
{
|
||||
E_Path *ep;
|
||||
char *env_path, *p, *last;
|
||||
|
||||
ep = e_path_new();
|
||||
env_path = getenv(env);
|
||||
|
||||
if (!env_path)
|
||||
return ep;
|
||||
printf("need to add all parts of %s\n", env_path);
|
||||
|
||||
env_path = strdup(env_path);
|
||||
last = env_path;
|
||||
for (p = env_path; *p; p++)
|
||||
{
|
||||
if (*p == ':')
|
||||
*p = '\0';
|
||||
|
||||
if (!*p)
|
||||
{
|
||||
e_path_default_path_append(ep, last);
|
||||
last = p+1;
|
||||
}
|
||||
|
||||
}
|
||||
if (p > last)
|
||||
e_path_default_path_append(ep, last);
|
||||
|
||||
free(env_path);
|
||||
return ep;
|
||||
}
|
||||
|
||||
void
|
||||
e_path_default_path_append(E_Path *ep, const char *path)
|
||||
{
|
||||
|
@ -352,12 +386,16 @@ e_path_dir_list_get(E_Path *ep)
|
|||
new_epd->dir = strdup(epd->dir);
|
||||
dir_list = evas_list_append(dir_list, new_epd);
|
||||
}
|
||||
for (l = *(ep->user_dir_list); l; l = l->next)
|
||||
|
||||
if (ep->user_dir_list)
|
||||
{
|
||||
epd = l->data;
|
||||
new_epd = malloc(sizeof(E_Path_Dir));
|
||||
new_epd->dir = strdup(epd->dir);
|
||||
dir_list = evas_list_append(dir_list, new_epd);
|
||||
for (l = *(ep->user_dir_list); l; l = l->next)
|
||||
{
|
||||
epd = l->data;
|
||||
new_epd = malloc(sizeof(E_Path_Dir));
|
||||
new_epd->dir = strdup(epd->dir);
|
||||
dir_list = evas_list_append(dir_list, new_epd);
|
||||
}
|
||||
}
|
||||
|
||||
return dir_list;
|
||||
|
|
|
@ -30,6 +30,7 @@ struct _E_Path
|
|||
|
||||
/* init and setup */
|
||||
EAPI E_Path *e_path_new(void);
|
||||
EAPI E_Path *e_path_from_env(char *env);
|
||||
EAPI void e_path_user_path_set(E_Path *ep, Evas_List **user_dir_list);
|
||||
EAPI void e_path_inherit_path_set(E_Path *ep, E_Path *path_inherit);
|
||||
/* append a hardcoded path */
|
||||
|
|
|
@ -123,19 +123,29 @@ e_util_utils_installed(void)
|
|||
int
|
||||
e_util_app_installed(char *app)
|
||||
{
|
||||
char *cmd, *tmp;
|
||||
int ret, len;
|
||||
char buf[PATH_MAX];
|
||||
Evas_List *list, *l;
|
||||
E_Path_Dir *dir;
|
||||
int found;
|
||||
|
||||
if (!app)
|
||||
return 0;
|
||||
|
||||
cmd = "which %s > /dev/null 2>&1";
|
||||
len = strlen(cmd) + strlen(app) - 1; // -1 is -2 for "%s" and +1 for "\0"
|
||||
tmp = malloc(len);
|
||||
snprintf(tmp, len, cmd, app);
|
||||
found = 0;
|
||||
list = e_path_dir_list_get(path_bin);
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
dir = l->data;
|
||||
snprintf(buf, strlen(dir->dir) + strlen(app) + 2, "%s/%s", dir->dir,
|
||||
app); // 2 = "/" + "\0"
|
||||
if (ecore_file_exists(buf) && ecore_file_can_exec(buf))
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = system(tmp);
|
||||
free(tmp);
|
||||
return (ret == 0);
|
||||
e_path_dir_list_free(list);
|
||||
return found;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue