Skip to content

Commit 3e11b6b

Browse files
committed
WIP
1 parent 226a20d commit 3e11b6b

File tree

3 files changed

+83
-90
lines changed

3 files changed

+83
-90
lines changed

src/gap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,8 @@ static Int InitKernel (
13351335
InitGlobalBag( &WindowCmdString, "src/gap.c:WindowCmdString" );
13361336
InitGlobalBag( &KernelArgs, "src/gap.c:KernelArgs" );
13371337

1338+
InitGlobalBag( &SyGapRootPaths, "src/gap.c:SyGapRootPaths" ); // FIXME
1339+
13381340
// init filters and functions
13391341
InitHdlrFuncsFromTable( GVarFuncs );
13401342

src/sysroots.c

Lines changed: 63 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "sysroots.h"
1313

1414
#include "gaputils.h"
15+
#include "listfunc.h"
1516
#include "plist.h"
1617
#include "stringobj.h"
1718
#include "sysfiles.h"
@@ -47,8 +48,7 @@ char SyDefaultRootPath[GAP_PATH_MAX] = "./";
4748
** name of a library file 'strcat( SyGapRootPaths[i], "lib/init.g" );' must
4849
** be a valid filename.
4950
*/
50-
enum { MAX_GAP_DIRS = 16 };
51-
static Char SyGapRootPaths[MAX_GAP_DIRS][GAP_PATH_MAX];
51+
Obj SyGapRootPaths;
5252

5353

5454
/****************************************************************************
@@ -62,13 +62,12 @@ static Char SyGapRootPaths[MAX_GAP_DIRS][GAP_PATH_MAX];
6262
Obj SyFindGapRootFile(const Char * filename)
6363
{
6464
int len = strlen(filename);
65-
for (int k = 0; k < ARRAY_SIZE(SyGapRootPaths); k++) {
66-
if (SyGapRootPaths[k][0]) {
67-
Obj path = MakeString(SyGapRootPaths[k]);
68-
AppendCStr(path, filename, len);
69-
if (SyIsReadableFile(CSTR_STRING(path)) == 0) {
70-
return path;
71-
}
65+
int npaths = LEN_PLIST(SyGapRootPaths);
66+
for (int k = 1; k <= npaths; k++) {
67+
Obj path = CopyToStringRep(ELM_PLIST(SyGapRootPaths, k));
68+
AppendCStr(path, filename, len);
69+
if (SyIsReadableFile(CSTR_STRING(path)) == 0) {
70+
return path;
7271
}
7372
}
7473
return 0;
@@ -95,10 +94,12 @@ Obj SyFindGapRootFile(const Char * filename)
9594
*/
9695
void SySetGapRootPath(const Char * string)
9796
{
98-
const Char * p;
99-
Char * q;
100-
Int i;
101-
Int n;
97+
Int pos = 1;
98+
99+
if (SyGapRootPaths == 0) {
100+
SyGapRootPaths = NEW_PLIST(T_PLIST_EMPTY, 0); // FIXME
101+
}
102+
102103

103104
// set string to a default value if unset
104105
if (string == 0 || *string == 0) {
@@ -107,94 +108,73 @@ void SySetGapRootPath(const Char * string)
107108

108109
// check if we append, prepend or overwrite.
109110
if (string[0] == ';') {
110-
// Count the number of root directories already present.
111-
n = 0;
112-
while (SyGapRootPaths[n][0] != '\0')
113-
n++;
111+
// append
112+
pos = LEN_PLIST(SyGapRootPaths) + 1;
114113

115114
// Skip leading semicolon.
116115
string++;
117116
}
118117
else if (string[strlen(string) - 1] == ';') {
119-
// Count the number of directories in 'string'.
120-
n = 0;
121-
p = string;
122-
while (*p)
123-
if (*p++ == ';')
124-
n++;
125-
126-
// Find last root path.
127-
for (i = 0; i < MAX_GAP_DIRS; i++)
128-
if (SyGapRootPaths[i][0] == '\0')
129-
break;
130-
i--;
131-
132-
#ifdef HPCGAP
133-
n *= 2; // for each root <ROOT> we also add <ROOT/hpcgap> as a root
134-
#endif
135-
136-
// Move existing root paths to the back
137-
if (i + n >= MAX_GAP_DIRS)
138-
return;
139-
while (i >= 0) {
140-
memcpy(SyGapRootPaths[i + n], SyGapRootPaths[i],
141-
sizeof(SyGapRootPaths[i + n]));
142-
i--;
143-
}
144-
145-
n = 0;
118+
// prepend
146119
}
147120
else {
148-
// Make sure to wipe out all possibly existing root paths
149-
for (i = 0; i < MAX_GAP_DIRS; i++)
150-
SyGapRootPaths[i][0] = '\0';
151-
n = 0;
121+
SET_LEN_PLIST(SyGapRootPaths, 0);
122+
RetypeBagSM(SyGapRootPaths, T_PLIST_EMPTY);
123+
// TODO: also adjust filters...
152124
}
153125

154126
// unpack the argument
155-
p = string;
127+
const Char * p = string;
156128
while (*p) {
157-
if (n >= MAX_GAP_DIRS)
158-
return;
159-
160-
q = SyGapRootPaths[n];
161-
while (*p && *p != ';') {
162-
*q = *p++;
163-
164-
#ifdef SYS_IS_CYGWIN32
165-
// change backslash to slash for Windows
166-
if (*q == '\\')
167-
*q = '/';
168-
#endif
129+
Obj path;
169130

131+
// locate next semicolon or string end
132+
const Char * q = p;
133+
while (*q && *q != ';') {
170134
q++;
171135
}
172-
if (q == SyGapRootPaths[n]) {
173-
strxcpy(SyGapRootPaths[n], "./", sizeof(SyGapRootPaths[n]));
174-
}
175-
else if (q[-1] != '/') {
176-
*q++ = '/';
177-
*q = '\0';
178-
}
179-
else {
180-
*q = '\0';
181-
}
182-
if (*p) {
183-
p++;
136+
137+
if (q == p) {
138+
// empty string treated as ./
139+
path = MakeString("./");
140+
} else {
141+
path = MakeStringWithLen(p, q - p);
142+
143+
Char * r = CSTR_STRING(path);
144+
#ifdef SYS_IS_CYGWIN32
145+
while (*r) {
146+
// change backslash to slash for Windows
147+
if (*r == '\\')
148+
*r = '/';
149+
r++;
150+
}
151+
#endif
152+
153+
// ensure path ends with a slash
154+
r = CSTR_STRING(path) + GET_LEN_STRING(path) - 1;
155+
if (*r != '/') {
156+
AppendCStr(path, "/", 1);
157+
}
184158
}
185-
n++;
159+
160+
p = *q ? q + 1 : q;
161+
162+
AddPlist3(SyGapRootPaths, path, pos);
163+
pos++;
164+
186165
#ifdef HPCGAP
187166
// for each root <ROOT> to be added, we first add <ROOT/hpcgap> as a root
188-
if (n < MAX_GAP_DIRS) {
189-
gap_strlcpy(SyGapRootPaths[n], SyGapRootPaths[n - 1],
190-
sizeof(SyGapRootPaths[n]));
191-
}
192-
strxcat(SyGapRootPaths[n - 1], "hpcgap/",
193-
sizeof(SyGapRootPaths[n - 1]));
194-
n++;
167+
path = CopyToStringRep(path);
168+
AppendCStr(path, "hpcgap/", 7);
169+
170+
AddPlist3(SyGapRootPaths, path, pos);
171+
pos++;
195172
#endif
196173
}
197174

175+
#if 0
176+
// TODO: add this code back in
177+
198178
// replace leading tilde ~ by HOME environment variable
199179
// TODO; instead of iterating over all entries each time, just
200180
// do this for the new entries
@@ -212,6 +192,7 @@ void SySetGapRootPath(const Char * string)
212192
memcpy(SyGapRootPaths[i], userhome, userhomelen);
213193
}
214194
}
195+
#endif
215196
}
216197

217198

@@ -221,12 +202,5 @@ void SySetGapRootPath(const Char * string)
221202
*/
222203
Obj SyGetGapRootPaths(void)
223204
{
224-
Obj tmp = NEW_PLIST_IMM(T_PLIST, MAX_GAP_DIRS);
225-
for (int i = 0; i < MAX_GAP_DIRS; i++) {
226-
if (SyGapRootPaths[i][0]) {
227-
PushPlist(tmp, MakeImmString(SyGapRootPaths[i]));
228-
}
229-
}
230-
MakeImmutableNoRecurse(tmp);
231-
return tmp;
205+
return SyGapRootPaths;
232206
}

src/sysroots.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,24 @@
2525
*/
2626
extern char SyDefaultRootPath[GAP_PATH_MAX];
2727

28-
#include <stddef.h>
28+
29+
/****************************************************************************
30+
**
31+
*V SyGapRootPaths . . . . . . . . . . . . . . . . . . . array of root paths
32+
**
33+
** 'SyGapRootPaths' contains the names of the directories where the GAP
34+
** files are located.
35+
**
36+
** It is modified by the command line option -l.
37+
**
38+
** It is copied into the GAP variable 'GAPInfo.RootPaths' and used by
39+
** 'SyFindGapRootFile'.
40+
**
41+
** Each entry must end with the pathname separator, e.g. if 'init.g' is the
42+
** name of a library file 'strcat( SyGapRootPaths[i], "lib/init.g" );' must
43+
** be a valid filename.
44+
*/
45+
extern Obj SyGapRootPaths;
2946

3047

3148
/****************************************************************************

0 commit comments

Comments
 (0)