anchor.diff:      end.
   
   
  -
  +filehash(FileName) ->
  +    case file:open(FileName, [read, raw, binary]) of
  +	 {ok, IoDevice} ->
  +	    Hash = filehash(IoDevice,  0),
  +	    file:close(IoDevice),
  +	    Hash;
  +	_ -> 0
  +    end.
  +
  +filehash(IoDevice, Crc) ->
  +    case file:read(IoDevice, 1024) of
  +        {ok, Data} ->
  +            filehash(IoDevice, erlang:crc32(Crc, Data));
  +        eof ->
  +            Crc;
  +        {error, _Reason} ->
  +            0 %% TODO error handling
  +    end.
  
positive.code:     case TabFile of 
  	none -> 
  	    case lists:keysearch(Key, 1, ASTs) of
  		{value, {Key, {AnnAST, Info, FileModifiedTime}}} ->
  		    case FileModifiedTime >= filelib:last_modified(FileName) of
  			true -> 
  			    log_errors(FileName, Info), {{ok, {AnnAST, Info}}, State};
  			false ->
  			    {ok, {AnnAST1, Info1}} = refac_util:parse_annotate_file_1(FileName, ByPassPreP, SearchPaths, TabWidth, FileFormat),
  			    log_errors(FileName, Info1),
  			    {{ok, {AnnAST1, Info1}}, #state{asts=lists:keyreplace(Key, 1, ASTs, {Key, {AnnAST1, Info1, filelib:last_modified(FileName)}})}}
  		    end;
  		false ->
  		    {ok, {AnnAST, Info}} = refac_util:parse_annotate_file_1(FileName, ByPassPreP, SearchPaths, TabWidth, FileFormat),
  		    log_errors(FileName, Info),
  		    {{ok, {AnnAST, Info}}, #state{asts=[{Key, {AnnAST, Info, filelib:last_modified(FileName)}} | ASTs]}}
  	    end;
  	_ -> 
  	    case dets:lookup(TabFile, Key) of
  		[{Key, {AnnAST, Info, FileModifiedTime}}]->
  		    case FileModifiedTime >= filelib:last_modified(FileName) of
  			true -> 
  			    {{ok, {AnnAST, Info}}, State};
  			false ->
  			    {ok, {AnnAST1, Info1}} = refac_util:parse_annotate_file_1(FileName, ByPassPreP, SearchPaths, TabWidth, FileFormat),
  			    dets:insert(TabFile, {Key, {AnnAST1, Info1, filelib:last_modified(FileName)}}),
  			    log_errors(FileName, Info1),
  			    {{ok, {AnnAST1, Info1}}, State}
  		    end;
  		_ ->
  		    {ok, {AnnAST, Info}} = refac_util:parse_annotate_file_1(FileName, ByPassPreP, SearchPaths, TabWidth, FileFormat),
  		    dets:insert(TabFile, {Key, {AnnAST, Info, filelib:last_modified(FileName)}}),
  		    log_errors(FileName, Info),
  		    {{ok, {AnnAST, Info}}, State}
  	    end
      end.
  
  update_ast_1({Key, {AnnAST, Info, Time}}, _State=#state{dets_tab=TabFile, asts=ASTs}) ->
      case TabFile of
  	none ->  case lists:keysearch(Key, 1, ASTs) of
  		     {value, {Key,  {_AnnAST1, _Info1, _Time}}} ->  
  			 #state{asts=lists:keyreplace(Key, 1, ASTs, {Key, {AnnAST, Info, Time}})};
  		     false ->
  			 #state{asts=[{Key, {AnnAST, Info, Time}} | ASTs]}
  		 end;
  	_ ->
  	    dets:delete(TabFile, Key),
  	    dets:insert(TabFile, [{Key, {AnnAST, Info, Time}}])
      end.
      
  log_errors(FileName, Info) ->
  
negative.code: -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
  	 terminate/2, code_change/3]).
  
  -export([start_ast_server/0, get_ast/1, update_ast/2, filehash/1]).
  
  -record(state, {dets_tab=none, asts=[]}).
  
  