keep on fixing absolute_name
This commit is contained in:
parent
588ef40a16
commit
712d79c7bb
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/************************************************************************* *
|
/************************************************************************* *
|
||||||
* YAP Prolog *
|
* YAP Prolog *
|
||||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||||
@ -2348,7 +2349,7 @@ X_API Int YAP_Init(YAP_init_args *yap_init) {
|
|||||||
int restore_result;
|
int restore_result;
|
||||||
int do_bootstrap = (yap_init->YapPrologBootFile != NULL);
|
int do_bootstrap = (yap_init->YapPrologBootFile != NULL);
|
||||||
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
|
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
|
||||||
char boot_file[256];
|
char boot_file[YAP_FILENAME_MAX+1];
|
||||||
static int initialized = FALSE;
|
static int initialized = FALSE;
|
||||||
|
|
||||||
/* ignore repeated calls to YAP_Init */
|
/* ignore repeated calls to YAP_Init */
|
||||||
@ -2367,7 +2368,7 @@ X_API Int YAP_Init(YAP_init_args *yap_init) {
|
|||||||
GLOBAL_argc = yap_init->Argc;
|
GLOBAL_argc = yap_init->Argc;
|
||||||
#if BOOT_FROM_SAVED_STATE
|
#if BOOT_FROM_SAVED_STATE
|
||||||
if (!yap_init->SavedState) {
|
if (!yap_init->SavedState) {
|
||||||
yap_init->SavedState = Yap_locateFile(YAP_STARTUP, LOCAL_FileNameBuf, sizeof(LOCAL_FileNameBuf)-1);
|
yap_init->SavedState = Yap_locateFile(YAP_STARTUP, boot_file, sizeof(boot_file)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
83
os/sysbits.c
83
os/sysbits.c
@ -294,11 +294,12 @@ Yap_IsAbsolutePath(const char *p0)
|
|||||||
// this is necessary because
|
// this is necessary because
|
||||||
// support for ~expansion at the beginning
|
// support for ~expansion at the beginning
|
||||||
// systems like Android do not do this.
|
// systems like Android do not do this.
|
||||||
static char *
|
static const char *
|
||||||
PlExpandVars (const char *source)
|
PlExpandVars (const char *source, const char *root, char *result)
|
||||||
{
|
{
|
||||||
const char *src = source;
|
const char *src = source;
|
||||||
char *result = LOCAL_FileNameBuf;
|
if (!result)
|
||||||
|
result = malloc(YAP_FILENAME_MAX+1);
|
||||||
|
|
||||||
if (strlen(source) >= YAP_FILENAME_MAX) {
|
if (strlen(source) >= YAP_FILENAME_MAX) {
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in true_file-name is larger than the buffer size (%d bytes)", source, strlen(source));
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in true_file-name is larger than the buffer size (%d bytes)", source, strlen(source));
|
||||||
@ -376,7 +377,21 @@ PlExpandVars (const char *source)
|
|||||||
strcpy( result, src);
|
strcpy( result, src);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strncpy (result, source, YAP_FILENAME_MAX);
|
size_t tocp = strlen(src);
|
||||||
|
if (root) {
|
||||||
|
tocp = strlen(root)+1;
|
||||||
|
}
|
||||||
|
if (tocp > YAP_FILENAME_MAX) {
|
||||||
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkStringTerm(src), "path too long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (root) {
|
||||||
|
strncpy (result, root, YAP_FILENAME_MAX );
|
||||||
|
strncat ( result, "/", YAP_FILENAME_MAX);
|
||||||
|
strncat ( result, source, YAP_FILENAME_MAX);
|
||||||
|
} else {
|
||||||
|
strncpy (result, source, strlen(src)+1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -618,14 +633,15 @@ Yap_AbsoluteFile(const char *spec, bool ok)
|
|||||||
{
|
{
|
||||||
const char*p;
|
const char*p;
|
||||||
const char*rc;
|
const char*rc;
|
||||||
rc = expandVars(spec);
|
rc = PlExpandVars(spec, NULL, NULL);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
return spec;
|
rc = spec;
|
||||||
if ((p = myrealpath(rc) ) ) {
|
if ((p = myrealpath(rc) ) ) {
|
||||||
return p;
|
return p;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
freeBuffer( rc );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -676,11 +692,8 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
|||||||
if (spec == NULL) {
|
if (spec == NULL) {
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
const char *espec = PlExpandVars( spec );
|
|
||||||
|
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
{
|
{
|
||||||
char u[YAP_FILENAME_MAX+1];
|
|
||||||
WIN32_FIND_DATA find;
|
WIN32_FIND_DATA find;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
CELL *dest;
|
CELL *dest;
|
||||||
@ -718,6 +731,8 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
|||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
#elif HAVE_WORDEXP || HAVE_GLOB
|
#elif HAVE_WORDEXP || HAVE_GLOB
|
||||||
|
char * espec = u;
|
||||||
|
strncpy( espec, spec, sizeof(u));
|
||||||
/* Expand the string for the program to run. */
|
/* Expand the string for the program to run. */
|
||||||
size_t pathcount;
|
size_t pathcount;
|
||||||
#if HAVE_GLOB
|
#if HAVE_GLOB
|
||||||
@ -1349,50 +1364,6 @@ working_directory(USES_REGS1)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
|
||||||
expandWithPrefix(const char *source, const char *root, char *target, bool expand)
|
|
||||||
{
|
|
||||||
char *work;
|
|
||||||
|
|
||||||
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 ) ) {
|
|
||||||
const char *s = expandVars( source);
|
|
||||||
if (!s)
|
|
||||||
return source;
|
|
||||||
const char *r0 = expandVars( root);
|
|
||||||
size_t sl = strlen(s);
|
|
||||||
size_t rl = strlen(r0);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
|
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -1410,7 +1381,6 @@ static const char *
|
|||||||
const char*
|
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)
|
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];
|
char save_buffer[YAP_FILENAME_MAX+1];
|
||||||
const char *root, *source = isource;
|
const char *root, *source = isource;
|
||||||
int rc = FAIL_RESTORE;
|
int rc = FAIL_RESTORE;
|
||||||
@ -1506,8 +1476,7 @@ Yap_findFile (const char *isource, const char * idef, const char *iroot, char *
|
|||||||
if (done)
|
if (done)
|
||||||
continue;
|
continue;
|
||||||
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "root= %s %s ", root, source) ; }
|
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "root= %s %s ", root, source) ; }
|
||||||
const char *work = expandWithPrefix( source, root, result, false );
|
const char *work = PlExpandVars( source, root, result);
|
||||||
|
|
||||||
|
|
||||||
// expand names in case you have
|
// expand names in case you have
|
||||||
// to add a prefix
|
// to add a prefix
|
||||||
@ -1554,7 +1523,7 @@ p_expand_file_name ( USES_REGS1 )
|
|||||||
text = Yap_TextTermToText( t, NULL, 0);
|
text = Yap_TextTermToText( t, NULL, 0);
|
||||||
if (!text)
|
if (!text)
|
||||||
return false;
|
return false;
|
||||||
if (!(text2 = PlExpandVars (text)))
|
if (!(text2 = PlExpandVars (text, NULL, NULL)))
|
||||||
return false;
|
return false;
|
||||||
freeBuffer( text );
|
freeBuffer( text );
|
||||||
bool rc = Yap_unify(ARG2, Yap_MkTextTerm(text2, t));
|
bool rc = Yap_unify(ARG2, Yap_MkTextTerm(text2, t));
|
||||||
|
Reference in New Issue
Block a user