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

Generated on Thu 02-Oct-2003 14:58:51 by m2html © 2003