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.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         %ind = find(strncmp(mdirs,mdir{i},length(mdir{i}))); %R.F.
0671         href1 = zeros(length(ind),length(hrefs));
0672         for j=1:length(hrefs), href1(:,j) = hrefs(ind,j); end
0673         href2 = zeros(length(ind));
0674         for j=1:length(ind), href2(j,:) = href1(j,ind); end
0675         mdot({href2,{names{ind}},options,{mfiles{ind}}}, mdotfile);
0676         %mdot({href2,{names{ind}},options,{mfiles{ind}}},mdotfile,mdir{i});%R.F.
0677         try
0678             %- see <http://www.research.att.com/sw/tools/graphviz/>
0679             %  <dot> must be in your system path:
0680             %    - on Linux, modify $PATH accordingly
0681             %    - on Windows, modify the environment variable PATH like this:
0682             
0683 % From the Start-menu open the Control Panel, open 'System' and activate the
0684 % panel named 'Extended'. Open the dialog 'Environment Variables'. Select the
0685 % variable 'Path' of the panel 'System Variables' and press the 'Modify button.
0686 % Then add 'C:\GraphViz\bin' to your current definition of PATH, assuming that
0687 % you did install GraphViz into directory 'C:\GraphViz'. Note that the various
0688 % paths in PATH have to be separated by a colon. Her is an example how the final
0689 % Path should look like:  ...;C:\WINNT\System32;...;C:\GraphViz\bin
0690 % (Note that this should have been done automatically during GraphViz installation)
0691 
0692             eval(['!' dot_exec ' -Tcmap -Tpng ' mdotfile ...
0693                 ' -o ' fullfile(options.htmlDir,mdir{i},[dotbase '.map']) ... 
0694                 ' -o ' fullfile(options.htmlDir,mdir{i},[dotbase '.png'])])
0695             % use '!' rather than 'system' for backward compability
0696         catch
0697             fprintf('failed.');
0698         end
0699         fprintf('\n');
0700         fid = openfile(fullfile(options.htmlDir,mdir{i},...
0701             [dotbase options.extension]),'w');
0702         tpl = set(tpl,'var','INDEX',[options.indexFile options.extension]);
0703         tpl = set(tpl,'var','MASTERPATH', backtomaster(mdir{i}));
0704         tpl = set(tpl,'var','MDIR',       mdir{i});
0705         tpl = set(tpl,'var','GRAPH_IMG',  [dotbase '.png']);
0706         fmap = openfile(fullfile(options.htmlDir,mdir{i},[dotbase '.map']),'r');
0707         tpl = set(tpl,'var','GRAPH_MAP',  fscanf(fmap,'%c'));
0708         fclose(fmap);
0709         tpl = parse(tpl,'OUT','TPL_GRAPH');
0710         fprintf(fid,'%s', get(tpl,'OUT'));
0711         fclose(fid);
0712     end
0713 end
0714 
0715 %-------------------------------------------------------------------------------
0716 %- Write an HTML file for each M-file
0717 %-------------------------------------------------------------------------------
0718 %- List of Matlab keywords (output from iskeyword)
0719 matlabKeywords = {'break', 'case', 'catch', 'continue', 'elseif', 'else', ...
0720                   'end', 'for', 'function', 'global', 'if', 'otherwise', ...
0721                   'persistent', 'return', 'switch', 'try', 'while'};
0722                   %'keyboard', 'pause', 'eps', 'NaN', 'Inf'
0723 
0724 tpl_mfile = 'mfile.tpl';
0725 
0726 tpl_mfile_code     = '<a href="%s" class="code" title="%s">%s</a>';
0727 tpl_mfile_keyword  = '<span class="keyword">%s</span>';
0728 tpl_mfile_comment  = '<span class="comment">%s</span>';
0729 tpl_mfile_string   = '<span class="string">%s</span>';
0730 tpl_mfile_aname    = '<a name="%s" href="#_subfunctions" class="code">%s</a>';
0731 tpl_mfile_line     = '%04d %s\n';
0732 
0733 %- Delimiters used in strtok: some of them may be useless (% " .), removed '.'
0734 strtok_delim = sprintf(' \t\n\r(){}[]<>+-*~!|\\@&/,:;="''%%');
0735 
0736 %- Create the HTML template
0737 tpl = template(options.template,'remove');
0738 tpl = set(tpl,'file','TPL_MFILE',tpl_mfile);
0739 tpl = set(tpl,'block','TPL_MFILE','pathline','pl');
0740 tpl = set(tpl,'block','TPL_MFILE','mexfile','mex');
0741 tpl = set(tpl,'block','TPL_MFILE','script','scriptfile');
0742 tpl = set(tpl,'block','TPL_MFILE','crossrefcall','crossrefcalls');
0743 tpl = set(tpl,'block','TPL_MFILE','crossrefcalled','crossrefcalleds');
0744 tpl = set(tpl,'block','TPL_MFILE','subfunction','subf');
0745 tpl = set(tpl,'block','subfunction','onesubfunction','onesubf');
0746 tpl = set(tpl,'block','TPL_MFILE','source','thesource');
0747 tpl = set(tpl,'var','DATE',[datestr(now,8) ' ' datestr(now,1) ' ' ...
0748                             datestr(now,13)]);
0749 
0750 for i=1:length(mdir)
0751     for j=1:length(mdirs)
0752         if strcmp(mdirs{j},mdir{i})
0753         
0754             curfile = fullfile(options.htmlDir,mdir{i},...
0755                                [names{j} options.extension]);
0756 
0757             %- Open for writing the HTML file
0758             if options.verbose
0759                 fprintf('Creating HTML file %s...\n',curfile);
0760             end
0761             fid = openfile(curfile,'w');
0762             
0763             %- Open for reading the M-file
0764             fid2 = openfile(mfiles{j},'r');
0765             
0766             %- Set some template fields
0767             tpl = set(tpl,'var','INDEX', [options.indexFile options.extension]);
0768             tpl = set(tpl,'var','MASTERPATH',       backtomaster(mdir{i}));
0769             tpl = set(tpl,'var','MDIR',             mdirs{j});
0770             tpl = set(tpl,'var','NAME',             names{j});
0771             tpl = set(tpl,'var','H1LINE',           h1line{j});
0772             tpl = set(tpl,'var','scriptfile',       '');
0773             if isempty(synopsis{j})
0774                 tpl = set(tpl,'var','SYNOPSIS',get(tpl,'var','script'));
0775             else
0776                 tpl = set(tpl,'var','SYNOPSIS', synopsis{j});
0777             end
0778             s = splitpath(mdir{i});
0779             tpl = set(tpl,'var','pl','');
0780             for k=1:length(s)
0781                 c = cell(1,k); for l=1:k, c{l} = filesep; end
0782                 cpath = {s{1:k};c{:}}; cpath = [cpath{:}];
0783                 if ~isempty(cpath), cpath = cpath(1:end-1); end
0784                 if ismember(cpath,mdir)
0785                     tpl = set(tpl,'var','LPATHDIR',[repmat('../',...
0786                         1,length(s)-k) options.indexFile options.extension]);
0787                 else
0788                     tpl = set(tpl,'var','LPATHDIR','#');
0789                 end
0790                 tpl = set(tpl,'var','PATHDIR',s{k});
0791                 tpl = parse(tpl,'pl','pathline',1);
0792             end
0793             
0794             %- Handle mex files
0795             tpl = set(tpl,'var','mex', '');
0796             samename = dir(fullfile(mdir{i},[names{j}    '.*']));
0797             samename = {samename.name};
0798             for k=1:length(samename)
0799                 [dummy, dummy, ext] = fileparts(samename{k});
0800                 switch ext
0801                     case '.c'
0802                         tpl = set(tpl,'var','MEXTYPE', 'c');
0803                     case {'.cpp' '.c++' '.cxx' '.C'}
0804                         tpl = set(tpl,'var','MEXTYPE', 'c++');
0805                     case {'.for' '.f' '.FOR' '.F'}
0806                         tpl = set(tpl,'var','MEXTYPE', 'fortran');
0807                 end
0808             end
0809             [exts, platform] = mexexts;
0810             mexplatforms = sprintf('%s, ',platform{find(ismex(j,:))});
0811             if ~isempty(mexplatforms)
0812                 tpl = set(tpl,'var','PLATFORMS', mexplatforms(1:end-2));
0813                 tpl = parse(tpl,'mex','mexfile');
0814             end
0815             
0816             %- Set description template field
0817             descr = '';
0818             flagsynopcont = 0;
0819             flag_seealso  = 0;
0820             while 1
0821                 tline = fgets(fid2);
0822                 if ~ischar(tline), break, end
0823                 tline = entity(fliplr(deblank(fliplr(tline))));
0824                 %- Synopsis line
0825                 if ~isempty(strmatch('function',tline))
0826                     if ~isempty(strmatch('...',fliplr(deblank(tline))))
0827                         flagsynopcont = 1;
0828                     end
0829                 %- H1 line and description
0830                 elseif ~isempty(strmatch('%',tline))
0831                     %- Hypertext links on the "See also" line
0832                     ind = findstr(lower(tline),'see also');
0833                     if ~isempty(ind) | flag_seealso
0834                         %- "See also" only in files in the same directory
0835                         indsamedir = find(strcmp(mdirs{j},mdirs));
0836                         hrefnames = {names{indsamedir}};
0837                         r = deblank(tline);
0838                         flag_seealso = 1; %(r(end) == ',');
0839                         tline = '';
0840                         while 1
0841                             [t,r,q] = strtok(r,sprintf(' \t\n\r.,;%%'));
0842                             tline = [tline q];
0843                             if isempty(t), break, end;
0844                             ii = strcmpi(hrefnames,t);
0845                             if any(ii)
0846                                 jj = find(ii);
0847                                 tline = [tline sprintf(tpl_mfile_code,...
0848                                     [hrefnames{jj(1)} options.extension],...
0849                                     synopsis{indsamedir(jj(1))},t)];
0850                             else
0851                                 tline = [tline t];
0852                             end
0853                         end
0854                         tline = sprintf('%s\n',tline);
0855                     end
0856                     descr = [descr tline(2:end)];
0857                 elseif isempty(tline)
0858                     if ~isempty(descr), break, end;
0859                 else
0860                     if flagsynopcont
0861                         if isempty(strmatch('...',fliplr(deblank(tline))))
0862                             flagsynopcont = 0;
0863                         end
0864                     else
0865                         break;
0866                     end
0867                 end
0868             end
0869             tpl = set(tpl,'var','DESCRIPTION',...
0870                 horztab(descr,options.tabs));
0871             
0872             %- Set cross-references template fields:
0873             %  Function called
0874             ind = find(hrefs(j,:) == 1);
0875             tpl = set(tpl,'var','crossrefcalls','');
0876             for k=1:length(ind)
0877                 if strcmp(mdirs{j},mdirs{ind(k)})
0878                     tpl = set(tpl,'var','L_NAME_CALL', ...
0879                         [names{ind(k)} options.extension]);
0880                 else
0881                     tpl = set(tpl,'var','L_NAME_CALL', ...
0882                               fullurl(backtomaster(mdirs{j}), ...
0883                                          mdirs{ind(k)}, ...
0884                                        [names{ind(k)} options.extension]));
0885                 end
0886                 tpl = set(tpl,'var','SYNOP_CALL',   synopsis{ind(k)});
0887                 tpl = set(tpl,'var','NAME_CALL',   names{ind(k)});
0888                 tpl = set(tpl,'var','H1LINE_CALL', h1line{ind(k)});
0889                 tpl = parse(tpl,'crossrefcalls','crossrefcall',1);
0890             end
0891             %  Callers
0892             ind = find(hrefs(:,j) == 1);
0893             tpl = set(tpl,'var','crossrefcalleds','');
0894             for k=1:length(ind)
0895                 if strcmp(mdirs{j},mdirs{ind(k)})
0896                     tpl = set(tpl,'var','L_NAME_CALLED', ...
0897                         [names{ind(k)} options.extension]);
0898                 else
0899                     tpl = set(tpl,'var','L_NAME_CALLED', ...
0900                         fullurl(backtomaster(mdirs{j}),...
0901                             mdirs{ind(k)}, ...
0902                             [names{ind(k)} options.extension]));
0903                 end
0904                 tpl = set(tpl,'var','SYNOP_CALLED',   synopsis{ind(k)});
0905                 tpl = set(tpl,'var','NAME_CALLED',   names{ind(k)});
0906                 tpl = set(tpl,'var','H1LINE_CALLED', h1line{ind(k)});
0907                 tpl = parse(tpl,'crossrefcalleds','crossrefcalled',1);
0908             end
0909             
0910             %- Set subfunction template field
0911             tpl = set(tpl,'var',{'subf' 'onesubf'},{'' ''});
0912             if ~isempty(subroutine{j}) & options.source
0913                 for k=1:length(subroutine{j})
0914                     tpl = set(tpl, 'var', 'L_SUB', ['#_sub' num2str(k)]);
0915                     tpl = set(tpl, 'var', 'SUB',   subroutine{j}{k});
0916                     tpl = parse(tpl, 'onesubf', 'onesubfunction',1);
0917                 end
0918                 tpl = parse(tpl,'subf','subfunction');
0919             end
0920             subname = extractname(subroutine{j});
0921             
0922             %- Display source code with cross-references
0923             if options.source & ~strcmpi(names{j},'contents')
0924                 fseek(fid2,0,-1);
0925                 it = 1;
0926                 matlabsource = '';
0927                 nbsubroutine = 1;
0928                 %- Get href function names of this file
0929                 indhrefnames = find(hrefs(j,:) == 1);
0930                 hrefnames = {names{indhrefnames}};
0931                 %- Loop over lines
0932                 while 1
0933                     tline = fgetl(fid2);
0934                     if ~ischar(tline), break, end
0935                     myline = '';
0936                     splitc = splitcode(entity(tline));
0937                     for k=1:length(splitc)
0938                         if isempty(splitc{k})
0939                         elseif ~isempty(strmatch('function',splitc{k}))
0940                             %- Subfunctions definition
0941                             myline = [myline ...
0942                                 sprintf(tpl_mfile_aname,...
0943                                     ['_sub' num2str(nbsubroutine-1)],splitc{k})];
0944                             nbsubroutine = nbsubroutine + 1;
0945                         elseif splitc{k}(1) == ''''
0946                             myline = [myline ...
0947                                 sprintf(tpl_mfile_string,splitc{k})];
0948                         elseif splitc{k}(1) == '%'
0949                             myline = [myline ...
0950                                 sprintf(tpl_mfile_comment,deblank(splitc{k}))];
0951                         elseif ~isempty(strmatch('...',splitc{k}))
0952                             myline = [myline sprintf(tpl_mfile_keyword,'...')];
0953                             if ~isempty(splitc{k}(4:end))
0954                                 myline = [myline ...
0955                                     sprintf(tpl_mfile_comment,splitc{k}(4:end))];
0956                             end
0957                         else
0958                             %- Look for keywords
0959                             r = splitc{k};
0960                             while 1
0961                                 [t,r,q] = strtok(r,strtok_delim);
0962                                 myline = [myline q];
0963                                 if isempty(t), break, end;
0964                                 %- Highlight Matlab keywords &
0965                                 %  cross-references on known functions
0966                                 if options.syntaxHighlighting & ...
0967                                         any(strcmp(matlabKeywords,t))
0968                                     if strcmp('end',t)
0969                                         rr = fliplr(deblank(fliplr(r)));
0970                                         icomma = strmatch(',',rr);
0971                                         isemicolon = strmatch(';',rr);
0972                                         if ~(isempty(rr) | ~isempty([icomma isemicolon]))
0973                                             myline = [myline t];
0974                                         else
0975                                             myline = [myline sprintf(tpl_mfile_keyword,t)];
0976                                         end
0977                                     else
0978                                         myline = [myline sprintf(tpl_mfile_keyword,t)];
0979                                     end
0980                                 elseif any(strcmp(hrefnames,t))
0981                                     indt = indhrefnames(logical(strcmp(hrefnames,t)));
0982                                     flink = [t options.extension];
0983                                     ii = ismember({mdirs{indt}},mdirs{j});
0984                                     if ~any(ii)
0985                                         % take the first one...
0986                                         flink = fullurl(backtomaster(mdirs{j}),...
0987                                                           mdirs{indt(1)}, flink);
0988                                     else
0989                                         indt = indt(logical(ii));
0990                                     end
0991                                     myline = [myline sprintf(tpl_mfile_code,...
0992                                               flink, synopsis{indt(1)}, t)];
0993                                 elseif any(strcmp(subname,t))
0994                                     ii = find(strcmp(subname,t));
0995                                     myline = [myline sprintf(tpl_mfile_code,...
0996                                         ['#_sub' num2str(ii)],...
0997                                         ['sub' subroutine{j}{ii}],t)];
0998                                 else
0999                                     myline = [myline t];
1000                                 end
1001                             end
1002                         end
1003                     end
1004                     matlabsource = [matlabsource sprintf(tpl_mfile_line,it,myline)];
1005                     it = it + 1;
1006                 end
1007                 tpl = set(tpl,'var','SOURCECODE',...
1008                           horztab(matlabsource,options.tabs));
1009                 tpl = parse(tpl,'thesource','source');
1010             else
1011                 tpl = set(tpl,'var','thesource','');
1012             end
1013             tpl = parse(tpl,'OUT','TPL_MFILE');
1014             fprintf(fid,'%s',get(tpl,'OUT'));
1015             fclose(fid2);
1016             fclose(fid);
1017         end
1018     end
1019 end
1020 
1021 %===============================================================================
1022 function mfiles = getmfiles(mdirs,mfiles,recursive)
1023     %- Extract M-files from a list of directories and/or M-files
1024 
1025     for i=1:length(mdirs)
1026         if exist(mdirs{i}) == 2 % M-file
1027             mfiles{end+1} = mdirs{i};
1028         elseif exist(mdirs{i}) == 7 % Directory
1029             w = what(mdirs{i});
1030             w = w(1); %- Sometimes an array is returned...
1031             for j=1:length(w.m)
1032                 mfiles{end+1} = fullfile(mdirs{i},w.m{j});
1033             end
1034             if recursive
1035                 d = dir(mdirs{i});
1036                 d = {d([d.isdir]).name};
1037                 d = {d{~ismember(d,{'.' '..'})}};
1038                 for j=1:length(d)
1039                     mfiles = getmfiles(cellstr(fullfile(mdirs{i},d{j})),...
1040                                        mfiles,recursive);
1041                 end
1042             end
1043         else
1044             fprintf('Warning: Unprocessed file %s.\n',mdirs{i});
1045         end
1046     end
1047 
1048 %===============================================================================
1049 function s = backtomaster(mdir)
1050     %- Provide filesystem path to go back to the root folder
1051 
1052     ldir = splitpath(mdir);
1053     s = repmat('../',1,length(ldir));
1054     
1055 %===============================================================================
1056 function ldir = splitpath(p)
1057     %- Split a filesystem path into parts using filesep as separator
1058 
1059     ldir = {};
1060     p = deblank(p);
1061     while 1
1062         [t,p] = strtok(p,filesep);
1063         if isempty(t), break; end
1064         if ~strcmp(t,'.')
1065             ldir{end+1} = t;
1066         end
1067     end
1068     if isempty(ldir)
1069         ldir{1} = '.'; % should be removed
1070     end
1071 
1072 %===============================================================================
1073 function name = extractname(synopsis)
1074     if ischar(synopsis), synopsis = {synopsis}; end
1075     name = cell(size(synopsis));
1076     for i=1:length(synopsis)
1077         ind = findstr(synopsis{i},'=');
1078         if isempty(ind)
1079             ind = findstr(synopsis{i},'function');
1080             s = synopsis{i}(ind(1)+8:end);
1081         else
1082             s = synopsis{i}(ind(1)+1:end);
1083         end
1084         name{i} = strtok(s,[9:13 32 '(']);
1085     end
1086     if length(name) == 1, name = name{1}; end
1087 
1088 %===============================================================================
1089 function f = fullurl(varargin)
1090     %- Build full url from parts (using '/' and not filesep)
1091     
1092     f = strrep(fullfile(varargin{:}),'\','/');
1093 
1094 %===============================================================================
1095 function str = entity(str)
1096     %- See http://www.w3.org/TR/html4/charset.html#h-5.3.2
1097     
1098     str = strrep(str,'&','&amp;');
1099     str = strrep(str,'<','&lt;');
1100     str = strrep(str,'>','&gt;');
1101     str = strrep(str,'"','&quot;');
1102     
1103 %===============================================================================
1104 function str = horztab(str,n)
1105     %- For browsers, the horizontal tab character is the smallest non-zero
1106     %- number of spaces necessary to line characters up along tab stops that are
1107     %- every 8 characters: behaviour obtained when n = 0.
1108     
1109     if n > 0
1110         str = strrep(str,sprintf('\t'),blanks(n));
1111     end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003