aboutsummaryrefslogtreecommitdiffstats
path: root/mcgoron/guix/patches/foment-0.4.1-library-path.patch
blob: 72312d7aa9e7ddc9c97e2fb860efc95292ec8afb (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
diff --git a/src/foment.cpp b/src/foment.cpp
index bafb058..7535a03 100644
--- a/src/foment.cpp
+++ b/src/foment.cpp
@@ -1402,6 +1402,57 @@ FObjectType ObjectTypes[] =
     {FreeTag, "free", 0, 0}
 };
 
+void PrependPath(const char *EnvarName)
+{
+    FObject lp = Assoc(MakeStringC(EnvarName), EnvironmentVariables);
+    if (PairP(lp))
+    {
+        FAssert(StringP(First(lp)));
+
+        lp = Rest(lp);
+
+        ulong_t strt = 0;
+        ulong_t idx = 0;
+        FObject InsertionPoint = LibraryPath;
+        while (InsertionPoint != EmptyListObject &&
+               Rest(InsertionPoint) != EmptyListObject) {
+            InsertionPoint = Rest(InsertionPoint);
+        }
+
+        while (idx < StringLength(lp))
+        {
+            if (AsString(lp)->String[idx] == PathSep)
+            {
+                if (idx > strt) {
+                    FObject str = MakeString(AsString(lp)->String + strt, idx - strt);
+                    if (InsertionPoint == EmptyListObject) {
+                        InsertionPoint = List(str);
+                    } else {
+                        SetRest(InsertionPoint, List(str));
+                        InsertionPoint = Rest(InsertionPoint);
+                    }
+                }
+
+                idx += 1;
+                strt = idx;
+            }
+
+            idx += 1;
+        }
+
+        if (idx > strt) {
+            FObject str = MakeString(AsString(lp)->String + strt, idx - strt);
+
+            if (InsertionPoint == EmptyListObject) {
+                InsertionPoint = List(str);
+            } else {
+                SetRest(InsertionPoint, List(str));
+                InsertionPoint = Rest(InsertionPoint);
+            }
+        }
+    }
+}
+
 long_t SetupFoment(FThreadState * ts)
 {
 #ifdef FOMENT_WINDOWS
@@ -1548,35 +1599,6 @@ long_t SetupFoment(FThreadState * ts)
 
     GetEnvironmentVariables();
 
-    FObject lp = Assoc(MakeStringC("FOMENT_LIBPATH"), EnvironmentVariables);
-    if (PairP(lp))
-    {
-        FAssert(StringP(First(lp)));
-
-        lp = Rest(lp);
-
-        ulong_t strt = 0;
-        ulong_t idx = 0;
-        while (idx < StringLength(lp))
-        {
-            if (AsString(lp)->String[idx] == PathSep)
-            {
-                if (idx > strt)
-                    LibraryPath = MakePair(
-                            MakeString(AsString(lp)->String + strt, idx - strt), LibraryPath);
-
-                idx += 1;
-                strt = idx;
-            }
-
-            idx += 1;
-        }
-
-        if (idx > strt)
-            LibraryPath = MakePair(
-                    MakeString(AsString(lp)->String + strt, idx - strt), LibraryPath);
-    }
-
     LibraryExtensions = List(MakeStringC("sld"), MakeStringC("scm"));
 
     if (CheckHeapFlag)
diff --git a/src/foment.hpp b/src/foment.hpp
index 745d5e4..22df578 100644
--- a/src/foment.hpp
+++ b/src/foment.hpp
@@ -1904,4 +1904,8 @@ inline long_t PathChP(FCh ch)
 }
 #endif // FOMENT_WINDOWS
 
+// Misc
+
+void PrependPath(const char *EnvarName);
+
 #endif // __FOMENT_HPP__
diff --git a/src/main.cpp b/src/main.cpp
index f333d47..da6ebd5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -873,7 +873,10 @@ int main(int argc, FChS * argv[])
             AddToLibraryPath(argv[pdx]);
         else if (RunMode == InteractiveMode)
             LibraryPath = ReverseListModify(MakePair(MakeStringC("."), LibraryPath));
+
         LibraryPathOptions();
+	PrependPath("FOMENT_LIBPATH");
+	PrependPath("R7RS_LIBRARY_PATH");
 
         if (ShowVersion != 0)
         {