rbmatlab 0.10.01
|
00001 function htdoc(topic) 00002 % function htdoc(topic) 00003 % opens mtoc++ documentation in a browser 00004 % 00005 % Opens documentation generated by mtoc++ and doxygen in a browser. The 00006 % directory where the HTML documentation is installed must be geiven by the 00007 % 'DOXYGEN_DIR' environment variable. This can be set with 00008 % @code 00009 % setenv('DOXYGEN_DIR', '/path/to/doxygen/docu'); 00010 % @endcode 00011 % in the 'startup.m' file, e.g. 00012 % 00013 % Parameters: 00014 % topic: a string or an object describing for which the documentation 00015 % site shall be opened. 00016 00017 doxy_dir = getenv('DOXYGEN_DIR'); 00018 if isempty(doxy_dir) || ~exist(fullfile(doxy_dir, 'index.html'), 'file') 00019 error('Environment variable DOXYGEN_DIR needs to be set to a valid documentation directory!'); 00020 end 00021 00022 if ~ischar(topic) 00023 classname = class(topic); 00024 else 00025 toks = get_tokens(topic); 00026 classname = get_max_token(toks); 00027 end 00028 00029 [st, headertag] = system(['sed -ne ''s/^.*<\([^>]*\)>File List.*$/\1/p'' ', fullfile(getenv('DOXYGEN_DIR'), 'files.html')]); 00030 headertag = ['<', headertag(1:end-1), '>']; 00031 00032 [st, res]=system(['grep -l ''', headertag, classname, ' '' ', fullfile(getenv('DOXYGEN_DIR'), '*'), ' | head -1' ]); 00033 if isempty(res) 00034 funcname = regexprep(which(classname), '\\.m$', ''); 00035 funcname = strrep(funcname, [rbmatlabhome, filesep], ''); 00036 [st, res]=system(['grep -l ''', headertag, funcname, ' '' ', fullfile(getenv('DOXYGEN_DIR'), '*'), ' | head -1' ]); 00037 end 00038 if isempty(res) 00039 web(fullfile(getenv('DOXYGEN_DIR'), 'index.html'), '-browser'); 00040 disp(['Could not find any entry for object ', classname, '.']); 00041 end 00042 00043 00044 web(res, '-browser'); 00045 00046 function toks = get_tokens(topic) 00047 % function toks = get_tokens(topic) 00048 % extracts possible tokens to search for in the documentation directory 00049 toks = textscan(topic, '%s', 'Delimiter', './'); 00050 toks = toks{1}; 00051 00052 function mtok = get_max_token(toks) 00053 % function mtok = get_max_token(toks) 00054 % returns the token of maximum possible length. 00055 00056 mtok_temp = toks{1}; 00057 for i= length(toks):-1:2 00058 mtok = [mtok_temp, sprintf('.%s', toks{2:i})]; 00059 if ~isempty(which(mtok)) 00060 return; 00061 end 00062 end 00063 mtok = toks{1};