anchor.diff:  locate_import_aux([], Import, _Opts) ->
       {error, {import_not_found, Import}}.
   
  +try_topsort_defs(Defs) ->
  +    G = digraph:new(),
  +    [digraph:add_vertex(G, M) || {{msg,M}, _Fields} <- Defs],
  +    [[digraph:add_edge(G, From, To) || #field{type={msg,To}} <- Fields]
  +     || {{msg,From},Fields} <- Defs],
  +    case digraph_utils:topsort(G) of
  +        false ->
  +            digraph:delete(G),
  +            {false, Defs};
  +        Order ->
  +            digraph:delete(G),
  +            ROrder = lists:reverse(Order),
  +            OrderedMsgDefs = [lists:keyfind({msg,M},1,Defs) || M <- ROrder],
  +            {true, OrderedMsgDefs ++ (Defs -- OrderedMsgDefs)}
  +    end.
  +
  +possibly_adjust_typespec_opt(true=_IsAcyclic, Opts) ->
  +    Opts;
  +possibly_adjust_typespec_opt(false=_IsAcyclic, Opts) ->
  +    case get_type_specs_by_opts(Opts) of
  +        true  ->
  +            io:format("Warning: omitting type specs "
  +                      "due to cyclic message references.~n"),
  +            lists:keydelete(type_specs, 1, Opts -- [type_specs]); % disable
  +        false ->
  +            Opts
  +    end.
  +
   format_erl(Mod, Defs, Opts) ->
       iolist_to_binary(
         [f("%% Automatically generated, do not edit~n"
  
positive.code:       [f("-ifndef(~p).~n", [Mod]),
         f("-define(~p, true).~n", [Mod]),
         "\n",
         string:join([format_msg_record(Msg,Fs,Opts) || {{msg,Msg},Fs} <- Defs],
                     "\n"),
         "\n",
         f("-endif.~n")]).
  
  format_msg_record(Msg, Fields, Opts) ->
      [f("-record(~p,~n", [Msg]),
       f("        {"),
       outdent_first(format_hfields(8+1, Fields, Opts)),
       "\n",
       f("        }).~n")].
  
  format_hfields(Indent, Fields, CompileOpts) ->
      TypeSpecs = proplists:get_value(type_specs, CompileOpts, false),
      string:join(
        lists:map(
          fun({I, #field{name=Name, fnum=FNum, opts=FOpts}=Field}) ->
  
negative.code: %% `false'. If you set it to `true', you may get into troubles for
  %% messages referencing other messages, when compiling the generated
  %% files.
  file(File, Opts0) ->
      case parse_file(File, Opts0) of
          {ok, Defs0} ->
              {IsAcyclic, Defs} = try_topsort_defs(Defs0),
              possibly_probe_defs(Defs, Opts0),
              Opts1 = possibly_adjust_typespec_opt(IsAcyclic, Opts0),
              Ext = filename:extension(File),
              Mod = list_to_atom(filename:basename(File, Ext)),
              Erl = change_ext(File, ".erl"),
              Hrl = change_ext(File, ".hrl"),
              file_write_file(Erl, format_erl(Mod, Defs, Opts1), Opts1),
              file_write_file(Hrl, format_hrl(Mod, Defs, Opts1), Opts1);
          {error, _Reason} = Error ->
              Error
      end.
  