m2html

PURPOSE ^

M2HTML - Documentation System for Matlab M-files in HTML

SYNOPSIS ^

function m2html(varargin)

DESCRIPTION ^

M2HTML - Documentation System for Matlab M-files in HTML
  M2HTML by itself generates an HTML documentation of Matlab M-files in the
  current directory. HTML files are also written in the current directory.
  M2HTML('PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,...)
  sets multiple option values. The list of option names and default values is:
    o mFiles - Cell array of strings or character array containing the
       list of M-files and/or directories of M-files for which an HTML
       documentation will be built [ '.' ]
    o htmlDir - Top level directory for generated HTML files [ '.' ]
    o recursive - Process subdirectories [ on | {off} ]
    o source - Include Matlab source code in the HTML documentation
                               [ {on} | off ]
    o syntaxHighlighting - Syntax Highlighting [ {on} | off ]
    o tabs - Replace '\t' (horizontal tab) in source code by n white space
        characters [ 0 ... {4} ... n ]
    o globalHypertextLinks - Hypertext links among separate Matlab 
        directories [ on | {off} ]
    o todo - Create a TODO file in each directory summarizing all the
        '% TODO %' lines found in Matlab code [ on | {off}]
    o graph - Compute a dependency graph using GraphViz [ on | {off}]
        'dot' required, see <http://www.research.att.com/sw/tools/graphviz/>
    o indexFile - Basename of the HTML index file [ 'index' ]
    o extension - Extension of generated HTML files [ '.html' ]
    o template - HTML template name to use [ 'blue' ]
    o save - Save current state after M-files parsing in 'm2html.mat' 
        in directory htmlDir [ on | {off}]
    o load - Load a previously saved '.mat' M2HTML state to generate HTML 
        files once again with possibly other options [ <none> ]
    o verbose - Verbose mode [ {on} | off ]

  Examples:
    >> m2html('mfiles','matlab', 'htmldir','doc');
    >> m2html('mfiles',{'matlab/signal' 'matlab/image'}, 'htmldir','doc');
    >> m2html('mfiles','matlab', 'htmldir','doc', 'recursive','on');
    >> m2html('mfiles','mytoolbox', 'htmldir','doc', 'source','off');
    >> m2html('mfiles','matlab', 'htmldir','doc', 'global','on');
    >> m2html( ... , 'template','frame', 'index','menu');

  See also HIGHLIGHT, MDOT, TEMPLATE.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function m2html(varargin)
0002 %M2HTML - Documentation System for Matlab M-files in HTML
0003 %  M2HTML by itself generates an HTML documentation of Matlab M-files in the
0004 %  current directory. HTML files are also written in the current directory.
0005 %  M2HTML('PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,...)
0006 %  sets multiple option values. The list of option names and default values is:
0007 %    o mFiles - Cell array of strings or character array containing the
0008 %       list of M-files and/or directories of M-files for which an HTML
0009 %       documentation will be built [ '.' ]
0010 %    o htmlDir - Top level directory for generated HTML files [ '.' ]
0011 %    o recursive - Process subdirectories [ on | {off} ]
0012 %    o source - Include Matlab source code in the HTML documentation
0013 %                               [ {on} | off ]
0014 %    o syntaxHighlighting - Syntax Highlighting [ {on} | off ]
0015 %    o tabs - Replace '\t' (horizontal tab) in source code by n white space
0016 %        characters [ 0 ... {4} ... n ]
0017 %    o globalHypertextLinks - Hypertext links among separate Matlab
0018 %        directories [ on | {off} ]
0019 %    o todo - Create a TODO file in each directory summarizing all the
0020 %        '% TODO %' lines found in Matlab code [ on | {off}]
0021 %    o graph - Compute a dependency graph using GraphViz [ on | {off}]
0022 %        'dot' required, see <http://www.research.att.com/sw/tools/graphviz/>
0023 %    o indexFile - Basename of the HTML index file [ 'index' ]
0024 %    o extension - Extension of generated HTML files [ '.html' ]
0025 %    o template - HTML template name to use [ 'blue' ]
0026 %    o save - Save current state after M-files parsing in 'm2html.mat'
0027 %        in directory htmlDir [ on | {off}]
0028 %    o load - Load a previously saved '.mat' M2HTML state to generate HTML
0029 %        files once again with possibly other options [ <none> ]
0030 %    o verbose - Verbose mode [ {on} | off ]
0031 %
0032 %  Examples:
0033 %    >> m2html('mfiles','matlab', 'htmldir','doc');
0034 %    >> m2html('mfiles',{'matlab/signal' 'matlab/image'}, 'htmldir','doc');
0035 %    >> m2html('mfiles','matlab', 'htmldir','doc', 'recursive','on');
0036 %    >> m2html('mfiles','mytoolbox', 'htmldir','doc', 'source','off');
0037 %    >> m2html('mfiles','matlab', 'htmldir','doc', 'global','on');
0038 %    >> m2html( ... , 'template','frame', 'index','menu');
0039 %
0040 %  See also HIGHLIGHT, MDOT, TEMPLATE.
0041 
0042 %  Copyright (C) 2003 Guillaume Flandin <Guillaume@artefact.tk>
0043 %  $Revision: 1.1 $Date: 2008-09-03 08:36:22 $
0044 
0045 %  This program is free software; you can redistribute it and/or
0046 %  modify it under the terms of the GNU General Public License
0047 %  as published by the Free Software Foundation; either version 2
0048 %  of the License, or any later version.
0049 %
0050 %  This program is distributed in the hope that it will be useful,
0051 %  but WITHOUT ANY WARRANTY; without even the implied warranty of
0052 %  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0053 %  GNU General Public License for more details.
0054 %
0055 %  You should have received a copy of the GNU General Public License
0056 %  along with this program; if not, write to the Free Software
0057 %  Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA.
0058 
0059 %  Suggestions for improvement and fixes are always welcome, although no
0060 %  guarantee is made whether and when they will be implemented.
0061 %  Send requests to Guillaume.Flandin@laposte.net
0062 
0063 %  For tips on how to write Matlab code, see:
0064 %     * MATLAB Programming Style Guidelines, by R. Johnson:
0065 %       <http://www.datatool.com/prod02.htm>
0066 %     * For tips on creating help for your m-files 'type help.m'.
0067 %     * Matlab documentation on M-file Programming:
0068 %  <http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch10_pr9.shtml>
0069 
0070 %  This function uses the Template class so that you can fully customize
0071 %  the output. You can modify .tpl files in templates/blue/ or create new
0072 %  templates in a new directory.
0073 %  See the template class documentation for more details.
0074 %  <http://www.madic.org/download/matlab/template/>
0075 
0076 %  Latest information on M2HTML is available on the web through:
0077 %  <http://www.artefact.tk/software/matlab/m2html/>
0078 
0079 %  Other Matlab to HTML converters available on the web:
0080 %  1/ mat2html.pl, J.C. Kantor, in Perl, 1995:
0081 %     <http://fresh.t-systems-sfr.com/unix/src/www/mat2html>
0082 %  2/ htmltools, B. Alsberg, in Matlab, 1997:
0083 %     <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=175>
0084 %  3/ mtree2html2001, H. Pohlheim, in Perl, 1996, 2001:
0085 %     <http://www.pohlheim.com/perl_main.html#matlabdocu>
0086 %  4/ MatlabToHTML, T. Kristjansson, binary, 2001:
0087 %     <http://www.psi.utoronto.ca/~trausti/MatlabToHTML/MatlabToHTML.html>
0088 %  5/ Highlight, G. Flandin, in Matlab, 2003:
0089 %     <http://www.madic.org/download/matlab/highlight/>
0090 %  6/ mdoc, P. Brinkmann, in Matlab, 2003:
0091 %     <http://www.math.uiuc.edu/~brinkman/software/mdoc/>
0092 %  7/ Ocamaweb, Miriad Technologies, in Ocaml, 2002:
0093 %     <http://ocamaweb.sourceforge.net/>
0094 %  8/ Matdoc, M. Kaminsky, in Perl, 2003:
0095 %     <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3498>
0096 %  9/ Matlab itself, The Mathworks Inc, with HELPWIN and DOC
0097 
0098 %-------------------------------------------------------------------------------
0099 %- Set up options and default parameters
0100 %-------------------------------------------------------------------------------
0101 msgInvalidPair = 'Bad value for argument: ''%s''';
0102 
0103 options = struct('verbose', 1,...
0104                  'mFiles', {{'.'}},...
0105                  'htmlDir', '.',...
0106                  'recursive', 0,...
0107                  'source', 1,...
0108                  'syntaxHighlighting', 1,...
0109                  'tabs', 4,...
0110                  'globalHypertextLinks', 0,...
0111                  'graph', 0,...
0112                  'todo', 0,...
0113                  'load', 0,...
0114                  'save', 0,...
0115                  'search', 0,...
0116                  'indexFile', 'index',...
0117                  'extension', '.html',...
0118                  'template', 'blue');
0119 
0120 if nargin == 1 & isstruct(varargin{1})
0121     paramlist = [ fieldnames(varargin{1}) ...
0122                   struct2cell(varargin{1}) ]';
0123     paramlist = { paramlist{:} };
0124 else
0125     if mod(nargin,2)
0126         error('Invalid parameter/value pair arguments.');
0127     end
0128     paramlist = varargin;
0129 end
0130 
0131 optionsnames = lower(fieldnames(options));
0132 for i=1:2:length(paramlist)
0133     pname = paramlist{i};
0134     pvalue = paramlist{i+1};
0135     ind = strmatch(lower(pname),optionsnames);
0136     if isempty(ind)
0137         error(['Invalid parameter: ''' pname '''.']);
0138     elseif length(ind) > 1
0139         error(['Ambiguous parameter: ''' pname '''.']);
0140     end
0141     switch(optionsnames{ind})
0142         case 'verbose'
0143             if strcmpi(pvalue,'on')
0144                 options.verbose = 1;
0145             elseif strcmpi(pvalue,'off')
0146                 options.verbose = 0;
0147             else
0148                 error(sprintf(msgInvalidPair,pname));
0149             end
0150         case 'mfiles'
0151             if iscellstr(pvalue)
0152                 options.mFiles = pvalue;
0153             elseif ischar(pvalue)
0154                 options.mFiles = cellstr(pvalue);
0155             else
0156                 error(sprintf(msgInvalidPair,pname));
0157             end
0158             options.load = 0;
0159         case 'htmldir'
0160             if ischar(pvalue)
0161                 if isempty(pvalue),
0162                     options.htmlDir = '.';
0163                 else
0164                     options.htmlDir = pvalue;
0165                 end
0166             else
0167                 error(sprintf(msgInvalidPair,pname));
0168             end
0169         case 'recursive'
0170             if strcmpi(pvalue,'on')
0171                 options.recursive = 1;
0172             elseif strcmpi(pvalue,'off')
0173                 options.recursive = 0;
0174             else
0175                 error(sprintf(msgInvalidPair,pname));
0176             end
0177             options.load = 0;
0178         case 'source'
0179             if strcmpi(pvalue,'on')
0180                 options.source = 1;
0181             elseif strcmpi(pvalue,'off')
0182                 options.source = 0;
0183             else
0184                 error(sprintf(msgInvalidPair,pname));
0185             end
0186         case 'syntaxhighlighting'
0187             if strcmpi(pvalue,'on')
0188                 options.syntaxHighlighting = 1;
0189             elseif strcmpi(pvalue,'off')
0190                 options.syntaxHighlighting = 0;
0191             else
0192                 error(sprintf(msgInvalidPair,pname));
0193             end
0194         case 'tabs'
0195             if pvalue >= 0
0196                 options.tabs = pvalue;
0197             else
0198                 error(sprintf(msgInvalidPair,pname));
0199             end
0200         case 'globalhypertextlinks'
0201             if strcmpi(pvalue,'on')
0202                 options.globalHypertextLinks = 1;
0203             elseif strcmpi(pvalue,'off')
0204                 options.globalHypertextLinks = 0;
0205             else
0206                 error(sprintf(msgInvalidPair,pname));
0207             end
0208             options.load = 0;
0209         case 'graph'
0210             if strcmpi(pvalue,'on')
0211                 options.graph = 1;
0212             elseif strcmpi(pvalue,'off')
0213                 options.graph = 0;
0214             else
0215                 error(sprintf(msgInvalidPair,pname));
0216             end
0217         case 'todo'
0218             if strcmpi(pvalue,'on')
0219                 options.todo = 1;
0220             elseif strcmpi(pvalue,'off')
0221                 options.todo = 0;
0222             else
0223                 error(sprintf(msgInvalidPair,pname));
0224             end
0225         case 'load'
0226             if ischar(pvalue)
0227                 try
0228                     load(pvalue);
0229                 catch
0230                     error(sprintf('Unable to load %s.',pvalue));
0231                 end
0232                 options.load = 1;
0233                 [dummy options.template] = fileparts(options.template);
0234             else
0235                 error(sprintf(msgInvalidPair,pname));
0236             end
0237         case 'save'
0238             if strcmpi(pvalue,'on')
0239                 options.save = 1;
0240             elseif strcmpi(pvalue,'off')
0241                 options.save = 0;
0242             else
0243                 error(sprintf(msgInvalidPair,pname));
0244             end
0245         case 'search'
0246             if strcmpi(pvalue,'on')
0247                 options.search = 1;
0248             elseif strcmpi(pvalue,'off')
0249                 options.search = 0;
0250             else
0251                 error(sprintf(msgInvalidPair,pname));
0252             end
0253         case 'indexfile'
0254             if ischar(pvalue)
0255                 options.indexFile = pvalue;
0256             else
0257                 error(sprintf(msgInvalidPair,pname));
0258             end
0259         case 'extension'
0260             if ischar(pvalue) & pvalue(1) == '.'
0261                 options.extension = pvalue;
0262             else
0263                 error(sprintf(msgInvalidPair,pname));
0264             end
0265         case 'template'
0266             if ischar(pvalue)
0267                 options.template = pvalue;
0268             else
0269                 error(sprintf(msgInvalidPair,pname));
0270             end
0271         otherwise
0272             error(['Invalid parameter: ''' pname '''.']);
0273     end
0274 end
0275 
0276 %-------------------------------------------------------------------------------
0277 %- Get template files location
0278 %-------------------------------------------------------------------------------
0279 s = fileparts(which(mfilename));
0280 options.template = fullfile(s,'templates',options.template);
0281 if exist(options.template) ~= 7
0282     error('[Template] Unknown template.');
0283 end
0284 
0285 %-------------------------------------------------------------------------------
0286 %- Get list of M-files
0287 %-------------------------------------------------------------------------------
0288 if ~options.load
0289     mfiles = getmfiles(options.mFiles,{},options.recursive);
0290     if ~length(mfiles), fprintf('Nothing to be done.\n'); return; end
0291     if options.verbose,
0292         fprintf('Found %d M-files.\n',length(mfiles));
0293     end
0294     mfiles = sort(mfiles); % sort list of M-files in dictionary order
0295 end
0296 
0297 %-------------------------------------------------------------------------------
0298 %- Get list of (unique) directories and (unique) names
0299 %-------------------------------------------------------------------------------
0300 if ~options.load
0301     mdirs = {};
0302     names = {};
0303     for i=1:length(mfiles)
0304         [mdirs{i}, names{i}] = fileparts(mfiles{i});
0305         if isempty(mdirs{i}), mdirs{i} = '.'; end
0306     end
0307 
0308     mdir = unique(mdirs);
0309     if options.verbose,
0310         fprintf('Found %d unique Matlab directories.\n',length(mdir));
0311     end
0312 
0313     name = names;
0314     %name = unique(names); % output is sorted
0315     %if options.verbose,
0316     %    fprintf('Found %d unique Matlab files.\n',length(name));
0317     %end
0318 end
0319 
0320 %-------------------------------------------------------------------------------
0321 %- Create output directory, if necessary
0322 %-------------------------------------------------------------------------------
0323 if isempty(dir(options.htmlDir))                                               
0324     %- Create the top level output directory
0325     if options.verbose                                                         
0326         fprintf('Creating directory %s...\n',options.htmlDir);                 
0327     end                                                                        
0328     if options.htmlDir(end) == filesep,                                        
0329         options.htmlDir(end) = [];                                             
0330     end                                                                        
0331     [pathdir, namedir] = fileparts(options.htmlDir);                           
0332     if isempty(pathdir)                                                        
0333         [status, msg] = mkdir(namedir);                                        
0334     else                                                                       
0335         [status, msg] = mkdir(pathdir, namedir);                               
0336     end                                                                        
0337     if ~status, error(msg); end                                                                
0338 end                                                                            
0339 
0340 %-------------------------------------------------------------------------------
0341 %- Get synopsis, H1 line, script/function, subroutines, cross-references, todo
0342 %-------------------------------------------------------------------------------
0343 if ~options.load
0344     synopsis   = cell(size(mfiles));
0345     h1line     = cell(size(mfiles));
0346     subroutine = cell(size(mfiles));
0347     hrefs      = sparse(length(mfiles),length(mfiles));
0348     todo       = struct('mfile',[],'line',[],'comment',{{}});
0349     ismex      = zeros(length(mfiles),length(mexexts));
0350 
0351     for i=1:length(mfiles)
0352         s = mfileparse(mfiles{i}, mdirs, names, options);
0353         synopsis{i}   = s.synopsis;
0354         h1line{i}     = s.h1line;
0355         subroutine{i} = s.subroutine;
0356         hrefs(i,:)    = s.hrefs;
0357         todo.mfile    = [todo.mfile repmat(i,1,length(s.todo.line))];
0358         todo.line     = [todo.line s.todo.line];
0359         todo.comment  = {todo.comment{:} s.todo.comment{:}};
0360         ismex(i,:)    = s.ismex;
0361     end
0362     hrefs = hrefs > 0;
0363 end
0364 
0365 %-------------------------------------------------------------------------------
0366 %- Save M-filenames and cross-references for further analysis
0367 %-------------------------------------------------------------------------------
0368 matfilesave = 'm2html.mat';
0369 
0370 if options.save
0371     if options.verbose
0372         fprintf('Saving MAT file %s...\n',matfilesave);
0373     end
0374     save(fullfile(options.htmlDir,matfilesave), ...
0375         'mfiles', 'names', 'mdirs', 'name', 'mdir', 'options', ...
0376         'hrefs', 'synopsis', 'h1line', 'subroutine', 'todo', 'ismex');
0377 end
0378 
0379 %-------------------------------------------------------------------------------
0380 %- Setup the output directories
0381 %-------------------------------------------------------------------------------
0382 for i=1:length(mdir)
0383     if exist(fullfile(options.htmlDir,mdir{i})) ~= 7
0384         ldir = splitpath(mdir{i});
0385         for j=1:length(ldir)
0386             if exist(fullfile(options.htmlDir,ldir{1:j})) ~= 7
0387                 %- Create the output directory
0388                 if options.verbose
0389                     fprintf('Creating directory %s...\n',...
0390                             fullfile(options.htmlDir,ldir{1:j}));
0391                 end
0392                 if j == 1
0393                     [status, msg] = mkdir(options.htmlDir,ldir{1});
0394                 else
0395                     [status, msg] = mkdir(options.htmlDir,fullfile(ldir{1:j}));
0396                 end
0397                 error(msg);
0398             end
0399         end
0400     end
0401 end
0402 
0403 %-------------------------------------------------------------------------------
0404 %- Write the master index file
0405 %-------------------------------------------------------------------------------
0406 tpl_master = 'master.tpl';
0407 tpl_master_identifier_nbyline = 4;
0408 
0409 %- Create the HTML template
0410 tpl = template(options.template,'remove');
0411 tpl = set(tpl,'file','TPL_MASTER',tpl_master);
0412 tpl = set(tpl,'block','TPL_MASTER','rowdir','rowdirs');
0413 tpl = set(tpl,'block','TPL_MASTER','idrow','idrows');
0414 tpl = set(tpl,'block','idrow','idcolumn','idcolumns');
0415 
0416 %- Open for writing the HTML master index file
0417 curfile = fullfile(options.htmlDir,[options.indexFile options.extension]);
0418 if options.verbose
0419     fprintf('Creating HTML file %s...\n',curfile);
0420 end
0421 fid = openfile(curfile,'w');
0422 
0423 %- Set some template variables
0424 tpl = set(tpl,'var','DATE',[datestr(now,8) ' ' datestr(now,1) ' ' ...
0425                             datestr(now,13)]);
0426 tpl = set(tpl,'var','MASTERPATH',       './');
0427 tpl = set(tpl,'var','DIRS',    sprintf('%s ',mdir{:}));
0428 
0429 %- Print list of unique directories
0430 for i=1:length(mdir)
0431     tpl = set(tpl,'var','L_DIR',...
0432               fullurl(mdir{i},[options.indexFile options.extension]));
0433     tpl = set(tpl,'var','DIR',mdir{i});
0434     tpl = parse(tpl,'rowdirs','rowdir',1);
0435 end
0436 
0437 %- Print full list of M-files (sorted by column)
0438 [sortnames, ind] = sort(names);
0439 m_mod = mod(length(sortnames), tpl_master_identifier_nbyline);
0440 ind = [ind zeros(1,tpl_master_identifier_nbyline-m_mod)];
0441 m_floor = floor(length(ind) / tpl_master_identifier_nbyline);
0442 ind = reshape(ind,m_floor,tpl_master_identifier_nbyline)';
0443 
0444 for i=1:prod(size(ind))
0445     if ind(i)
0446         tpl = set(tpl,'var','L_IDNAME',...
0447             fullurl(mdirs{ind(i)},[names{ind(i)} options.extension]));
0448         tpl = set(tpl,'var','T_IDNAME',mdirs{ind(i)});
0449         tpl = set(tpl,'var','IDNAME',names{ind(i)});
0450         tpl = parse(tpl,'idcolumns','idcolumn',1);
0451     else
0452         tpl = set(tpl,'var','L_IDNAME','');
0453         tpl = set(tpl,'var','T_IDNAME','');
0454         tpl = set(tpl,'var','IDNAME','');
0455         tpl = parse(tpl,'idcolumns','idcolumn',1);
0456     end
0457     if mod(i,tpl_master_identifier_nbyline) == 0
0458         tpl = parse(tpl,'idrows','idrow',1);
0459         tpl = set(tpl,'var','idcolumns','');
0460     end
0461 end
0462 
0463 %- Print the template in the HTML file
0464 tpl = parse(tpl,'OUT','TPL_MASTER');
0465 fprintf(fid,'%s',get(tpl,'OUT'));
0466 fclose(fid);
0467 
0468 %-------------------------------------------------------------------------------
0469 %- Copy template files (CSS, images, ...)
0470 %-------------------------------------------------------------------------------
0471 % Get list of files
0472 d = dir(options.template);
0473 d = {d(~[d.isdir]).name};
0474 % Copy files
0475 for i=1:length(d)
0476     [p, n, ext] = fileparts(d{i});
0477     if ~strcmp(ext,'.tpl') % do not copy .tpl files
0478         if ~(exist(fullfile(options.htmlDir,d{i})))
0479             if options.verbose
0480                 fprintf('Copying template file %s...\n',d{i});
0481             end
0482             [status, errmsg] = copyfile(fullfile(options.template,d{i}),...
0483                                         options.htmlDir);
0484             error(errmsg);
0485         end
0486     end
0487 end
0488 
0489 %-------------------------------------------------------------------------------
0490 %- Write an index for each output directory
0491 %-------------------------------------------------------------------------------
0492 tpl_mdir = 'mdir.tpl';
0493 tpl_mdir_link = '<a href="%s">%s</a>';
0494 dotbase = 'graph';
0495 
0496 %- Create the HTML template
0497 tpl = template(options.template,'remove');
0498 tpl = set(tpl,'file','TPL_MDIR',tpl_mdir);
0499 tpl = set(tpl,'block','TPL_MDIR','row-m','rows-m');
0500 tpl = set(tpl,'block','row-m','mexfile','mex');
0501 tpl = set(tpl,'block','TPL_MDIR','othermatlab','other');
0502 tpl = set(tpl,'block','othermatlab','row-other','rows-other');
0503 tpl = set(tpl,'block','TPL_MDIR','subfolder','subfold');
0504 tpl = set(tpl,'block','subfolder','subdir','subdirs');
0505 tpl = set(tpl,'block','TPL_MDIR','todolist','todolists');
0506 tpl = set(tpl,'block','TPL_MDIR','graph','graphs');
0507 tpl = set(tpl,'var','DATE',[datestr(now,8) ' ' datestr(now,1) ' ' ...
0508                             datestr(now,13)]);
0509 
0510 for i=1:length(mdir)
0511     %- Open for writing each output directory index file
0512     curfile = fullfile(options.htmlDir,mdir{i},...
0513                        [options.indexFile options.extension]);
0514     if options.verbose
0515         fprintf('Creating HTML file %s...\n',curfile);
0516     end
0517     fid = openfile(curfile,'w');
0518 
0519     %- Set template fields
0520     tpl = set(tpl,'var','INDEX',     [options.indexFile options.extension]);
0521     tpl = set(tpl,'var','MASTERPATH',backtomaster(mdir{i}));
0522     tpl = set(tpl,'var','MDIR',      mdir{i});
0523     
0524     %- Display Matlab m-files, their H1 line and their Mex status
0525     tpl = set(tpl,'var','rows-m','');
0526     for j=1:length(mdirs)
0527         if strcmp(mdirs{j},mdir{i})
0528             tpl = set(tpl,'var','L_NAME', [names{j} options.extension]);
0529             tpl = set(tpl,'var','NAME',   names{j});
0530             tpl = set(tpl,'var','H1LINE', h1line{j});
0531             if any(ismex(j,:))
0532                 tpl = parse(tpl,'mex','mexfile');
0533             else
0534                 tpl = set(tpl,'var','mex','');
0535             end
0536             tpl = parse(tpl,'rows-m','row-m',1);
0537         end
0538     end
0539     
0540     %- Display other Matlab-specific files (.mat,.mdl,.p)
0541     tpl = set(tpl,'var','other','');
0542     tpl = set(tpl,'var','rows-other','');
0543     w = what(mdir{i}); w = w(1);
0544     w = {w.mat{:} w.mdl{:} w.p{:}};
0545     for j=1:length(w)
0546         tpl = set(tpl,'var','OTHERFILE',w{j});
0547         tpl = parse(tpl,'rows-other','row-other',1);
0548     end
0549     if ~isempty(w)
0550         tpl = parse(tpl,'other','othermatlab');
0551     end
0552     
0553     %- Display subsequent directories and classes
0554     tpl = set(tpl,'var','subdirs','');
0555     tpl = set(tpl,'var','subfold','');
0556     d = dir(mdir{i});
0557     d = {d([d.isdir]).name};
0558     d = {d{~ismember(d,{'.' '..'})}};
0559     for j=1:length(d)
0560         if ismember(fullfile(mdir{i},d{j}),mdir)
0561             tpl = set(tpl,'var','SUBDIRECTORY',...
0562                 sprintf(tpl_mdir_link,...
0563                 fullurl(d{j},[options.indexFile options.extension]),d{j}));
0564         else
0565             tpl = set(tpl,'var','SUBDIRECTORY',d{j});
0566         end
0567         tpl = parse(tpl,'subdirs','subdir',1);
0568     end
0569     if ~isempty(d)
0570         tpl = parse(tpl,'subfold','subfolder');
0571     end
0572     
0573     %- Link to the TODO list if necessary
0574     tpl = set(tpl,'var','todolists','');
0575     if options.todo
0576         if ~isempty(intersect(find(strcmp(mdir{i},mdirs)),todo.mfile))
0577             tpl = set(tpl,'var','LTODOLIST',['todo' options.extension]);
0578             tpl = parse(tpl,'todolists','todolist',1);
0579         end
0580     end
0581     
0582     %- Link to the dependency graph if necessary
0583     tpl = set(tpl,'var','graphs','');
0584     if options.graph
0585         tpl = set(tpl,'var','LGRAPH',[dotbase options.extension]);
0586         tpl = parse(tpl,'graphs','graph',1);
0587     end
0588     
0589     %- Print the template in the HTML file
0590     tpl = parse(tpl,'OUT','TPL_MDIR');
0591     fprintf(fid,'%s',get(tpl,'OUT'));
0592     fclose(fid);
0593 end
0594 
0595 %-------------------------------------------------------------------------------
0596 %- Write a TODO list file for each output directory, if necessary
0597 %-------------------------------------------------------------------------------
0598 tpl_todo = 'todo.tpl';
0599 
0600 if options.todo
0601     %- Create the HTML template
0602     tpl = template(options.template,'remove');
0603     tpl = set(tpl,'file','TPL_TODO',tpl_todo);
0604     tpl = set(tpl,'block','TPL_TODO','filelist','filelists');
0605     tpl = set(tpl,'block','filelist','row','rows');
0606     tpl = set(tpl,'var','DATE',[datestr(now,8) ' ' datestr(now,1) ' ' ...
0607                                 datestr(now,13)]);
0608 
0609     for i=1:length(mdir)
0610         mfilestodo = intersect(find(strcmp(mdir{i},mdirs)),todo.mfile);
0611         if ~isempty(mfilestodo)
0612             %- Open for writing each TODO list file
0613             curfile = fullfile(options.htmlDir,mdir{i},...
0614                                ['todo' options.extension]);
0615             if options.verbose
0616                 fprintf('Creating HTML file %s...\n',curfile);
0617             end
0618             fid = openfile(curfile,'w');
0619             
0620             %- Set template fields
0621             tpl = set(tpl,'var','INDEX',[options.indexFile options.extension]);
0622             tpl = set(tpl,'var','MASTERPATH', backtomaster(mdir{i}));
0623             tpl = set(tpl,'var','MDIR',       mdir{i});
0624             tpl = set(tpl,'var','filelists',  '');
0625     
0626             for k=1:length(mfilestodo)
0627                 tpl = set(tpl,'var','MFILE',names{mfilestodo(k)});
0628                 tpl = set(tpl,'var','rows','');
0629                 nbtodo = find(todo.mfile == mfilestodo(k));
0630                 for l=1:length(nbtodo)
0631                     tpl = set(tpl,'var','L_NBLINE',...
0632                         [names{mfilestodo(k)} ...
0633                             options.extension ...
0634                             '#l' num2str(todo.line(nbtodo(l)))]);
0635                     tpl = set(tpl,'var','NBLINE',num2str(todo.line(nbtodo(l))));
0636                     tpl = set(tpl,'var','COMMENT',todo.comment{nbtodo(l)});
0637                     tpl = parse(tpl,'rows','row',1);
0638                 end
0639                 tpl = parse(tpl,'filelists','filelist',1);
0640             end
0641     
0642             %- Print the template in the HTML file
0643             tpl = parse(tpl,'OUT','TPL_TODO');
0644             fprintf(fid,'%s',get(tpl,'OUT'));
0645             fclose(fid);
0646         end
0647     end
0648 end
0649 
0650 %-------------------------------------------------------------------------------
0651 %- Create a dependency graph for each output directory, if requested
0652 %-------------------------------------------------------------------------------
0653 tpl_graph = 'graph.tpl';
0654 dot_exec  = 'dot';
0655 %dotbase defined earlier
0656 
0657 if options.graph
0658     %- Create the HTML template
0659     tpl = template(options.template,'remove');
0660     tpl = set(tpl,'file','TPL_GRAPH',tpl_graph);
0661     tpl = set(tpl,'var','DATE',[datestr(now,8) ' ' datestr(now,1) ' ' ...
0662                                 datestr(now,13)]);
0663     
0664     for i=1:length(mdir)
0665         mdotfile = fullfile(options.htmlDir,mdir{i},[dotbase '.dot']);
0666         if options.verbose
0667             fprintf('Creating dependency graph %s...',mdotfile);
0668         end
0669         ind = find(strcmp(mdirs,mdir{i}));
0670         href1 = zeros(length(ind),length(hrefs));
0671         for j=1:length(hrefs), href1(:,j) = hrefs(ind,j); end
0672         href2 = zeros(length(ind));
0673         for j=1:length(ind), href2(j,:) = href1(j,ind); end
0674         mdot({href2,{names{ind}},options,{mfiles{ind}}}, mdotfile);
0675         try
0676             %- see <http://www.research.att.com/sw/tools/graphviz/>
0677             %  <dot> must be in your system path:
0678             %    - on Linux, modify $PATH accordingly
0679             %    - on Windows, modify the environment variable PATH like this:
0680             
0681 % From the Start-menu open the Control Panel, open 'System' and activate the
0682 % panel named 'Extended'. Open the dialog 'Environment Variables'. Select the
0683 % variable 'Path' of the panel 'System Variables' and press the 'Modify button.
0684 % Then add 'C:\GraphViz\bin' to your current definition of PATH, assuming that
0685 % you did install GraphViz into directory 'C:\GraphViz'. Note that the various
0686 % paths in PATH have to be separated by a colon. Her is an example how the final
0687 % Path should look like:  ...;C:\WINNT\System32;...;C:\GraphViz\bin
0688 % (Note that this should have been done automatically during GraphViz installation)
0689 
0690             eval(['!' dot_exec ' -Tcmap -Tpng ' mdotfile ...
0691                 ' -o ' fullfile(options.htmlDir,mdir{i},[dotbase '.map']) ... 
0692                 ' -o ' fullfile(options.htmlDir,mdir{i},[dotbase '.png'])])
0693             % use '!' rather than 'system' for backward compability
0694         catch
0695             fprintf('failed.');
0696         end
0697         fprintf('\n');
0698         fid = openfile(fullfile(options.htmlDir,mdir{i},...
0699             [dotbase options.extension]),'w');
0700         tpl = set(tpl,'var','INDEX',[options.indexFile options.extension]);
0701         tpl = set(tpl,'var','MASTERPATH', backtomaster(mdir{i}));
0702         tpl = set(tpl,'var','MDIR',       mdir{i});
0703         tpl = set(tpl,'var','GRAPH_IMG',  [dotbase '.png']);
0704         fmap = openfile(fullfile(options.htmlDir,mdir{i},[dotbase '.map']),'r');
0705         tpl = set(tpl,'var','GRAPH_MAP',  fscanf(fmap,'%c'));
0706         fclose(fmap);
0707         tpl = parse(tpl,'OUT','TPL_GRAPH');
0708         fprintf(fid,'%s', get(tpl,'OUT'));
0709         fclose(fid);
0710     end
0711 end
0712 
0713 %-------------------------------------------------------------------------------
0714 %- Write an HTML file for each M-file
0715 %-------------------------------------------------------------------------------
0716 %- List of Matlab keywords (output from iskeyword)
0717 matlabKeywords = {'break', 'case', 'catch', 'continue', 'elseif', 'else', ...
0718                   'end', 'for', 'function', 'global', 'if', 'otherwise', ...
0719                   'persistent', 'return', 'switch', 'try', 'while'};
0720                   %'keyboard', 'pause', 'eps', 'NaN', 'Inf'
0721 
0722 tpl_mfile = 'mfile.tpl';
0723 
0724 tpl_mfile_code     = '<a href="%s" class="code" title="%s">%s</a>';
0725 tpl_mfile_keyword  = '<span class="keyword">%s</span>';
0726 tpl_mfile_comment  = '<span class="comment">%s</span>';
0727 tpl_mfile_string   = '<span class="string">%s</span>';
0728 tpl_mfile_aname    = '<a name="%s" href="#_subfunctions" class="code">%s</a>';
0729 tpl_mfile_line     = '%04d %s\n';
0730 
0731 %- Delimiters used in strtok: some of them may be useless (% " .), removed '.'
0732 strtok_delim = sprintf(' \t\n\r(){}[]<>+-*~!|\\@&/,:;="''%%');
0733 
0734 %- Create the HTML template
0735 tpl = template(options.template,'remove');
0736 tpl = set(tpl,'file','TPL_MFILE',tpl_mfile);
0737 tpl = set(tpl,'block','TPL_MFILE','pathline','pl');
0738 tpl = set(tpl,'block','TPL_MFILE','mexfile','mex');
0739 tpl = set(tpl,'block','TPL_MFILE','script','scriptfile');
0740 tpl = set(tpl,'block','TPL_MFILE','crossrefcall','crossrefcalls');
0741 tpl = set(tpl,'block','TPL_MFILE','crossrefcalled','crossrefcalleds');
0742 tpl = set(tpl,'block','TPL_MFILE','subfunction','subf');
0743 tpl = set(tpl,'block','subfunction','onesubfunction','onesubf');
0744 tpl = set(tpl,'block','TPL_MFILE','source','thesource');
0745 tpl = set(tpl,'var','DATE',[datestr(now,8) ' ' datestr(now,1) ' ' ...
0746                             datestr(now,13)]);
0747 
0748 for i=1:length(mdir)
0749     for j=1:length(mdirs)
0750         if strcmp(mdirs{j},mdir{i})
0751         
0752             curfile = fullfile(options.htmlDir,mdir{i},...
0753                                [names{j} options.extension]);
0754 
0755             %- Open for writing the HTML file
0756             if options.verbose
0757                 fprintf('Creating HTML file %s...\n',curfile);
0758             end
0759             fid = openfile(curfile,'w');
0760             
0761             %- Open for reading the M-file
0762             fid2 = openfile(mfiles{j},'r');
0763             
0764             %- Set some template fields
0765             tpl = set(tpl,'var','INDEX', [options.indexFile options.extension]);
0766             tpl = set(tpl,'var','MASTERPATH',       backtomaster(mdir{i}));
0767             tpl = set(tpl,'var','MDIR',             mdirs{j});
0768             tpl = set(tpl,'var','NAME',             names{j});
0769             tpl = set(tpl,'var','H1LINE',           h1line{j});
0770             tpl = set(tpl,'var','scriptfile',       '');
0771             if isempty(synopsis{j})
0772                 tpl = set(tpl,'var','SYNOPSIS',get(tpl,'var','script'));
0773             else
0774                 tpl = set(tpl,'var','SYNOPSIS', synopsis{j});
0775             end
0776             s = splitpath(mdir{i});
0777             tpl = set(tpl,'var','pl','');
0778             for k=1:length(s)
0779                 c = cell(1,k); for l=1:k, c{l} = filesep; end
0780                 cpath = {s{1:k};c{:}}; cpath = [cpath{:}];
0781                 if ~isempty(cpath), cpath = cpath(1:end-1); end
0782                 if ismember(cpath,mdir)
0783                     tpl = set(tpl,'var','LPATHDIR',[repmat('../',...
0784                         1,length(s)-k) options.indexFile options.extension]);
0785                 else
0786                     tpl = set(tpl,'var','LPATHDIR','#');
0787                 end
0788                 tpl = set(tpl,'var','PATHDIR',s{k});
0789                 tpl = parse(tpl,'pl','pathline',1);
0790             end
0791             
0792             %- Handle mex files
0793             tpl = set(tpl,'var','mex', '');
0794             samename = dir(fullfile(mdir{i},[names{j}    '.*']));
0795             samename = {samename.name};
0796             for k=1:length(samename)
0797                 [dummy, dummy, ext] = fileparts(samename{k});
0798                 switch ext
0799                     case '.c'
0800                         tpl = set(tpl,'var','MEXTYPE', 'c');
0801                     case {'.cpp' '.c++' '.cxx' '.C'}
0802                         tpl = set(tpl,'var','MEXTYPE', 'c++');
0803                     case {'.for' '.f' '.FOR' '.F'}
0804                         tpl = set(tpl,'var','MEXTYPE', 'fortran');
0805                 end
0806             end
0807             [exts, platform] = mexexts;
0808             mexplatforms = sprintf('%s, ',platform{find(ismex(j,:))});
0809             if ~isempty(mexplatforms)
0810                 tpl = set(tpl,'var','PLATFORMS', mexplatforms(1:end-2));
0811                 tpl = parse(tpl,'mex','mexfile');
0812             end
0813             
0814             %- Set description template field
0815             descr = '';
0816             flagsynopcont = 0;
0817             flag_seealso  = 0;
0818             while 1
0819                 tline = fgets(fid2);
0820                 if ~ischar(tline), break, end
0821                 tline = entity(fliplr(deblank(fliplr(tline))));
0822                 %- Synopsis line
0823                 if ~isempty(strmatch('function',tline))
0824                     if ~isempty(strmatch('...',fliplr(deblank(tline))))
0825                         flagsynopcont = 1;
0826                     end
0827                 %- H1 line and description
0828                 elseif ~isempty(strmatch('%',tline))
0829                     %- Hypertext links on the "See also" line
0830                     ind = findstr(lower(tline),'see also');
0831                     if ~isempty(ind) | flag_seealso
0832                         %- "See also" only in files in the same directory
0833                         indsamedir = find(strcmp(mdirs{j},mdirs));
0834                         hrefnames = {names{indsamedir}};
0835                         r = deblank(tline);
0836                         flag_seealso = 1; %(r(end) == ',');
0837                         tline = '';
0838                         while 1
0839                             [t,r,q] = strtok(r,sprintf(' \t\n\r.,;%%'));
0840                             tline = [tline q];
0841                             if isempty(t), break, end;
0842                             ii = strcmpi(hrefnames,t);
0843                             if any(ii)
0844                                 jj = find(ii);
0845                                 tline = [tline sprintf(tpl_mfile_code,...
0846                                     [hrefnames{jj(1)} options.extension],...
0847                                     synopsis{indsamedir(jj(1))},t)];
0848                             else
0849                                 tline = [tline t];
0850                             end
0851                         end
0852                         tline = sprintf('%s\n',tline);
0853                     end
0854                     descr = [descr tline(2:end)];
0855                 elseif isempty(tline)
0856                     if ~isempty(descr), break, end;
0857                 else
0858                     if flagsynopcont
0859                         if isempty(strmatch('...',fliplr(deblank(tline))))
0860                             flagsynopcont = 0;
0861                         end
0862                     else
0863                         break;
0864                     end
0865                 end
0866             end
0867             tpl = set(tpl,'var','DESCRIPTION',...
0868                 horztab(descr,options.tabs));
0869             
0870             %- Set cross-references template fields:
0871             %  Function called
0872             ind = find(hrefs(j,:) == 1);
0873             tpl = set(tpl,'var','crossrefcalls','');
0874             for k=1:length(ind)
0875                 if strcmp(mdirs{j},mdirs{ind(k)})
0876                     tpl = set(tpl,'var','L_NAME_CALL', ...
0877                         [names{ind(k)} options.extension]);
0878                 else
0879                     tpl = set(tpl,'var','L_NAME_CALL', ...
0880                               fullurl(backtomaster(mdirs{j}), ...
0881                                          mdirs{ind(k)}, ...
0882                                        [names{ind(k)} options.extension]));
0883                 end
0884                 tpl = set(tpl,'var','SYNOP_CALL',   synopsis{ind(k)});
0885                 tpl = set(tpl,'var','NAME_CALL',   names{ind(k)});
0886                 tpl = set(tpl,'var','H1LINE_CALL', h1line{ind(k)});
0887                 tpl = parse(tpl,'crossrefcalls','crossrefcall',1);
0888             end
0889             %  Callers
0890             ind = find(hrefs(:,j) == 1);
0891             tpl = set(tpl,'var','crossrefcalleds','');
0892             for k=1:length(ind)
0893                 if strcmp(mdirs{j},mdirs{ind(k)})
0894                     tpl = set(tpl,'var','L_NAME_CALLED', ...
0895                         [names{ind(k)} options.extension]);
0896                 else
0897                     tpl = set(tpl,'var','L_NAME_CALLED', ...
0898                         fullurl(backtomaster(mdirs{j}),...
0899                             mdirs{ind(k)}, ...
0900                             [names{ind(k)} options.extension]));
0901                 end
0902                 tpl = set(tpl,'var','SYNOP_CALLED',   synopsis{ind(k)});
0903                 tpl = set(tpl,'var','NAME_CALLED',   names{ind(k)});
0904                 tpl = set(tpl,'var','H1LINE_CALLED', h1line{ind(k)});
0905                 tpl = parse(tpl,'crossrefcalleds','crossrefcalled',1);
0906             end
0907             
0908             %- Set subfunction template field
0909             tpl = set(tpl,'var',{'subf' 'onesubf'},{'' ''});
0910             if ~isempty(subroutine{j}) & options.source
0911                 for k=1:length(subroutine{j})
0912                     tpl = set(tpl, 'var', 'L_SUB', ['#_sub' num2str(k)]);
0913                     tpl = set(tpl, 'var', 'SUB',   subroutine{j}{k});
0914                     tpl = parse(tpl, 'onesubf', 'onesubfunction',1);
0915                 end
0916                 tpl = parse(tpl,'subf','subfunction');
0917             end
0918             subname = extractname(subroutine{j});
0919             
0920             %- Display source code with cross-references
0921             if options.source & ~strcmpi(names{j},'contents')
0922                 fseek(fid2,0,-1);
0923                 it = 1;
0924                 matlabsource = '';
0925                 nbsubroutine = 1;
0926                 %- Get href function names of this file
0927                 indhrefnames = find(hrefs(j,:) == 1);
0928                 hrefnames = {names{indhrefnames}};
0929                 %- Loop over lines
0930                 while 1
0931                     tline = fgetl(fid2);
0932                     if ~ischar(tline), break, end
0933                     myline = '';
0934                     splitc = splitcode(entity(tline));
0935                     for k=1:length(splitc)
0936                         if isempty(splitc{k})
0937                         elseif ~isempty(strmatch('function',splitc{k}))
0938                             %- Subfunctions definition
0939                             myline = [myline ...
0940                                 sprintf(tpl_mfile_aname,...
0941                                     ['_sub' num2str(nbsubroutine-1)],splitc{k})];
0942                             nbsubroutine = nbsubroutine + 1;
0943                         elseif splitc{k}(1) == ''''
0944                             myline = [myline ...
0945                                 sprintf(tpl_mfile_string,splitc{k})];
0946                         elseif splitc{k}(1) == '%'
0947                             myline = [myline ...
0948                                 sprintf(tpl_mfile_comment,deblank(splitc{k}))];
0949                         elseif ~isempty(strmatch('...',splitc{k}))
0950                             myline = [myline sprintf(tpl_mfile_keyword,'...')];
0951                             if ~isempty(splitc{k}(4:end))
0952                                 myline = [myline ...
0953                                     sprintf(tpl_mfile_comment,splitc{k}(4:end))];
0954                             end
0955                         else
0956                             %- Look for keywords
0957                             r = splitc{k};
0958                             while 1
0959                                 [t,r,q] = strtok(r,strtok_delim);
0960                                 myline = [myline q];
0961                                 if isempty(t), break, end;
0962                                 %- Highlight Matlab keywords &
0963                                 %  cross-references on known functions
0964                                 if options.syntaxHighlighting & ...
0965                                         any(strcmp(matlabKeywords,t))
0966                                     if strcmp('end',t)
0967                                         rr = fliplr(deblank(fliplr(r)));
0968                                         icomma = strmatch(',',rr);
0969                                         isemicolon = strmatch(';',rr);
0970                                         if ~(isempty(rr) | ~isempty([icomma isemicolon]))
0971                                             myline = [myline t];
0972                                         else
0973                                             myline = [myline sprintf(tpl_mfile_keyword,t)];
0974                                         end
0975                                     else
0976                                         myline = [myline sprintf(tpl_mfile_keyword,t)];
0977                                     end
0978                                 elseif any(strcmp(hrefnames,t))
0979                                     indt = indhrefnames(logical(strcmp(hrefnames,t)));
0980                                     flink = [t options.extension];
0981                                     ii = ismember({mdirs{indt}},mdirs{j});
0982                                     if ~any(ii)
0983                                         % take the first one...
0984                                         flink = fullurl(backtomaster(mdirs{j}),...
0985                                                           mdirs{indt(1)}, flink);
0986                                     else
0987                                         indt = indt(logical(ii));
0988                                     end
0989                                     myline = [myline sprintf(tpl_mfile_code,...
0990                                               flink, synopsis{indt(1)}, t)];
0991                                 elseif any(strcmp(subname,t))
0992                                     ii = find(strcmp(subname,t));
0993                                     myline = [myline sprintf(tpl_mfile_code,...
0994                                         ['#_sub' num2str(ii)],...
0995                                         ['sub' subroutine{j}{ii}],t)];
0996                                 else
0997                                     myline = [myline t];
0998                                 end
0999                             end
1000                         end
1001                     end
1002                     matlabsource = [matlabsource sprintf(tpl_mfile_line,it,myline)];
1003                     it = it + 1;
1004                 end
1005                 tpl = set(tpl,'var','SOURCECODE',...
1006                           horztab(matlabsource,options.tabs));
1007                 tpl = parse(tpl,'thesource','source');
1008             else
1009                 tpl = set(tpl,'var','thesource','');
1010             end
1011             tpl = parse(tpl,'OUT','TPL_MFILE');
1012             fprintf(fid,'%s',get(tpl,'OUT'));
1013             fclose(fid2);
1014             fclose(fid);
1015         end
1016     end
1017 end
1018 
1019 %===============================================================================
1020 function mfiles = getmfiles(mdirs,mfiles,recursive)
1021     %- Extract M-files from a list of directories and/or M-files
1022 
1023     for i=1:length(mdirs)
1024         if exist(mdirs{i}) == 2 % M-file
1025             mfiles{end+1} = mdirs{i};
1026         elseif exist(mdirs{i}) == 7 % Directory
1027             w = what(mdirs{i});
1028             w = w(1); %- Sometimes an array is returned...
1029             for j=1:length(w.m)
1030                 mfiles{end+1} = fullfile(mdirs{i},w.m{j});
1031             end
1032             if recursive
1033                 d = dir(mdirs{i});
1034                 d = {d([d.isdir]).name};
1035                 d = {d{~ismember(d,{'.' '..'})}};
1036                 for j=1:length(d)
1037                     mfiles = getmfiles(cellstr(fullfile(mdirs{i},d{j})),...
1038                                        mfiles,recursive);
1039                 end
1040             end
1041         else
1042             fprintf('Warning: Unprocessed file %s.\n',mdirs{i});
1043         end
1044     end
1045 
1046 %===============================================================================
1047 function s = backtomaster(mdir)
1048     %- Provide filesystem path to go back to the root folder
1049 
1050     ldir = splitpath(mdir);
1051     s = repmat('../',1,length(ldir));
1052     
1053 %===============================================================================
1054 function ldir = splitpath(p)
1055     %- Split a filesystem path into parts using filesep as separator
1056 
1057     ldir = {};
1058     p = deblank(p);
1059     while 1
1060         [t,p] = strtok(p,filesep);
1061         if isempty(t), break; end
1062         if ~strcmp(t,'.')
1063             ldir{end+1} = t;
1064         end
1065     end
1066     if isempty(ldir)
1067         ldir{1} = '.'; % should be removed
1068     end
1069 
1070 %===============================================================================
1071 function name = extractname(synopsis)
1072     if ischar(synopsis), synopsis = {synopsis}; end
1073     name = cell(size(synopsis));
1074     for i=1:length(synopsis)
1075         ind = findstr(synopsis{i},'=');
1076         if isempty(ind)
1077             ind = findstr(synopsis{i},'function');
1078             s = synopsis{i}(ind(1)+8:end);
1079         else
1080             s = synopsis{i}(ind(1)+1:end);
1081         end
1082         name{i} = strtok(s,[9:13 32 '(']);
1083     end
1084     if length(name) == 1, name = name{1}; end
1085 
1086 %===============================================================================
1087 function f = fullurl(varargin)
1088     %- Build full url from parts (using '/' and not filesep)
1089     
1090     f = strrep(fullfile(varargin{:}),'\','/');
1091 
1092 %===============================================================================
1093 function str = entity(str)
1094     %- See http://www.w3.org/TR/html4/charset.html#h-5.3.2
1095     
1096     str = strrep(str,'&','&amp;');
1097     str = strrep(str,'<','&lt;');
1098     str = strrep(str,'>','&gt;');
1099     str = strrep(str,'"','&quot;');
1100     
1101 %===============================================================================
1102 function str = horztab(str,n)
1103     %- For browsers, the horizontal tab character is the smallest non-zero
1104     %- number of spaces necessary to line characters up along tab stops that are
1105     %- every 8 characters: behaviour obtained when n = 0.
1106     
1107     if n > 0
1108         str = strrep(str,sprintf('\t'),blanks(n));
1109     end

Generated on Fri 22-Aug-2008 15:38:13 by m2html © 2003