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) {
|
||||
CACHE_REGS
|
||||
char *buf = NULL;
|
||||
char *buf = Yap_AllocCodeSpace(FILENAME_MAX+1);
|
||||
int len;
|
||||
if (!Yap_getcwd(LOCAL_FileNameBuf, YAP_FILENAME_MAX))
|
||||
if (!Yap_getcwd(buf, FILENAME_MAX))
|
||||
return FALSE;
|
||||
len = strlen(LOCAL_FileNameBuf);
|
||||
buf = Yap_AllocCodeSpace(len + 1);
|
||||
if (!buf)
|
||||
return NULL;
|
||||
strncpy(buf, LOCAL_FileNameBuf, len);
|
||||
len = strlen(buf);
|
||||
buf = Yap_ReallocCodeSpace(buf,len+1);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -970,7 +970,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
|
||||
number_overflow();
|
||||
*sp++ = ch;
|
||||
ch = getchr(st);
|
||||
if (!iswhexnumber(ch)) {
|
||||
if (!my_isxdigit(ch, 'F', 'f')) {
|
||||
Yap_InitError(SYNTAX_ERROR, TermNil, "empty hexadecimal number 0x%C",ch) ;
|
||||
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) {
|
||||
if (o->prev)
|
||||
o->prev->next = o->next;
|
||||
if (o->next)
|
||||
o->next->prev = o->prev;
|
||||
int lvl = o->lvl;
|
||||
if (LOCAL_TextBuffer->first[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) {
|
||||
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) {
|
||||
@ -192,14 +192,13 @@ void *Realloc(void *pt, size_t sz USES_REGS) {
|
||||
* @return new object
|
||||
*/
|
||||
const void *MallocExportAsRO(const void *pt USES_REGS) {
|
||||
struct mblock *old = pt, *o;
|
||||
if (o == NULL)
|
||||
struct mblock *old = pt, *o = old-1;
|
||||
if (old == NULL)
|
||||
return NULL;
|
||||
old--;
|
||||
release_block(old);
|
||||
size_t sz = strlen(pt)+1;
|
||||
memcpy((void*)pt,old,sz);
|
||||
return realloc((void *)pt, sz);
|
||||
size_t sz = o->sz;
|
||||
release_block(o);
|
||||
memcpy((void*)o, pt,sz);
|
||||
return realloc((void *)o, sz);
|
||||
}
|
||||
|
||||
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;
|
||||
c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, full, &oactive);
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
@ -189,6 +189,7 @@ static void consult(const char *b_file USES_REGS) {
|
||||
CACHE_REGS
|
||||
YAP_Reset(YAP_FULL_RESET, false);
|
||||
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();
|
||||
t = YAP_ReadClauseFromStream(c_stream, vs, pos);
|
||||
// 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_SHAREDIR = "/assets/Yap";
|
||||
Yap_DLLDIR = "/assets/lib";
|
||||
Yap_PLDIR = "/assets/Yap";
|
||||
Yap_BOOTPLDIR = "/assets/Yap/pl";
|
||||
if (iap->PrologBootFile == NULL)
|
||||
iap->PrologBootFile = "boot.yap";
|
||||
Yap_BOOTFILE = "/assets/Yap/pl/boot.yap";
|
||||
Yap_PLDIR = iap->PlDir;
|
||||
Yap_BOOTPLDIR = iap->PrologBootFile;
|
||||
Yap_BOOTFILE = iap->PrologBootFile;
|
||||
Yap_COMMONSDIR =NULL;
|
||||
if (iap->SavedState == NULL) {
|
||||
if (iap->OutputSavedState)
|
||||
@ -506,27 +505,27 @@ static void Yap_set_locations(YAP_init_args *iap) {
|
||||
iap->OutputSavedState = "startup.yss";
|
||||
Yap_OUTPUT_STARTUP = NULL;
|
||||
#else
|
||||
Yap_ROOTDIR = MallocExportAsRO(find_directory(iap, template->root, NULL) );
|
||||
Yap_LIBDIR = MallocExportAsRO( find_directory(iap, template->lib, NULL) );
|
||||
// Yap_BINDIR = MallocExportAsROfind_directory(iap, template->bin, NULL);
|
||||
Yap_SHAREDIR = MallocExportAsRO( find_directory(iap, template->share, NULL) );
|
||||
Yap_DLLDIR = MallocExportAsRO( find_directory(iap, template->dll, NULL) );
|
||||
Yap_PLDIR = MallocExportAsRO( find_directory(iap, template->pl, NULL) );
|
||||
Yap_BOOTPLDIR = MallocExportAsRO( find_directory(iap, template->bootpldir, NULL) );
|
||||
Yap_ROOTDIR = find_directory(iap, template->root, NULL) ;
|
||||
Yap_LIBDIR = find_directory(iap, template->lib, NULL) ;
|
||||
// Yap_BINDIR = MallocExportAsROfind_directory(iap, template->bin, NULL;
|
||||
Yap_SHAREDIR = find_directory(iap, template->share, NULL) ;
|
||||
Yap_DLLDIR = find_directory(iap, template->dll, NULL) ;
|
||||
Yap_PLDIR = find_directory(iap, template->pl, NULL) ;
|
||||
Yap_BOOTPLDIR = find_directory(iap, template->bootpldir, NULL);
|
||||
if (iap->PrologBootFile == NULL)
|
||||
iap->PrologBootFile = "boot.yap";
|
||||
Yap_BOOTFILE = MallocExportAsRO( find_directory(iap, template->bootpldir, iap->PrologBootFile) ) ;
|
||||
Yap_COMMONSDIR = MallocExportAsRO( find_directory(iap, template->commons, NULL) );
|
||||
Yap_BOOTFILE = find_directory(iap, template->bootpldir, iap->PrologBootFile);
|
||||
Yap_COMMONSDIR = find_directory(iap, template->commons, NULL);
|
||||
if (iap->SavedState == NULL) {
|
||||
if (iap->OutputSavedState)
|
||||
iap->SavedState = iap->OutputSavedState;
|
||||
else
|
||||
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)
|
||||
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
|
||||
if (Yap_ROOTDIR)
|
||||
|
@ -169,4 +169,6 @@ int SzOfFileAliases void
|
||||
|
||||
struct vfs* VFS =Yap_InitAssetManager()
|
||||
|
||||
char* cwd =NULL
|
||||
|
||||
END_GLOBAL_DATA
|
||||
|
@ -141,4 +141,5 @@
|
||||
#define GLOBAL_NOfFileAliases Yap_global->NOfFileAliases_
|
||||
#define GLOBAL_SzOfFileAliases Yap_global->SzOfFileAliases_
|
||||
#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_SzOfFileAliases;
|
||||
EXTERNAL struct vfs* GLOBAL_VFS;
|
||||
EXTERNAL char* GLOBAL_cwd;
|
||||
|
||||
|
@ -141,4 +141,5 @@ const char* RestoreFile_;
|
||||
int NOfFileAliases_;
|
||||
int SzOfFileAliases_;
|
||||
struct vfs* VFS_;
|
||||
char* cwd_;
|
||||
} w_shared;
|
||||
|
@ -141,4 +141,5 @@ static void InitGlobal(void) {
|
||||
|
||||
|
||||
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) {
|
||||
|
||||
chdir("/assets");
|
||||
if (virtual_cwd) {
|
||||
free(virtual_cwd);
|
||||
if (GLOBAL_cwd) {
|
||||
free(GLOBAL_cwd);
|
||||
}
|
||||
virtual_cwd = malloc(strlen(dirName)+1);
|
||||
strcpy(virtual_cwd, dirName);
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", virtual_cwd);
|
||||
GLOBAL_cwd = malloc(strlen(dirName)+1);
|
||||
strcpy(GLOBAL_cwd, dirName);
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", GLOBAL_cwd);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ Yap_InitAssetManager(void) {
|
||||
|
||||
#if __ANDROID__
|
||||
VFS_t *me;
|
||||
|
||||
return NULL;
|
||||
/* init standard VFS */
|
||||
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
|
||||
me->name = "/assets";
|
||||
@ -248,7 +248,7 @@ Yap_InitAssetManager(void) {
|
||||
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->writers = NULL;
|
||||
virtual_cwd = NULL;
|
||||
GLOBAL_cwd = NULL;
|
||||
LOCK(BGL);
|
||||
me->next = GLOBAL_VFS;
|
||||
GLOBAL_VFS = me;
|
||||
|
@ -1565,7 +1565,7 @@ int Yap_OpenStream(const char *fname, const char *io_mode, Term user_name) {
|
||||
// read, write, append
|
||||
st->file = NULL;
|
||||
st->status = 0;
|
||||
fname = Yap_VF(fname);
|
||||
//fname = Yap_VF(fname);
|
||||
if ((vfsp = vfs_owner(fname)) != NULL) {
|
||||
if (!vfsp->open(vfsp, sno, fname, "r")) {
|
||||
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) {
|
||||
VFS_t *vfs;
|
||||
// f = Yap_VFAlloc(f);
|
||||
f = Yap_VFAlloc(f);
|
||||
if ((vfs = vfs_owner(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); }
|
||||
|
||||
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
||||
if (virtual_cwd && virtual_cwd[0]) {
|
||||
if (!cwd) {
|
||||
cwd = malloc(cwdlen + 1);
|
||||
}
|
||||
strcpy(cwd, virtual_cwd);
|
||||
if (GLOBAL_cwd && GLOBAL_cwd[0]) {
|
||||
strcpy(cwd, GLOBAL_cwd);
|
||||
return cwd;
|
||||
}
|
||||
#if _WIN32 || defined(__MINGW32__)
|
||||
@ -1135,10 +1132,7 @@ const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
||||
}
|
||||
return (char *)cwd;
|
||||
#endif
|
||||
if (!cwd) {
|
||||
cwd = malloc(cwdlen + 1);
|
||||
}
|
||||
return getcwd((char *)cwd, cwdlen);
|
||||
return getcwd(cwd, FILENAME_MAX);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
extern char *virtual_cwd;
|
||||
|
||||
|
||||
extern char *GLOBAL_cwd;
|
||||
|
||||
|
||||
INLINE_ONLY inline EXTERN char *Yap_VF(const char *path){
|
||||
char *out;
|
||||
|
||||
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;
|
||||
}
|
||||
strcpy(out, virtual_cwd);
|
||||
strcpy(out, GLOBAL_cwd);
|
||||
strcat(out, "/" );
|
||||
strcat(out, path);
|
||||
return out;
|
||||
@ -173,10 +175,10 @@ INLINE_ONLY inline EXTERN char *Yap_VFAlloc(const char *path){
|
||||
char *out;
|
||||
|
||||
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;
|
||||
}
|
||||
strcpy(out, virtual_cwd);
|
||||
strcpy(out, GLOBAL_cwd);
|
||||
strcat(out, "/" );
|
||||
strcat(out, path);
|
||||
return out;
|
||||
|
Reference in New Issue
Block a user