small changes
This commit is contained in:
parent
994c5d0dfd
commit
9860b6244f
@ -141,7 +141,6 @@ Yap_LoadForeignFile(char *file, int flags)
|
||||
else
|
||||
dlflag |= RTLD_LOCAL;
|
||||
#endif
|
||||
if (!Yap_TrueFileName(file, LOCAL_FileNameBuf, true)){
|
||||
if (!Yap_locateFile(file, LOCAL_FileNameBuf, true)){
|
||||
/* use LD_LIBRARY_PATH */
|
||||
strncpy(LOCAL_FileNameBuf,file, YAP_FILENAME_MAX-1);
|
||||
@ -219,6 +218,7 @@ LoadForeign(StringList ofiles, StringList libs,
|
||||
other routines */
|
||||
|
||||
/* dlopen wants to follow the LD_CONFIG_PATH */
|
||||
if (!Yap_locateFile((char *)AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE)) {
|
||||
strcpy(LOCAL_ErrorSay, "%% Trying to open unexisting file in LoadForeign");
|
||||
return LOAD_FAILLED;
|
||||
}
|
||||
|
2
C/qlyr.c
2
C/qlyr.c
@ -1161,7 +1161,7 @@ qload_program( USES_REGS1 )
|
||||
}
|
||||
|
||||
int
|
||||
Yap_Restore(char *s, char *lib_dir)
|
||||
Yap_Restore(const char *s, char *lib_dir)
|
||||
{
|
||||
CACHE_REGS
|
||||
|
||||
|
6
C/save.c
6
C/save.c
@ -1441,7 +1441,6 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
|
||||
int mode;
|
||||
char fname[PATH_MAX+1];
|
||||
|
||||
|
||||
if (!Yap_findFile( inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_SAVED_STATE, true, true))
|
||||
return false;
|
||||
@ -1465,6 +1464,11 @@ Yap_OpenRestore(char *inpf, char *YapLibDir)
|
||||
{
|
||||
FILE *stream = NULL;
|
||||
|
||||
if (!inpf)
|
||||
inpf = "startup.yss";
|
||||
if (!YapLibDir) {
|
||||
YapLibDir = YAP_LIBDIR;
|
||||
}
|
||||
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
|
||||
return stream;
|
||||
}
|
||||
|
@ -1333,7 +1333,7 @@ static Int p_statistics_lu_db_size(USES_REGS1) {
|
||||
|
||||
static Int p_executable(USES_REGS1) {
|
||||
if (GLOBAL_argv && GLOBAL_argv[0])
|
||||
Yap_TrueFileName(GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE);
|
||||
Yap_locateFile(GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE);
|
||||
else
|
||||
strncpy(LOCAL_FileNameBuf, Yap_FindExecutable(), YAP_FILENAME_MAX - 1);
|
||||
|
||||
|
78
C/text.c
78
C/text.c
@ -76,9 +76,13 @@ SkipListCodes(unsigned char **bufp, Term *l, Term **tailp, Int *atoms, bool *wid
|
||||
}
|
||||
|
||||
if (!st0) {
|
||||
if (inp->type & YAP_STRING_MALLOC) {
|
||||
*bufp = st0 = (unsigned char *)malloc(MAXPATHLEN+1);
|
||||
smax = st0+(MAXPATHLEN-8); // give 8 bytes for max UTF-8 size + '\0';
|
||||
} else {
|
||||
*bufp = st0 = (unsigned char *)Yap_PreAllocCodeSpace();
|
||||
|
||||
smax = (unsigned char *)AuxTop-8; // give 8 bytes for max UTF-8 size + '\0';
|
||||
}
|
||||
} else if (inp->sz > 0) {
|
||||
smax = st0+(inp->sz-8); // give 8 bytes for max UTF-8 size + '\0';
|
||||
} else {
|
||||
@ -113,7 +117,7 @@ SkipListCodes(unsigned char **bufp, Term *l, Term **tailp, Int *atoms, bool *wid
|
||||
int ch;
|
||||
length++;
|
||||
if (length == max) {
|
||||
*st++ = '\0';
|
||||
*st++ = '\0';
|
||||
}
|
||||
{ Term hd = Deref(RepPair(*l)[0]);
|
||||
if (IsVarTerm(hd)) {
|
||||
@ -158,11 +162,11 @@ SkipListCodes(unsigned char **bufp, Term *l, Term **tailp, Int *atoms, bool *wid
|
||||
// now copy char to buffer
|
||||
size_t chsz = put_utf8( st, ch );
|
||||
if (smax <= st+chsz) {
|
||||
*st++ = '\0';
|
||||
*tailp = l;
|
||||
return length;
|
||||
*st++ = '\0';
|
||||
*tailp = l;
|
||||
return length;
|
||||
} else {
|
||||
st += chsz;
|
||||
st += chsz;
|
||||
}
|
||||
l = RepPair(*l)+1;
|
||||
do_derefa(v,l,derefa2_unk,derefa2_nonvar);
|
||||
@ -1425,3 +1429,65 @@ Yap_Splice_Text( int n, size_t cuts[], seq_tv_t *inp, encoding_t encv[], seq_tv
|
||||
}
|
||||
return (void *)outv;;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert a generic text term (string, atom, list of codes, list of atoms) into a buff
|
||||
er.
|
||||
*
|
||||
* @param t the term
|
||||
* @param buf the buffer, if NULL a buffer is malloced, and the user should reclai it
|
||||
* @param len buffer size
|
||||
* @param enc encoding (UTF-8 is strongly recommended)
|
||||
*
|
||||
* @return the buffer, or NULL in case of failure. If so, Yap_Error may be called.
|
||||
*/
|
||||
const char *
|
||||
Yap_TextTermToText(Term t, char *buf, size_t len)
|
||||
{ CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
encoding_t enc = LOCAL_encoding;
|
||||
|
||||
inp.val.t = t;
|
||||
if (IsAtomTerm(t))
|
||||
inp.type = YAP_STRING_ATOM;
|
||||
else if (IsStringTerm(t))
|
||||
inp.type = YAP_STRING_STRING;
|
||||
else if (IsPairTerm(t) )
|
||||
inp.type = (YAP_STRING_CODES|YAP_STRING_ATOMS);
|
||||
else {
|
||||
Yap_Error(TYPE_ERROR_TEXT, t, NULL);
|
||||
return false;
|
||||
}
|
||||
out.enc = enc;
|
||||
out.type = YAP_STRING_CHARS;
|
||||
if (!buf) {
|
||||
inp.type |= YAP_STRING_MALLOC;
|
||||
out.type |= YAP_STRING_MALLOC;
|
||||
}
|
||||
out.val.c = buf;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return NULL;
|
||||
return out.val.c;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert from a text buffer (8-bit) to a term that has the same type as _Tguide_
|
||||
*
|
||||
* @param s the buffer
|
||||
* @param tguide the guide
|
||||
*
|
||||
* @return the term
|
||||
*/
|
||||
Term Yap_MkTextTerm(const char *s,
|
||||
Term tguide ) {
|
||||
CACHE_REGS
|
||||
if (IsAtomTerm(tguide))
|
||||
return MkAtomTerm(Yap_LookupAtom(s));
|
||||
if (IsStringTerm(tguide))
|
||||
return MkStringTerm(s);
|
||||
if (IsPairTerm(tguide) && IsAtomTerm(HeadOfTerm(tguide))) {
|
||||
return Yap_CharsToListOfAtoms( s, LOCAL_encoding PASS_REGS );
|
||||
}
|
||||
return Yap_CharsToListOfCodes( s, LOCAL_encoding PASS_REGS );
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
#define GIT_SHA1 "703ac357357858351b27cb33b12830193e591282"
|
||||
#define GIT_SHA1 "bea2431c3ed833d81f5297e32c3776760c047561"
|
||||
const char g_GIT_SHA1[] = GIT_SHA1;
|
||||
|
11
H/Yapproto.h
11
H/Yapproto.h
@ -346,7 +346,7 @@ void Yap_InitReadUtil(void);
|
||||
|
||||
/* qly.c */
|
||||
void Yap_InitQLY(void);
|
||||
int Yap_Restore(char *, char *);
|
||||
int Yap_Restore(const char *, char *);
|
||||
void Yap_InitQLYR(void);
|
||||
|
||||
/* range.c */
|
||||
@ -409,19 +409,22 @@ void Yap_InitSysbits(int wid);
|
||||
void Yap_InitSysPreds(void);
|
||||
void Yap_InitcTime(int);
|
||||
void Yap_InitTime(int);
|
||||
int Yap_TrueFileName(const char *, char *, bool);
|
||||
int Yap_TruePrefixedFileName(const char *, const char *, char *, int);
|
||||
const char *Yap_locateFile(const char *, char *, bool);
|
||||
double Yap_random(void);
|
||||
#ifdef _WIN32
|
||||
char *Yap_RegistryGetString(char *);
|
||||
void Yap_WinError(char *);
|
||||
#endif
|
||||
const char *Yap_TextTermToText(Term t, char *buf, size_t len);
|
||||
Term Yap_MkTextTerm(const char *s, Term tguide );
|
||||
|
||||
typedef enum { YAP_STD, YAP_SAVED_STATE, YAP_OBJ, YAP_PL, YAP_QLY } file_type_t;
|
||||
|
||||
const char *Yap_AbsoluteFile(const char *spec, bool ok);
|
||||
const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz, bool ok);
|
||||
|
||||
const char *Yap_findFile(const char *isource, const char *idef, const char *root,
|
||||
char *result, bool access, file_type_t ftype,
|
||||
bool expand_root, bool in_lib);
|
||||
/* threads.c */
|
||||
void Yap_InitThreadPreds(void);
|
||||
void Yap_InitFirstWorkerThreadHandle(void);
|
||||
|
@ -208,7 +208,7 @@ typedef enum {
|
||||
|
||||
typedef struct yap_boot_params {
|
||||
/* if NON-NULL, path where we can find the saved state */
|
||||
char *SavedState;
|
||||
const char *SavedState;
|
||||
/* if NON-0, minimal size for Heap or Code Area */
|
||||
unsigned long int HeapSize;
|
||||
/* if NON-0, maximal size for Heap or Code Area */
|
||||
|
@ -50,6 +50,7 @@ E(DOMAIN_ERROR_ARRAY_TYPE, DOMAIN_ERROR, "array_type")
|
||||
E(DOMAIN_ERROR_CLOSE_OPTION, DOMAIN_ERROR, "close_option")
|
||||
E(DOMAIN_ERROR_FILE_ERRORS, DOMAIN_ERROR, "file_errors")
|
||||
E(DOMAIN_ERROR_FILE_TYPE, DOMAIN_ERROR, "file_type")
|
||||
E(DOMAIN_ERROR_GENERIC_ARGUMENT, DOMAIN_ERROR, "generic_argument")
|
||||
E(DOMAIN_ERROR_IO_MODE, DOMAIN_ERROR, "io_mode")
|
||||
E(DOMAIN_ERROR_MUTABLE, DOMAIN_ERROR, "mutable")
|
||||
E(DOMAIN_ERROR_NON_EMPTY_LIST, DOMAIN_ERROR, "non_empty_list")
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
/* Define to 1 if you have the <openssl/ripemd.h> header file. */
|
||||
#ifndef HAVE_APR_1_APR_MD5_H
|
||||
#define HAVE_APR_1_APR_MD5_H 1
|
||||
/* #undef HAVE_APR_1_APR_MD5_H */
|
||||
#endif
|
||||
|
||||
|
||||
|
13
os/files.c
13
os/files.c
@ -451,15 +451,18 @@ is_absolute_file_name ( USES_REGS1 )
|
||||
Yap_Error(INSTANTIATION_ERROR, t, "file_base_name/2");
|
||||
return FALSE;
|
||||
}
|
||||
at = AtomOfTerm(t);
|
||||
if (IsWideAtom(at)) {
|
||||
const char *buf = Yap_TextTermToText( t, NULL, 0);
|
||||
if (buf) {
|
||||
return Yap_IsAbsolutePath( buf );
|
||||
} else {
|
||||
at = AtomOfTerm(t);
|
||||
if (IsWideAtom(at)) {
|
||||
#if _WIN32
|
||||
return PathIsRelativeW(RepAtom(at)->WStrOfAE);
|
||||
return PathIsRelativeW(RepAtom(at)->WStrOfAE);
|
||||
#else
|
||||
return RepAtom(at)->WStrOfAE[0] == '/';
|
||||
#endif
|
||||
} else {
|
||||
return Yap_IsAbsolutePath( RepAtom(at)->StrOfAE );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1385,6 +1385,7 @@ do_open(Term file_name, Term t2,
|
||||
LOCAL_Error_TYPE = DOMAIN_ERROR_OPEN_OPTION;
|
||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, "option handling in open/3" );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/* done */
|
||||
sno = GetFreeStreamD();
|
||||
@ -1614,8 +1615,8 @@ static Int p_file_expansion(USES_REGS1) { /* '$file_expansion'(+File,-Name) */
|
||||
PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3");
|
||||
return (FALSE);
|
||||
}
|
||||
if (!Yap_TrueFileName(RepAtom(AtomOfTerm(file_name))->StrOfAE,
|
||||
LOCAL_FileNameBuf, FALSE))
|
||||
if (!Yap_locateFile(RepAtom(AtomOfTerm(file_name))->StrOfAE,
|
||||
LOCAL_FileNameBuf, false))
|
||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name,
|
||||
"absolute_file_name/3"));
|
||||
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))));
|
||||
|
146
os/sysbits.c
146
os/sysbits.c
@ -52,7 +52,7 @@ static Term do_glob(const char *spec, bool ok_to);
|
||||
static int chdir(char *);
|
||||
/* #define signal skel_signal */
|
||||
#endif /* MACYAP */
|
||||
static char *
|
||||
static const char *
|
||||
expandVars(const char *spec);
|
||||
|
||||
void exit(int);
|
||||
@ -278,7 +278,7 @@ bool
|
||||
Yap_IsAbsolutePath(const char *p0)
|
||||
{
|
||||
// verify first if expansion is needed: ~/ or $HOME/
|
||||
char *p = expandVars( p0 );
|
||||
const char *p = expandVars( p0 );
|
||||
bool nrc;
|
||||
#if _WIN32 || __MINGW32__
|
||||
nrc = !PathIsRelative(p);
|
||||
@ -582,7 +582,7 @@ static const char *myrealpath( const char *path)
|
||||
return out;
|
||||
}
|
||||
|
||||
static char *
|
||||
static const char *
|
||||
expandVars(const char *spec)
|
||||
{
|
||||
#if _WIN32 || defined(__MINGW32__)
|
||||
@ -593,20 +593,16 @@ expandVars(const char *spec)
|
||||
return NULL;
|
||||
spec = u;
|
||||
#endif
|
||||
bool ok_to = true;
|
||||
if (spec == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
bool ok_to = LOCAL_PrologMode &&
|
||||
!(LOCAL_PrologMode & BootMode);
|
||||
if ( ok_to )
|
||||
{
|
||||
Term t = do_glob( spec, true );
|
||||
if (IsPairTerm(t))
|
||||
return RepAtom(AtomOfTerm(HeadOfTerm(t)))->StrOfAE;
|
||||
return RepAtom(AtomOfTerm(HeadOfTerm(t)))->StrOfAE;
|
||||
return NULL;
|
||||
} else {
|
||||
return PlExpandVars( spec );
|
||||
}
|
||||
return (char *)spec;
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -646,6 +642,7 @@ Yap_AbsoluteFile(const char *spec, bool ok)
|
||||
const char *
|
||||
Yap_AbsoluteFileInBuffer(const char *spec, char *out, size_t sz, bool ok)
|
||||
{
|
||||
|
||||
const char*p;
|
||||
const char*rc;
|
||||
if (ok) {
|
||||
@ -676,6 +673,11 @@ static Term
|
||||
/* Expand the string for the program to run. */
|
||||
do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
{
|
||||
if (spec == NULL) {
|
||||
return TermNil;
|
||||
}
|
||||
const char *espec = PlExpandVars( spec );
|
||||
|
||||
#if _WIN32 || defined(__MINGW32__)
|
||||
{
|
||||
char u[YAP_FILENAME_MAX+1];
|
||||
@ -684,14 +686,14 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
CELL *dest;
|
||||
|
||||
// first pass, remove Unix style stuff
|
||||
if (unix2win(spec, u, YAP_FILENAME_MAX) == NULL)
|
||||
if (unix2win(espec, u, YAP_FILENAME_MAX) == NULL)
|
||||
return TermNil;
|
||||
spec = (const char *)u;
|
||||
espec = (const char *)u;
|
||||
|
||||
if (!use_system_expansion) {
|
||||
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(spec)), TermNil);
|
||||
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(espec)), TermNil);
|
||||
}
|
||||
hFind = FindFirstFile(spec, &find);
|
||||
hFind = FindFirstFile(espec, &find);
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@ -738,7 +740,7 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
#ifdef GLOB_BRACE
|
||||
flags |= GLOB_BRACE|GLOB_TILDE;
|
||||
#endif
|
||||
switch (glob (spec, flags, NULL, &gresult))
|
||||
switch (glob (espec, flags, NULL, &gresult))
|
||||
{
|
||||
case 0: /* Successful. */
|
||||
ss = gresult.gl_pathv;
|
||||
@ -769,7 +771,7 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
#if HAVE_WORDEXP
|
||||
int rc;
|
||||
memset( &wresult,0,sizeof(wresult) );
|
||||
switch ((rc = wordexp (spec, &wresult, flags)))
|
||||
switch ((rc = wordexp (espec, &wresult, flags)))
|
||||
{
|
||||
case 0: /* Successful. */
|
||||
ss = wresult.we_wordv;
|
||||
@ -778,7 +780,7 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
break;
|
||||
} else {
|
||||
Term t;
|
||||
t = MkAtomTerm( Yap_LookupAtom( expandVars(spec) ) );
|
||||
t = MkAtomTerm( Yap_LookupAtom( expandVars(espec) ) );
|
||||
wordfree (&wresult);
|
||||
return MkPairTerm( t, TermNil );
|
||||
}
|
||||
@ -799,11 +801,7 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
Term tf = TermNil;
|
||||
for (j = 0; j < pathcount; j++) {
|
||||
const char *s = ss[pathcount-(j+1)];
|
||||
#if HAVE_REALPATH
|
||||
tmp = myrealpath(s);
|
||||
#else
|
||||
tmp = s;
|
||||
#endif
|
||||
//if (!exists(s))
|
||||
// continue;
|
||||
Atom a = Yap_LookupAtom(tmp);
|
||||
@ -817,12 +815,10 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
if ( !glob_vs_wordexp)
|
||||
wordfree( &wresult );
|
||||
#endif
|
||||
if (tmp)
|
||||
freeBuffer( (void *)tmp );
|
||||
return tf;
|
||||
#else
|
||||
// just use basic
|
||||
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(spec)), TermNil);
|
||||
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(espec)), TermNil);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -916,7 +912,7 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
||||
switch (i) {
|
||||
case EXPAND_FILENAME_PARAMETER_EXPANSION:
|
||||
if (t == TermProlog) {
|
||||
char *s = expandVars( spec);
|
||||
const char *s = expandVars( spec);
|
||||
if (s == NULL) {
|
||||
return TermNil;
|
||||
}
|
||||
@ -944,7 +940,7 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
||||
|
||||
|
||||
if (!use_system_expansion) {
|
||||
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(spec)), TermNil);
|
||||
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(expandVars(spec))), TermNil);
|
||||
}
|
||||
tf = do_glob(spec, true);
|
||||
return tf;
|
||||
@ -997,17 +993,14 @@ absolute_file_system_path( USES_REGS1 )
|
||||
const char *fp;
|
||||
bool rc;
|
||||
char s[MAXPATHLEN+1];
|
||||
const char *text = Yap_TextTermToText( t, s, MAXPATHLEN);
|
||||
|
||||
if (IsVarTerm(t)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t, "absolute_file_system_path");
|
||||
return false;
|
||||
} else if (!IsAtomTerm(t)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM, t, "absolute_file_system_path");
|
||||
if (text == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (!(fp = Yap_AbsoluteFile( RepAtom(AtomOfTerm(t))->StrOfAE, true)))
|
||||
return false;
|
||||
rc = Yap_unify(MkAtomTerm(Yap_LookupAtom(fp)), ARG2);
|
||||
return false;
|
||||
rc = Yap_unify(Yap_MkTextTerm(fp, t), ARG2);
|
||||
if (fp != s)
|
||||
freeBuffer( (void *)fp );
|
||||
return rc;
|
||||
@ -1278,10 +1271,6 @@ Yap_InitPageSize(void)
|
||||
|
||||
/* TrueFileName -> Finds the true name of a file */
|
||||
|
||||
bool Yap_trueFileName(const char *isource, const char *idef, const char *root,
|
||||
char *result, bool access, file_type_t ftype,
|
||||
bool expand_root, bool in_lib);
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
@ -1347,31 +1336,51 @@ working_directory(USES_REGS1)
|
||||
}
|
||||
|
||||
static const char *
|
||||
expandWithPrefix(const char *source, const char *root)
|
||||
expandWithPrefix(const char *source, const char *root, char *target, bool expand)
|
||||
{
|
||||
char *work;
|
||||
|
||||
work = expandVars( source );
|
||||
if (expand)
|
||||
work = (char *)expandVars( source );
|
||||
else {
|
||||
if (!target)
|
||||
target = malloc(YAP_FILENAME_MAX);
|
||||
work = target;
|
||||
if (root) {
|
||||
strncpy( work, root , YAP_FILENAME_MAX-1 );
|
||||
strncat( work, "/" , YAP_FILENAME_MAX-1 );
|
||||
strncat( work, source , YAP_FILENAME_MAX-1 );
|
||||
} else {
|
||||
strncpy( work, source , YAP_FILENAME_MAX-1 );
|
||||
}
|
||||
return work;
|
||||
}
|
||||
// expand names first
|
||||
if (root && !Yap_IsAbsolutePath( source ) ) {
|
||||
char *s = expandVars( source);
|
||||
const char *s = expandVars( source);
|
||||
if (!s)
|
||||
return source;
|
||||
char *r0 = expandVars( root);
|
||||
const char *r0 = expandVars( root);
|
||||
size_t sl = strlen(s);
|
||||
size_t rl = strlen(r0);
|
||||
char *r = malloc( sl+rl+2);
|
||||
if (!target)
|
||||
target = malloc(YAP_FILENAME_MAX);
|
||||
char *r = target;
|
||||
strncat( r, r0, sl+rl+2 );
|
||||
strncat( r, "/", sl+rl+2 );
|
||||
strncat( r, s , sl+rl+2);
|
||||
return r;
|
||||
} else {
|
||||
if (target != work) {
|
||||
strncpy( target, work, sizeof(LOCAL_FileNameBuf)-1);
|
||||
freeBuffer( work );
|
||||
}
|
||||
return target;
|
||||
}
|
||||
strncpy( LOCAL_FileNameBuf, work, MAXPATHLEN-1);
|
||||
return LOCAL_FileNameBuf;
|
||||
}
|
||||
|
||||
/** Yap_trueFileName: tries to generate the true name of file
|
||||
aaaaaaaaaaaaaaaaaaaaa*
|
||||
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
|
||||
*
|
||||
*
|
||||
* @param isource the proper file
|
||||
* @param idef the default name fo rthe file, ie, startup.yss
|
||||
@ -1384,8 +1393,8 @@ expandWithPrefix(const char *source, const char *root)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
bool
|
||||
Yap_trueFileName (const char *isource, const char * idef, const char *iroot, char *result, bool access, file_type_t ftype, bool expand_root, bool in_lib)
|
||||
const char*
|
||||
Yap_findFile (const char *isource, const char * idef, const char *iroot, char *result, bool access, file_type_t ftype, bool expand_root, bool in_lib)
|
||||
{
|
||||
|
||||
char save_buffer[YAP_FILENAME_MAX+1];
|
||||
@ -1461,7 +1470,7 @@ Yap_trueFileName (const char *isource, const char * idef, const char *iroot, ch
|
||||
|
||||
if (pt) {
|
||||
source = ( ftype == YAP_SAVED_STATE || ftype == YAP_OBJ ? "../../lib/Yap" : "../../share/Yap" ) ;
|
||||
if (Yap_trueFileName(source, NULL, pt, save_buffer, access, ftype, expand_root, in_lib) )
|
||||
if (Yap_findFile(source, NULL, pt, save_buffer, access, ftype, expand_root, in_lib) )
|
||||
root = save_buffer;
|
||||
else
|
||||
done = true;
|
||||
@ -1483,27 +1492,21 @@ Yap_trueFileName (const char *isource, const char * idef, const char *iroot, ch
|
||||
if (done)
|
||||
continue;
|
||||
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "root= %s %s ", root, source) ; }
|
||||
const char *work = expandWithPrefix( source, root );
|
||||
const char *work = expandWithPrefix( source, root, result, false );
|
||||
|
||||
|
||||
// expand names in case you have
|
||||
// to add a prefix
|
||||
if ( !access || exists( work ) )
|
||||
return true; // done
|
||||
return work; // done
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
Yap_TrueFileName (const char *source, char *result, bool in_lib)
|
||||
const char*
|
||||
Yap_locateFile (const char *source, char *result, bool in_lib)
|
||||
{
|
||||
return Yap_trueFileName (source, NULL, NULL, result, true, YAP_PL, true, in_lib);
|
||||
}
|
||||
|
||||
int
|
||||
Yap_TruePrefixedFileName (const char *source, const char *root, char *result, int in_lib)
|
||||
{
|
||||
return Yap_trueFileName (source, NULL, root, result, true, YAP_PL, true, in_lib);
|
||||
return Yap_findFile (source, NULL, NULL, result, true, YAP_PL, true, in_lib);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -1528,18 +1531,21 @@ static Int
|
||||
p_expand_file_name ( USES_REGS1 )
|
||||
{
|
||||
Term t = Deref(ARG1);
|
||||
const char *text, *text2;
|
||||
|
||||
if (IsVarTerm(t)) {
|
||||
Yap_Error(INSTANTIATION_ERROR,t,"argument to true_file_name unbound");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsAtomTerm(t)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM,t,"argument to true_file_name");
|
||||
return FALSE;
|
||||
}
|
||||
if (!Yap_trueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, NULL, LOCAL_FileNameBuf, true, YAP_PL, true, false))
|
||||
text = Yap_TextTermToText( t, NULL, 0);
|
||||
if (!text)
|
||||
return false;
|
||||
if (!(text2 = PlExpandVars (text)))
|
||||
return false;
|
||||
return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
|
||||
freeBuffer( text );
|
||||
bool rc = Yap_unify(ARG2, Yap_MkTextTerm(text2, t));
|
||||
freeBuffer( text2 );
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -1563,7 +1569,7 @@ true_file_name3 ( USES_REGS1 )
|
||||
}
|
||||
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
||||
}
|
||||
if (!Yap_trueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, root, LOCAL_FileNameBuf, false, YAP_PL, false, false))
|
||||
if (!Yap_findFile (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, root, LOCAL_FileNameBuf, false, YAP_PL, false, false))
|
||||
return FALSE;
|
||||
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
|
||||
}
|
||||
|
@ -27,6 +27,6 @@
|
||||
|
||||
/* Define to 1 if you have the <util.h> header file. */
|
||||
#ifndef HAVE_UTIL_H
|
||||
#define HAVE_UTIL_H 1
|
||||
/* #undef HAVE_UTIL_H */
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user