summaryrefslogtreecommitdiff
blob: d36d2a5607c9912fa20f9737d33dde3987439c1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--- src/comp/gbi.c.org	2003-10-27 21:51:41.000000000 +0100
+++ src/comp/gbi.c	2003-11-17 23:41:29.000000000 +0100
@@ -54,6 +54,34 @@
 #include "str.h"
 #include "gambas.h"
 
+/* needed to install in a different location than /usr */
+char *which(const char *app)
+{
+	char *path = NULL;
+	char *p = NULL;
+	char *rValue = NULL;
+		
+	path = getenv("PATH");
+	if (!path) {
+		path = "/usr/bin/";
+	}
+	p = strtok(strdup(path), ":");
+	while (p) {
+		rValue = (char *)calloc(sizeof(char), strlen(p)+strlen(app)+2);
+		strcat(rValue, p);
+		rValue[strlen(p)] = '/';
+		strcat(rValue, app);
+		rValue[strlen(p)+1+strlen(app)] = '\0';
+		if (access(rValue, X_OK) == 0) {
+			return rValue;
+		}
+		p = strtok(NULL, ":");
+		free(rValue);
+		rValue = NULL;
+	}
+	return NULL;
+}
+																														
 
 PRIVATE char _lib_path[MAX_PATH + 1];
 PRIVATE FILE *out;
@@ -102,7 +129,7 @@
 
   /* chemin d'installation de Gambas */
 
-  path = FILE_readlink(GAMBAS_LINK_PATH);
+  path = which("gbx");
   if (!path)
   {
     path = GAMBAS_LINK_PATH;
@@ -422,7 +450,7 @@
   if (strcmp(name, "gb") == 0)
   {
     sprintf(path, LIB_PATTERN, _lib_path, name);
-    dlib = dlopen("/usr/bin/gbx", RTLD_NOW);
+    dlib = dlopen(which("gbx"), RTLD_NOW);
     if (!dlib)
       error2("Cannot open component:", dlerror());
 
@@ -472,7 +500,7 @@
   sprintf(buf, "LD_PRELOAD=%s", lib);
   putenv(buf);
   putenv("GAMBAS_PRELOAD=1");
-  execv("/usr/bin/gbi", argv);
+  execvp("gbi", argv);
 #endif
 }