anchor.diff:  %%
   %% Compile example dictionaries in examples/dict.
   
  --define(EXAMPLES, [rfc4004_mip,
  -                   rfc4005_nas,
  -                   rfc4006_cc,
  -                   rfc4072_eap,
  -                   rfc4590_digest,
  -                   rfc4740_sip]).
  -
   dict() ->
  -    [{timetrap, {minutes, length(?EXAMPLES)}}].
  +    [{timetrap, {minutes, 10}}].
   
   dict(_Config) ->
  -    Dir = filename:join([code:lib_dir(diameter, examples), "dict"]),
  -    [] = [RC || D <- ?EXAMPLES,
  -                RC <- [dict(atom_to_list(D), Dir)],
  +    Dirs = [filename:join(H ++ ["examples", "dict"])
  +            || H <- [[code:lib_dir(diameter)], [here(), ".."]]],
  +    [] = [RC || {_,F} <- sort(find_files(Dirs, ".*\\.dia")),
  +                RC <- [make(F)],
                   RC /= ok].
   
  -dict(Dict, Dir) ->
  +sort([{_,_} | _] = Files) ->
  +    lists:sort(fun({A,_},{B,_}) ->
  +                       sort([filename:rootname(F) || F <- [A,B]])
  +               end,
  +               Files);
  +
  +sort([A,B] = L) ->
  +    [DA,DB] = [dep([D],[]) || D <- L],
  +    case {[A] -- DB, [B] -- DA} of
  +        {[], [_]} ->  %% B depends on A
  +            true;
  +        {[_], []} ->  %% A depends on B
  +            false;
  +        {[_],[_]} ->  %% or not
  +            length(DA) < length(DB)
  +    end.
  +
  +%% Recursively accumulate inherited dictionaries.
  +dep([D|Rest], Acc) ->
  +    dep(opts(D), Rest, Acc);
  +dep([], Acc) ->
  +    Acc.
  +
  +dep([{inherits, Map} | T], Rest, Acc) ->
  +    [Dict, _] = filename:split(Map),
  +    dep(T, [Dict | Rest], [Dict | Acc]);
  +dep([], Rest, Acc) ->
  +    dep(Rest, Acc).
  +
  +make(Path) ->
  +    Dict = filename:rootname(filename:basename(Path)),
       {Name, Pre} = make_name(Dict),
       try
  -        ok = make(filename:join([Dir, Dict ++ ".dia"]),
  -                  [{name, Name},
  -                   {prefix, Pre},
  -                   inherits("rfc3588_base")
  -                   | opts(Dict)]),
  +        ok = make(Path, [{name, Name},
  +                         {prefix, Pre},
  +                         inherits(rfc3588_base)
  +                         | opts(Dict)]),
           ok = compile(Name)
       catch
           throw: {_,_} = E ->
  
positive.code: install(PrivDir) ->
      Top = install(here(), PrivDir),
      Src = filename:join([Top, "examples", "code"]),
      Files = find_files(Src, ".*\\.erl"),
      [] = [{F,E} || F <- Files,
                     {error, _, _} = E <- [compile:file(F, [warnings_as_errors,
                                                            return_errors])]].
  
  
negative.code:     %% Return the top directory containing examples/code.
      Top.
  
  find_files(Dirs, RE) ->
      lists:foldl(fun(D,A) -> fold_files(D, RE, A) end,
                  orddict:new(),
                  Dirs).
  
  fold_files(Dir, RE, Acc) ->
      filelib:fold_files(Dir, RE, false, fun store/2, Acc).
  
  store(Path, Dict) ->
      orddict:store(filename:basename(Path), Path, Dict).
  
  %% ===========================================================================
  
  