This commit is contained in:
Vitor Santos Costa 2017-12-01 10:42:10 +00:00
parent 2a93f1da99
commit 876e42d629
16 changed files with 111 additions and 66 deletions

View File

@ -2144,7 +2144,6 @@ X_API int YAP_InitConsult(int mode, const char *fname, char *full,
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl); GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname)); GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
GLOBAL_Stream[sno].encoding = LOCAL_encoding; GLOBAL_Stream[sno].encoding = LOCAL_encoding;
pop_text_stack(lvl);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno; return sno;
@ -2263,7 +2262,7 @@ X_API int YAP_WriteDynamicBuffer(YAP_Term t, char *buf, size_t sze,
char *b; char *b;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
b = Yap_TermToString(t, enc, flags); b = Yap_TermToBuffer(t, enc, flags);
strncpy(buf, b, sze); strncpy(buf, b, sze);
buf[sze] = 0; buf[sze] = 0;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
@ -2431,9 +2430,8 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
if (!LOCAL_TextBuffer) if (!LOCAL_TextBuffer)
LOCAL_TextBuffer = Yap_InitTextAllocator(); LOCAL_TextBuffer = Yap_InitTextAllocator();
int lvl = push_text_stack(); yroot = malloc(YAP_FILENAME_MAX + 1);
yroot = Malloc(YAP_FILENAME_MAX + 1); boot_file = malloc(YAP_FILENAME_MAX + 1);
boot_file = Malloc(YAP_FILENAME_MAX + 1);
/* ignore repeated calls to YAP_Init */ /* ignore repeated calls to YAP_Init */
Yap_embedded = yap_init->Embedded; Yap_embedded = yap_init->Embedded;
Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
@ -2674,7 +2672,6 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
start_modules(); start_modules();
YAP_initialized = true; YAP_initialized = true;
pop_text_stack(lvl);
return return
YAP_BOOT_PL; YAP_BOOT_PL;
} }

View File

@ -487,7 +487,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
#endif #endif
if (inp->type & YAP_STRING_TERM) { if (inp->type & YAP_STRING_TERM) {
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
char *s = (char *)Yap_TermToString(inp->val.t, ENC_ISO_UTF8, 0); char *s = (char *) Yap_TermToBuffer(inp->val.t, ENC_ISO_UTF8, 0);
return inp->val.uc = (unsigned char *)s; return inp->val.uc = (unsigned char *)s;
} }
if (inp->type & YAP_STRING_CHARS) { if (inp->type & YAP_STRING_CHARS) {

View File

@ -501,7 +501,7 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
#endif #endif
if (inp->type & YAP_STRING_TERM) { if (inp->type & YAP_STRING_TERM) {
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
char *s = (char *)Yap_TermToString(inp->val.t, lengp, ENC_ISO_UTF8, 0); char *s = (char *) Yap_TermToBuffer(inp->val.t, lengp, ENC_ISO_UTF8, 0);
return inp->val.uc = (unsigned char *)s; return inp->val.uc = (unsigned char *)s;
} }
if (inp->type & YAP_STRING_CHARS) { if (inp->type & YAP_STRING_CHARS) {

View File

@ -87,7 +87,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
continue; continue;
} }
} }
const char *sn = Yap_TermToString(args[i], LOCAL_encoding, const char *sn = Yap_TermToBuffer(args[i], LOCAL_encoding,
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
size_t sz; size_t sz;
if (sn == NULL) { if (sn == NULL) {

View File

@ -1255,7 +1255,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
Yap_CloseSlots(sls); Yap_CloseSlots(sls);
} }
char *Yap_TermToString(Term t, encoding_t enc, int flags) { char *Yap_TermToBuffer(Term t, encoding_t enc, int flags) {
CACHE_REGS CACHE_REGS
int sno = Yap_open_buf_write_stream(enc, flags); int sno = Yap_open_buf_write_stream(enc, flags);
const char *sf; const char *sf;

View File

@ -12,7 +12,7 @@ extern "C" {
#include "YapInterface.h" #include "YapInterface.h"
#include "blobs.h" #include "blobs.h"
X_API char *Yap_TermToString(Term t, encoding_t encodingp, X_API char *Yap_TermToBuffer(Term t, encoding_t encodingp,
int flags); int flags);
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity); X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);

View File

@ -241,7 +241,7 @@ public:
char *os; char *os;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), enc, Handle_vars_f))) { if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(t), enc, Handle_vars_f))) {
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return 0; return 0;
} }

