boot
This commit is contained in:
parent
311e1d697d
commit
76d0d54a34
31
C/yap-args.c
31
C/yap-args.c
@ -20,8 +20,8 @@
|
||||
#include "YapHeap.h"
|
||||
#include "YapInterface.h"
|
||||
#include "YapStreams.h"
|
||||
#include "iopreds.h"
|
||||
#include "config.h"
|
||||
#include "iopreds.h"
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
|
||||
@ -247,7 +247,9 @@ typedef struct config {
|
||||
|
||||
#if __ANDROID__
|
||||
const char *gd_root[] = {"@RootDir", "/assets"};
|
||||
const char *gd_lib[] = {"@LibDir", "[lib]", "(root)/lib/" "x86"};
|
||||
const char *gd_lib[] = {"@LibDir", "[lib]",
|
||||
"(root)/lib/"
|
||||
"x86"};
|
||||
const char *gd_share[] = {"@ShareDir", "(root)"};
|
||||
const char *gd_include[] = {"@IncludeDir", "[include]", "(root)/include"};
|
||||
const char *gd_dll[] = {"@DLLDir", "(lib)"};
|
||||
@ -256,7 +258,7 @@ const char *gd_commons[] = {"@CommonsDir", "(share)/PrologCommons"};
|
||||
const char *gd_ss[] = {"(dll)"};
|
||||
const char *gd_oss[] = {"."};
|
||||
const char *gd_bootpldir[] = {"@BootPlDir", "@PrologBootFile/..", "(pl)/pl"};
|
||||
const char *gd_bootpl[] = {"(bootpldir)" };
|
||||
const char *gd_bootpl[] = {"(bootpldir)"};
|
||||
#else
|
||||
const char *gd_root[] = {"@RootDir", "[root]", "(execdir)/.."};
|
||||
const char *gd_lib[] = {"@LibDir", "[lib]", "(root)/lib"};
|
||||
@ -294,7 +296,7 @@ char *location(YAP_init_args *iap, const char *inp) {
|
||||
if (inp == NULL || inp[0] == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
char * out = Malloc(FILENAME_MAX+1);
|
||||
char *out = Malloc(FILENAME_MAX + 1);
|
||||
out[0] = '\0';
|
||||
if (inp[0] == '(') {
|
||||
if (strstr(inp + 1, "root") == inp + 1 && Yap_ROOTDIR &&
|
||||
@ -457,10 +459,8 @@ static const char *find_directory(YAP_init_args *iap, const char *paths[],
|
||||
char *out = Malloc(YAP_FILENAME_MAX + 1);
|
||||
const char *inp;
|
||||
if (filename) {
|
||||
strcpy(out, filename);
|
||||
if (Yap_IsAbsolutePath(out, true)) {
|
||||
out = pop_output_text_stack(lvl, out);
|
||||
return out;
|
||||
if (Yap_IsAbsolutePath(filename, true)) {
|
||||
return pop_output_text_stack(lvl, filename);
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
@ -469,10 +469,11 @@ static const char *find_directory(YAP_init_args *iap, const char *paths[],
|
||||
if (filename && o) {
|
||||
strcat(o, "/");
|
||||
strcat(o, filename);
|
||||
if (o =(const char *) Yap_AbsoluteFile(o, false)) {
|
||||
o = pop_output_text_stack(lvl, o);
|
||||
return o;
|
||||
if ((o = Yap_AbsoluteFile(o, false))) {
|
||||
return pop_output_text_stack(lvl, o);
|
||||
}
|
||||
} else if (o && Yap_isDirectory(o)) {
|
||||
return pop_output_text_stack(lvl, o);
|
||||
}
|
||||
}
|
||||
pop_text_stack(lvl);
|
||||
@ -492,10 +493,14 @@ static void Yap_set_locations(YAP_init_args *iap) {
|
||||
Yap_BOOTPLDIR = find_directory(iap, template->bootpldir, NULL);
|
||||
if (iap->PrologBootFile == NULL)
|
||||
iap->PrologBootFile = "boot.yap";
|
||||
Yap_BOOTFILE = find_directory(iap, template->bootpldir,iap->PrologBootFile );
|
||||
Yap_BOOTFILE = find_directory(iap, template->bootpldir, iap->PrologBootFile);
|
||||
Yap_COMMONSDIR = find_directory(iap, template->commons, NULL);
|
||||
if (iap->SavedState == NULL)
|
||||
if (iap->SavedState == NULL) {
|
||||
if (iap->OutputSavedState)
|
||||
iap->SavedState = iap->OutputSavedState;
|
||||
else
|
||||
iap->SavedState = "startup.yss";
|
||||
}
|
||||
Yap_STARTUP = find_directory(iap, template->ss, iap->SavedState);
|
||||
if (iap->OutputSavedState == NULL)
|
||||
iap->OutputSavedState = "startup.yss";
|
||||
|
76
os/sysbits.c
76
os/sysbits.c
@ -165,7 +165,7 @@ static const char *PlExpandVars(const char *source, const char *root) {
|
||||
CACHE_REGS
|
||||
int lvl = push_text_stack();
|
||||
const char *src = source;
|
||||
char * result = Malloc(YAP_FILENAME_MAX + 1);
|
||||
char *result = Malloc(YAP_FILENAME_MAX + 1);
|
||||
|
||||
if (strlen(source) >= YAP_FILENAME_MAX) {
|
||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
||||
@ -366,38 +366,37 @@ bool Yap_ChDir(const char *path) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
static char * close_path(char *b0,char *o0, char *o ){
|
||||
static char *close_path(char *b0, char *o0, char *o) {
|
||||
|
||||
if (b0[0] == '\0') {
|
||||
if (b0[0] == '\0') {
|
||||
return o;
|
||||
} else if (!strcmp(b0, "..")) {
|
||||
while (o-- > o0) {
|
||||
} else if (!strcmp(b0, "..")) {
|
||||
while (o-- > o0) {
|
||||
if (dir_separator(*o)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strcmp(b0, ".") != 0) {
|
||||
} else if (strcmp(b0, ".") != 0) {
|
||||
*o++ = '/';
|
||||
strcpy(o, b0);
|
||||
o += strlen(b0);
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
static char * clean_path(const char *path)
|
||||
{
|
||||
static char *clean_path(const char *path) {
|
||||
const char *p, *p0;
|
||||
int lvl = push_text_stack();
|
||||
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " looking at %s", path) ;
|
||||
char *o0 = Malloc(FILENAME_MAX+1),*o = o0;
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " looking at %s", path);
|
||||
char *o0 = Malloc(FILENAME_MAX + 1), *o = o0;
|
||||
int ch;
|
||||
char *b0 = Malloc(FILENAME_MAX+1), *b = b0;
|
||||
char *b0 = Malloc(FILENAME_MAX + 1), *b = b0;
|
||||
p = p0 = path;
|
||||
while((ch = *p++)) {
|
||||
while ((ch = *p++)) {
|
||||
if (dir_separator(ch)) {
|
||||
if (b==b0) {
|
||||
if (b == b0) {
|
||||
o = o0;
|
||||
} else {
|
||||
b[0] = '\0';
|
||||
@ -415,25 +414,22 @@ static char * clean_path(const char *path)
|
||||
if (o == o0)
|
||||
*o++ = '/';
|
||||
*o = '\0';
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " %s at %s, %p-%p", p0, o0, o, o0) ;
|
||||
return pop_output_text_stack(lvl,o0);
|
||||
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " %s at %s, %p-%p", p0, o0,
|
||||
o, o0);
|
||||
return pop_output_text_stack(lvl, o0);
|
||||
}
|
||||
|
||||
static const char *myrealpath(const char *path USES_REGS) {
|
||||
|
||||
int lvl = push_text_stack();
|
||||
VFS_t *v;
|
||||
char *out, *o;
|
||||
if (Yap_IsAbsolutePath(path,true)) {
|
||||
char *out, *o;
|
||||
if (Yap_IsAbsolutePath(path, true)) {
|
||||
o = clean_path(path);
|
||||
if ((v = vfs_owner(o))
|
||||
) {
|
||||
return pop_output_text_stack(lvl, o);
|
||||
|
||||
}
|
||||
} else {
|
||||
out = Malloc(FILENAME_MAX+1);
|
||||
out = Malloc(FILENAME_MAX + 1);
|
||||
Yap_getcwd(out, FILENAME_MAX);
|
||||
strcat(out, "/");
|
||||
strcat(out, path);
|
||||
@ -441,7 +437,7 @@ char *out, *o;
|
||||
if ((v = vfs_owner(o))) {
|
||||
return pop_output_text_stack(lvl, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if _WIN32
|
||||
DWORD retval = 0;
|
||||
|
||||
@ -458,24 +454,29 @@ char *out, *o;
|
||||
char *rc = realpath(path, o);
|
||||
|
||||
if (rc) {
|
||||
rc = pop_output_text_stack(lvl, rc);
|
||||
return pop_output_text_stack(lvl, rc);
|
||||
}
|
||||
// rc = NULL;
|
||||
if (errno == ENOENT || errno == EACCES) {
|
||||
char *base = Malloc(FILENAME_MAX + 1);
|
||||
strncpy(base, path, FILENAME_MAX);
|
||||
char *p = base+strlen(base);
|
||||
while (p>base && !dir_separator(*--p));
|
||||
if (p == base) p[1] = '\0';
|
||||
else p[0] = '\0';
|
||||
char *p = base + strlen(base);
|
||||
while (p > base && !dir_separator(*--p))
|
||||
;
|
||||
if (p == base)
|
||||
p[1] = '\0';
|
||||
else
|
||||
p[0] = '\0';
|
||||
char *tmp = Malloc(FILENAME_MAX + 1);
|
||||
rc = realpath(base, tmp);
|
||||
|
||||
if (rc) {
|
||||
// base may have been destroyed
|
||||
char *b = base+strlen(base);
|
||||
while (b>base && !dir_separator(*--b));
|
||||
if (b[0] && !dir_separator(b[0])) b++;
|
||||
char *b = base + strlen(base);
|
||||
while (b > base && !dir_separator(*--b))
|
||||
;
|
||||
if (b[0] && !dir_separator(b[0]))
|
||||
b++;
|
||||
size_t e = strlen(rc);
|
||||
size_t bs = strlen(b);
|
||||
|
||||
@ -565,7 +566,7 @@ const char *Yap_AbsoluteFile(const char *spec, bool ok) {
|
||||
spec2 = spec1;
|
||||
}
|
||||
rc = myrealpath(spec2 PASS_REGS);
|
||||
return pop_output_text_stack(lvl,rc);
|
||||
return pop_output_text_stack(lvl, rc);
|
||||
}
|
||||
|
||||
static Term
|
||||
@ -754,13 +755,13 @@ static Int real_path(USES_REGS1) {
|
||||
}
|
||||
cmd = rc;
|
||||
#endif
|
||||
int lvl = push_text_stack();
|
||||
int lvl = push_text_stack();
|
||||
rc0 = myrealpath(cmd PASS_REGS);
|
||||
if (!rc0) {
|
||||
PlIOError(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, NULL);
|
||||
}
|
||||
bool out = Yap_unify(MkAtomTerm(Yap_LookupAtom(rc0)), ARG2);
|
||||
pop_output_text_stack(lvl,rc0);
|
||||
pop_output_text_stack(lvl, rc0);
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -1227,8 +1228,7 @@ static Int true_file_name3(USES_REGS1) {
|
||||
int lvl = push_text_stack();
|
||||
const char *tmp = Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, true);
|
||||
Atom at = NULL;
|
||||
bool rc = (tmp != NULL &&
|
||||
(at = Yap_LookupAtom(tmp)) != NULL);
|
||||
bool rc = (tmp != NULL && (at = Yap_LookupAtom(tmp)) != NULL);
|
||||
pop_text_stack(lvl);
|
||||
return rc && Yap_unify(ARG3, MkAtomTerm(at));
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ considered.
|
||||
'$exec_directive'(use_module(F, Is), _, M, _, _) :-
|
||||
use_module(M:F, Is).
|
||||
'$exec_directive'(use_module(Mod,F,Is), _, _, _, _) :-
|
||||
'$use_module'(Mod,F,Is).
|
||||
use_module(Mod,F,Is).
|
||||
'$exec_directive'(block(BlockSpec), _, _, _, _) :-
|
||||
'$block'(BlockSpec).
|
||||
'$exec_directive'(wait(BlockSpec), _, _, _, _) :-
|
||||
|
@ -83,7 +83,7 @@ trying goal _G_.
|
||||
**/
|
||||
qsave_program(File) :-
|
||||
'$save_program_status'([], qsave_program(File)),
|
||||
open(File, write, S, [type(binary)]),
|
||||
open(File, write, S, [type(binary)]),
|
||||
'$qsave_program'(S),
|
||||
close(S).
|
||||
|
||||
|
Reference in New Issue
Block a user