virtual_dir -> GLOBAL_dir
android ckf
This commit is contained in:
parent
13f36c1f67
commit
1cdd8a482b
@ -2501,15 +2501,12 @@ X_API int YAP_HaltRegisterHook(HaltHookFunc hook, void *closure) {
|
|||||||
|
|
||||||
X_API char *YAP_cwd(void) {
|
X_API char *YAP_cwd(void) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
char *buf = NULL;
|
char *buf = Yap_AllocCodeSpace(FILENAME_MAX+1);
|
||||||
int len;
|
int len;
|
||||||
if (!Yap_getcwd(LOCAL_FileNameBuf, YAP_FILENAME_MAX))
|
if (!Yap_getcwd(buf, FILENAME_MAX))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
len = strlen(LOCAL_FileNameBuf);
|
len = strlen(buf);
|
||||||
buf = Yap_AllocCodeSpace(len + 1);
|
buf = Yap_ReallocCodeSpace(buf,len+1);
|
||||||
if (!buf)
|
|
||||||
return NULL;
|
|
||||||
strncpy(buf, LOCAL_FileNameBuf, len);
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -970,7 +970,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
|
|||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(st);
|
ch = getchr(st);
|
||||||
if (!iswhexnumber(ch)) {
|
if (!my_isxdigit(ch, 'F', 'f')) {
|
||||||
Yap_InitError(SYNTAX_ERROR, TermNil, "empty hexadecimal number 0x%C",ch) ;
|
Yap_InitError(SYNTAX_ERROR, TermNil, "empty hexadecimal number 0x%C",ch) ;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
21
C/text.c
21
C/text.c
@ -121,10 +121,6 @@ void insert_block(struct mblock *o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void release_block(struct mblock *o) {
|
void release_block(struct mblock *o) {
|
||||||
if (o->prev)
|
|
||||||
o->prev->next = o->next;
|
|
||||||
if (o->next)
|
|
||||||
o->next->prev = o->prev;
|
|
||||||
int lvl = o->lvl;
|
int lvl = o->lvl;
|
||||||
if (LOCAL_TextBuffer->first[lvl] == o) {
|
if (LOCAL_TextBuffer->first[lvl] == o) {
|
||||||
if (LOCAL_TextBuffer->last[lvl] == o) {
|
if (LOCAL_TextBuffer->last[lvl] == o) {
|
||||||
@ -134,6 +130,10 @@ void release_block(struct mblock *o) {
|
|||||||
} else if (LOCAL_TextBuffer->last[lvl] == o) {
|
} else if (LOCAL_TextBuffer->last[lvl] == o) {
|
||||||
LOCAL_TextBuffer->last[lvl] = o->prev;
|
LOCAL_TextBuffer->last[lvl] = o->prev;
|
||||||
}
|
}
|
||||||
|
if (o->prev)
|
||||||
|
o->prev->next = o->next;
|
||||||
|
if (o->next)
|
||||||
|
o->next->prev = o->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Malloc(size_t sz USES_REGS) {
|
void *Malloc(size_t sz USES_REGS) {
|
||||||
@ -192,14 +192,13 @@ void *Realloc(void *pt, size_t sz USES_REGS) {
|
|||||||
* @return new object
|
* @return new object
|
||||||
*/
|
*/
|
||||||
const void *MallocExportAsRO(const void *pt USES_REGS) {
|
const void *MallocExportAsRO(const void *pt USES_REGS) {
|
||||||
struct mblock *old = pt, *o;
|
struct mblock *old = pt, *o = old-1;
|
||||||
if (o == NULL)
|
if (old == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
old--;
|
size_t sz = o->sz;
|
||||||
release_block(old);
|
release_block(o);
|
||||||
size_t sz = strlen(pt)+1;
|
memcpy((void*)o, pt,sz);
|
||||||
memcpy((void*)pt,old,sz);
|
return realloc((void *)o, sz);
|
||||||
return realloc((void *)pt, sz);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free(void *pt USES_REGS) {
|
void Free(void *pt USES_REGS) {
|
||||||
|
33
C/yap-args.c
33
C/yap-args.c
@ -176,7 +176,7 @@ static void consult(const char *b_file USES_REGS) {
|
|||||||
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) {
|
if (c_stream < 0) {
|
||||||
fprintf(stderr, "[ FATAL ERROR: could not open stream %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);
|
||||||
}
|
}
|
||||||
@ -189,6 +189,7 @@ static void consult(const char *b_file USES_REGS) {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
YAP_Reset(YAP_FULL_RESET, false);
|
YAP_Reset(YAP_FULL_RESET, false);
|
||||||
Yap_StartSlots();
|
Yap_StartSlots();
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "read %s <%d>", b_file, GLOBAL_Stream[c_stream].linecount);
|
||||||
Term vs = YAP_MkVarTerm(), pos = MkVarTerm();
|
Term vs = YAP_MkVarTerm(), pos = MkVarTerm();
|
||||||
t = YAP_ReadClauseFromStream(c_stream, vs, pos);
|
t = YAP_ReadClauseFromStream(c_stream, vs, pos);
|
||||||
// Yap_GetNèwSlot(t);
|
// Yap_GetNèwSlot(t);
|
||||||
@ -490,11 +491,9 @@ static void Yap_set_locations(YAP_init_args *iap) {
|
|||||||
// Yap_BINDIR = MallocExportAsROfind_directory(iap, template->bin, NULL);
|
// Yap_BINDIR = MallocExportAsROfind_directory(iap, template->bin, NULL);
|
||||||
Yap_SHAREDIR = "/assets/Yap";
|
Yap_SHAREDIR = "/assets/Yap";
|
||||||
Yap_DLLDIR = "/assets/lib";
|
Yap_DLLDIR = "/assets/lib";
|
||||||
Yap_PLDIR = "/assets/Yap";
|
Yap_PLDIR = iap->PlDir;
|
||||||
Yap_BOOTPLDIR = "/assets/Yap/pl";
|
Yap_BOOTPLDIR = iap->PrologBootFile;
|
||||||
if (iap->PrologBootFile == NULL)
|
Yap_BOOTFILE = iap->PrologBootFile;
|
||||||
iap->PrologBootFile = "boot.yap";
|
|
||||||
Yap_BOOTFILE = "/assets/Yap/pl/boot.yap";
|
|
||||||
Yap_COMMONSDIR =NULL;
|
Yap_COMMONSDIR =NULL;
|
||||||
if (iap->SavedState == NULL) {
|
if (iap->SavedState == NULL) {
|
||||||
if (iap->OutputSavedState)
|
if (iap->OutputSavedState)
|
||||||
@ -506,27 +505,27 @@ static void Yap_set_locations(YAP_init_args *iap) {
|
|||||||
iap->OutputSavedState = "startup.yss";
|
iap->OutputSavedState = "startup.yss";
|
||||||
Yap_OUTPUT_STARTUP = NULL;
|
Yap_OUTPUT_STARTUP = NULL;
|
||||||
#else
|
#else
|
||||||
Yap_ROOTDIR = MallocExportAsRO(find_directory(iap, template->root, NULL) );
|
Yap_ROOTDIR = find_directory(iap, template->root, NULL) ;
|
||||||
Yap_LIBDIR = MallocExportAsRO( find_directory(iap, template->lib, NULL) );
|
Yap_LIBDIR = find_directory(iap, template->lib, NULL) ;
|
||||||
// Yap_BINDIR = MallocExportAsROfind_directory(iap, template->bin, NULL);
|
// Yap_BINDIR = MallocExportAsROfind_directory(iap, template->bin, NULL;
|
||||||
Yap_SHAREDIR = MallocExportAsRO( find_directory(iap, template->share, NULL) );
|
Yap_SHAREDIR = find_directory(iap, template->share, NULL) ;
|
||||||
Yap_DLLDIR = MallocExportAsRO( find_directory(iap, template->dll, NULL) );
|
Yap_DLLDIR = find_directory(iap, template->dll, NULL) ;
|
||||||
Yap_PLDIR = MallocExportAsRO( find_directory(iap, template->pl, NULL) );
|
Yap_PLDIR = find_directory(iap, template->pl, NULL) ;
|
||||||
Yap_BOOTPLDIR = MallocExportAsRO( find_directory(iap, template->bootpldir, NULL) );
|
Yap_BOOTPLDIR = find_directory(iap, template->bootpldir, NULL);
|
||||||
if (iap->PrologBootFile == NULL)
|
if (iap->PrologBootFile == NULL)
|
||||||
iap->PrologBootFile = "boot.yap";
|
iap->PrologBootFile = "boot.yap";
|
||||||
Yap_BOOTFILE = MallocExportAsRO( find_directory(iap, template->bootpldir, iap->PrologBootFile) ) ;
|
Yap_BOOTFILE = find_directory(iap, template->bootpldir, iap->PrologBootFile);
|
||||||
Yap_COMMONSDIR = MallocExportAsRO( 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)
|
if (iap->OutputSavedState)
|
||||||
iap->SavedState = iap->OutputSavedState;
|
iap->SavedState = iap->OutputSavedState;
|
||||||
else
|
else
|
||||||
iap->SavedState = "startup.yss";
|
iap->SavedState = "startup.yss";
|
||||||
}
|
}
|
||||||
Yap_STARTUP = MallocExportAsRO( 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";
|
||||||
Yap_OUTPUT_STARTUP = MallocExportAsRO( find_directory(iap, template->ss, iap->OutputSavedState) );
|
Yap_OUTPUT_STARTUP = find_directory(iap, template->ss, iap->OutputSavedState) ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if (Yap_ROOTDIR)
|
if (Yap_ROOTDIR)
|
||||||
|
@ -169,4 +169,6 @@ int SzOfFileAliases void
|
|||||||
|
|
||||||
struct vfs* VFS =Yap_InitAssetManager()
|
struct vfs* VFS =Yap_InitAssetManager()
|
||||||
|
|
||||||
|
char* cwd =NULL
|
||||||
|
|
||||||
END_GLOBAL_DATA
|
END_GLOBAL_DATA
|
||||||
|
@ -141,4 +141,5 @@
|
|||||||
#define GLOBAL_NOfFileAliases Yap_global->NOfFileAliases_
|
#define GLOBAL_NOfFileAliases Yap_global->NOfFileAliases_
|
||||||
#define GLOBAL_SzOfFileAliases Yap_global->SzOfFileAliases_
|
#define GLOBAL_SzOfFileAliases Yap_global->SzOfFileAliases_
|
||||||
#define GLOBAL_VFS Yap_global->VFS_
|
#define GLOBAL_VFS Yap_global->VFS_
|
||||||
|
#define GLOBAL_cwd Yap_global->cwd_
|
||||||
|
|
||||||
|
@ -141,4 +141,5 @@ EXTERNAL struct AliasDescS* GLOBAL_FileAliases;
|
|||||||
EXTERNAL int GLOBAL_NOfFileAliases;
|
EXTERNAL int GLOBAL_NOfFileAliases;
|
||||||
EXTERNAL int GLOBAL_SzOfFileAliases;
|
EXTERNAL int GLOBAL_SzOfFileAliases;
|
||||||
EXTERNAL struct vfs* GLOBAL_VFS;
|
EXTERNAL struct vfs* GLOBAL_VFS;
|
||||||
|
EXTERNAL char* GLOBAL_cwd;
|
||||||
|
|
||||||
|
@ -141,4 +141,5 @@ const char* RestoreFile_;
|
|||||||
int NOfFileAliases_;
|
int NOfFileAliases_;
|
||||||
int SzOfFileAliases_;
|
int SzOfFileAliases_;
|
||||||
struct vfs* VFS_;
|
struct vfs* VFS_;
|
||||||
|
char* cwd_;
|
||||||
} w_shared;
|
} w_shared;
|
||||||
|
@ -141,4 +141,5 @@ static void InitGlobal(void) {
|
|||||||
|
|
||||||
|
|
||||||
GLOBAL_VFS = Yap_InitAssetManager();
|
GLOBAL_VFS = Yap_InitAssetManager();
|
||||||
|
GLOBAL_cwd = NULL;
|
||||||
}
|
}
|
||||||
|
14
os/assets.c
14
os/assets.c
@ -208,12 +208,12 @@ char *virtual_cwd;
|
|||||||
static bool set_cwd(VFS_t *me, const char *dirName) {
|
static bool set_cwd(VFS_t *me, const char *dirName) {
|
||||||
|
|
||||||
chdir("/assets");
|
chdir("/assets");
|
||||||
if (virtual_cwd) {
|
if (GLOBAL_cwd) {
|
||||||
free(virtual_cwd);
|
free(GLOBAL_cwd);
|
||||||
}
|
}
|
||||||
virtual_cwd = malloc(strlen(dirName)+1);
|
GLOBAL_cwd = malloc(strlen(dirName)+1);
|
||||||
strcpy(virtual_cwd, dirName);
|
strcpy(GLOBAL_cwd, dirName);
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", virtual_cwd);
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", GLOBAL_cwd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ Yap_InitAssetManager(void) {
|
|||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
VFS_t *me;
|
VFS_t *me;
|
||||||
|
return NULL;
|
||||||
/* init standard VFS */
|
/* init standard VFS */
|
||||||
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
|
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
|
||||||
me->name = "/assets";
|
me->name = "/assets";
|
||||||
@ -248,7 +248,7 @@ Yap_InitAssetManager(void) {
|
|||||||
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
|
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
|
||||||
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
|
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
|
||||||
me->writers = NULL;
|
me->writers = NULL;
|
||||||
virtual_cwd = NULL;
|
GLOBAL_cwd = NULL;
|
||||||
LOCK(BGL);
|
LOCK(BGL);
|
||||||
me->next = GLOBAL_VFS;
|
me->next = GLOBAL_VFS;
|
||||||
GLOBAL_VFS = me;
|
GLOBAL_VFS = me;
|
||||||
|
@ -1565,7 +1565,7 @@ int Yap_OpenStream(const char *fname, const char *io_mode, Term user_name) {
|
|||||||
// read, write, append
|
// read, write, append
|
||||||
st->file = NULL;
|
st->file = NULL;
|
||||||
st->status = 0;
|
st->status = 0;
|
||||||
fname = Yap_VF(fname);
|
//fname = Yap_VF(fname);
|
||||||
if ((vfsp = vfs_owner(fname)) != NULL) {
|
if ((vfsp = vfs_owner(fname)) != NULL) {
|
||||||
if (!vfsp->open(vfsp, sno, fname, "r")) {
|
if (!vfsp->open(vfsp, sno, fname, "r")) {
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
|
14
os/sysbits.c
14
os/sysbits.c
@ -94,7 +94,7 @@ bool Yap_isDirectory(const char *FileName) {
|
|||||||
|
|
||||||
bool Yap_Exists(const char *f) {
|
bool Yap_Exists(const char *f) {
|
||||||
VFS_t *vfs;
|
VFS_t *vfs;
|
||||||
// f = Yap_VFAlloc(f);
|
f = Yap_VFAlloc(f);
|
||||||
if ((vfs = vfs_owner(f))) {
|
if ((vfs = vfs_owner(f))) {
|
||||||
return vfs->exists(vfs, f);
|
return vfs->exists(vfs, f);
|
||||||
}
|
}
|
||||||
@ -1121,11 +1121,8 @@ static int volume_header(char *file) {
|
|||||||
int Yap_volume_header(char *file) { return volume_header(file); }
|
int Yap_volume_header(char *file) { return volume_header(file); }
|
||||||
|
|
||||||
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
||||||
if (virtual_cwd && virtual_cwd[0]) {
|
if (GLOBAL_cwd && GLOBAL_cwd[0]) {
|
||||||
if (!cwd) {
|
strcpy(cwd, GLOBAL_cwd);
|
||||||
cwd = malloc(cwdlen + 1);
|
|
||||||
}
|
|
||||||
strcpy(cwd, virtual_cwd);
|
|
||||||
return cwd;
|
return cwd;
|
||||||
}
|
}
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
@ -1135,10 +1132,7 @@ const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
|||||||
}
|
}
|
||||||
return (char *)cwd;
|
return (char *)cwd;
|
||||||
#endif
|
#endif
|
||||||
if (!cwd) {
|
return getcwd(cwd, FILENAME_MAX);
|
||||||
cwd = malloc(cwdlen + 1);
|
|
||||||
}
|
|
||||||
return getcwd((char *)cwd, cwdlen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int working_directory(USES_REGS1) {
|
static Int working_directory(USES_REGS1) {
|
||||||
|
12
os/yapio.h
12
os/yapio.h
@ -152,17 +152,19 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
|
|||||||
return MkAtomTerm(Yap_ULookupAtom(cs));
|
return MkAtomTerm(Yap_ULookupAtom(cs));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char *virtual_cwd;
|
|
||||||
|
|
||||||
|
extern char *GLOBAL_cwd;
|
||||||
|
|
||||||
|
|
||||||
INLINE_ONLY inline EXTERN char *Yap_VF(const char *path){
|
INLINE_ONLY inline EXTERN char *Yap_VF(const char *path){
|
||||||
char *out;
|
char *out;
|
||||||
|
|
||||||
out = (char *)malloc(YAP_FILENAME_MAX+1);
|
out = (char *)malloc(YAP_FILENAME_MAX+1);
|
||||||
if ( virtual_cwd == NULL || virtual_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) {
|
if ( GLOBAL_cwd == NULL || GLOBAL_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) {
|
||||||
return (char *) path;
|
return (char *) path;
|
||||||
}
|
}
|
||||||
strcpy(out, virtual_cwd);
|
strcpy(out, GLOBAL_cwd);
|
||||||
strcat(out, "/" );
|
strcat(out, "/" );
|
||||||
strcat(out, path);
|
strcat(out, path);
|
||||||
return out;
|
return out;
|
||||||
@ -173,10 +175,10 @@ INLINE_ONLY inline EXTERN char *Yap_VFAlloc(const char *path){
|
|||||||
char *out;
|
char *out;
|
||||||
|
|
||||||
out = (char *)malloc(YAP_FILENAME_MAX+1);
|
out = (char *)malloc(YAP_FILENAME_MAX+1);
|
||||||
if ( virtual_cwd == NULL || virtual_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) {
|
if ( GLOBAL_cwd == NULL || GLOBAL_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) {
|
||||||
return (char *) path;
|
return (char *) path;
|
||||||
}
|
}
|
||||||
strcpy(out, virtual_cwd);
|
strcpy(out, GLOBAL_cwd);
|
||||||
strcat(out, "/" );
|
strcat(out, "/" );
|
||||||
strcat(out, path);
|
strcat(out, path);
|
||||||
return out;
|
return out;
|
||||||
|
Reference in New Issue
Block a user