View File

@ -416,7 +416,7 @@ extern AAssetManager *Yap_assetManager;
extern void *Yap_openAssetFile(const char *path); extern void *Yap_openAssetFile(const char *path);
extern bool Yap_isAsset(const char *path); extern bool Yap_isAsset(const char *path);
#endif #endif
extern const char *Yap_getcwd(const char *, size_t); extern const char *Yap_getcwd( char *, size_t);
extern void Yap_cputime_interval(Int *, Int *); extern void Yap_cputime_interval(Int *, Int *);
extern void Yap_systime_interval(Int *, Int *); extern void Yap_systime_interval(Int *, Int *);
extern void Yap_InitSysbits(int wid); extern void Yap_InitSysbits(int wid);

View File

@ -178,7 +178,7 @@ static bool set_cwd(VFS_t *me, const char *dirName) {
strcpy(virtual_cwd, dirName); strcpy(virtual_cwd, dirName);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", __android_log_print(ANDROID_LOG_INFO, "YAPDroid",
"chdir %s", virtual_cwd); "chdir %s", virtual_cwd);
Yap_do_low_level_trace = true; Yap_do_low_level_trace=1;
return true; return true;
} }

View File

@ -460,7 +460,7 @@ static Int exists_directory(USES_REGS1) {
#if HAVE_STAT #if HAVE_STAT
struct SYSTEM_STAT ss; struct SYSTEM_STAT ss;
file_name = RepAtom(AtomOfTerm(tname))->StrOfAE; file_name = Yap_VF(RepAtom(AtomOfTerm(tname))->StrOfAE);
if (SYSTEM_STAT(file_name, &ss) != 0) { if (SYSTEM_STAT(file_name, &ss) != 0) {
/* ignore errors while checking a file */ /* ignore errors while checking a file */
return false; return false;
@ -483,7 +483,7 @@ static Int is_absolute_file_name(USES_REGS1) { /* file_base_name(Stream,N) */
int l = push_text_stack(); int l = push_text_stack();
const char *buf = Yap_TextTermToText(t PASS_REGS); const char *buf = Yap_TextTermToText(t PASS_REGS);
if (buf) { if (buf) {
rc = Yap_IsAbsolutePath(buf); rc = Yap_IsAbsolutePath(buf, true);
} else { } else {
at = AtomOfTerm(t); at = AtomOfTerm(t);
#if _WIN32 #if _WIN32

View File

@ -119,7 +119,7 @@ bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
FILE *f; FILE *f;
// like any file stream. // like any file stream.
st->file = f = fmemopen(buf, nchars, "r"); st->file = f = fmemopen((char *)buf, nchars, "r");
st->status = Input_Stream_f | Seekable_Stream_f | InMemory_Stream_f; st->status = Input_Stream_f | Seekable_Stream_f | InMemory_Stream_f;
st->vfs = NULL; st->vfs = NULL;
st->encoding = LOCAL_encoding; st->encoding = LOCAL_encoding;
@ -292,17 +292,15 @@ void Yap_MemOps(StreamDesc *st) {
st->stream_getc = PlGetc; st->stream_getc = PlGetc;
} }
static int sssno;
bool Yap_CloseMemoryStream(int sno) { bool Yap_CloseMemoryStream(int sno) {
sssno++; if ((GLOBAL_Stream[sno].status & Output_Stream_f) && GLOBAL_Stream[sno].file) {
// if (sssno > 1720) Yap_do_low_level_trace=1;
if ((GLOBAL_Stream[sno].status & Output_Stream_f)) {
fflush(GLOBAL_Stream[sno].file); fflush(GLOBAL_Stream[sno].file);
fclose(GLOBAL_Stream[sno].file); fclose(GLOBAL_Stream[sno].file);
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f) if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
free(GLOBAL_Stream[sno].nbuf); free(GLOBAL_Stream[sno].nbuf);
} else { } else {
if (GLOBAL_Stream[sno].file)
fclose(GLOBAL_Stream[sno].file); fclose(GLOBAL_Stream[sno].file);
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f) if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
free(GLOBAL_Stream[sno].nbuf); free(GLOBAL_Stream[sno].nbuf);

View File

@ -1183,7 +1183,6 @@ do_open(Term file_name, Term t2,
const char *fname; const char *fname;
char fbuf[FILENAME_MAX]; char fbuf[FILENAME_MAX];
stream_flags_t flags; stream_flags_t flags;
FILE *fd;
const char *s_encoding; const char *s_encoding;
encoding_t encoding; encoding_t encoding;
Term tenc; Term tenc;
@ -1515,7 +1514,6 @@ int Yap_OpenStream(const char *fname, const char *io_mode) {
struct vfs *vfsp; struct vfs *vfsp;
FILE *fd; FILE *fd;
int flags; int flags;
SMALLUNSGN s;
sno = GetFreeStreamD(); sno = GetFreeStreamD();
if (sno < 0) { if (sno < 0) {
@ -1526,6 +1524,7 @@ int Yap_OpenStream(const char *fname, const char *io_mode) {
st = GLOBAL_Stream + sno; st = GLOBAL_Stream + sno;
// read, write, append // read, write, append
st->file = NULL; st->file = NULL;
fname = Yap_VF(fname);
if ((vfsp = vfs_owner(fname)) != NULL ) { if ((vfsp = vfs_owner(fname)) != NULL ) {
if (!vfsp->open(vfsp, sno, fname, io_mode)) { if (!vfsp->open(vfsp, sno, fname, io_mode)) {
UNLOCK(st->streamlock); UNLOCK(st->streamlock);

View File

@ -959,7 +959,8 @@ static void CloseStream(int sno) {
CACHE_REGS CACHE_REGS
fflush(NULL); fflush(NULL);
if (!(GLOBAL_Stream[sno].status & if (GLOBAL_Stream[sno].file &&
!(GLOBAL_Stream[sno].status &
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f))) (Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
fclose(GLOBAL_Stream[sno].file); fclose(GLOBAL_Stream[sno].file);
#if HAVE_SOCKET #if HAVE_SOCKET

View File

@ -95,6 +95,7 @@ static bool is_directory(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);
if ((vfs = vfs_owner(f))) { if ((vfs = vfs_owner(f))) {
return vfs->exists(vfs,f); return vfs->exists(vfs,f);
} }
@ -106,8 +107,9 @@ bool Yap_Exists(const char *f) {
} }
return false; return false;
#elif HAVE_ACCESS #elif HAVE_ACCESS
if (access(f, F_OK) == 0) if (access(f, F_OK) == 0) {
return true; return true;
}
if (errno == EINVAL) { if (errno == EINVAL) {
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access"); Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
} }
@ -139,10 +141,13 @@ int Yap_dir_separator(int ch) { return dir_separator(ch); }
char *libdir = NULL; char *libdir = NULL;
#endif #endif
bool Yap_IsAbsolutePath(const char *p0) { bool Yap_IsAbsolutePath(const char *p0, bool expand) {
// verify first if expansion is needed: ~/ or $HOME/ // verify first if expansion is needed: ~/ or $HOME/
const char *p = expandVars(p0, LOCAL_FileNameBuf); const char *p = p0;
bool nrc; bool nrc;
if (expand) {
p = expandVars(p0, LOCAL_FileNameBuf);
}
#if _WIN32 || __MINGW32__ #if _WIN32 || __MINGW32__
nrc = !PathIsRelative(p); nrc = !PathIsRelative(p);
#else #else
@ -258,7 +263,7 @@ static const char *PlExpandVars(const char *source, const char *root,
pop_text_stack(lvl); pop_text_stack(lvl);
return NULL; return NULL;
} }
if (root && !Yap_IsAbsolutePath(source)) { if (root && !Yap_IsAbsolutePath(source, false)) {
strncpy(result, root, YAP_FILENAME_MAX); strncpy(result, root, YAP_FILENAME_MAX);
if (root[strlen(root) - 1] != '/') if (root[strlen(root) - 1] != '/')
strncat(result, "/", YAP_FILENAME_MAX); strncat(result, "/", YAP_FILENAME_MAX);
@ -364,14 +369,15 @@ char virtual_cwd[YAP_FILENAME_MAX + 1];
return rc; return rc;
} }
static const char *myrealpath(const char *path, char *out) { static const char *myrealpath(const char *path, char *out) {
if (!out) int lvl = push_text_stack();
out = LOCAL_FileNameBuf; #if _WIN32
#if _WIN32
DWORD retval = 0; DWORD retval = 0;
// notice that the file does not need to exist // notice that the file does not need to exist
retval = GetFullPathName(path, YAP_FILENAME_MAX, out, NULL); retval = GetFullPathName(path, YAP_FILENAME_MAX, out, NULL);
pop_text_stack(lvl);
if (retval == 0) { if (retval == 0) {
Yap_WinError("Generating a full path name for a file"); Yap_WinError("Generating a full path name for a file");
return NULL; return NULL;
@ -382,12 +388,13 @@ static const char *myrealpath(const char *path, char *out) {
char *rc = realpath(path, NULL); char *rc = realpath(path, NULL);
if (rc) { if (rc) {
pop_text_stack(lvl);
return rc; return rc;
} }
// rc = NULL; // rc = NULL;
if (errno == ENOENT || errno == EACCES) { if (errno == ENOENT || errno == EACCES) {
char base[YAP_FILENAME_MAX + 1]; char *base= Malloc(YAP_FILENAME_MAX + 1);
strncpy(base, path, YAP_FILENAME_MAX - 1); strncpy(base, path, YAP_FILENAME_MAX );
rc = realpath(dirname(base), out); rc = realpath(dirname(base), out);
if (rc) { if (rc) {
@ -411,6 +418,7 @@ static const char *myrealpath(const char *path, char *out) {
} }
#endif #endif
strcat(rc, b); strcat(rc, b);
rc = pop_output_text_stack(lvl, rc);
return rc; return rc;
} }
} }
@ -418,6 +426,7 @@ static const char *myrealpath(const char *path, char *out) {
#endif #endif
out = malloc(strlen(path) + 1); out = malloc(strlen(path) + 1);
strcpy(out, path); strcpy(out, path);
pop_text_stack(lvl);
return out; return out;
} }
@ -923,7 +932,7 @@ static Int make_directory(USES_REGS1) {
#if defined(__MINGW32__) || _MSC_VER #if defined(__MINGW32__) || _MSC_VER
if (_mkdir(fd) == -1) { if (_mkdir(fd) == -1) {
#else #else
if (mkdir(fd, 0777) == -1) { if (mkdir(Yap_VFAlloc(fd), 0777) == -1) {
#endif #endif
/* return an error number */ /* return an error number */
return false; // errno? return false; // errno?
@ -932,7 +941,7 @@ static Int make_directory(USES_REGS1) {
} }
static Int p_rmdir(USES_REGS1) { static Int p_rmdir(USES_REGS1) {
const char *fd = AtomName(AtomOfTerm(ARG1)); const char *fd = Yap_VFAlloc(AtomName(AtomOfTerm(ARG1)));
#if defined(__MINGW32__) || _MSC_VER #if defined(__MINGW32__) || _MSC_VER
if (_rmdir(fd) == -1) { if (_rmdir(fd) == -1) {
#else #else
@ -1130,7 +1139,7 @@ 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(const char *cwd, size_t cwdlen) { const char *Yap_getcwd(char *cwd, size_t cwdlen) {
if (virtual_cwd[0]) { if (virtual_cwd[0]) {
if (!cwd) { if (!cwd) {
cwd = malloc(cwdlen+1); cwd = malloc(cwdlen+1);
@ -1189,7 +1198,7 @@ const char *Yap_findFile(const char *isource, const char *idef,
YAP_file_type_t ftype, bool expand_root, bool in_lib) { YAP_file_type_t ftype, bool expand_root, bool in_lib) {
char *save_buffer = NULL; char *save_buffer = NULL;
char *root = iroot, *source = isource; char *root, *source;
int rc = FAIL_RESTORE; int rc = FAIL_RESTORE;
int try = 0; int try = 0;
bool abspath = false; bool abspath = false;
@ -1216,10 +1225,10 @@ const char *Yap_findFile(const char *isource, const char *idef,
strcpy(source, idef); strcpy(source, idef);
} }
if (source[0]) { if (source[0]) {
abspath = Yap_IsAbsolutePath(source); abspath = Yap_IsAbsolutePath(source, expand_root);
} }
if (!abspath && !root[0] && ftype == YAP_BOOT_PL) { if (!abspath && !root[0] && ftype == YAP_BOOT_PL) {
root = YAP_PL_SRCDIR; strcpy(root, YAP_PL_SRCDIR);
} }
break; break;
case 1: // library directory is given in command line case 1: // library directory is given in command line
@ -1246,8 +1255,7 @@ const char *Yap_findFile(const char *isource, const char *idef,
if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) { if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) {
eroot = getenv("YAPLIBDIR"); eroot = getenv("YAPLIBDIR");
} else if (ftype == YAP_BOOT_PL) { } else if (ftype == YAP_BOOT_PL) {
eroot = getenv("YAPSHAREDIR" eroot = getenv("YAPSHAREDIR");
"/pl");
if (eroot == NULL) { if (eroot == NULL) {
continue; continue;
} else { } else {
@ -1306,24 +1314,27 @@ const char *Yap_findFile(const char *isource, const char *idef,
const char *pt = Yap_FindExecutable(); const char *pt = Yap_FindExecutable();
if (pt) { if (pt) {
if (ftype == YAP_BOOT_PL) { if (ftype == YAP_BOOT_PL) {
#if __ANDROID__ #if __ANDROID__
strcpy(root, "../../../files/Yap/pl"); strcpy(root, "../../../files/Yap/pl");
#else #else
root = "../../share/Yap/pl"; root = "../../share/Yap/pl";
#endif #endif
} else { } else {
strcpy(root, (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ strcpy(root, (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
? "../../lib/Yap" ? "../../lib/Yap"
: "../../share/Yap")); : "../../share/Yap"));
} }
if (strcmp(root, iroot)==0) { if (strcmp(root, iroot) == 0) {
done = true; done = true;
continue; continue;
} }
if (!save_buffer) if (!save_buffer) {
save_buffer = Malloc(YAP_FILENAME_MAX+1); save_buffer = Malloc(YAP_FILENAME_MAX + 1);
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
save_buffer[0] = 0;
}
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
expand_root, in_lib)) expand_root, in_lib))
strcpy(root, save_buffer); strcpy(root, save_buffer);
else else
@ -1361,9 +1372,13 @@ const char *Yap_findFile(const char *isource, const char *idef,
if (!access || Yap_Exists(work)) { if (!access || Yap_Exists(work)) {
work = pop_output_text_stack(lvl,work); work = pop_output_text_stack(lvl,work);
return work; // done return work; // done
} else if (abspath) } else if (abspath) {
return NULL; pop_text_stack(lvl);
return NULL;
}
} }
pop_text_stack(lvl);
return NULL; return NULL;
} }
@ -1452,7 +1467,7 @@ static Int p_sh(USES_REGS1) { /* sh */
shell = (char *)getenv("SHELL"); shell = (char *)getenv("SHELL");
if (shell == NULL) if (shell == NULL)
shell = "/bin/sh"; shell = "/bin/sh";
if (system(shell) < 0) { if (system(Yap_VFAlloc(shell)) < 0) {
#if HAVE_STRERROR #if HAVE_STRERROR
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in sh/0", Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in sh/0",
strerror(errno)); strerror(errno));
@ -1658,10 +1673,12 @@ static Int p_mv(USES_REGS1) { /* rename(+OldName,+NewName) */
} else if (!IsAtomTerm(t2)) { } else if (!IsAtomTerm(t2)) {
Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom"); Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom");
} else { } else {
oldname = (RepAtom(AtomOfTerm(t1)))->StrOfAE; oldname = Yap_VFAlloc((RepAtom(AtomOfTerm(t1)))->StrOfAE);
newname = (RepAtom(AtomOfTerm(t2)))->StrOfAE; newname = Yap_VFAlloc((RepAtom(AtomOfTerm(t2)))->StrOfAE);
if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0) if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0)
unlink(newname); unlink(newname);
free(oldname);
free(newname);
if (r != 0) { if (r != 0) {
#if HAVE_STRERROR #if HAVE_STRERROR
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, t2, "%s in rename(%s,%s)", Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, t2, "%s in rename(%s,%s)",

View File

@ -678,7 +678,7 @@ static Int term_to_string(USES_REGS1) {
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1); Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
const char *s; const char *s;
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
s = Yap_TermToString(ARG1,LOCAL_encoding, s = Yap_TermToBuffer(ARG1, LOCAL_encoding,
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
if (!s || !MkStringTerm(s)) { if (!s || !MkStringTerm(s)) {
Yap_Error(RESOURCE_ERROR_HEAP, t1, Yap_Error(RESOURCE_ERROR_HEAP, t1,
@ -699,7 +699,7 @@ static Int term_to_atom(USES_REGS1) {
Term t2 = Deref(ARG2), ctl, rc = false; Term t2 = Deref(ARG2), ctl, rc = false;
Atom at; Atom at;
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
const char *s = Yap_TermToString(Deref(ARG1), LOCAL_encoding, const char *s = Yap_TermToBuffer(Deref(ARG1), LOCAL_encoding,
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) { if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
Yap_Error(RESOURCE_ERROR_HEAP, t2, Yap_Error(RESOURCE_ERROR_HEAP, t2,

View File

@ -88,7 +88,7 @@ extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term); extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(const char*, const char*); extern int Yap_OpenStream(const char*, const char*);
extern int Yap_FileStream(FILE*, char *, Term, int); extern int Yap_FileStream(FILE*, char *, Term, int);
extern char *Yap_TermToString(Term t, encoding_t encoding, int flags); extern char *Yap_TermToBuffer(Term t, encoding_t encoding, int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length, extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
encoding_t *encoding, int flags); encoding_t *encoding, int flags);
extern int Yap_GetFreeStreamD(void); extern int Yap_GetFreeStreamD(void);
@ -103,7 +103,7 @@ extern int Yap_growheap_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
extern int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **); extern int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
extern int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **); extern int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
extern bool Yap_IsAbsolutePath(const char *p); extern bool Yap_IsAbsolutePath(const char *p, bool);
extern Atom Yap_TemporaryFile(const char *prefix, int *fd); extern Atom Yap_TemporaryFile(const char *prefix, int *fd);
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool expand); extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool expand);
@ -156,6 +156,37 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
return MkAtomTerm(Yap_ULookupAtom(cs)); return MkAtomTerm(Yap_ULookupAtom(cs));
} }
INLINE_ONLY inline EXTERN char *Yap_VF(const char *path){
char out[YAP_FILENAME_MAX+1], *p = (char *)path;
extern char virtual_cwd[];
if ( virtual_cwd[0] == 0 || Yap_IsAbsolutePath(path, false)) {
return p;
}
strcpy(out, virtual_cwd);
strcat(out, "/" );
strcat(out, p);
strcpy(p, out);
return p;
}
INLINE_ONLY inline EXTERN char *Yap_VFAlloc(const char *path){
char *out;
extern char virtual_cwd[];
out = (char *)malloc(YAP_FILENAME_MAX+1);
if ( virtual_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) {
return (char *)path;
}
strcpy(out, virtual_cwd);
strcat(out, "/" );
strcat(out, path);
return out;
}
/// UT when yap started /// UT when yap started
extern uint64_t Yap_StartOfWTimes; extern uint64_t Yap_StartOfWTimes;
@ -165,4 +196,6 @@ extern bool Yap_HandleSIGINT(void);
extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *bufi, extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *bufi,
size_t nchars USES_REGS); size_t nchars USES_REGS);
#endif #endif