From d6773df81549dee87884bfd173d378df491b2371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 2 Aug 2012 09:36:37 -0500 Subject: [PATCH] fix current_stream/3. --- docs/yap.tex | 5 ++++- pl/yio.yap | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/yap.tex b/docs/yap.tex index 1d69bd5d5..377050407 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -4664,7 +4664,10 @@ will not have a leading dot. Defines the relation: The stream @var{S} is opened on the file @var{F} in mode @var{M}. It might be used to obtain all open streams (by backtracking) or to access the stream for a file @var{F} in mode -@var{M}, or to find properties for a stream @var{S}. +@var{M}, or to find properties for a stream @var{S}. Notice that some +streams might not be associated to a file: in this case YAP tries to +return the file number. If that is not available, YAP unifies @var{F} +with @var(S}. @item is_stream(@var{S}) @findex is_stream/1 diff --git a/pl/yio.yap b/pl/yio.yap index 68498e671..331e51852 100644 --- a/pl/yio.yap +++ b/pl/yio.yap @@ -98,6 +98,16 @@ socket(Domain, Type, Protocol, Sock) :- ), yap_sockets:ip_socket(Domain, Type, Protocol, Sock). +socket_connect(Sock, Host, Read) :- + ( + '$undefined'(ip_socket(_,_),yap_sockets) + -> + load_files(library(sockets), [silent(true),if(not_loaded)]) + ; + true + ), + yap_sockets:ip_socket(Domain, Type, Protocol, Sock). + open_pipe_streams(Read, Write) :- ( '$undefined'(pipe(_,_),unix) @@ -263,6 +273,7 @@ current_line_number(Stream,N) :- stream_position(Stream, Position) :- stream_property(Stream, position(Position)). + stream_position(Stream, Position, NewPosition) :- stream_property(Stream, position(Position)), set_stream_position(Stream, NewPosition). @@ -292,8 +303,15 @@ current_char_conversion(X,Y) :- '$fetch_char_conversion'(List,X,Y). -current_stream(File, Opts, Stream) :- - '$current_stream'(File, Opts, Stream). +current_stream(File, Mode, Stream) :- + stream_property(Stream, mode(Mode)), + '$stream_name'(Stream, File). + +'$stream_name'(Stream, File) :- + stream_property(Stream, file_name(File)), !. +'$stream_name'(Stream, file_no(File)) :- + stream_property(Stream, file_no(File)), !. +'$stream_name'(Stream, Stream). '$extend_file_search_path'(P) :- atom_codes(P,S),