io_lib.erl

Klacke klacke@REDACTED
Wed Oct 6 11:37:59 CEST 1999


The following diff has proved to be extremely valuable for us
at bluetail.


The idea is to let io:format's of ports to show a
little bit more than #Port. In particular the #Port<closed>
printouts ere very very good to have for debugging purposes.

/klacke



cvs diff -rstart io_lib.erl 
Index: io_lib.erl
===================================================================
RCS file: /home/share/erlang/cvsroot/ose/erlang-47.4.1/lib/stdlib/src/io_lib.erl,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- io_lib.erl  1999/05/10 13:24:09     1.1.1.1
+++ io_lib.erl  1999/09/22 06:11:21     1.3
@@ -20,7 +20,7 @@
 %% File    : io_lib.erl
 %% Author  : Robert Virding
 %% Purpose : Library of useful i/o functions.
-%% Revision: $Id: io_lib.erl,v 1.1.1.1 1999/05/10 13:24:09 erlang Exp $
+%% Revision: $Id: io_lib.erl,v 1.3 1999/09/22 06:11:21 magnus Exp $
 
 %% This module is a library of useful i/o functions. It is hoped that the
 %% functions defined in it are basic enough to be used without modification
@@ -88,6 +88,16 @@
 indentation(Chars, Current) ->
     io_lib_format:indentation(Chars, Current).
 
+
+fmt_port(P) when node(P) == node() ->
+    case erlang:port_info(P) of
+       undefined ->   "#Port<closed>";
+       L -> {value, {id, Id}} = lists:keysearch(id,1,L),
+            lists:flatten(format("#Port<~p>", [Id]))
+    end;
+fmt_port(P) ->
+    lists:flatten(format("#Port<~p>", [node(P)])).
+
 %% write(Term)
 %% write(Term, Depth)
 %% write(Term, Depth, Pretty)
@@ -105,7 +115,7 @@
 write(Term, D) when integer(Term) -> integer_to_list(Term);
 write(Term, D) when float(Term) -> io_lib_format:fwrite_g(Term);
 write(Atom, D) when atom(Atom) -> write_atom(Atom);
-write(Term, D) when port(Term) -> "#Port";
+write(Term, D) when port(Term) -> fmt_port(Term);  %% "#Port";
 write(Term, D) when pid(Term) -> pid_to_list(Term);
 write(Term, D) when reference(Term) -> "#Ref";
 write(Term, D) when binary(Term) -> "#Bin";




More information about the erlang-questions mailing list