This commit is contained in:
Vitor Santos Costa 2017-11-27 13:36:19 +00:00
parent 06485f071a
commit 8feca162bf
18 changed files with 221 additions and 141 deletions

View File

@ -134,11 +134,12 @@ inline static Atom SearchInInvisible(const unsigned char *atom) {
static inline Atom SearchAtom(const unsigned char *p, Atom a) {
AtomEntry *ae;
const char *ps = (const char *)p;
/* search atom in chain */
while (a != NIL) {
ae = RepAtom(a);
if (strcmp(ae->UStrOfAE, p) == 0) {
if (strcmp(ae->StrOfAE, ps) == 0) {
return (a);
}
a = ae->NextOfAE;

View File

@ -77,10 +77,11 @@ void *my_malloc(size_t sz) {
p = malloc(sz);
// Yap_DebugPuts(stderr,"gof\n");
if (Yap_do_low_level_trace)
#if __ANDROID__
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc,p);
#else
fprintf(stderr, "+s %p\n @%p %ld\n", p, TR, LCL0 - (CELL *)LCL0);
if (sz > 500 && write_malloc++ > 0)
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc,
p);
#endif
return p;
}
@ -100,7 +101,7 @@ void *my_realloc(void *ptr, size_t sz) {
void my_free(void *p) {
// printf("f %p\n",p);
if (Yap_do_low_level_trace)
fprintf(stderr, "- %p\n @%p %ld\n", p, TR, LCL0 - (CELL *)LCL0);
fprintf(stderr, "- %p\n @%p %ld\n", p, TR, (long int)(LCL0 - (CELL *)B) );
if (write_malloc && write_malloc++ > 0)
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "- %d %p", write_malloc,
p);

View File

@ -2112,38 +2112,39 @@ X_API void YAP_ClearExceptions(void) {
Yap_ResetException(worker_id);
}
X_API int YAP_InitConsult(int mode, const char *filename, char *full,
X_API int YAP_InitConsult(int mode, const char *fname, char *full,
int *osnop) {
CACHE_REGS
FILE *f = NULL;
int sno;
BACKUP_MACHINE_REGS();
int lvl = push_text_stack();
if (mode == YAP_BOOT_MODE) {
mode = YAP_CONSULT_MODE;
}
char *bfp = Malloc(YAP_FILENAME_MAX+1);
bfp[0] = '\0';
if(fname != NULL && fname[0] != 0 )
strcpy( bfp, fname );
bool consulted = (mode == YAP_CONSULT_MODE);
Yap_init_consult(consulted, filename);
const char *fl = Yap_findFile(filename, NULL, BootFilePath, full, true,
const char *fl = Yap_findFile(bfp, NULL, NULL, full, true,
YAP_BOOT_PL, true, true);
if (!fl)
return -1;
f = fopen(fl, "r");
if (!f)
return -1;
if (!f) {
if (!fl || !fl[0]) {
pop_text_stack(lvl);
return -1;
}
sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f);
Yap_init_consult(consulted,bfp);
sno = Yap_OpenStream(fl, "r" );
*osnop = Yap_CheckAlias(AtomLoopStream);
if (!Yap_AddAlias(AtomLoopStream, sno)) {
Yap_CloseStream(sno);
sno = -1;
pop_text_stack(lvl);
sno = -1;
}
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(filename));
GLOBAL_Stream[sno].encoding = ENC_ISO_UTF8;
RECOVER_MACHINE_REGS();
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
pop_text_stack(lvl);
RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno;
}
@ -2181,7 +2182,7 @@ X_API void YAP_EndConsult(int sno, int *osnop) {
X_API Term YAP_Read(FILE *f) {
Term o;
int sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f);
int sno = Yap_FileStream(f, NULL, TermNil, Input_Stream_f);
BACKUP_MACHINE_REGS();
o = Yap_read_term(sno, TermNil, 1);
@ -2210,7 +2211,7 @@ X_API Term YAP_ReadClauseFromStream(int sno) {
X_API void YAP_Write(Term t, FILE *f, int flags) {
BACKUP_MACHINE_REGS();
int sno = Yap_OpenStream(f, NULL, TermNil, Output_Stream_f);
int sno = Yap_FileStream(f, NULL, TermNil, Output_Stream_f);
Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority);
Yap_ReleaseStream(sno);
@ -2453,7 +2454,12 @@ free(full);
if (yap_init->SavedState == NULL) {
yap_init->SavedState = YAP_STARTUP;
}
if (!LOCAL_TextBuffer)
LOCAL_TextBuffer = Yap_InitTextAllocator();
#if __ANDROID__
//if (yap_init->assetManager)
Yap_InitAssetManager( );
#endif
#if USE_DL_MALLOC
if (yap_init->SavedState == NULL)
yap_init->SavedState = YAP_STARTUP;
@ -2655,7 +2661,7 @@ free(full);
#define DEFAULT_SCHEDULERLOOP 10
#define DEFAULT_DELAYEDRELEASELOAD 3
X_API YAP_file_type_t YAP_FastInit(char saved_state[], int argc, char *argv[]) {
X_API YAP_file_type_t YAP_FastInit(char *saved_state, int argc, char *argv[]) {
YAP_init_args init_args;
YAP_file_type_t out;

View File

@ -1873,8 +1873,6 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
} else {
tf = Yap_MkStaticRefTerm(ClauseCodeToStaticClause(cp), p);
}
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "add %s/%ld %p",
RepAtom(at)->StrOfAE, Arity);
if (mod == PROLOG_MODULE)
mod = TermProlog;
if (pflags & MultiFileFlag) {
@ -2059,36 +2057,33 @@ Atom Yap_ConsultingFile(USES_REGS1) {
if (LOCAL_consult_level == 0) {
return (AtomUser);
} else {
return (Yap_ULookupAtom(LOCAL_ConsultBase[2].filename));
return (Yap_ULookupAtom(LOCAL_ConsultBase[2].f_name));
}
}
/* consult file *file*, *mode* may be one of either consult or reconsult */
static void init_consult(int mode, const unsigned char *file) {
CACHE_REGS
if (!LOCAL_ConsultSp) {
InitConsultStack();
}
if (LOCAL_ConsultSp >= LOCAL_ConsultLow + 6) {
expand_consult();
}
LOCAL_ConsultSp--;
LOCAL_ConsultSp->filename = file;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->mode = mode;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->c = (LOCAL_ConsultBase - LOCAL_ConsultSp);
LOCAL_ConsultBase = LOCAL_ConsultSp;
void Yap_init_consult(int mode, const char *filenam) {
CACHE_REGS
if (!LOCAL_ConsultSp) {
InitConsultStack();
}
if (LOCAL_ConsultSp >= LOCAL_ConsultLow + 6) {
expand_consult();
}
LOCAL_ConsultSp--;
LOCAL_ConsultSp->f_name = (const unsigned char *)filenam;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->mode = mode;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->c = (LOCAL_ConsultBase - LOCAL_ConsultSp);
LOCAL_ConsultBase = LOCAL_ConsultSp;
#if !defined(YAPOR) && !defined(YAPOR_SBA)
/* if (LOCAL_consult_level == 0)
do_toggle_static_predicates_in_use(TRUE); */
#endif
LOCAL_consult_level++;
LOCAL_LastAssertedPred = NULL;
}
LOCAL_consult_level++;
LOCAL_LastAssertedPred = NULL;
void Yap_init_consult(int mode, const char *file) {
init_consult(mode, (const unsigned char *)file);
}
static Int p_startconsult(USES_REGS1) { /* '$start_consult'(+Mode) */
@ -2097,7 +2092,7 @@ static Int p_startconsult(USES_REGS1) { /* '$start_consult'(+Mode) */
int mode;
mode = strcmp("consult", (char *)smode);
init_consult(mode, RepAtom(AtomOfTerm(Deref(ARG2)))->UStrOfAE);
Yap_init_consult(mode, RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE);
t = MkIntTerm(LOCAL_consult_level);
return (Yap_unify_constant(ARG3, t));
}

View File

@ -82,7 +82,7 @@ int pop_text_stack__(int i) {
return lvl;
}
void *pop_output_text_stack__(int i, void *export) {
void *pop_output_text_stack__(int i, const void *export) {
int lvl = LOCAL_TextBuffer->lvl;
while (lvl >= i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];

View File

@ -147,12 +147,14 @@ static int dump_runtime_variables(void) {
return 1;
}
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char saved_state[],
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char *saved_state,
int argc, char *argv[]) {
memset(iap, 0, sizeof(YAP_init_args));
#if __ANDROID__
iap->boot_file_type = YAP_BOOT_PL;
iap->SavedState = NULL;
iap->SavedState = malloc(strlen(saved_state)+1);
strcpy(iap->SavedState, saved_state);
iap->assetManager = true;
#else
iap->boot_file_type = YAP_QLY;
iap->SavedState = saved_state;

View File

@ -464,7 +464,7 @@ IF (WITH_SWIG)
# macro_log_feature (SWIG_FOUND "Swig"
# "Use SWIG Interface Generator "
# "http://www.swig.org" ON)
ENDIF (WITH_SWIG OR ANDROID)
ENDIF (WITH_SWIG)
option(WITH_PYTHON

View File

@ -927,7 +927,7 @@ void Yap_displayWithJava(int c)
void YAPEngine::doInit(YAP_file_type_t BootMode)
{
if ((BootMode = YAP_Init(&engine_args->init_args)) == YAP_FOUND_BOOT_ERROR)
if ((BootMode = YAP_Init(engine_args)) == YAP_FOUND_BOOT_ERROR)
{
return;
throw YAPError();
@ -960,7 +960,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
YAP_file_type_t BootMode;
engine_args = new YAPEngineArgs();
BootMode = YAP_parse_yap_arguments(argc, argv, &engine_args->init_args);
BootMode = YAP_parse_yap_arguments(argc, argv, engine_args);
// delYAPCallback()b
// if (cb)
// setYAPCallback(cb);

View File

@ -185,178 +185,179 @@ public:
virtual void run(char *s) {}
};
void YAP_init_args::YAP_init_args()
{
Yap_InitDefaults(this, NULL, 0, NULL);
} ;
/// @brief Setup all arguments to a new engine
class X_API YAPEngineArgs {
struct X_API YAPEngineArgs: YAP_init_args {
public:
YAP_init_args init_args;
YAPEngineArgs(): yap_boot_params() {
#if YAP_PYTHON
Embedded = true;
python_in_python = Py_IsInitialized();
#endif
};
inline void setEmbedded( bool fl )
{
init_args.Embedded = fl;
Embedded = fl;
};
inline bool getEmbedded( )
{
return init_args.Embedded;
return Embedded;
};
inline void setStackSize( bool fl )
{
init_args.StackSize = fl;
StackSize = fl;
};
inline bool getStackSize( )
{
return init_args.StackSize;
return StackSize;
};
inline void setTrailSize( bool fl )
{
init_args.TrailSize = fl;
TrailSize = fl;
};
inline bool getTrailSize( )
{
return init_args.TrailSize;
return TrailSize;
};
inline bool getMStackSize( )
{
return init_args.StackSize;
return StackSize;
};
inline void setMaxTrailSize( bool fl )
{
init_args.MaxTrailSize = fl;
MaxTrailSize = fl;
};
inline bool getMaxTrailSize( )
{
return init_args.MaxTrailSize;
return MaxTrailSize;
};
inline void setYapLibDir( const char * fl )
{
init_args.YapLibDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapLibDir, fl);
YapLibDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)YapLibDir, fl);
};
inline const char * getYapLibDir( )
{
return init_args.YapLibDir;
return YapLibDir;
};
inline void setYapShareDir( const char * fl )
{
init_args.YapShareDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapShareDir, fl);
YapShareDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)YapShareDir, fl);
};
inline const char * getYapShareDir( )
{
return init_args.YapShareDir;
return YapShareDir;
};
inline void setSavedState( const char * fl )
{
init_args.SavedState = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.SavedState, fl);
SavedState = (const char *)malloc(strlen(fl)+1);
strcpy((char *)SavedState, fl);
};
inline const char * getSavedState( )
{
return init_args.SavedState;
return SavedState;
};
inline void setYapPrologBootFile( const char * fl )
{
init_args.YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapPrologBootFile, fl);
YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
strcpy((char *)YapPrologBootFile, fl);
};
inline const char * getYapPrologBootFile( )
{
return init_args.YapPrologBootFile;
return YapPrologBootFile;
};
inline void setYapPrologGoal( const char * fl )
{
init_args.YapPrologGoal = fl;
YapPrologGoal = fl;
};
inline const char * getYapPrologGoal( )
{
return init_args.YapPrologGoal;
return YapPrologGoal;
};
inline void setYapPrologTopLevelGoal( const char * fl )
{
init_args.YapPrologTopLevelGoal = fl;
YapPrologTopLevelGoal = fl;
};
inline const char * getYapPrologTopLevelGoal( )
{
return init_args.YapPrologTopLevelGoal;
return YapPrologTopLevelGoal;
};
inline void setHaltAfterConsult( bool fl )
{
init_args.HaltAfterConsult = fl;
HaltAfterConsult = fl;
};
inline bool getHaltAfterConsult( )
{
return init_args.HaltAfterConsult;
return HaltAfterConsult;
};
inline void setFastBoot( bool fl )
{
init_args.FastBoot = fl;
FastBoot = fl;
};
inline bool getFastBoot( )
{
return init_args.FastBoot;
return FastBoot;
};
#if __ANDROID__
//> export ResoourceManager
inline void setAssetManager( AAssetManager *mgr )
{
init_args.assetManager = mgr;
assetManager = mgr;
};
#endif
inline void setArgc( int fl )
{
init_args.Argc = fl;
Argc = fl;
};
inline int getArgc( )
{
return init_args.Argc;
return Argc;
};
inline void setArgv( char ** fl )
{
init_args.Argv = fl;
Argv = fl;
};
inline char ** getArgv( )
{
return init_args.Argv;
return Argv;
};
YAPEngineArgs() {
Yap_InitDefaults(&init_args, NULL, 0, NULL);
#if YAP_PYTHON
init_args.Embedded = true;
python_in_python = Py_IsInitialized();
#endif
};
};
@ -381,7 +382,7 @@ private:
YAPEngine(YAPEngineArgs *cargs)
{
engine_args = cargs;
//doInit(cargs->init_args.boot_file_type);
//doInit(cargs->boot_file_type);
doInit(YAP_QLY);
}; /// construct a new engine, including aaccess to callbacks
/// construct a new engine using argc/argv list of arguments

View File

@ -67,7 +67,7 @@ extern int pop_text_stack__(int lvl USES_REGS);
(/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, \
__FUNCTION__, __LINE__),*/ \
pop_output_text_stack__(lvl,p))
extern void *pop_output_text_stack__(int lvl, void *ox USES_REGS);
extern void *pop_output_text_stack__(int lvl, const void *ox USES_REGS);
/****************** character definition table **************************/

View File

@ -24,7 +24,7 @@
/* consulting files */
typedef union CONSULT_OBJ {
const unsigned char *filename;
const unsigned char *f_name;
int mode;
Prop p;
UInt c;

View File

@ -351,11 +351,14 @@ typedef struct yap_boot_params {
int ErrorNo;
//> errorstring
char *ErrorCause;
#ifdef __cplusplus
void YAP_init_args();
#endif
} YAP_init_args;
#ifdef YAP_H
YAP_file_type_t Yap_InitDefaults(YAP_init_args *init_args, char saved_state[],
int Argc, char *Argv[]);
int Argc, char **Argv);
#endif
/* this should be opaque to the user */

View File

@ -40,16 +40,14 @@ static char SccsId[] = "%W% %G%";
AAssetManager * Yap_assetManager;
jboolean Java_pt_up_yap_app_assetAssetManager(JNIEnv* env, jclass clazz, jobject assetManager)
jboolean Java_pt_up_yap_app_YAPDroid_setAssetManager(JNIEnv* env, jclass clazz, jobject assetManager)
{
Yap_assetManager = AAssetManager_fromJava(env, assetManager);
return true;
}
static void *
open_asset__
( int sno, const char *fname, const char
*io_mode)
open_asset__( int sno, const char *fname, const char *io_mode)
{
int mode;
const void *buf;
@ -57,14 +55,16 @@ open_asset__
if (strstr(fname,"/assets") == fname) {
// we're in
if ( Yap_assetManager == NULL) {
return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"asset manager",
fname);
return NULL;
}
if (strchr(io_mode, 'w') || strchr(io_mode, 'a')) {
return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"%s: no writing but flags are %s",
fname, io_mode);
return NULL;
}
if (strchr(io_mode, 'B'))
mode = AASSET_MODE_BUFFER;
@ -85,13 +85,13 @@ open_asset__
} else if ((buf = AAsset_getBuffer(a))) {
// copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz);
AAsset_close(a);
return rc;
if (rc) AAsset_close(a);
return st;
}
// should be done, but if not
GLOBAL_Stream[sno].vfs_handle= a;
st->vfs = me;
return true;
return a;
}
return NULL;
}
@ -169,14 +169,14 @@ bool is_dir_a( VFS_t *me,const char *dirName)
}
static
bool exists_a(VFS_t *me, const char *dirName)
VFS_t *exists_a(VFS_t *me, const char *dirName)
{
// try not to use it as an asset
AAsset *d = AAssetManager_open ( Yap_assetManager, dirName, AASSET_MODE_UNKNOWN);
if (d == NULL)
return false;
return NULL;
AAsset_close(d);
return true;
return me;
}
@ -192,14 +192,13 @@ static bool set_cwd (VFS_t *me, const char *dirName) {
#endif
/* create a new alias arg for stream sno */
VFS_t *
Yap_InitAssetManager( AAssetManager* mgr )
Yap_InitAssetManager( void )
{
#if __ANDROID__
VFS_t *me;
Yap_assetManager = mgr;
/* init standard VFS */
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets";

View File

@ -1520,7 +1520,56 @@ static Int p_open_null_stream(USES_REGS1) {
return (Yap_unify(ARG1, t));
}
int Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags) {
int Yap_OpenStream(const char *fname, const char * io_mode) {
CACHE_REGS
int sno;
StreamDesc *st;
Atom at;
struct vfs *vfsp;
FILE *fd;
int flags;
sno = GetFreeStreamD();
if (sno < 0)
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, MkAtomTerm(Yap_LookupAtom(fname)),
"new stream not available for opening"));
st = GLOBAL_Stream+sno;
vfsp = NULL;
if ((vfsp = vfs_owner(fname)) != NULL) {
st->u.private_data = vfsp->open(sno, fname, io_mode);
UNLOCK(st->streamlock);
fd = NULL;
if (st->u.private_data == NULL)
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)), "%s", fname));
st->vfs = vfsp;
} else if ((fd = fopen(fname, io_mode)) == NULL ||
(!strchr(io_mode, 'b') && binary_file(fname))) {
UNLOCK(st->streamlock);
if (errno == ENOENT && !strchr(io_mode, 'r')) {
return PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)), "%s: %s", fname,
strerror(errno));
} else {
return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)), "%s: %s",
fname, strerror(errno));
}
}
if (strchr(io_mode, 'r')) {
if (strchr(io_mode, 'a')) {
at = AtomAppend;
flags = Append_Stream_f | Output_Stream_f;
} else {
at = AtomWrite;
flags = Output_Stream_f;
}
} else {
at = AtomRead;
flags = Input_Stream_f;
}
Yap_initStream(sno, fd, fname, fname, LOCAL_encoding, flags, at, NULL);
return sno;
}
int Yap_FileStream(FILE *fd, char *name, Term file_name, int flags) {
CACHE_REGS
int sno;
Atom at;
@ -1540,6 +1589,26 @@ int Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags) {
return sno;
}
int FileStream(FILE* fd, char *name, Term file_name, int flags )
{
int sno;
Atom at;
sno = GetFreeStreamD();
if (sno < 0)
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, name,
"new stream not available for opening"));
if (flags & Output_Stream_f) {
if (flags & Append_Stream_f)
at = AtomAppend;
else
at = AtomWrite;
} else
at = AtomRead;
Yap_initStream(sno, fd, name, file_name, LOCAL_encoding, flags, at, NULL);
return sno;
}
#define CheckStream(arg, kind, msg) \
CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
@ -1867,10 +1936,6 @@ static Int get_abs_file_parameter(USES_REGS1) {
void Yap_InitPlIO(struct yap_boot_params *argi) {
Int i;
#if __ANDROID__
if (argi->assetManager)
Yap_InitAssetManager( argi->assetManager );
#endif
if (argi->inp > 0)
Yap_stdin = fdopen(argi->inp - 1, "r");
else if (argi->inp)

View File

@ -283,8 +283,4 @@ static inline void freeBuffer(const void *ptr) {
free((void *)ptr);
}
/** VFS handling */
VFS_t *Yap_InitAssetManager(AAssetManager *mgr);
#endif

View File

@ -102,13 +102,9 @@ static bool is_directory(const char *FileName) {
}
bool Yap_Exists(const char *f) {
VFS_t *vfs = GLOBAL_VFS;
while(vfs) {
VFS_t *n=vfs->exists(vfs,f);
if (n==vfs) return true;
if (!n) return false;
vfs = n;
VFS_t *vfs;
if ((vfs = vfs_owner(f))) {
return vfs->exists(vfs,f) != NULL;
}
#if _WIN32
if (_access(f, 0) == 0)
@ -172,9 +168,10 @@ bool Yap_IsAbsolutePath(const char *p0) {
static const char *PlExpandVars(const char *source, const char *root,
char *result) {
CACHE_REGS
int lvl = push_text_stack();
const char *src = source;
if (!result)
result = BaseMalloc(YAP_FILENAME_MAX + 1);
result = Malloc(YAP_FILENAME_MAX + 1);
if (strlen(source) >= YAP_FILENAME_MAX) {
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
@ -197,6 +194,7 @@ static const char *PlExpandVars(const char *source, const char *root,
if (s != NULL)
strncpy(result, s, YAP_FILENAME_MAX);
strcat(result, src);
result = pop_output_text_stack(lvl, result);
return result;
} else {
#if HAVE_GETPWNAM
@ -211,6 +209,7 @@ static const char *PlExpandVars(const char *source, const char *root,
FileError(SYSTEM_ERROR_OPERATING_SYSTEM,
MkAtomTerm(Yap_LookupAtom(source)),
"User %s does not exist in %s", result, source);
pop_text_stack(lvl);
return NULL;
}
strncpy(result, user_passwd->pw_dir, YAP_FILENAME_MAX);
@ -222,6 +221,7 @@ static const char *PlExpandVars(const char *source, const char *root,
return NULL;
#endif
}
result = pop_output_text_stack(lvl, result);
return result;
}
// do VARIABLE expansion
@ -263,6 +263,7 @@ static const char *PlExpandVars(const char *source, const char *root,
if (tocp > YAP_FILENAME_MAX) {
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkStringTerm(src),
"path too long");
pop_text_stack(lvl);
return NULL;
}
if (root && !Yap_IsAbsolutePath(source)) {
@ -274,6 +275,7 @@ static const char *PlExpandVars(const char *source, const char *root,
strncpy(result, source, strlen(src) + 1);
}
}
result = pop_output_text_stack(lvl, result);
return result;
}

View File

@ -29,6 +29,7 @@
#include "YapIOConfig.h"
#include <Yatom.h>
#include <VFS.h>
#ifndef _PL_WRITE_
@ -47,6 +48,13 @@ typedef struct AliasDescS {
/* parser stack, used to be AuxSp, now is ASP */
#define ParserAuxSp LOCAL_ScannerStack
/**
*
* @return a new VFS that will support /assets
*/
extern VFS_t *Yap_InitAssetManager( void );
/* routines in parser.c */
extern VarEntry *Yap_LookupVar(const char *);
extern Term Yap_VarNames(VarEntry *, Term);
@ -78,7 +86,8 @@ extern int Yap_PlGetWchar(void);
extern int Yap_PlFGetchar(void);
extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(FILE *, char *, Term, int);
extern int Yap_OpenStream(const char*, const char *);
extern int Yap_FileStream(FILE*, char *, Term, int);
extern char *Yap_TermToString(Term t, encoding_t encoding, int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
encoding_t *encoding, int flags);

View File

@ -19,7 +19,7 @@ for the relative license.
FILE *open_file (char *filename, const char *mode);
FILE *open_file (char *file_name, const char *mode);
static YAP_Bool compute_prob(void);
variables createVars(YAP_Term t,DdManager * mgr, int create_dot, char inames[1000][20])
@ -214,14 +214,14 @@ void init_my_predicates()
YAP_UserCPredicate("compute_prob",compute_prob,4);
}
FILE * open_file(char *filename, const char *mode)
FILE * open_file(char *file_name, const char *mode)
/* opens a file */
{
FILE *fp;
if ((fp = fopen(filename, mode)) == NULL)
if ((fp = fopen(file_name, mode)) == NULL)
{
perror(filename);
perror(file_name);
exit(1);
}
return fp;