This commit is contained in:
Vitor Santos Costa 2018-02-14 10:37:07 +00:00
parent 311e1d697d
commit 76d0d54a34
4 changed files with 146 additions and 141 deletions

View File

@ -20,8 +20,8 @@
#include "YapHeap.h" #include "YapHeap.h"
#include "YapInterface.h" #include "YapInterface.h"
#include "YapStreams.h" #include "YapStreams.h"
#include "iopreds.h"
#include "config.h" #include "config.h"
#include "iopreds.h"
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
@ -247,7 +247,9 @@ typedef struct config {
#if __ANDROID__ #if __ANDROID__
const char *gd_root[] = {"@RootDir", "/assets"}; 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_share[] = {"@ShareDir", "(root)"};
const char *gd_include[] = {"@IncludeDir", "[include]", "(root)/include"}; const char *gd_include[] = {"@IncludeDir", "[include]", "(root)/include"};
const char *gd_dll[] = {"@DLLDir", "(lib)"}; const char *gd_dll[] = {"@DLLDir", "(lib)"};
@ -457,10 +459,8 @@ static const char *find_directory(YAP_init_args *iap, const char *paths[],
char *out = Malloc(YAP_FILENAME_MAX + 1); char *out = Malloc(YAP_FILENAME_MAX + 1);
const char *inp; const char *inp;
if (filename) { if (filename) {
strcpy(out, filename); if (Yap_IsAbsolutePath(filename, true)) {
if (Yap_IsAbsolutePath(out, true)) { return pop_output_text_stack(lvl, filename);
out = pop_output_text_stack(lvl, out);
return out;
} }
} }
int i = 0; int i = 0;
@ -469,10 +469,11 @@ static const char *find_directory(YAP_init_args *iap, const char *paths[],
if (filename && o) { if (filename && o) {
strcat(o, "/"); strcat(o, "/");
strcat(o, filename); strcat(o, filename);
if (o =(const char *) Yap_AbsoluteFile(o, false)) { if ((o = Yap_AbsoluteFile(o, false))) {
o = pop_output_text_stack(lvl, o); return pop_output_text_stack(lvl, o);
return o;
} }
} else if (o && Yap_isDirectory(o)) {
return pop_output_text_stack(lvl, o);
} }
} }
pop_text_stack(lvl); pop_text_stack(lvl);
@ -494,8 +495,12 @@ static void Yap_set_locations(YAP_init_args *iap) {
iap->PrologBootFile = "boot.yap"; 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); 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"; iap->SavedState = "startup.yss";
}
Yap_STARTUP = find_directory(iap, template->ss, iap->SavedState); Yap_STARTUP = find_directory(iap, template->ss, iap->SavedState);
if (iap->OutputSavedState == NULL) if (iap->OutputSavedState == NULL)
iap->OutputSavedState = "startup.yss"; iap->OutputSavedState = "startup.yss";

View File

@ -385,8 +385,7 @@ while (o-- > o0) {
return o; return o;
} }
static char * clean_path(const char *path) static char *clean_path(const char *path) {
{
const char *p, *p0; const char *p, *p0;
int lvl = push_text_stack(); int lvl = push_text_stack();
@ -415,9 +414,9 @@ static char * clean_path(const char *path)
if (o == o0) if (o == o0)
*o++ = '/'; *o++ = '/';
*o = '\0'; *o = '\0';
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " %s at %s, %p-%p", p0, o0, o, o0) ; __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " %s at %s, %p-%p", p0, o0,
o, o0);
return pop_output_text_stack(lvl, o0); return pop_output_text_stack(lvl, o0);
} }
static const char *myrealpath(const char *path USES_REGS) { static const char *myrealpath(const char *path USES_REGS) {
@ -427,11 +426,8 @@ static const char *myrealpath(const char *path USES_REGS) {
char *out, *o; char *out, *o;
if (Yap_IsAbsolutePath(path, true)) { if (Yap_IsAbsolutePath(path, true)) {
o = clean_path(path); o = clean_path(path);
if ((v = vfs_owner(o))
) {
return pop_output_text_stack(lvl, o); return pop_output_text_stack(lvl, o);
}
} else { } else {
out = Malloc(FILENAME_MAX + 1); out = Malloc(FILENAME_MAX + 1);
Yap_getcwd(out, FILENAME_MAX); Yap_getcwd(out, FILENAME_MAX);
@ -458,24 +454,29 @@ char *out, *o;
char *rc = realpath(path, o); char *rc = realpath(path, o);
if (rc) { if (rc) {
rc = pop_output_text_stack(lvl, rc); return pop_output_text_stack(lvl, rc);
} }
// rc = NULL; // rc = NULL;
if (errno == ENOENT || errno == EACCES) { if (errno == ENOENT || errno == EACCES) {
char *base = Malloc(FILENAME_MAX + 1); char *base = Malloc(FILENAME_MAX + 1);
strncpy(base, path, FILENAME_MAX); strncpy(base, path, FILENAME_MAX);
char *p = base + strlen(base); char *p = base + strlen(base);
while (p>base && !dir_separator(*--p)); while (p > base && !dir_separator(*--p))
if (p == base) p[1] = '\0'; ;
else p[0] = '\0'; if (p == base)
p[1] = '\0';
else
p[0] = '\0';
char *tmp = Malloc(FILENAME_MAX + 1); char *tmp = Malloc(FILENAME_MAX + 1);
rc = realpath(base, tmp); rc = realpath(base, tmp);
if (rc) { if (rc) {
// base may have been destroyed // base may have been destroyed
char *b = base + strlen(base); char *b = base + strlen(base);
while (b>base && !dir_separator(*--b)); while (b > base && !dir_separator(*--b))
if (b[0] && !dir_separator(b[0])) b++; ;
if (b[0] && !dir_separator(b[0]))
b++;
size_t e = strlen(rc); size_t e = strlen(rc);
size_t bs = strlen(b); size_t bs = strlen(b);
@ -1227,8 +1228,7 @@ static Int true_file_name3(USES_REGS1) {
int lvl = push_text_stack(); int lvl = push_text_stack();
const char *tmp = Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, true); const char *tmp = Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, true);
Atom at = NULL; Atom at = NULL;
bool rc = (tmp != NULL && bool rc = (tmp != NULL && (at = Yap_LookupAtom(tmp)) != NULL);
(at = Yap_LookupAtom(tmp)) != NULL);
pop_text_stack(lvl); pop_text_stack(lvl);
return rc && Yap_unify(ARG3, MkAtomTerm(at)); return rc && Yap_unify(ARG3, MkAtomTerm(at));
} }

View File

@ -193,7 +193,7 @@ considered.
'$exec_directive'(use_module(F, Is), _, M, _, _) :- '$exec_directive'(use_module(F, Is), _, M, _, _) :-
use_module(M:F, Is). use_module(M:F, Is).
'$exec_directive'(use_module(Mod,F,Is), _, _, _, _) :- '$exec_directive'(use_module(Mod,F,Is), _, _, _, _) :-
'$use_module'(Mod,F,Is). use_module(Mod,F,Is).
'$exec_directive'(block(BlockSpec), _, _, _, _) :- '$exec_directive'(block(BlockSpec), _, _, _, _) :-
'$block'(BlockSpec). '$block'(BlockSpec).
'$exec_directive'(wait(BlockSpec), _, _, _, _) :- '$exec_directive'(wait(BlockSpec), _, _, _, _) :-