diff --git a/src/bin/e.h b/src/bin/e.h index ac1dfbc39..58b7d48f9 100644 --- a/src/bin/e.h +++ b/src/bin/e.h @@ -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; diff --git a/src/bin/e_main.c b/src/bin/e_main.c index faca26b15..755ff866e 100644 --- a/src/bin/e_main.c +++ b/src/bin/e_main.c @@ -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; } diff --git a/src/bin/e_path.c b/src/bin/e_path.c index b67eea3fe..e3a16d280 100644 --- a/src/bin/e_path.c +++ b/src/bin/e_path.c @@ -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; diff --git a/src/bin/e_path.h b/src/bin/e_path.h index a2a1a6f77..d3ac9c535 100644 --- a/src/bin/e_path.h +++ b/src/bin/e_path.h @@ -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 */ diff --git a/src/bin/e_utils.c b/src/bin/e_utils.c index cf60076e0..fe30de475 100644 --- a/src/bin/e_utils.c +++ b/src/bin/e_utils.c @@ -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; }