new $stream(T) checks if a term is a stream,
so that I don't have an excuse to call current_stream(_,_,S) with S something not a stream. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@39 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
5c0d82b07d
commit
59fdfadfa9
21
C/iopreds.c
21
C/iopreds.c
@ -2077,9 +2077,12 @@ init_cur_s (void)
|
|||||||
{ /* Init current_stream */
|
{ /* Init current_stream */
|
||||||
Term t3 = Deref(ARG3);
|
Term t3 = Deref(ARG3);
|
||||||
if (!IsVarTerm(t3)) {
|
if (!IsVarTerm(t3)) {
|
||||||
Int i = CheckStream (t3, Input_Stream_f|Output_Stream_f, "current_stream/3");
|
|
||||||
Term t1 = StreamName(i), t2;
|
|
||||||
|
|
||||||
|
Int i;
|
||||||
|
Term t1, t2;
|
||||||
|
|
||||||
|
i = CheckStream (t3, Input_Stream_f|Output_Stream_f, "current_stream/3");
|
||||||
|
t1 = StreamName(i);
|
||||||
t2 = (Stream[i].status & Input_Stream_f ?
|
t2 = (Stream[i].status & Input_Stream_f ?
|
||||||
MkAtomTerm (AtomRead) :
|
MkAtomTerm (AtomRead) :
|
||||||
MkAtomTerm (AtomWrite));
|
MkAtomTerm (AtomWrite));
|
||||||
@ -4519,6 +4522,19 @@ StreamToFileNo(Term t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
p_stream(Term t)
|
||||||
|
{
|
||||||
|
Term in = Deref(ARG1);
|
||||||
|
if (IsVarTerm(in))
|
||||||
|
return(FALSE);
|
||||||
|
if (IsAtomTerm(in))
|
||||||
|
return(CheckAlias(AtomOfTerm(in)) >= 0);
|
||||||
|
if (IsApplTerm(in))
|
||||||
|
return(FunctorOfTerm(in) == FunctorStream);
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
InitBackIO (void)
|
InitBackIO (void)
|
||||||
{
|
{
|
||||||
@ -4589,6 +4605,7 @@ InitIOPreds(void)
|
|||||||
InitCPred ("$change_alias_to_stream", 2, p_change_alias_to_stream, SafePredFlag|SyncPredFlag);
|
InitCPred ("$change_alias_to_stream", 2, p_change_alias_to_stream, SafePredFlag|SyncPredFlag);
|
||||||
InitCPred ("$check_if_valid_new_alias", 1, p_check_if_valid_new_alias, TestPredFlag|SafePredFlag|SyncPredFlag);
|
InitCPred ("$check_if_valid_new_alias", 1, p_check_if_valid_new_alias, TestPredFlag|SafePredFlag|SyncPredFlag);
|
||||||
InitCPred ("$fetch_stream_alias", 2, p_fetch_stream_alias, SafePredFlag|SyncPredFlag);
|
InitCPred ("$fetch_stream_alias", 2, p_fetch_stream_alias, SafePredFlag|SyncPredFlag);
|
||||||
|
InitCPred ("$stream", 2, p_stream, SafePredFlag|TestPredFlag),
|
||||||
#if HAVE_SELECT
|
#if HAVE_SELECT
|
||||||
InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
|
InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
|
||||||
#endif
|
#endif
|
||||||
|
@ -250,7 +250,7 @@ see(F) :- current_input(Stream),
|
|||||||
'$user_file_name'(Stream,F).
|
'$user_file_name'(Stream,F).
|
||||||
see(F) :- current_stream(_,read,Stream), '$user_file_name'(Stream,F), !,
|
see(F) :- current_stream(_,read,Stream), '$user_file_name'(Stream,F), !,
|
||||||
set_input(Stream).
|
set_input(Stream).
|
||||||
see(Stream) :- current_stream(_,read,Stream), !,
|
see(Stream) :- '$stream'(Stream), current_stream(_,read,Stream), !,
|
||||||
set_input(Stream).
|
set_input(Stream).
|
||||||
see(F) :- open(F,read,Stream), set_input(Stream).
|
see(F) :- open(F,read,Stream), set_input(Stream).
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ tell(F) :- current_output(Stream),
|
|||||||
'$user_file_name'(Stream,F), !.
|
'$user_file_name'(Stream,F), !.
|
||||||
tell(F) :- current_stream(_,write,Stream), '$user_file_name'(Stream, F), !,
|
tell(F) :- current_stream(_,write,Stream), '$user_file_name'(Stream, F), !,
|
||||||
set_output(Stream).
|
set_output(Stream).
|
||||||
tell(Stream) :- current_stream(_,write,Stream), !,
|
tell(Stream) :- '$stream'(Stream), current_stream(_,write,Stream), !,
|
||||||
set_output(Stream).
|
set_output(Stream).
|
||||||
tell(F) :- open(F,write,Stream), set_output(Stream).
|
tell(F) :- open(F,write,Stream), set_output(Stream).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user