diff --git a/C/iopreds.c b/C/iopreds.c index 9435c4852..40bb68b17 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -1658,6 +1658,22 @@ p_open (void) } +static Int +p_file_expansion (void) +{ /* '$file_expansion'(+File,-Name) */ + Term file_name = Deref(ARG1); + + /* we know file_name is bound */ + if (!IsAtomTerm (file_name)) { + PlIOError(TYPE_ERROR_ATOM, file_name, "absolute_file_name/3"); + return(FALSE); + } + if (!TrueFileName (RepAtom (AtomOfTerm (file_name))->StrOfAE, FileNameBuf, FALSE)) + return (PlIOError (EXISTENCE_ERROR_SOURCE_SINK,file_name,"absolute_file_name/3")); + return(unify(ARG2,MkAtomTerm(LookupAtom(FileNameBuf)))); +} + + static Int p_add_alias_to_stream (void) { Term tname = Deref(ARG1); @@ -4782,6 +4798,7 @@ InitIOPreds(void) InitCPred ("$get0_line_codes", 2, p_get0_line_codes, SafePredFlag|SyncPredFlag); InitCPred ("$get_byte", 2, p_get_byte, SafePredFlag|SyncPredFlag); InitCPred ("$open", 4, p_open, SafePredFlag|SyncPredFlag); + InitCPred ("$file_expansion", 2, p_file_expansion, SafePredFlag|SyncPredFlag); InitCPred ("$open_null_stream", 1, p_open_null_stream, SafePredFlag|SyncPredFlag); InitCPred ("$open_pipe_stream", 2, p_open_pipe_stream, SafePredFlag|SyncPredFlag); InitCPred ("open_mem_read_stream", 2, p_open_mem_read_stream, SyncPredFlag); diff --git a/C/sysbits.c b/C/sysbits.c index 6b4d0b529..aa7df4f47 100644 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -1611,7 +1611,7 @@ p_shell (void) #else #if HAVE_SYSTEM char *shell; - char *command = AllocTmpSpaceFromGlobal(); +#define command ((char *)TR) register int bourne = FALSE; Term t1 = Deref (ARG1); @@ -1651,6 +1651,7 @@ p_shell (void) return (result); } } +#undef command #else /* HAVE_SYSTEM */ #ifdef MSH register char *shell; @@ -1670,7 +1671,7 @@ static Int p_system (void) { /* '$system'(+SystCommand) */ #ifdef HAVE_SYSTEM - char *command = AllocTmpSpaceFromGlobal(); +#define command ((char *)TR) Term t1 = Deref (ARG1); if (!GetName (command, t1)) { Error(SYSTEM_ERROR,t1,"argument to system/1 is not valid"); @@ -1688,6 +1689,7 @@ p_system (void) /* CloseStreams(); */ system (shell); return (TRUE); +#undef command #else Error(SYSTEM_ERROR,TermNil,"sh not available in this machine"); return(FALSE); diff --git a/H/Regs.h b/H/Regs.h index a29c4af47..5a4e5cef2 100644 --- a/H/Regs.h +++ b/H/Regs.h @@ -10,7 +10,7 @@ * File: Regs.h * * mods: * * comments: YAP abstract machine registers * -* version: $Id: Regs.h,v 1.8 2001-12-07 20:27:03 vsc Exp $ * +* version: $Id: Regs.h,v 1.9 2002-01-02 05:35:20 vsc Exp $ * *************************************************************************/ @@ -678,9 +678,6 @@ EXTERN inline void restore_B(void) { #define BBREG BB #endif -/* use global stack for intermediate data-structures */ -#define AllocTmpSpaceFromGlobal() ((char *)H) - #if !THREADS /* use actual addresses for regs */ #define PRECOMPUTE_REGADDRESS 1 diff --git a/docs/yap.tex b/docs/yap.tex index 50e051ffe..6d6308c78 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -3329,6 +3329,14 @@ Closes the stream @var{S}, following options @var{O}. The only valid options are @code{force(true)} and @code{force(false)}. YAP currently ignores these options. +@item absolute_file_name(+@var{Name},-@var{FullPath}) +@findex absolute_file_name/2 +@syindex absolute_file_name/2 +@cnindex absolute_file_name/2 +Give the path a full path @var{FullPath} Yap would use to consule a file +named @var{Name}. Unify @var{FullPath} with @code{user} if the file +name is @code{user}. + @item current_stream(@var{F},@var{M},@var{S}) @findex current_stream/3 @syindex current_stream/3 diff --git a/pl/yio.yap b/pl/yio.yap index 125e7c109..1abb8bc60 100644 --- a/pl/yio.yap +++ b/pl/yio.yap @@ -871,10 +871,14 @@ at_end_of_stream(S) :- consult_depth(LV) :- '$show_consult_level'(LV). +absolute_file_name(V,Out) :- + throw(error(instantiation_error, absolute_file_name(V, Out))). +absolute_file_name(user,user) :- !. absolute_file_name(RelFile,AbsFile) :- '$find_in_path'(RelFile,PathFile), - '$exists'(PathFile,'$csult', AbsFile). - + '$exists'(PathFile,'$csult', AbsFile), !. +absolute_file_name(RelFile, AbsFile) :- + '$file_expansion'(RelFile, AbsFile). '$exists'(F,Mode,AbsFile) :- '$get_value'(fileerrors,V),