Enlightenment CVS committal

Author  : handyande
Project : e17
Module  : apps/e

Dir     : e17/apps/e/src/bin


Modified Files:
        e.h e_main.c e_path.c e_path.h e_utils.c 


Log Message:
Add a path for the PATH environment, then use it to fix the ugly 
system(which...) hack
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- e.h 2 Jun 2005 21:55:11 -0000       1.20
+++ e.h 6 Jun 2005 10:37:15 -0000       1.21
@@ -103,6 +103,7 @@
 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;
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_main.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -3 -r1.92 -r1.93
--- e_main.c    6 Jun 2005 03:00:09 -0000       1.92
+++ e_main.c    6 Jun 2005 10:37:15 -0000       1.93
@@ -35,6 +35,7 @@
 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_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;
 }
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_path.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- e_path.c    25 May 2005 08:08:44 -0000      1.11
+++ e_path.c    6 Jun 2005 10:37:15 -0000       1.12
@@ -18,6 +18,40 @@
    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 @@
        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;
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_path.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- e_path.h    20 May 2005 03:09:44 -0000      1.7
+++ e_path.h    6 Jun 2005 10:37:15 -0000       1.8
@@ -30,6 +30,7 @@
 
 /* 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 */
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_utils.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- e_utils.c   5 Jun 2005 15:02:42 -0000       1.8
+++ e_utils.c   6 Jun 2005 10:37:15 -0000       1.9
@@ -123,19 +123,29 @@
 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;
 }
 




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to