diff --git a/C/sysbits.c b/C/sysbits.c index 62b5398b2..b989aed0d 100755 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -1955,7 +1955,7 @@ int Yap_getcwd(const char *buf, int len) TODO: rewrite to use wordexp ****/ static int -TrueFileName (char *source, char *root, char *result, int in_lib) +TrueFileName (char *source, char *root, char *result, int in_lib, int expand_root) { CACHE_REGS char *work; @@ -2031,7 +2031,7 @@ TrueFileName (char *source, char *root, char *result, int in_lib) strncpy (result, source, YAP_FILENAME_MAX); } /* step 3: get the full file name */ - if (!dir_separator(result[0]) && !volume_header(result)) { + if (expand_root && !dir_separator(result[0]) && !volume_header(result)) { if (!Yap_getcwd(ares1, YAP_FILENAME_MAX)) return FALSE; #if _MSC_VER || defined(__MINGW32__) @@ -2139,7 +2139,7 @@ TrueFileName (char *source, char *root, char *result, int in_lib) int Yap_TrueFileName (char *source, char *result, int in_lib) { - return TrueFileName (source, NULL, result, in_lib); + return TrueFileName (source, NULL, result, in_lib, TRUE); } static Int @@ -2155,7 +2155,24 @@ p_true_file_name ( USES_REGS1 ) Yap_Error(TYPE_ERROR_ATOM,t,"argument to true_file_name"); return FALSE; } - TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, LOCAL_FileNameBuf, FALSE); + TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, LOCAL_FileNameBuf, FALSE, TRUE); + return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))); +} + +static Int +p_expand_file_name ( USES_REGS1 ) +{ + Term t = Deref(ARG1); + + 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; + } + TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, LOCAL_FileNameBuf, FALSE, FALSE); return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))); } @@ -2180,7 +2197,7 @@ p_true_file_name3 ( USES_REGS1 ) } root = RepAtom(AtomOfTerm(t2))->StrOfAE; } - TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, root, LOCAL_FileNameBuf, FALSE); + TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, root, LOCAL_FileNameBuf, FALSE, FALSE); return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))); } @@ -2344,8 +2361,8 @@ p_mv ( USES_REGS1 ) } else if (!IsAtomTerm(t2)) { Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom"); } - TrueFileName (RepAtom(AtomOfTerm(t1))->StrOfAE, NULL, oldname, FALSE); - TrueFileName (RepAtom(AtomOfTerm(t2))->StrOfAE, NULL, newname, FALSE); + TrueFileName (RepAtom(AtomOfTerm(t1))->StrOfAE, NULL, oldname, FALSE, TRUE); + TrueFileName (RepAtom(AtomOfTerm(t2))->StrOfAE, NULL, newname, FALSE, TRUE); if ((r = link (oldname, newname)) == 0 && (r = unlink (oldname)) != 0) unlink (newname); if (r != 0) { @@ -3100,6 +3117,7 @@ Yap_InitSysPreds(void) Yap_InitCPred ("$win32", 0, p_win32, SafePredFlag); Yap_InitCPred ("$ld_path", 1, p_ld_path, SafePredFlag); Yap_InitCPred ("$address_bits", 1, p_address_bits, SafePredFlag); + Yap_InitCPred ("$expand_file_name", 2, p_expand_file_name, SyncPredFlag); #ifdef _WIN32 Yap_InitCPred ("win_registry_get_value", 3, p_win_registry_get_value,0); #endif diff --git a/pl/consult.yap b/pl/consult.yap index 0c6c98edd..f04ffeb2f 100755 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -895,12 +895,14 @@ absolute_file_name(File,Opts,TrueFileName) :- fail. '$find_in_path'(S, Opts, NewFile, Call) :- S =.. [Name,File0], - '$cat_file_name'(File0,File), !, + '$cat_file_name'(File0,File1), !, + '$expand_file_name'(File1, File), '$dir_separator'(D), atom_codes(A,[D]), '$extend_path_directory'(Name, A, File, Opts, NewFile, Call). '$find_in_path'(File0,Opts,NewFile,_) :- - '$cat_file_name'(File0,File), !, + '$cat_file_name'(File0,File1), !, + '$expand_file_name'(File1, File), '$add_path'(File,PFile), '$get_abs_file'(PFile,Opts,AbsFile), '$search_in_path'(AbsFile,Opts,NewFile). @@ -928,9 +930,13 @@ absolute_file_name(File,Opts,TrueFileName) :- ( nonvar(RelTo) -> - '$dir_separator'(D), + '$dir_separator'(D), atom_codes(DA,[D]), - atom_concat([RelTo, DA, File], ActualFile) + ( sub_atom(File, 0, 1, _, DA) -> + ActualFile = File + ; + atom_concat([RelTo, DA, File], ActualFile) + ) ; ActualFile = File ), @@ -982,6 +988,10 @@ absolute_file_name(File,Opts,TrueFileName) :- atom_concat([File,'.',Ext],F). '$add_type_extensions'(_,File,File). +'$add_path'(File,File) :- + '$dir_separator'(D), + atom_codes(DA,[D]), + sub_atom(File, 0, 1, _, DA), !. '$add_path'(File,File). '$add_path'(File,PFile) :- recorded('$path',Path,_), @@ -997,6 +1007,8 @@ absolute_file_name(File,Opts,TrueFileName) :- get_value(prolog_commons_directory,Dir). +'$extend_path_directory'(_Name, D, File, _Opts, File, Call) :- + sub_atom(File, 0, 1, _, D), !. '$extend_path_directory'(Name, D, File, Opts, NewFile, Call) :- user:file_search_path(Name, Dir), '$extend_pathd'(Dir, D, File, Opts, NewFile, Call).