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 "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)"};
@ -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);
@ -494,8 +495,12 @@ static void Yap_set_locations(YAP_init_args *iap) {
iap->PrologBootFile = "boot.yap";
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";

View File

@ -385,8 +385,7 @@ while (o-- > o0) {
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();
@ -415,9 +414,9 @@ 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) ;
__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) {
@ -427,11 +426,8 @@ static const char *myrealpath(const char *path USES_REGS) {
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);
Yap_getcwd(out, FILENAME_MAX);
@ -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';
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++;
while (b > base && !dir_separator(*--b))
;
if (b[0] && !dir_separator(b[0]))
b++;
size_t e = strlen(rc);
size_t bs = strlen(b);
@ -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));
}

View File

@ -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), _, _, _, _) :-