anchor.diff:           code_change/3,
            terminate/2]).
   
  +-define(NUM_MESSAGES, 3). % Number of the most recent messages to log on crash
  +
   -define(UNEXPECTED, 1).
  --export([ns_log_cat/1, ns_log_code_string/1]).
   
   -include_lib("eunit/include/eunit.hrl").
   
   %% Server state
  --record(state, {port, name}).
  +-record(state, {port, name, messages}).
   
   
   %% API
  
positive.code: 
  init({Name, _Cmd, _Args, _Opts} = Params) ->
      Port = open_port(Params),
      {ok, #state{port = Port, name = Name}}.
  
  handle_info({_Port, {data, Msg}}, State) ->
      log_messages(State#state.name, [Msg]),
      {noreply, State};
  handle_info({_Port, {exit_status, 0}}, State) ->
      {stop, normal, State};
  handle_info({_Port, {exit_status, Status}}, State) ->
      ns_log:log(?MODULE, ?ABNORMAL,
                 "Port server ~p exited with status ~p. Restarting.~n",
                 [State#state.name, Status]),
      {stop, {abnormal, Status}, State}.
  
  handle_call(unhandled, unhandled, unhandled) ->
  
negative.code: -define(ABNORMAL, 0).
  
  -behavior(gen_server).
  
  -include("ns_common.hrl").
  
  