anchor.diff:  %%% Misc. functions.
   %%% ------------------------------------------------------
   
  -tag_event(Event) ->    
  -    {erlang:universaltime(), Event}.
  -
  -write_events(Fd, Events) -> write_events1(Fd, lists:reverse(Events)).
  -
  -write_events1(Fd, [Event|Es]) ->
  -    write_event(Fd, Event),
  -    write_events1(Fd, Es);
  -write_events1(_, []) ->
  +write_events(State, [Ev|Es]) ->
  +    %% Write the events in reversed order.
  +    write_events(State, Es),
  +    write_event(State, Ev);
  +write_events(_State, []) ->
       ok.
   
  -write_event(Fd, {Time, {error, _GL, {Pid, Format, Args}}}) ->
  -    T = write_time(maybe_utc(Time)),
  -    case catch io_lib:format(add_node(Format,Pid), Args) of
  -	S when is_list(S) ->
  -	    io:format(Fd, T ++ S, []);
  -	_ ->
  -	    F = add_node("ERROR: ~p - ~p~n", Pid),
  -	    io:format(Fd, T ++ F, [Format,Args])
  -    end;
  -write_event(Fd, {Time, {error_report, _GL, {Pid, std_error, Rep}}}) ->
  -    T = write_time(maybe_utc(Time)),
  -    S = format_report(Rep),
  -    io:format(Fd, T ++ S ++ add_node("", Pid), []);
  -write_event(Fd, {Time, {info_report, _GL, {Pid, std_info, Rep}}}) ->
  -    T = write_time(maybe_utc(Time), "INFO REPORT"),
  -    S = format_report(Rep),
  -    io:format(Fd, T ++ S ++ add_node("", Pid), []);
  -write_event(Fd, {Time, {info_msg, _GL, {Pid, Format, Args}}}) ->
  -    T = write_time(maybe_utc(Time), "INFO REPORT"),
  -    case catch io_lib:format(add_node(Format,Pid), Args) of
  -	S when is_list(S) ->
  -	    io:format(Fd, T ++ S, []);
  -	_ ->
  -	    F = add_node("ERROR: ~p - ~p~n", Pid),
  -	    io:format(Fd, T ++ F, [Format,Args])
  -    end;
  -write_event(Fd, {Time, {warning_report, _GL, {Pid, std_warning, Rep}}}) ->
  -    T = write_time(maybe_utc(Time), "WARNING REPORT"),
  -    S = format_report(Rep),
  -    io:format(Fd, T ++ S ++ add_node("", Pid), []);
  -write_event(Fd, {Time, {warning_msg, _GL, {Pid, Format, Args}}}) ->
  -    T = write_time(maybe_utc(Time), "WARNING REPORT"),
  -    case catch io_lib:format(add_node(Format,Pid), Args) of
  -	S when is_list(S) ->
  -	    io:format(Fd, T ++ S, []);
  -	_ ->
  -	    F = add_node("ERROR: ~p - ~p~n", Pid),
  -	    io:format(Fd, T ++ F, [Format,Args])
  -    end;
  -write_event(_, _) ->
  -    ok.
  +write_event(#st{fd=Fd}=State, Event) ->
  +    case parse_event(Event) of
  +	ignore ->
  +	    ok;
  +	{Head,Pid,FormatList} ->
  +	    Time = maybe_utc(erlang:universaltime()),
  +	    Header = write_time(Time, Head),
  +	    Body = format_body(State, FormatList),
  +	    AtNode = if
  +			 node(Pid) =/= node() ->
  +			     ["** at node ",atom_to_list(node(Pid))," **\n"];
  +			 true ->
  +			     []
  +		     end,
  +	    io:put_chars(Fd, [Header,Body,AtNode])
  +    end.
  +
  +format_body(State, [{Format,Args}|T]) ->
  +    S = try io_lib:format(Format, Args) of
  +	    S0 ->
  +		S0
  +	catch
  +	    _:_ ->
  +		io_lib:format("ERROR: ~p - ~p\n", [Format,Args])
  +	end,
  +    [S|format_body(State, T)];
  +format_body(_State, []) ->
  +    [].
  +
  +parse_event({error, _GL, {Pid, Format, Args}}) ->
  +    {"ERROR REPORT",Pid,[{Format,Args}]};
  +parse_event({info_msg, _GL, {Pid, Format, Args}}) ->
  +    {"INFO REPORT",Pid,[{Format, Args}]};
  +parse_event({warning_msg, _GL, {Pid, Format, Args}}) ->
  +    {"WARNING REPORT",Pid,[{Format,Args}]};
  +parse_event({error_report, _GL, {Pid, std_error, Args}}) ->
  +    {"ERROR REPORT",Pid,format_term(Args)};
  +parse_event({info_report, _GL, {Pid, std_info, Args}}) ->
  +    {"INFO REPORT",Pid,format_term(Args)};
  +parse_event({warning_report, _GL, {Pid, std_warning, Args}}) ->
  +    {"WARNING REPORT",Pid,format_term(Args)};
  +parse_event(_) -> ignore.
   
   maybe_utc(Time) ->
       UTC = case application:get_env(sasl, utc_log) of
  
positive.code: maybe_utc(Time, true) -> {utc, Time};
  maybe_utc(Time, _) -> {local, calendar:universal_time_to_local_time(Time)}.
  
  format_report(Rep) when is_list(Rep) ->
      case string_p(Rep) of
  	true ->
  	    io_lib:format("~s~n",[Rep]);
  	_ ->
  	    format_rep(Rep)
      end;
  format_report(Rep) ->
      io_lib:format("~p~n",[Rep]).
  
  format_rep([{Tag,Data}|Rep]) ->
      io_lib:format("    ~p: ~p~n",[Tag,Data]) ++ format_rep(Rep);
  format_rep([Other|Rep]) ->
      io_lib:format("    ~p~n",[Other]) ++ format_rep(Rep);
  format_rep(_) ->
      [].
  
  add_node(X, Pid) when is_atom(X) ->
      add_node(atom_to_list(X), Pid);
  add_node(X, Pid) when node(Pid) =/= node() ->
      lists:concat([X,"** at node ",node(Pid)," **~n"]);
  add_node(X, _) ->
      X.
  
  string_p([]) ->
      false;
  
negative.code: string_p1([$\f|T]) -> string_p1(T);
  string_p1([$\e|T]) -> string_p1(T);
  string_p1([H|T]) when is_list(H) ->
      string_p1(H) andalso string_p1(T);
  string_p1([]) -> true;
  string_p1(_) ->  false.
  
  write_time({utc,{{Y,Mo,D},{H,Mi,S}}}, Type) ->
      io_lib:format("~n=~s==== ~p-~s-~p::~s:~s:~s UTC ===~n",
  