function helpDir = docroot
%DOCROOT A utility to determine the root directory of MATLAB Help

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.4 $  $Date: 1997/11/21 23:31:42 $

% get user docpath
if (strncmp(computer,'PC',2))
    helpDir = getprofl('Matlab Settings', 'Help Dir', '', 'matlab.ini');
elseif (strncmp(computer,'MAC',3))
    helpDir = system_dependent(17);
else
    [doccmd,options,helpDir] = docopt;
end

% verify user docpath
if (~isempty(helpDir))
    % remove trailing directory separator
    if (helpDir(end)==filesep)
        helpDir = helpDir(1:end-1);
    end
    % see if user docpath is valid
    if (exist(fullfile(helpDir,'helpdesk.html')) ~= 2)		
        helpDir = '';
    end
end

% try default
if (isempty(helpDir))
    helpDir = fullfile(matlabroot,'help','');
    if (exist(fullfile(helpDir,'helpdesk.html')) ~= 2)		
        helpDir = '';
    end
end
