%% prf_file_call
%   callback for the check status menu option, this function will
%   check the current status of the table, if the table has been
%   proven it will alert the user and update the status, if it has
%   not been proven it will alert the user.
% inputs:
%   obj:GUI - GUI objecto
%   src:double - source of the callback calling
%   event:eventdata - event that triggered the callback
% outputs:
%   none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = prf_file_call(object,src,event)
object.save_data;
% check if a pvs file exists
if (~exist([object.Data.function_name '.pvs'],'file'))
    errordlg(['PVS theory file for this function does not exist' sprintf('\n') 'Nothing to check']);
    return;
end
% check if prf file exists
if (~exist([object.Data.function_name '.prf'],'file'))
    errordlg(['PVS proof (.prf) file for this function does not exist' sprintf('\n') 'Nothing to check']);
    return;
end
% check if pvs file is different from current table
temp_pvs = [object.Data.function_name '_temp'];
object.PVS.generate_pvs_file(temp_pvs);

% read pvs theory on file
pvs1 = textread([object.Data.function_name '.pvs'], '%s', 'whitespace', '', 'bufsize', 268435456);
pvs2 = textread([temp_pvs '.pvs'], '%s', 'whitespace', '', 'bufsize', 268435456);

if(size(pvs1{1},2) ~= size(pvs2{1},2))
    errordlg(['pvs-theory file is different from the given graphical representation, ' sprintf('\n') ' you will need to reprove']);
    return;
else
    
    if ~all(pvs1{1} == pvs2{1})
        errordlg(['pvs-theory file is different from the given graphical representation, ' sprintf('\n') ' you will need to reprove']);
        return;
    end
    
    
end
delete([temp_pvs '.pvs']);


status = object.PVS.check_status;
if (status ~= object.pvs_checked)
    
    object.pvs_checked = status;
    object.update_Statusbar;
    if (object.mode == 1)
        TableBlock.set_block_display(object.block_handle,object.pvs_checked);
    end
    
end

if (status == 1)
    msgbox('Table has been proven');
else
    msgbox('Table has not been proven');
end

end

