Fixes, mostly to the biting o

This commit is contained in:
Vitor Santos Costa 2017-12-10 01:22:45 +00:00
parent 645b2c7d93
commit 3061844c95
22 changed files with 3137 additions and 3546 deletions

File diff suppressed because it is too large Load Diff

View File

@ -167,18 +167,10 @@ static Int LoadForeign(StringList
while (libs) {
const char *file = AtomName(libs->name);
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true,
true)) {
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
/* use LD_LIBRARY_PATH */
strncpy(LOCAL_ErrorMessage, (char *)AtomName(libs->name),
YAP_FILENAME_MAX);
}
#ifdef __osf__
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
#else
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY | RTLD_GLOBAL)) ==
if ((libs->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
NULL)
#endif
{
@ -195,20 +187,9 @@ static Int LoadForeign(StringList
/* load libraries first so that their symbols are available to
other routines */
const char *file = AtomName(ofiles->name);
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true,
true)) {
if (LOCAL_ErrorMessage == NULL) {
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
strcpy(LOCAL_ErrorMessage,
"%% Trying to open non-existing file in LoadForeign");
}
}
#ifdef __osf__
if ((ofiles->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
#else
if ((ofiles->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY | RTLD_GLOBAL)) ==
if ((ofiles->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
NULL)
#endif
{
if (LOCAL_ErrorMessage == NULL) {
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);

View File

@ -1097,10 +1097,10 @@ static Int qload_program(USES_REGS1) {
return true;
}
YAP_file_type_t Yap_Restore(const char *s, const char *lib_dir) {
YAP_file_type_t Yap_Restore(const char *s) {
CACHE_REGS
FILE *stream = Yap_OpenRestore(s, lib_dir);
FILE *stream = Yap_OpenRestore(s);
if (!stream)
return -1;
GLOBAL_RestoreFile = s;

View File

@ -87,7 +87,7 @@ void initIO(void);
static int myread(FILE *, char *, Int);
static Int mywrite(FILE *, char *, Int);
static FILE *open_file(char *, int);
static FILE *open_file(const char *, int);
static int close_file(void);
static Int putout(CELL);
static Int putcellptr(CELL *);
@ -123,7 +123,7 @@ static void restore_heap(void);
static void ShowAtoms(void);
static void ShowEntries(PropEntry *);
#endif
static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *,
static int OpenRestore(const char *, CELL *, CELL *, CELL *,
CELL *, FILE **);
static void CloseRestore(void);
#ifndef _WIN32
@ -233,7 +233,7 @@ static Int OldHeapUsed;
static CELL which_save;
/* Open a file to read or to write */
static FILE *open_file(char *my_file, int flag) {
static FILE *open_file(const char *my_file, int flag) {
FILE *splfild;
char flags[6];
int i = 0;
@ -1307,10 +1307,11 @@ static void ShowAtoms() {
#include <stdio.h>
static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
static int commit_to_saved_state(const char *s, CELL *Astate, CELL *ATrail,
CELL *AStack, CELL *AHeap) {
CACHE_REGS
int mode;
char tmp[YAP_FILENAME_MAX+1];
if ((mode = check_header(Astate, ATrail, AStack, AHeap PASS_REGS)) ==
FAIL_RESTORE)
@ -1318,9 +1319,8 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
LOCAL_PrologMode = BootMode;
if (Yap_HeapBase) {
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true,
true);
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
Yap_AbsoluteFile(s, tmp, true);
fprintf(stderr, "%% Restoring file %s\n", tmp);
}
Yap_CloseStreams(TRUE);
}
@ -1333,7 +1333,7 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
return mode;
}
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
static int try_open(const char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
CELL *AHeap, FILE **streamp) {
int mode;
@ -1355,18 +1355,13 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
return mode;
}
static int OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate,
static int OpenRestore(const char *fname, CELL *Astate,
CELL *ATrail, CELL *AStack, CELL *AHeap,
FILE **streamp) {
CACHE_REGS
int mode;
char fname[YAP_FILENAME_MAX + 1];
if (!Yap_findFile(inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_QLY,
true, true))
return FAIL_RESTORE;
if (fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
if (fname && fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
streamp)) != FAIL_RESTORE) {
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(fname)));
@ -1378,22 +1373,19 @@ static int OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate,
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
"incorrect saved state ");
} else {
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX - 1);
strncpy(LOCAL_FileNameBuf, fname, YAP_FILENAME_MAX - 1);
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
"could not open saved state");
}
return FAIL_RESTORE;
}
FILE *Yap_OpenRestore(const char *inpf, const char *YapLibDir) {
FILE *Yap_OpenRestore(const char *inpf) {
FILE *stream = NULL;
if (!inpf)
inpf = "startup.yss";
if (!YapLibDir) {
YapLibDir = YAP_LIBDIR;
}
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
OpenRestore(inpf, NULL, NULL, NULL, NULL, &stream);
return stream;
}
@ -1467,14 +1459,14 @@ static void RestoreHeap(OPCODE old_ops[] USES_REGS) {
* This function is called to know about the parameters of the last saved
* state
*/
int Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail,
int Yap_SavedInfo(const char *FileName, CELL *ATrail,
CELL *AStack, CELL *AHeap) {
return DO_ONLY_CODE;
CELL MyTrail, MyStack, MyHeap, MyState;
int mode;
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap,
mode = OpenRestore(FileName, &MyState, &MyTrail, &MyStack, &MyHeap,
NULL);
if (mode == FAIL_RESTORE) {
return -1;
@ -1554,13 +1546,13 @@ static void FreeRecords(void) {
* This function is called when wanting only to restore the heap and
* associated registers
*/
static int Restore(char *s, char *lib_dir USES_REGS) {
static int Restore(char *s_dir USES_REGS) {
int restore_mode;
OPCODE old_ops[_std_top + 1];
CELL MyTrail, MyStack, MyHeap, MyState;
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack,
if ((restore_mode = OpenRestore(s_dir, &MyState, &MyTrail, &MyStack,
&MyHeap, NULL)) == FAIL_RESTORE)
return (FALSE);
Yap_ShutdownLoadForeign();
@ -1612,9 +1604,9 @@ static int Restore(char *s, char *lib_dir USES_REGS) {
return restore_mode;
}
int Yap_SavedStateRestore(char *s, char *lib_dir) {
int Yap_SavedStateRestore(char *s) {
CACHE_REGS
return Restore(s, lib_dir PASS_REGS);
return Restore(s PASS_REGS);
}
static Int p_restore(USES_REGS1) {
@ -1640,7 +1632,7 @@ static Int p_restore(USES_REGS1) {
Yap_Error(TYPE_ERROR_LIST, t1, "restore/1");
return (FALSE);
}
if ((mode = Restore(s, NULL PASS_REGS)) == DO_ONLY_CODE) {
if ((mode = Restore(s PASS_REGS)) == DO_ONLY_CODE) {
Yap_RestartYap(3);
}
return (mode != FAIL_RESTORE);

View File

@ -1349,13 +1349,13 @@ static Int p_statistics_lu_db_size(USES_REGS1) {
}
static Int p_executable(USES_REGS1) {
char tmp[YAP_FILENAME_MAX+1];
if (GLOBAL_argv && GLOBAL_argv[0])
Yap_findFile(GLOBAL_argv[0], NULL, NULL, LOCAL_FileNameBuf, true, YAP_EXE,
true, true);
Yap_AbsoluteFile(GLOBAL_argv[0], tmp, true);
else
strncpy(LOCAL_FileNameBuf, Yap_FindExecutable(), YAP_FILENAME_MAX - 1);
strncpy(tmp, Yap_FindExecutable(), YAP_FILENAME_MAX);
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)), ARG1);
return Yap_unify(MkAtomTerm(Yap_LookupAtom(tmp)), ARG1);
}
static Int p_system_mode(USES_REGS1) {

View File

@ -31,7 +31,7 @@ inline static size_t min_size(size_t i, size_t j) { return (i < j ? i : j); }
#define wcsnlen(S, N) min_size(N, wcslen(S))
#endif
#ifndef HAVE_STPCPY
#if !defined(HAVE_STPCPY) && !defined(__APPLE__)
inline static void* __stpcpy(void * i, const void * j) { return strcpy(i,j)+strlen(j);}
#define stpcpy __stpcpy
#endif

File diff suppressed because it is too large Load Diff

View File

@ -17,8 +17,8 @@ cmake_policy(VERSION 3.4)
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/cmake")
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
message(STATUS "ANACONDA found: ${ANACONDA}")
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
message(STATUS "ANACONDA found: ${ANACONDA}")
include(CheckIncludeFiles)
include(CheckLibraryExists)
@ -222,6 +222,7 @@ if (ANACONDA)
#set( CMAKE_INSTALL_FULL_PREFIX $ENV{PREFIX} )
set( PYTHON_LIBRARY $ENV{PREFIX}/lib/libpython$ENV{PY_VER}m$ENV{SHLIB_EXT})
set( PYTHON_INCLUDE_DIR $ENV{PREFIX}/include/python$ENV{PY_VER}m)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CONDA_BUILD=1)
set(YAP_IS_MOVABLE 1)
endif()
@ -814,7 +815,7 @@ endif(NOT ANDROID)
#
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${YAP_INCLUDEDIR} )
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap )

View File

@ -151,7 +151,8 @@ typedef void *(*fptr_t)(void);
main exports in YapInterface.h
*************************************************************************************************/
extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, *Yap_PLDIR;
extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, *Yap_PLDIR, *Yap_COMMONSDIR, *Yap_STARTUP, *Yap_BOOTFILE;
/* Basic exports */

View File

@ -236,7 +236,7 @@ process, namely, on choice-points.
YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL),
YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag,
"false", NULL),
/* YAP_FLAG(HOME_FLAG, "home", false, isatom, rootdir, NULL),*/ /**< home `
YAP_FLAG(HOME_FLAG, "home", false, isatom, rootdir, NULL), /**< home `
the root of the YAP installation, by default `/usr/local` in Unix or
`c:\Yap` in Windows system. Can only be set at configure time

View File

@ -1,169 +0,0 @@
/*************************************************************************
* *
* YAP Prolog %W% %G% *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: Yap.h *
* mods: *
* comments: abstract type definitions for YAP *
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
*************************************************************************/
#ifndef YAP_H
#include "YapTermConfig.h"
#include "config.h"
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
/* truth-values */
/* stdbool defines the booleam type, bool,
and the constants false and true */
#if HAVE_STDBOOL_H
#include <stdbool.h>
#else
#ifndef true
typedef int _Bool;
#define bool _Bool;
#define false 0
#define true 1
#endif
#endif /* HAVE_STDBOOL_H */
#define ALIGN_BY_TYPE(X, TYPE) \
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
#ifndef EXTERN
#ifdef MSC_VER
#define EXTERN
#else
#define EXTERN extern
#endif
#endif
/* defines integer types Int and UInt (unsigned) with the same size as a ptr
** and integer types Short and UShort with half the size of a ptr */
#if defined(PRIdPTR)
typedef intptr_t YAP_Int;
typedef uintptr_t YAP_UInt;
#elif defined(_WIN64)
typedef int64_t YAP_Int;
typedef uint64_t YAP_UInt;
#elif defined(_WIN32)
typedef int32_t YAP_Int;
typedef uint32_t YAP_UInt;
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
typedef long int YAP_Int;
typedef unsigned long int YAP_UInt;
#elif SIZEOF_INT == SIZEOF_INT_P
typedef int YAP_Int;
typedef unsigned int YAP_UInt;
#else
#error Yap require integer types of the same size as a pointer
#endif
/* */ typedef short int YAP_Short;
/* */ typedef unsigned short int YAP_UShort;
typedef YAP_UInt YAP_CELL;
typedef YAP_UInt YAP_Term;
/* Type definitions */
#ifndef TRUE
#define TRUE true
#endif
#ifndef FALSE
#endif
typedef bool YAP_Bool;
#define FALSE false
typedef YAP_Int YAP_handle_t;
typedef double YAP_Float;
typedef void *YAP_Atom;
typedef void *YAP_Functor;
#ifdef YAP_H
typedef YAP_Int Int;
typedef YAP_UInt UInt;
typedef YAP_Short Short;
typedef YAP_UShort UShort;
typedef uint16_t BITS16;
typedef int16_t SBITS16;
typedef uint32_t BITS32;
typedef YAP_CELL CELL;
typedef YAP_Term Term;
#define WordSize sizeof(BITS16)
#define CellSize sizeof(CELL)
#define SmallSize sizeof(SMALLUNSGN)
typedef YAP_Int Int;
typedef YAP_Float Float;
typedef YAP_handle_t yhandle_t;
#endif
#include "YapError.h"
#include "../os/encoding.h"
typedef encoding_t YAP_encoding_t;
#include "YapFormat.h"
/*************************************************************************************************
type casting macros
*************************************************************************************************/
#if SIZEOF_INT < SIZEOF_INT_P
#define SHORT_INTS 1
#else
#define SHORT_INTS 0
#endif
#ifdef __GNUC__
typedef long long int YAP_LONG_LONG;
typedef unsigned long long int YAP_ULONG_LONG;
#else
typedef long int YAP_LONG_LONG;
typedef unsigned long int YAP_ULONG_LONG;
#endif
#define Unsigned(V) ((CELL)(V))
#define Signed(V) ((Int)(V))

View File

@ -354,16 +354,16 @@ extern void Yap_InitReadUtil(void);
/* qly.c */
extern void Yap_InitQLY(void);
extern YAP_file_type_t Yap_Restore(const char *, const char *);
extern YAP_file_type_t Yap_Restore(const char *);
extern void Yap_InitQLYR(void);
/* range.c */
extern void Yap_InitRange(void);
/* save.c */
extern int Yap_SavedInfo(const char *, const char *, CELL *, CELL *, CELL *);
extern int Yap_SavedStateRestore(char *, char *);
extern FILE *Yap_OpenRestore(const char *, const char *);
extern int Yap_SavedInfo(const char *, CELL *, CELL *, CELL *);
extern int Yap_SavedStateRestore(char *);
extern FILE *Yap_OpenRestore(const char *);
extern void Yap_InitSavePreds(void);
/* scanner.c */
@ -432,10 +432,10 @@ extern void Yap_WinError(char *);
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool ok);
extern const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz,
bool ok);
extern const char *Yap_findFile(const char *isource, const char *idef,
const char *root, char *result, bool access,
YAP_file_type_t ftype, bool expand_root, bool in_lib);
extern bool Yap_ChDir(const char *path);
bool Yap_isDirectory(const char *FileName);
extern bool Yap_Exists(const char *f);
/* threads.c */
extern void Yap_InitThreadPreds(void);

View File

@ -1971,7 +1971,6 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
#ifndef YAP_IS_MOVABLE
/* name of YAP instaii */
#ifndef YAP_ROOTDIR
#define YAP_ROOTDIR "${YAP_ROOTDIR}"
@ -2001,13 +2000,14 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
#define YAP_SHAREDIR "${YAP_ROOTDIR}/share"
#endif
#else
extern char
*YAP_BINDIR,
*YAP_ROOTDIR,
*YAP_SHAREDIR,
*YAP_LIBDIR,
*YAP_YAPLIB;
/* name of YAP PL library */
#ifndef YAP_PLDIR
#define YAP_PLDIR "${YAP_SHAREDIR}/Yap"
#endif
/* name of Commons library */
#ifndef YAP_COMMONSDIR
#define YAP COMMONSDIR "${YAP_SHAREDIR}/PrologCommmons"
#endif

View File

@ -1370,7 +1370,7 @@ writable.
*/
static Int open3(USES_REGS1) {
static Int open3(USES_RfEGS1) {
/* '$open'(+File,+Mode,?Stream,-ReturnCode) */
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
}
@ -1465,11 +1465,11 @@ static Int p_file_expansion(USES_REGS1) { /* '$file_expansion'(+File,-Name) */
PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3");
return (FALSE);
}
if (!Yap_findFile(RepAtom(AtomOfTerm(file_name))->StrOfAE, NULL, NULL,
LOCAL_FileNameBuf, true, YAP_ANY_FILE, true, false))
char tmp[YAP_FILENAME_MAX+1];
if (!Yap_AbsoluteFile(RepAtom(AtomOfTerm(file_name))->StrOfAE,tmp, false))
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name,
"absolute_file_name/3"));
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))));
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(tmp))));
}
static Int p_open_null_stream(USES_REGS1) {

View File

@ -273,7 +273,6 @@ extern FILE *Yap_stderr;
char *Yap_MemExportStreamPtr(int sno);
extern bool Yap_Exists(const char *f);
static inline void freeBuffer(const void *ptr) {
CACHE_REGS

View File

@ -34,7 +34,6 @@ static void FileError(yap_error_number type, Term where, const char *format,
}
}
static Int p_sh(USES_REGS1);
static Int p_shell(USES_REGS1);
static Int p_system(USES_REGS1);
@ -67,11 +66,11 @@ void Yap_WinError(char *yap_error) {
/// is_directory: verifies whether an expanded file name
/// points at a readable directory
static bool is_directory(const char *FileName) {
bool Yap_isDirectory(const char *FileName) {
VFS_t *vfs;
if ((vfs = vfs_owner(FileName))) {
return vfs->isdir(vfs,FileName);
return vfs->isdir(vfs, FileName);
}
#ifdef _WIN32
DWORD dwAtts = GetFileAttributes(FileName);
@ -94,10 +93,10 @@ static bool is_directory(const char *FileName) {
}
bool Yap_Exists(const char *f) {
VFS_t *vfs;
f = Yap_VFAlloc(f);
if ((vfs = vfs_owner(f))) {
return vfs->exists(vfs,f);
VFS_t *vfs;
f = Yap_VFAlloc(f);
if ((vfs = vfs_owner(f))) {
return vfs->exists(vfs, f);
}
#if _WIN32
if (_access(f, 0) == 0)
@ -108,7 +107,7 @@ bool Yap_Exists(const char *f) {
return false;
#elif HAVE_ACCESS
if (access(f, F_OK) == 0) {
return true;
return true;
}
if (errno == EINVAL) {
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
@ -145,9 +144,9 @@ bool Yap_IsAbsolutePath(const char *p0, bool expand) {
// verify first if expansion is needed: ~/ or $HOME/
const char *p = p0;
bool nrc;
if (expand) {
p = expandVars(p0, LOCAL_FileNameBuf);
}
if (expand) {
p = expandVars(p0, LOCAL_FileNameBuf);
}
#if _WIN32 || __MINGW32__
nrc = !PathIsRelative(p);
#else
@ -345,7 +344,7 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
char virtual_cwd[YAP_FILENAME_MAX + 1];
bool Yap_ChDir(const char *path) {
bool Yap_ChDir(const char *path) {
bool rc = false;
char qp[FILENAME_MAX + 1];
const char *qpath = Yap_AbsoluteFile(path, qp, true);
@ -369,10 +368,9 @@ char virtual_cwd[YAP_FILENAME_MAX + 1];
return rc;
}
static const char *myrealpath(const char *path, char *out) {
int lvl = push_text_stack();
#if _WIN32
int lvl = push_text_stack();
#if _WIN32
DWORD retval = 0;
// notice that the file does not need to exist
@ -388,13 +386,13 @@ static const char *myrealpath(const char *path, char *out) {
char *rc = realpath(path, NULL);
if (rc) {
pop_text_stack(lvl);
pop_text_stack(lvl);
return rc;
}
// rc = NULL;
if (errno == ENOENT || errno == EACCES) {
char *base= Malloc(YAP_FILENAME_MAX + 1);
strncpy(base, path, YAP_FILENAME_MAX );
char *base = Malloc(YAP_FILENAME_MAX + 1);
strncpy(base, path, YAP_FILENAME_MAX);
rc = realpath(dirname(base), out);
if (rc) {
@ -418,7 +416,7 @@ static const char *myrealpath(const char *path, char *out) {
}
#endif
strcat(rc, b);
rc = pop_output_text_stack(lvl, rc);
rc = pop_output_text_stack(lvl, rc);
return rc;
}
}
@ -426,7 +424,7 @@ static const char *myrealpath(const char *path, char *out) {
#endif
out = malloc(strlen(path) + 1);
strcpy(out, path);
pop_text_stack(lvl);
pop_text_stack(lvl);
return out;
}
@ -957,97 +955,12 @@ static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
bool commons_done) {
CACHE_REGS
int len;
char *dir;
char *dir;
#if __WINDOWS__
{
if ((dir = Yap_RegistryGetString("library")) && is_directory(dir)) {
dir_done = true;
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(dir))))
return false;
}
if ((dir = Yap_RegistryGetString("prolog_commons")) && is_directory(dir)) {
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(dir))))
return false;
commons_done = true;
}
}
if (dir_done && commons_done)
return true;
#endif
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))))
return false;
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))))
return false;
if (!commons_done) {
LOCAL_FileNameBuf[len] = '\0';
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
if (is_directory(LOCAL_FileNameBuf)) {
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
return FALSE;
}
commons_done = true;
}
if (dir_done && commons_done)
return TRUE;
#if __WINDOWS__
{
size_t buflen;
char *pt;
/* couldn't find it where it was supposed to be,
let's try using the executable */
if (!GetModuleFileName(NULL, LOCAL_FileNameBuf, YAP_FILENAME_MAX)) {
Yap_WinError("could not find executable name");
/* do nothing */
return FALSE;
}
buflen = strlen(LOCAL_FileNameBuf);
pt = LOCAL_FileNameBuf + buflen;
while (*--pt != '\\') {
/* skip executable */
if (pt == LOCAL_FileNameBuf) {
FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
"could not find executable name");
/* do nothing */
return FALSE;
}
}
while (*--pt != '\\') {
/* skip parent directory "bin\\" */
if (pt == LOCAL_FileNameBuf) {
FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
"could not find executable name");
/* do nothing */
return FALSE;
}
}
/* now, this is a possible location for the ROOT_DIR, let's look for a share
* directory here */
pt[1] = '\0';
/* grosse */
strncat(LOCAL_FileNameBuf, "lib\\Yap", YAP_FILENAME_MAX);
libdir = Yap_AllocCodeSpace(strlen(LOCAL_FileNameBuf) + 1);
strncpy(libdir, LOCAL_FileNameBuf, strlen(LOCAL_FileNameBuf) + 1);
pt[1] = '\0';
strncat(LOCAL_FileNameBuf, "share", YAP_FILENAME_MAX);
}
strncat(LOCAL_FileNameBuf, "\\", YAP_FILENAME_MAX);
len = strlen(LOCAL_FileNameBuf);
strncat(LOCAL_FileNameBuf, "Yap", YAP_FILENAME_MAX);
if (!dir_done && is_directory(LOCAL_FileNameBuf)) {
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
return FALSE;
dir_done = true;
}
LOCAL_FileNameBuf[len] = '\0';
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
if (!commons_done && is_directory(LOCAL_FileNameBuf)) {
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
return FALSE;
commons_done = true;
}
#endif
return dir_done && commons_done;
return Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(Yap_COMMONSDIR)));
}
static Int libraries_directories(USES_REGS1) {
@ -1133,10 +1046,10 @@ int Yap_volume_header(char *file) { return volume_header(file); }
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
if (virtual_cwd[0]) {
if (!cwd) {
cwd = malloc(cwdlen+1);
if (!cwd) {
cwd = malloc(cwdlen + 1);
}
strcpy( cwd, virtual_cwd);
strcpy(cwd, virtual_cwd);
return cwd;
}
#if _WIN32 || defined(__MINGW32__)
@ -1171,184 +1084,6 @@ static Int working_directory(USES_REGS1) {
return Yap_ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
}
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
*
*
* @param isource the proper file
* @param idef the default name fothe file, ie, startup.yss
* @param root the prefix
* @param result the output
* @param access verify whether the file has access permission
* @param ftype saved state, object, saved file, prolog file
* @param expand_root expand $ ~, etc
* @param in_lib library file
*
* @return
*/
const char *Yap_findFile(const char *isource, const char *idef,
const char *iroot, char *result, bool access,
YAP_file_type_t ftype, bool expand_root, bool in_lib) {
char *save_buffer = NULL;
char *root, *source;
int rc = FAIL_RESTORE;
int try = 0;
bool abspath = false;
int lvl = push_text_stack();
root = Malloc(YAP_FILENAME_MAX+1);
source= Malloc(YAP_FILENAME_MAX+1);
if (iroot && iroot[0])
strcpy(root, iroot);
else
root[0] = 0;
if (isource && isource[0])
strcpy(source, isource);
else
source[0] = 0;
//__android_log_print(ANDROID_LOG_ERROR, "YAPDroid " __FUNCTION__,
// "try=%d %s %s", try, isource, iroot) ; }
while (rc == FAIL_RESTORE) {
// means we failed this iteration
bool done = false;
// { CACHE_REGS
switch (try ++) {
case 0: // path or file name is given;
if (!source[0] && idef && idef[0]) {
strcpy(source, idef);
}
if (source[0]) {
abspath = Yap_IsAbsolutePath(source, expand_root);
}
if (!abspath && !root[0] && ftype == YAP_BOOT_PL) {
strcpy(root, YAP_PL_SRCDIR);
}
break;
case 1: // library directory is given in command line
if (in_lib && ftype == YAP_SAVED_STATE) {
if (iroot && iroot[0])
strcpy(root, iroot);
else
root[0] = 0;
if (isource && isource[0])
strcpy(source, isource);
else if (idef && idef[0])
strcpy(source, idef);
else
source[0] = 0;
} else {
done = true;
}
break;
case 3: // use compilation variable YAPLIBDIR
if (in_lib) {
if (isource && isource[0])
strcpy(source, isource);
else if (idef && idef[0])
strcpy(source, idef);
else
source[0] = 0;
if (ftype == YAP_PL) {
strcpy(root,YAP_SHAREDIR);
} else if (ftype == YAP_BOOT_PL) {
strcpy(root, YAP_SHAREDIR);
strcat(root,"/pl");
} else {
strcpy(root,YAP_LIBDIR);
}
} else
done = true;
break;
case 4: // WIN stuff: registry
#if __WINDOWS
if (in_lib) {
const char *key = (ftype == YAP_PL || ftype == YAP_QLY ? "library" : "startup");
strcpy( source, Yap_RegistryGetString(source) );
root[0] = 0;
} else
#endif
done = true;
break;
case 5: // search from the binary
#ifndef __ANDROID__
{
done = true;
} break;
#endif
{
const char *pt = Yap_FindExecutable();
if (pt) {
if (ftype == YAP_BOOT_PL) {
#if __ANDROID__
strcpy(root, "../../../files/Yap/pl");
#else
root = "../../share/Yap/pl";
#endif
} else {
strcpy(root, (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
? "../../lib/Yap"
: "../../share/Yap"));
}
if (strcmp(root, iroot) == 0) {
done = true;
continue;
}
if (!save_buffer) {
save_buffer = Malloc(YAP_FILENAME_MAX + 1);
save_buffer[0] = 0;
}
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
expand_root, in_lib))
strcpy(root, save_buffer);
else
done = true;
} else {
done = true;
}
if (isource && isource[0])
strcpy(source, isource);
else if (idef && idef[0])
strcpy(source, idef);
else
source[0] = 0;
}
break;
case 6: // default, try current directory
if (!isource && ftype == YAP_SAVED_STATE)
strcpy(source, idef);
root[0] = 0;
break;
default:
pop_text_stack(lvl);
return NULL;
}
if (done)
continue;
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__,
// "root= %s %s ", root, source) ; }
const char *work = PlExpandVars(source, root, result);
// expand names in case you have
// to add a prefix
if (!access || Yap_Exists(work)) {
work = pop_output_text_stack(lvl,work);
return work; // done
} else if (abspath) {
pop_text_stack(lvl);
return NULL;
}
}
pop_text_stack(lvl);
return NULL;
}
static Int true_file_name(USES_REGS1) {
Term t = Deref(ARG1);
const char *s;
@ -1414,10 +1149,10 @@ static Int true_file_name3(USES_REGS1) {
}
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
}
if (!Yap_findFile(RepAtom(AtomOfTerm(t))->StrOfAE, NULL, root,
LOCAL_FileNameBuf, false, YAP_PL, false, false))
char tmp[YAP_FILENAME_MAX + 1];
if (!Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, tmp, true))
return FALSE;
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(tmp)));
}
/* Executes $SHELL under Prolog */
@ -1644,8 +1379,8 @@ static Int p_mv(USES_REGS1) { /* rename(+OldName,+NewName) */
newname = Yap_VFAlloc((RepAtom(AtomOfTerm(t2)))->StrOfAE);
if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0)
unlink(newname);
free(oldname);
free(newname);
free(oldname);
free(newname);
if (r != 0) {
#if HAVE_STRERROR
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, t2, "%s in rename(%s,%s)",
@ -1771,18 +1506,18 @@ static Int p_host_type(USES_REGS1) {
}
static Int p_yap_home(USES_REGS1) {
Term out;
Term out;
out = MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR));
return Yap_unify(out, ARG1);
out = MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR));
return Yap_unify(out, ARG1);
}
static Int p_yap_paths(USES_REGS1) {
Term out1, out2, out3;
out1 = MkAtomTerm(Yap_LookupAtom(Yap_LIBDIR));
out2 = MkAtomTerm(Yap_LookupAtom(Yap_SHAREDIR));
out3 = MkAtomTerm(Yap_LookupAtom(Yap_BINDIR));
out1 = MkAtomTerm(Yap_LookupAtom(Yap_LIBDIR));
out2 = MkAtomTerm(Yap_LookupAtom(Yap_SHAREDIR));
out3 = MkAtomTerm(Yap_LookupAtom(Yap_BINDIR));
return (Yap_unify(out1, ARG1) && Yap_unify(out2, ARG2) &&
Yap_unify(out3, ARG3));
@ -1864,7 +1599,7 @@ static Int p_win32(USES_REGS1) {
}
static Int p_ld_path(USES_REGS1) {
return Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(YAP_DLLDIR)));
return Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR)));
}
static Int p_address_bits(USES_REGS1) {

View File

@ -7,6 +7,7 @@ set(PL_BOOT_SOURCES
attributes.yap
boot.yap
bootlists.yap
bootutils.yap
callcount.yap
checker.yap
consult.yap
@ -84,6 +85,9 @@ install(FILES ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
endif()
install(FILES ${PL_SOURCES}
install(FILES ${PL_BOOT_SOURCES}
DESTINATION ${libpl}/pl
)
install(FILES ../library/ypp.yap
DESTINATION ${libpl}/library
)

View File

@ -22,7 +22,7 @@
:- system_module( '$_arith', [compile_expressions/0,
expand_exprs/2,
plus/3,
succ/2], ['$c_built_in'/3]).
succ/2], ['$c_built_in'/4]).
:- private( [do_c_built_in/3,
do_c_built_metacall/3,
@ -86,7 +86,6 @@ expand_exprs(Old,New) :-
After a call to this predicate, arithmetical expressions will be compiled.
(see example below). This is the default behavior.
*/
compile_expressions :- set_value('$c_arith',true).
/** @pred do_not_compile_expressions

View File

@ -1305,10 +1305,10 @@ not(G) :- \+ '$execute'(G).
bootstrap(F) :-
yap_flag(verbose_load, Old, silent),
open(F, read, Stream),
stream_property(Stream, [file_name(File)]),
'$start_consult'(consult, File, LC),
file_directory_name(File, Dir),
open(F, read, Stream),
stream_property(Stream, [file_name(File)]),
'$start_consult'(consult, File, LC),
file_directory_name(File, Dir),
working_directory(OldD, Dir),
(
current_prolog_flag(verbose_load, silent)

View File

@ -118,6 +118,7 @@ otherwise.
:- compile_expressions.
:- bootstrap('bootutils.yap').
:- bootstrap('bootlists.yap').
:- bootstrap('consult.yap').

View File

@ -57,7 +57,7 @@ variable:
+ YAPLIBDIR
if defined, or in the default library.
available as
YAP supports the SWI-Prolog interface to loading foreign code, the shlib package.
*/

View File

@ -30,6 +30,9 @@ meta_predicate declaration
% directive now meta_predicate Ps :- $meta_predicate(Ps).
:- use_system_module( '$_arith', ['$c_built_in'/4]).
:- dynamic prolog:'$meta_predicate'/4.
:- multifile prolog:'$meta_predicate'/4,