support time_file and access_file from SWI library.
This commit is contained in:
parent
a41627ef1d
commit
9efbc0fce8
70
C/iopreds.c
70
C/iopreds.c
@ -2518,75 +2518,6 @@ p_access(void)
|
||||
}
|
||||
}
|
||||
|
||||
static Int
|
||||
p_access2(void)
|
||||
{
|
||||
Term tname = Deref(ARG1);
|
||||
Term tmode = Deref(ARG2);
|
||||
char ares[YAP_FILENAME_MAX];
|
||||
Atom atmode;
|
||||
|
||||
if (IsVarTerm(tmode)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, tmode, "access");
|
||||
return FALSE;
|
||||
} else if (!IsAtomTerm (tmode)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM, tname, "access");
|
||||
return FALSE;
|
||||
}
|
||||
atmode = AtomOfTerm(tmode);
|
||||
if (IsVarTerm(tname)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, tname, "access");
|
||||
return FALSE;
|
||||
} else if (!IsAtomTerm (tname)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM, tname, "access");
|
||||
return FALSE;
|
||||
} else {
|
||||
if (atmode == AtomNone)
|
||||
return TRUE;
|
||||
if (!Yap_TrueFileName (RepAtom(AtomOfTerm(tname))->StrOfAE, ares, (atmode == AtomCsult)))
|
||||
return FALSE;
|
||||
}
|
||||
#if HAVE_ACCESS
|
||||
{
|
||||
int mode;
|
||||
|
||||
if (atmode == AtomExist)
|
||||
mode = F_OK;
|
||||
else if (atmode == AtomWrite)
|
||||
mode = W_OK;
|
||||
else if (atmode == AtomRead)
|
||||
mode = R_OK;
|
||||
else if (atmode == AtomAppend)
|
||||
mode = W_OK;
|
||||
else if (atmode == AtomCsult)
|
||||
mode = R_OK;
|
||||
else if (atmode == AtomExecute)
|
||||
mode = X_OK;
|
||||
else {
|
||||
Yap_Error(DOMAIN_ERROR_IO_MODE, tmode, "access_file/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (access(ares, mode) != 0) {
|
||||
/* ignore errors while checking a file */
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#elif HAVE_STAT
|
||||
{
|
||||
struct SYSTEM_STAT ss;
|
||||
|
||||
if (SYSTEM_STAT(ares, &ss) != 0) {
|
||||
/* ignore errors while checking a file */
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
static Int
|
||||
p_exists_directory(void)
|
||||
{
|
||||
@ -6756,7 +6687,6 @@ Yap_InitIOPreds(void)
|
||||
Yap_InitCPred ("get0", 2, p_get0, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$get0_line_codes", 2, p_get0_line_codes, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$get_byte", 2, p_get_byte, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("access_file", 2, p_access2, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$access", 1, p_access, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("exists_directory", 1, p_exists_directory, SafePredFlag|SyncPredFlag);
|
||||
Yap_InitCPred ("$open", 6, p_open, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
|
33
C/sysbits.c
33
C/sysbits.c
@ -2501,38 +2501,6 @@ static Int p_putenv(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* set a variable in YAP's environment */
|
||||
static Int p_file_age(void)
|
||||
{
|
||||
char *file_name = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
|
||||
if (strcmp(file_name,"user_input") == 0) {
|
||||
return(Yap_unify(ARG2,MkIntTerm(-1)));
|
||||
}
|
||||
#if HAVE_LSTAT
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
if (lstat(file_name, &buf) == -1) {
|
||||
/* file does not exist, but was opened? Return -1 */
|
||||
return(Yap_unify(ARG2, MkIntTerm(-1)));
|
||||
}
|
||||
return(Yap_unify(ARG2, MkIntegerTerm(buf.st_mtime)));
|
||||
}
|
||||
#elif defined(__MINGW32__) || _MSC_VER
|
||||
{
|
||||
struct _stat buf;
|
||||
|
||||
if (_stat(file_name, &buf) != 0) {
|
||||
/* return an error number */
|
||||
return(Yap_unify(ARG2, MkIntTerm(-1)));
|
||||
}
|
||||
return(Yap_unify(ARG2, MkIntegerTerm(buf.st_mtime)));
|
||||
}
|
||||
#else
|
||||
return(Yap_unify(ARG2, MkIntTerm(-1)));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* wrapper for alarm system call */
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
|
||||
@ -3352,7 +3320,6 @@ Yap_InitSysPreds(void)
|
||||
Yap_InitCPred ("$alarm", 4, p_alarm, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$getenv", 2, p_getenv, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$putenv", 2, p_putenv, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$file_age", 2, p_file_age, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$set_fpu_exceptions", 0, p_set_fpu_exceptions, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$first_signal", 1, p_first_signal, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$host_type", 1, p_host_type, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
|
@ -1359,3 +1359,6 @@ b_getval(GlobalVariable, Val) :-
|
||||
'$do_error'(existence_error(variable, GlobalVariable),b_getval(GlobalVariable, Val))
|
||||
).
|
||||
|
||||
access_file(File, Mode) :- swi_access_file(File, Mode).
|
||||
time_file(File, Time) :- swi_time_file(File, Time).
|
||||
|
||||
|
@ -537,7 +537,7 @@ prolog_load_context(term_position, Position) :-
|
||||
'$file_is_unchanged'(F, R, Age).
|
||||
|
||||
'$file_is_unchanged'(F, R, Age) :-
|
||||
'$file_age'(F,CurrentAge),
|
||||
time_file(F,CurrentAge),
|
||||
((CurrentAge = Age ; Age = -1) -> true; erase(R), fail).
|
||||
|
||||
|
||||
@ -621,8 +621,7 @@ remove_from_path(New) :- '$check_path'(New,Path),
|
||||
Stream \= user_input,
|
||||
'$file_name'(Stream,F),
|
||||
( recorded('$lf_loaded','$lf_loaded'(F,M,_,_),R), erase(R), fail ; true ),
|
||||
|
||||
'$file_age'(F,Age),
|
||||
time_file(F,Age),
|
||||
recorda('$lf_loaded','$lf_loaded'(F,M,Age,Reconsult),_),
|
||||
fail.
|
||||
'$record_loaded'(_, _, _).
|
||||
|
@ -356,7 +356,7 @@ open_pipe_streams(P1,P2) :- '$open_pipe_stream'(P1, P2).
|
||||
fileerrors :- set_value(fileerrors,1).
|
||||
nofileerrors :- set_value(fileerrors,0).
|
||||
|
||||
exists(F) :- access_file(F,'$csult').
|
||||
exists(F) :- access_file(F,exist).
|
||||
|
||||
see(user) :- !, set_input(user_input).
|
||||
see(F) :- var(F), !,
|
||||
@ -1099,9 +1099,6 @@ write_depth(T,L) :- write_depth(T,L,_).
|
||||
is_stream(S) :-
|
||||
catch('$check_stream'(S), _, fail), !.
|
||||
|
||||
time_file(File, Time) :-
|
||||
'$file_age'(File, Time).
|
||||
|
||||
stream_position_data(line_count, '$stream_position'(_,Data,_,_,_), Data).
|
||||
stream_position_data(line_position, '$stream_position'(_,_,Data,_,_), Data).
|
||||
%stream_position_data(char_count, '$stream_position'(Data,_,_,_,_), Data).
|
||||
|
Reference in New Issue
Block a user