android
This commit is contained in:
parent
d0418167a1
commit
44be8cf600
@ -2106,45 +2106,42 @@ X_API void YAP_ClearExceptions(void) {
|
|||||||
|
|
||||||
X_API int YAP_InitConsult(int mode, const char *fname, char **full,
|
X_API int YAP_InitConsult(int mode, const char *fname, char **full,
|
||||||
int *osnop) {
|
int *osnop) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
const char *fl = NULL;
|
const char *fl = NULL;
|
||||||
int lvl = push_text_stack();
|
if (mode == YAP_BOOT_MODE) {
|
||||||
if (mode == YAP_BOOT_MODE) {
|
mode = YAP_CONSULT_MODE;
|
||||||
mode = YAP_CONSULT_MODE;
|
|
||||||
}
|
|
||||||
if (fname == NULL || fname[0] == '\0') {
|
|
||||||
fl = Yap_BOOTFILE;
|
|
||||||
}
|
|
||||||
if (fname) {
|
|
||||||
fl = Yap_AbsoluteFile(fname, true);
|
|
||||||
if (!fl || !fl[0]) {
|
|
||||||
pop_text_stack(lvl);
|
|
||||||
*full = NULL;
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
*full = pop_output_text_stack(lvl, fl);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (fname == NULL || fname[0] == '\0') {
|
||||||
pop_text_stack(lvl);
|
fl = Yap_BOOTFILE;
|
||||||
|
}
|
||||||
|
if (!fname || !(fl = Yap_AbsoluteFile(fname, true)) || !fl[0]) {
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "failed ABSOLUTEFN %s ", fl);
|
||||||
|
*full = NULL;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "done init_ consult %s ",fl);
|
||||||
|
|
||||||
lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
char *d = Malloc(strlen(fl) + 1);
|
char *d = Malloc(strlen(fl) + 1);
|
||||||
strcpy(d, fl);
|
strcpy(d, fl);
|
||||||
bool consulted = (mode == YAP_CONSULT_MODE);
|
bool consulted = (mode == YAP_CONSULT_MODE);
|
||||||
Term tat = MkAtomTerm(Yap_LookupAtom(d));
|
Term tat = MkAtomTerm(Yap_LookupAtom(d));
|
||||||
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
|
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
|
||||||
LOCAL_encoding);
|
LOCAL_encoding);
|
||||||
if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "OpenStream got %d ",sno);
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
|
if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
|
||||||
*full = NULL;
|
*full = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
|
*full = pop_output_text_stack__(lvl, fl);
|
||||||
Yap_init_consult(consulted, pop_output_text_stack__(lvl, fl));
|
Yap_init_consult(consulted,*full);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return sno;
|
return sno;
|
||||||
|
262
C/yap-args.c
262
C/yap-args.c
@ -153,22 +153,25 @@ const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
|
|||||||
* recursive consulting.
|
* recursive consulting.
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
static bool consult(const char *b_file USES_REGS) {
|
static bool load_file(const char *b_file USES_REGS) {
|
||||||
Term t;
|
Term t;
|
||||||
int c_stream, osno, oactive;
|
int c_stream, osno, oactive;
|
||||||
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
|
|
||||||
|
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
|
||||||
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
|
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
|
||||||
Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1);
|
Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1);
|
||||||
|
|
||||||
/* consult in C */
|
/* consult in C */
|
||||||
int lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
char *full;
|
char *full;
|
||||||
/* the consult mode does not matter here, really */
|
/* the consult mode does not matter here, really */
|
||||||
if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) {
|
if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) {
|
||||||
osno = 0;
|
osno = 0;
|
||||||
}
|
}
|
||||||
c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, &full, &oactive);
|
c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, &full, &oactive);
|
||||||
if (c_stream < 0) {
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "done init_ consult %s ",b_file);
|
||||||
|
if (c_stream < 0) {
|
||||||
fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file);
|
fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file);
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -177,6 +180,8 @@ static bool consult(const char *b_file USES_REGS) {
|
|||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "do reset %s ",b_file);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -197,7 +202,7 @@ static bool consult(const char *b_file USES_REGS) {
|
|||||||
FunctorOfTerm(t) == functor_command1)) {
|
FunctorOfTerm(t) == functor_command1)) {
|
||||||
t = ArgOfTerm(1, t);
|
t = ArgOfTerm(1, t);
|
||||||
if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) {
|
if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) {
|
||||||
consult(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE);
|
load_file(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE);
|
||||||
Yap_ResetException(LOCAL_ActiveError);
|
Yap_ResetException(LOCAL_ActiveError);
|
||||||
} else {
|
} else {
|
||||||
YAP_RunGoalOnce(t);
|
YAP_RunGoalOnce(t);
|
||||||
@ -221,16 +226,82 @@ static bool consult(const char *b_file USES_REGS) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char * EOLIST ="EOLINE";
|
||||||
|
|
||||||
|
|
||||||
|
static bool is_dir( const char *path, const void *info) {
|
||||||
|
|
||||||
|
if (Yap_isDirectory( path ))
|
||||||
|
return true;
|
||||||
|
char s[YAP_FILENAME_MAX + 1];
|
||||||
|
Int i = strlen(path);
|
||||||
|
strncpy(s, path, YAP_FILENAME_MAX);
|
||||||
|
while (--i) {
|
||||||
|
if (Yap_dir_separator((int)path[i]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 0) {
|
||||||
|
s[0] = '.';
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
s[i] = '\0';
|
||||||
|
return
|
||||||
|
strcmp(info,s) == 0 ||
|
||||||
|
Yap_isDirectory( s );
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_file( const char *path, const void *info) {
|
||||||
|
|
||||||
|
return Yap_Exists( path );
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_wfile( const char *path, const void *info) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef bool testf(const char *s, const void *info);
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
static const char *sel(bool dir, bool ok1, const char *s1, bool ok2,
|
static const char *sel(
|
||||||
const char *s2, ...) {
|
testf test, const void *info, const char *s1, ...) {
|
||||||
if (ok1 && s1)
|
const char *fmt = s1;
|
||||||
return s1;
|
va_list ap;
|
||||||
if (ok2)
|
char *buf = malloc(FILENAME_MAX + 1);
|
||||||
return s2;
|
__android_log_print(
|
||||||
return NULL;
|
ANDROID_LOG_INFO, "YAPDroid", "try %s", s1);
|
||||||
}
|
|
||||||
|
va_start(ap, s1);
|
||||||
|
while (fmt != EOLIST) {
|
||||||
|
__android_log_print( ANDROID_LOG_INFO, "YAPDroid", "loop %s", fmt);
|
||||||
|
|
||||||
|
if (fmt == NULL || fmt[0]=='\0') {
|
||||||
|
fmt = va_arg(ap, const char *);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
strncpy(buf, fmt, FILENAME_MAX); // Yap_AbsoluteFile(fmt,true), FILENAME_MAX);
|
||||||
|
__android_log_print( ANDROID_LOG_INFO, "YAPDroid", "triyimh %s", buf);
|
||||||
|
if (test(buf,info)) {
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "got %s", buf);
|
||||||
|
buf = realloc(buf, strlen(buf) + 1);
|
||||||
|
va_end(ap);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "tried %s, failed", buf);
|
||||||
|
fmt = va_arg(ap, const char *);
|
||||||
|
}
|
||||||
|
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "failed search ");
|
||||||
|
va_end(ap);
|
||||||
|
free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *join(const char *s0, const char *s1) {
|
static const char *join(const char *s0, const char *s1) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -256,103 +327,130 @@ static void Yap_set_locations(YAP_init_args *iap) {
|
|||||||
// --_not useful in Android, WIN32;
|
// --_not useful in Android, WIN32;
|
||||||
/// -- DESTDIR/ in Anaconda
|
/// -- DESTDIR/ in Anaconda
|
||||||
/// -- /usr/locall in most Unix style systems
|
/// -- /usr/locall in most Unix style systems
|
||||||
Yap_ROOTDIR = sel(true, iap->ROOTDIR != NULL, iap->ROOTDIR, true,
|
#if 0
|
||||||
|
Yap_ROOTDIR = sel( is_dir, NULL,
|
||||||
|
iap->ROOTDIR,
|
||||||
|
getenv("YAPROOTDIR"),
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
NULL,
|
"/",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_ROOTDIR),
|
join(getenv("DESTDIR"), YAP_ROOTDIR),
|
||||||
|
join(getenv("DESTDIR"), join(getenv("ḦOME"),".local")),
|
||||||
|
join(getenv("DESTDIR"), "/usr/local"),
|
||||||
|
join(getenv("DESTDIR"), "/usr"),
|
||||||
|
join(getenv("DESTDIR"), "/opt"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST
|
||||||
/// BINDIR: where the OS stores header files, namely libYap...
|
);
|
||||||
Yap_BINDIR = sel(true, iap->BINDIR != NULL, iap->BINDIR, true,
|
|
||||||
#if __ANDROID__
|
/// BINDIR: where the OS stores header files, namely libYap...
|
||||||
NULL,
|
Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR,
|
||||||
#else
|
getenv("YAPBINDIR"),
|
||||||
|
#if !defined(__ANDROID__)
|
||||||
join(getenv("DESTDIR"), YAP_BINDIR),
|
join(getenv("DESTDIR"), YAP_BINDIR),
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/bin"),
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
/// LIBDIR: where the OS stores dynamic libraries, namely libYap...
|
/// LIBDIR: where the OS stores dynamic libraries, namely libYap...
|
||||||
Yap_LIBDIR = sel(true, iap->LIBDIR != NULL, iap->LIBDIR, true,
|
Yap_LIBDIR = sel( is_dir, Yap_ROOTDIR, iap->LIBDIR,
|
||||||
#if __ANDROID__
|
#if !defined(__ANDROID__)
|
||||||
NULL,
|
|
||||||
#else
|
|
||||||
join(getenv("DESTDIR"), YAP_LIBDIR),
|
join(getenv("DESTDIR"), YAP_LIBDIR),
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/lib"),
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
/// DLLDIR: where libraries can find expicitely loaded DLLs
|
/// DLLDIR: where libraries can find expicitely loaded DLLs
|
||||||
Yap_DLLDIR = sel(true, iap->DLLDIR != NULL, iap->DLLDIR, true,
|
Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR,
|
||||||
#if __ANDROID__
|
getenv("YAPLIBDIR"),
|
||||||
NULL,
|
#if !defined(__ANDROID__)
|
||||||
#else
|
join(getenv("DESTDIR"), YAP_DLLDIR),
|
||||||
join(getenv("DESTDIR"), YAP_DLLDIR),
|
join(Yap_LIBDIR, "/yap"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST);
|
||||||
|
|
||||||
/// INCLUDEDIR: where the OS stores header files, namely libYap...
|
/// INCLUDEDIR: where the OS stores header files, namely libYap...
|
||||||
Yap_INCLUDEDIR = sel(true, iap->INCLUDEDIR != NULL, iap->INCLUDEDIR, true,
|
Yap_INCLUDEDIR = sel(is_dir, Yap_ROOTDIR, iap->INCLUDEDIR,
|
||||||
#if __ANDROID__
|
#if !defined(__ANDROID__)
|
||||||
NULL,
|
join(getenv("DESTDIR"), YAP_INCLUDEDIR),
|
||||||
#else
|
|
||||||
join(getenv("DESTDIR"), YAP_INCLUDEDIR),
|
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/include"),
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
/// SHAREDIR: where OS & ARCH independent files live
|
/// SHAREDIR: where OS & ARCH independent files live
|
||||||
Yap_SHAREDIR = sel(true, iap->SHAREDIR != NULL, iap->SHAREDIR, true,
|
Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR,
|
||||||
#if __ANDROID__
|
getenv("YAPSHAREDIR"),
|
||||||
"/assets",
|
#if !defined(__ANDROID__)
|
||||||
#else
|
join(getenv("DESTDIR"), YAP_SHAREDIR),
|
||||||
join(getenv("DESTDIR"), YAP_SHAREDIR),
|
join(Yap_ROOTDIR, "/share"),
|
||||||
|
"/assets",
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/files"),
|
||||||
|
EOLIST);
|
||||||
/// PLDIR: where we can find Prolog files
|
/// PLDIR: where we can find Prolog files
|
||||||
Yap_PLDIR = sel(true, iap->PLDIR != NULL, iap->PLDIR, true,
|
Yap_PLDIR = sel( is_dir, Yap_SHAREDIR, iap->PLDIR,
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
|
YAP_PLDIR,
|
||||||
"/assets/Yap",
|
"/assets/Yap",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_PLDIR),
|
join(getenv("DESTDIR"), YAP_PLDIR),
|
||||||
|
join(Yap_SHAREDIR, "/Yap"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST);
|
||||||
/// ``COMMONSDIR: Prolog Commons
|
/// ``COMMONSDIR: Prolog Commons
|
||||||
Yap_COMMONSDIR = sel(true, iap->COMMONSDIR != NULL, iap->COMMONSDIR, true,
|
Yap_COMMONSDIR = sel(is_dir, Yap_SHAREDIR, iap->COMMONSDIR,
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
"/assets/PrologCommons",
|
"/assets/PrologCommons",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_SHAREDIR "/PrologCommons"),
|
join(getenv("DESTDIR"), YAP_SHAREDIR "/PrologCommons"),
|
||||||
|
join(Yap_SHAREDIR, "PrologCommons"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST);
|
||||||
/// BOOTPLDIR: where we can find Prolog bootstrap files
|
/// BOOTPLDIR: where we can find Prolog bootstrap files
|
||||||
Yap_BOOTSTRAP = sel(true, iap->BOOTSTRAP != NULL, iap->BOOTSTRAP, true,
|
Yap_BOOTSTRAP = sel( is_file, NULL, iap->BOOTSTRAP,
|
||||||
#if __ANDROID__
|
YAP_BOOTSTRAP,
|
||||||
"/assets/Yap/pl/boot.yap",
|
EOLIST);
|
||||||
#else
|
|
||||||
join(getenv("DESTDIR"), YAP_BOOTSTRAP),
|
|
||||||
#endif
|
|
||||||
false);
|
|
||||||
/// BOOTFILE: where we can find the core Prolog boot file
|
/// BOOTFILE: where we can find the core Prolog boot file
|
||||||
Yap_BOOTFILE = sel(false, iap->BOOTFILE != NULL, iap->BOOTFILE, true,
|
|
||||||
|
const char * Yap_PLBOOTDIR = sel( is_dir, Yap_PLDIR,
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
"/assets/Yap/pl/boot.yap",
|
"/assets/Yap/pl",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_BOOTFILE),
|
join(Yap_PLDIR, "/pl"),
|
||||||
|
#endif
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
|
Yap_BOOTFILE = sel( is_wfile, Yap_PLBOOTDIR, iap->BOOTFILE,
|
||||||
|
#if __ANDROID__
|
||||||
|
"/assets/Yap/pl/boot.yap",
|
||||||
|
#else
|
||||||
|
join(Yap_PLBOOTDIR, "/boot.yap"),
|
||||||
|
#endif
|
||||||
|
EOLIST);
|
||||||
#endif
|
#endif
|
||||||
false);
|
|
||||||
/// STARTUP: where we can find the core Prolog bootstrap file
|
/// STARTUP: where we can find the core Prolog bootstrap file
|
||||||
Yap_OUTPUT_STARTUP =
|
Yap_OUTPUT_STARTUP =
|
||||||
sel(false, iap->OUTPUT_STARTUP != NULL, iap->OUTPUT_STARTUP, true,
|
sel( is_wfile, Yap_AbsoluteFile(".",false), iap->OUTPUT_STARTUP,
|
||||||
#if __ANDROID__
|
#if defined(__ANDROID__)
|
||||||
NULL,
|
EOLIST,
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_OUTPUT_STARTUP),
|
YAP_OUTPUT_STARTUP,
|
||||||
#endif
|
#endif
|
||||||
false);
|
"startup.yss",
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
Yap_INPUT_STARTUP =
|
Yap_INPUT_STARTUP =
|
||||||
sel(false, iap->INPUT_STARTUP != NULL, iap->INPUT_STARTUP, true,
|
sel( is_wfile, Yap_DLLDIR, iap->INPUT_STARTUP,
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
NULL,
|
EOLIST,
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_INPUT_STARTUP),
|
join(getenv("DESTDIR"), YAP_INPUT_STARTUP),
|
||||||
#endif
|
#endif
|
||||||
false);
|
"startup.yss",
|
||||||
if (Yap_ROOTDIR)
|
join(Yap_DLLDIR, "/startup.yss"),
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
|
if (Yap_ROOTDIR)
|
||||||
setAtomicGlobalPrologFlag(HOME_FLAG,
|
setAtomicGlobalPrologFlag(HOME_FLAG,
|
||||||
MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR)));
|
MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR)));
|
||||||
if (Yap_PLDIR)
|
if (Yap_PLDIR)
|
||||||
@ -461,17 +559,18 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
|||||||
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
||||||
YAP_init_args *iap = x;
|
YAP_init_args *iap = x;
|
||||||
memset(iap, 0, sizeof(YAP_init_args));
|
memset(iap, 0, sizeof(YAP_init_args));
|
||||||
|
iap->Argc = argc;
|
||||||
|
iap->Argv = argv;
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
iap->boot_file_type = YAP_BOOT_PL;
|
iap->boot_file_type = YAP_BOOT_PL;
|
||||||
iap->INPUT_STARTUP = NULL;
|
iap->INPUT_STARTUP = NULL;
|
||||||
iap->assetManager = NULL;
|
iap->assetManager = NULL;
|
||||||
|
return YAP_BOOT_PL;
|
||||||
#else
|
#else
|
||||||
iap->boot_file_type = YAP_QLY;
|
iap->boot_file_type = YAP_QLY;
|
||||||
iap->INPUT_STARTUP = saved_state;
|
iap->INPUT_STARTUP = saved_state;
|
||||||
#endif
|
|
||||||
iap->Argc = argc;
|
|
||||||
iap->Argv = argv;
|
|
||||||
return YAP_QLY;
|
return YAP_QLY;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1006,7 +1105,8 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
|||||||
bool try_restore = yap_init->boot_file_type == YAP_QLY;
|
bool try_restore = yap_init->boot_file_type == YAP_QLY;
|
||||||
bool do_bootstrap = yap_init->boot_file_type == YAP_BOOT_PL;
|
bool do_bootstrap = yap_init->boot_file_type == YAP_BOOT_PL;
|
||||||
struct ssz_t minfo;
|
struct ssz_t minfo;
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "start init ");
|
||||||
if (YAP_initialized)
|
if (YAP_initialized)
|
||||||
/* ignore repeated calls to YAP_Init */
|
/* ignore repeated calls to YAP_Init */
|
||||||
return;
|
return;
|
||||||
@ -1039,16 +1139,20 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
|||||||
Yap_ExecutionMode = yap_init->ExecutionMode;
|
Yap_ExecutionMode = yap_init->ExecutionMode;
|
||||||
Yap_set_locations(yap_init);
|
Yap_set_locations(yap_init);
|
||||||
|
|
||||||
if (do_bootstrap || !try_restore ||
|
if (Yap_INPUT_STARTUP==NULL)
|
||||||
|
try_restore = false;
|
||||||
|
if (do_bootstrap || !try_restore ||
|
||||||
!Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack,
|
!Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack,
|
||||||
&minfo.Heap)) {
|
&minfo.Heap)) {
|
||||||
init_globals(yap_init);
|
init_globals(yap_init);
|
||||||
|
|
||||||
start_modules();
|
start_modules();
|
||||||
CurrentModule = PROLOG_MODULE;
|
CurrentModule = PROLOG_MODULE;
|
||||||
TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file"));
|
TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file"));
|
||||||
LOCAL_consult_level = -1;
|
LOCAL_consult_level = -1;
|
||||||
consult(Yap_BOOTSTRAP PASS_REGS);
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "init %s ", Yap_BOOTSTRAP);
|
||||||
|
load_file(Yap_BOOTSTRAP PASS_REGS);
|
||||||
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||||
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
|
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
|
||||||
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
|
||||||
@ -1056,6 +1160,8 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
|||||||
if (yap_init->QuietMode) {
|
if (yap_init->QuietMode) {
|
||||||
setVerbosity(TermSilent);
|
setVerbosity(TermSilent);
|
||||||
}
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "restore %s ",Yap_INPUT_STARTUP );
|
||||||
Yap_Restore(Yap_INPUT_STARTUP);
|
Yap_Restore(Yap_INPUT_STARTUP);
|
||||||
init_globals(yap_init);
|
init_globals(yap_init);
|
||||||
|
|
||||||
|
@ -320,6 +320,7 @@ set(YAP_ROOTDIR ${prefix})
|
|||||||
# libdir defined above
|
# libdir defined above
|
||||||
set(YAP_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
|
set(YAP_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
|
||||||
set(YAP_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Yap)
|
set(YAP_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Yap)
|
||||||
|
set(YAP_BINDIR ${CMAKE_INSTALL_FULL_BINDIR})
|
||||||
set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap)
|
set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap)
|
||||||
set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap)
|
set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap)
|
||||||
|
@ -270,6 +270,8 @@ public:
|
|||||||
inline void setArgv(char **fl) { Argv = fl; };
|
inline void setArgv(char **fl) { Argv = fl; };
|
||||||
|
|
||||||
inline char **getArgv() { return Argv; };
|
inline char **getArgv() { return Argv; };
|
||||||
|
|
||||||
|
inline void setROOTDIR(char *fl) { ROOTDIR = fl; };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -293,7 +295,14 @@ public:
|
|||||||
YAPEngine(YAPEngineArgs *cargs) {
|
YAPEngine(YAPEngineArgs *cargs) {
|
||||||
engine_args = cargs;
|
engine_args = cargs;
|
||||||
// doInit(cargs->boot_file_type);
|
// doInit(cargs->boot_file_type);
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "start engine ");
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
doInit(YAP_BOOT_PL, cargs);
|
||||||
|
|
||||||
|
#else
|
||||||
doInit(YAP_QLY, cargs);
|
doInit(YAP_QLY, cargs);
|
||||||
|
#endif
|
||||||
}; /// construct a new engine, including aaccess to callbacks
|
}; /// construct a new engine, including aaccess to callbacks
|
||||||
/// construct a new engine using argc/argv list of arguments
|
/// construct a new engine using argc/argv list of arguments
|
||||||
YAPEngine(int argc, char *argv[],
|
YAPEngine(int argc, char *argv[],
|
||||||
|
@ -2030,7 +2030,7 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
|
|
||||||
/* name of Commons library */
|
/* name of Commons library */
|
||||||
#ifndef YAP_COMMONSDIR
|
#ifndef YAP_COMMONSDIR
|
||||||
#define YAP COMMONSDIR "${YAP_DATADIR}/PrologCommmons"
|
#define YAP_COMMONSDIR "${YAP_DATADIR}/PrologCommmons"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
10
os/assets.c
10
os/assets.c
@ -77,18 +77,20 @@ open_asset(VFS_t *me, const char *fname, const char *io_mode, int sno) {
|
|||||||
// AAssetDir *dp = AAssetManager_openDir( Yap_assetManager(), dirname(dir) );
|
// AAssetDir *dp = AAssetManager_openDir( Yap_assetManager(), dirname(dir) );
|
||||||
// strcpy(dir, fname);
|
// strcpy(dir, fname);
|
||||||
// char *d = basename(dir);
|
// char *d = basename(dir);
|
||||||
am = AAssetManager_open(Yap_assetManager(), fname, mode);
|
am = AAssetManager_open(Yap_assetManager(), fname, io_mode);
|
||||||
//if (am==NULL)
|
//if (am==NULL)
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed open %s <%s>", fname, strerror(errno) );
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed open %s <%s>", fname, strerror(errno) );
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", fname, io_mode);
|
||||||
// while (dp) {
|
// while (dp) {
|
||||||
// char *f = AAssetDir_getNextFileName(dp);
|
// char *f = AAssetDir_getNextFileName(dp);
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", f, d);
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", fname, mode);
|
||||||
// if (f && strcasecmp(d,f) == 0) {
|
// if (f && strcasecmp(d,f) == 0) {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
if (!am) {
|
if (!am) {
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed %s <%s>", fname, io_mode);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// try not to use it as an asset
|
// try not to use it as an asset
|
||||||
@ -111,7 +113,7 @@ open_asset(VFS_t *me, const char *fname, const char *io_mode, int sno) {
|
|||||||
st->vfs = NULL;
|
st->vfs = NULL;
|
||||||
st->vfs_handle = NULL;
|
st->vfs_handle = NULL;
|
||||||
st->status = Seekable_Stream_f|Input_Stream_f;
|
st->status = Seekable_Stream_f|Input_Stream_f;
|
||||||
return st;
|
return st->file;
|
||||||
} else {
|
} else {
|
||||||
// should be done, but if not
|
// should be done, but if not
|
||||||
GLOBAL_Stream[sno].vfs_handle = am;
|
GLOBAL_Stream[sno].vfs_handle = am;
|
||||||
|
134
os/iopreds.c
134
os/iopreds.c
@ -1135,7 +1135,7 @@ bool Yap_initStream(int sno, FILE *fd, Atom name, const char *io_mode,
|
|||||||
ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>", io_mode,
|
ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>", io_mode,
|
||||||
CurrentModule == 0 ? "prolog"
|
CurrentModule == 0 ? "prolog"
|
||||||
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
||||||
name, sno);
|
RepAtom(name)->StrOfAE, sno);
|
||||||
if (io_mode == NULL)
|
if (io_mode == NULL)
|
||||||
Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno),
|
Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno),
|
||||||
"File opened with NULL Permissions");
|
"File opened with NULL Permissions");
|
||||||
@ -1242,74 +1242,80 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
|
|||||||
|
|
||||||
st->file = NULL;
|
st->file = NULL;
|
||||||
if (fname) {
|
if (fname) {
|
||||||
if ((vfsp = vfs_owner(fname)) != NULL &&
|
if ((vfsp = vfs_owner(fname)) != NULL) {
|
||||||
vfsp->open(vfsp, fname, io_mode, sno)) {
|
if (vfsp->open(vfsp, fname, io_mode, sno)) {
|
||||||
// read, write, append
|
// read, write, append
|
||||||
user_name = st->user_name;
|
user_name = st->user_name;
|
||||||
st->vfs = vfsp;
|
st->vfs = vfsp;
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
} else {
|
__android_log_print(
|
||||||
st->file = fopen(fname, io_mode);
|
ANDROID_LOG_INFO, "YAPDroid", "got %d ", sno);
|
||||||
if (st->file == NULL) {
|
} else {
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
__android_log_print(
|
||||||
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname,
|
ANDROID_LOG_INFO, "YAPDroid", "failed %s ",fname);
|
||||||
strerror(errno));
|
return false;
|
||||||
} else {
|
}
|
||||||
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname,
|
} else {
|
||||||
strerror(errno));
|
st->file = fopen(fname, io_mode);
|
||||||
}
|
if (st->file == NULL) {
|
||||||
}
|
__android_log_print(
|
||||||
st->vfs = NULL;
|
ANDROID_LOG_INFO, "YAPDroid", "failed %s ",fname);
|
||||||
}
|
UNLOCK(st->streamlock);
|
||||||
if (!st->file && !st->vfs) {
|
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
||||||
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s", fname);
|
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname,
|
||||||
/* extract BACK info passed through the stream descriptor */
|
strerror(errno));
|
||||||
return false;
|
} else {
|
||||||
}
|
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname,
|
||||||
} else if (IsApplTerm(tin)) {
|
strerror(errno));
|
||||||
Functor f = FunctorOfTerm(tin);
|
}
|
||||||
if (f == FunctorAtom || f == FunctorString || f == FunctorCodes1 ||
|
return false;
|
||||||
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars) {
|
}
|
||||||
if (strchr(io_mode, 'r')) {
|
|
||||||
return Yap_OpenBufWriteStream(PASS_REGS1);
|
|
||||||
} else {
|
|
||||||
int j = push_text_stack();
|
|
||||||
const char *buf;
|
|
||||||
|
|
||||||
buf = Yap_TextTermToText(tin PASS_REGS);
|
|
||||||
if (!buf) {
|
|
||||||
pop_text_stack(j);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
buf = pop_output_text_stack(j, buf);
|
|
||||||
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf, 32));
|
|
||||||
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
|
|
||||||
MEM_BUF_MALLOC, nat,
|
|
||||||
MkAtomTerm(NameOfFunctor(f)));
|
|
||||||
pop_text_stack(j);
|
|
||||||
return Yap_OpenBufWriteStream(PASS_REGS1);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {
|
|
||||||
const char *buf;
|
|
||||||
int i = push_text_stack();
|
|
||||||
buf = Yap_TextTermToText(ArgOfTerm(1, tin) PASS_REGS);
|
|
||||||
if (buf == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
} else if (IsApplTerm(tin)) {
|
||||||
|
Functor f = FunctorOfTerm(tin);
|
||||||
|
if (f == FunctorAtom || f == FunctorString || f == FunctorCodes1 ||
|
||||||
|
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars) {
|
||||||
|
if (strchr(io_mode, 'r')) {
|
||||||
|
return Yap_OpenBufWriteStream(PASS_REGS1);
|
||||||
|
} else {
|
||||||
|
int j = push_text_stack();
|
||||||
|
const char *buf;
|
||||||
|
|
||||||
|
buf = Yap_TextTermToText(tin PASS_REGS);
|
||||||
|
if (!buf) {
|
||||||
|
pop_text_stack(j);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
buf = pop_output_text_stack(j, buf);
|
||||||
|
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf, 32));
|
||||||
|
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
|
||||||
|
MEM_BUF_MALLOC, nat,
|
||||||
|
MkAtomTerm(NameOfFunctor(f)));
|
||||||
|
pop_text_stack(j);
|
||||||
|
return Yap_OpenBufWriteStream(PASS_REGS1);
|
||||||
|
}
|
||||||
|
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {
|
||||||
|
const char *buf;
|
||||||
|
int i = push_text_stack();
|
||||||
|
buf = Yap_TextTermToText(ArgOfTerm(1, tin) PASS_REGS);
|
||||||
|
if (buf == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
st->file = _popen(buf, io_mode);
|
st->file = _popen(buf, io_mode);
|
||||||
#else
|
#else
|
||||||
st->file = popen(buf, io_mode);
|
st->file = popen(buf, io_mode);
|
||||||
#endif
|
#endif
|
||||||
fname = "popen";
|
fname = "popen";
|
||||||
user_name = tin;
|
user_name = tin;
|
||||||
st->status |= Popen_Stream_f;
|
st->status |= Popen_Stream_f;
|
||||||
pop_text_stack(i);
|
pop_text_stack(i);
|
||||||
} else {
|
} else {
|
||||||
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open");
|
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!strchr(io_mode, 'b') && binary_file(fname)) {
|
if (!strchr(io_mode, 'b') && binary_file(fname)) {
|
||||||
st->status |= Binary_Stream_f;
|
st->status |= Binary_Stream_f;
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ bool Yap_ChDir(const char *path) {
|
|||||||
int lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
|
|
||||||
const char *qpath = Yap_AbsoluteFile(path, true);
|
const char *qpath = Yap_AbsoluteFile(path, true);
|
||||||
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", path);
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", path);
|
||||||
VFS_t *v;
|
VFS_t *v;
|
||||||
if ((v = vfs_owner(qpath))) {
|
if ((v = vfs_owner(qpath))) {
|
||||||
rc = v->chdir(v, (qpath));
|
rc = v->chdir(v, (qpath));
|
||||||
|
Reference in New Issue
Block a user