--- io_lib_format.erl 2004-12-14 14:36:11.000000000 +0100 +++ io_lib_format.erl.new 2005-09-07 13:09:33.000000000 +0200 @@ -97,6 +97,7 @@ collect_cc([$w|Fmt], [A|Args]) -> {$w,[A],Fmt,Args}; collect_cc([$p|Fmt], [A|Args]) -> {$p,[A],Fmt,Args}; +collect_cc([$r|Fmt], [A|Args]) -> {$r,[A],Fmt,Args}; collect_cc([$W|Fmt], [A,Depth|Args]) -> {$W,[A,Depth],Fmt,Args}; collect_cc([$P|Fmt], [A,Depth|Args]) -> {$P,[A,Depth],Fmt,Args}; collect_cc([$s|Fmt], [A|Args]) -> {$s,[A],Fmt,Args}; @@ -120,6 +121,7 @@ pcount(Cs) -> pcount(Cs, 0). pcount([{$p,_As,_F,_Ad,_P,_Pad}|Cs], Acc) -> pcount(Cs, Acc+1); +pcount([{$r,_As,_F,_Ad,_P,_Pad}|Cs], Acc) -> pcount(Cs, Acc+1); pcount([{$P,_As,_F,_Ad,_P,_Pad}|Cs], Acc) -> pcount(Cs, Acc+1); pcount([_|Cs], Acc) -> pcount(Cs, Acc); pcount([], Acc) -> Acc. @@ -167,6 +169,9 @@ term(io_lib:write(A, -1), F, Adj, P, Pad); control($p, [A], F, Adj, P, Pad, I) -> print(A, -1, F, Adj, P, Pad, I); +control($r, [A0], F, Adj, P, Pad, I) -> + A = record_format(I,A0), + string(A, F, Adj, P, Pad); control($W, [A,Depth], F, Adj, P, Pad, _I) when integer(Depth) -> term(io_lib:write(A, Depth), F, Adj, P, Pad); control($P, [A,Depth], F, Adj, P, Pad, I) when integer(Depth) -> @@ -210,6 +215,26 @@ control($n, [], F, Adj, P, Pad, _I) -> newline(F, Adj, P, Pad); control($i, [_A], _F, _Adj, _P, _Pad, _I) -> []. + +record_format(I,T) when tuple(T) -> + ensure_started(), + F = shell:record_print_fun(rec_table), + case F(element(1, T), size(T)-1) of + no -> + load_all(), + case F(element(1, T), size(T)) of + no -> + erlang:fault(norecord); + _Fs -> + io_lib_pretty:print(T,F) + end; + _Fs -> + io_lib_pretty:print(T,F) + end; +record_format(_,Other) -> + Other. + + %% Default integer base base(none) -> 10; @@ -482,5 +507,42 @@ [(H-$A+$a)|lowercase(T)]; lowercase([H|T]) -> [H|lowercase(T)]; + lowercase([]) -> []. + + +ensure_started() -> + Self = self(), + case ets:info(rec_table) of + undefined -> + start(Self, + fun() -> + case (catch ets:new(rec_table, [public,ordered_set, + named_table])) of + {'EXIT', _} -> + Self ! {self(), ok}, + exit(normal); + _ -> + load_all(), + Self ! {self(), ok}, + timer:sleep(infinity) + end + end); + _ -> + ok + end. + +start(Pid, Fun) -> + New = spawn(Fun), + receive {New, ok } -> ok end. + + + +load_all() -> + lists:foreach( + fun({Mod,_}) -> + shell:read_and_add_records(Mod, '_', [],[],rec_table) + end, code:all_loaded()). + +