% makehtml() - generate .html function-index page and function help pages % composed automatically from formatted Matlab function help messages % % Usage: % >> makehtml(list, outputdir); % >> makehtml(list, outputdir, 'key1', val1, 'key2', val2, ...); % % Input: % list - (1) List (cell array) of filenames to convert. % Ex: {'filename1' 'filename2' 'filename3'} % By default, the filename extension .m is understood. % (2) Cell array of filenames to convert and the text link % on the summary page for them. % {{'filename1' 'link1'} {'filename2' 'link2'}} ... % Ex: 'link1' = 'Reject by kurtosis'. % (3) Cell array of 2 or 3 cell array elements containing % info to generate .html function-index and help pages. % Ex: { {'directory1' 'heading1' 'dirindexfunc1'} ... % {'directory2' 'heading2' 'dirindexfunc2'} } % - 'directory': Function file directory name % - 'heading': Index-file heading for the directory functions % - 'dirindexfunc': A optional Matlab pop-up help function for % referencing the directory functions {default: none} % (4) To scan several directories under the same heading, use % {{{'directory1' 'directory2'} 'heading1' 'dirindexfunc1' ... } % outputdir - Directory for output .html help files % % Optional inputs: % 'outputfile' - Output file name. {default: 'index.html'} % 'header' - Command to insert in the header of all .html files (e.g., javascript % declaration or meta-tag). {default: javascript 'openhelp()' % function. See help2htm() code for details.} % 'footer' - Command to insert at the end of all .html files (e.g., back % button. {default: reference back to the function-index file} % 'refcall' - Syntax format to call references. {default is % 'javascript:openhelp(''%s.js'')'} Use '%s.html' for an .html link. % 'font' - Font name (default: 'Helvetica') % 'background' - Background HTML body section. Include "<" and ">". % 'outputlink' - Help page calling command for the function index page. {default is % 'javascript:openhelp(''%s.js'')'. Use '%s.html' to use a % standard .html page link instead.} % 'fontindex' - Font for the .html index file (default: 'Helvetica') % 'backindex' - Background tag for the index file (c.f. 'background') % 'mainheader' - Text file to insert at the beggining of the index page. Default is % none. % 'mainonly' - ['on'|'off'] 'on' -> Generate the index page only. % {default: 'off' -> generate both the index and help pages} % % Author: Arnaud Delorme, CNL / Salk Institute, 2002 % % Example: Generate EEGLAB help menus at SCCN: % makehtml({ { 'adminfunc' 'Admin functions' 'adminfunc/eeg_helpadmin.m' } ... % { 'popfunc', 'Interactive pop_functions' 'adminfunc/eeg_helppop.m' } ... % { { 'toolbox', 'toolbox2' } 'Signal processing functions' 'adminfunc/eeg_helpsigproc.m' }}, ... % '/home/www/eeglab/allfunctions', 'mainheader', '/data/common/matlab/indexfunchdr.txt'); % % See also: help2html() % Copyright (C) Arnaud Delorme, CNL / Salk Institute, 2002 % % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation; either version 2 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA % $Log: makehtml.m,v $ % Revision 1.19 2007/03/22 02:08:50 toby % correction to previous % % Revision 1.18 2007/03/22 01:58:53 toby % edit to inform user what file was crashed on. % % Revision 1.17 2006/03/11 06:50:36 arno % output only etc... % % Revision 1.16 2003/05/23 17:45:20 arno % update header % % Revision 1.15 2003/01/28 19:51:11 arno % deleting destination filename % % Revision 1.14 2002/12/04 17:40:36 arno % mainheader option and tags for titles % % Revision 1.13 2002/11/21 23:06:37 arno % indexfunc -> index % % Revision 1.12 2002/11/15 02:44:32 arno % same % % Revision 1.11 2002/11/15 02:43:54 arno % header for web % % Revision 1.10 2002/11/15 01:46:47 scott % can not -> cannot % % Revision 1.9 2002/09/07 22:51:11 scott % help msg -sm & ad % % Revision 1.8 2002/09/07 22:11:58 scott % help msg -scott % % Revision 1.7 2002/08/17 20:12:55 arno % same % % Revision 1.6 2002/08/17 20:03:52 arno % new background color % % Revision 1.5 2002/08/17 00:42:33 arno % new modifs % % Revision 1.4 2002/08/16 16:29:36 arno % new revision % % Revision 1.3 2002/08/16 15:12:21 arno % after crash % % Revision 1.2 2002/04/06 01:58:16 arno % debugging destination of html files % % Revision 1.1 2002/04/05 17:39:45 jorn % Initial revision % function makehtml( directorylist, outputdir, varargin ); if nargin < 2 help makehtml; return; end; if outputdir(end) ~= '/', outputdir(end+1) = '/'; end; if ~isempty( varargin ) g = struct( varargin{:} ); else g = []; end; try, g.mainonly; catch, g.mainonly = 'off'; end; try, g.mainheader; catch, g.mainheader = ''; end; try, g.outputfile; catch, g.outputfile = 'index.html'; end; try, g.fontindex; catch, g.fontindex = 'Helvetica'; end; try, g.backindex; catch, g.backindex = ''; end; try, g.header; catch, g.header = [ '' ]; end; try, g.background; catch, g.background = ''; end; %try, g.background; catch, g.background = ''; end; try, g.refcall; catch, g.refcall = 'javascript:openhelp(''%s.html'')'; end; try, g.font; catch, g.font = 'Helvetica'; end; try, g.footer; catch, g.footer = 'Back to functions'; end; try, g.outputlink; catch, g.outputlink = [ '%s%s' ]; end; % read header text file % --------------------- if ~isempty(g.mainheader) doc = []; fid = fopen(g.mainheader , 'r'); if (fid == -1), error(['Can not open file ''' g.mainheader '''' ]); end; str = fgets( fid ); while ~feof(fid) str = deblank(str(1:end-1)); doc = [ doc str(1:end) ]; str = fgets( fid ); end; g.backindex = [ g.backindex doc ]; end; options = { 'footer', g.footer, 'background', g.background, ... 'refcall', g.refcall, 'font', g.font, 'header', g.header, 'outputlink', g.outputlink}; if strcmpi( g.mainonly, 'on') options = { options{:}, 'outputonly', g.mainonly }; end; % ------------------------------------------- % scrips which generate a web page for eeglab % ------------------------------------------- STYLEHEADER = '

%s

\n'; OPENWIN = [ '']; ORIGIN = pwd; % determine mode % -------------- if iscell(directorylist{1}) & exist(directorylist{1}{1}) == 7 fprintf('First cell array element is not a file\n'); fprintf('Scanning directories...\n'); mode = 'dir'; % scan directories % ---------------- for index = 1:length( directorylist ) direct{ index } = scandir( directorylist{index}{1} ); end; else fprintf('First cell array element has been identified as a file\n'); fprintf('Scanning all files...\n'); mode = 'files'; end; % remove . directory % ------------------ rmpath('.'); % write .html file % ---------------- fo = fopen([ outputdir g.outputfile], 'w'); if fo == -1, error(['cannot open file ''' [ outputdir g.outputfile] '''']); end; fprintf(fo, '%s%s\n', OPENWIN, g.backindex, g.fontindex); if strcmp(mode, 'files') makehelphtml( directorylist, fo, 'MAIN TITLE', STYLEHEADER, outputdir, mode, options, g.mainonly ); else % direcotry for index = 1:length( directorylist ) makehelphtml( direct{ index }, fo, directorylist{index}{2}, STYLEHEADER, outputdir, mode, options, g.mainonly ); end; end; fprintf( fo, ''); fclose( fo ); if isunix chmodcom = sprintf('!chmod 777 %s*', outputdir); eval(chmodcom); end; % ------------------------------ % Generate help files for EEGLAB % ------------------------------ if strcmp(mode, 'dir') for index = 1:length( directorylist ) if length(directorylist{index}) > 2 makehelpmatlab( directorylist{index}{3}, direct{ index },directorylist{index}{2}); end; end; end; addpath('.'); return; % scan directory list or directory % -------------------------------- function filelist = scandir( dirlist ) filelist = {}; if iscell( dirlist ) for index = 1:length( dirlist ) tmplist = scandir( dirlist{index} ); filelist = { filelist{:} tmplist{:} }; end; else if dirlist(end) ~= '/', dirlist(end+1) = '/'; end; if exist(dirlist) ~= 7 error([ dirlist ' is not a directory']); end; tmpdir = dir([dirlist '*.m']); filelist = { tmpdir(:).name }; end; filelist = sort( filelist ); return; % ------------------------------ Function to generate help for a bunch of files - function makehelphtml( files, fo, title, STYLEHEADER, DEST, mode, options, mainonly); % files = cell array of string containing file names or % cell array of 2-strings cell array containing titles and filenames % fo = output file % title = title of the page or section tmpdir = pwd; if strcmp(mode, 'files') % processing subtitle and File fprintf(fo, '' ); else fprintf(fo, STYLEHEADER, title, title ); fprintf(fo, '' ); for index = 1:length(files) % Processing file only if ~exist(fullfile(DEST, [ files{index}(1:end-1) 'html' ])) fprintf('Processing %s\n', files{index}); cd(DEST); com = help2html( files{index}, [], options{:}); cd(tmpdir); fprintf( fo, '%s', com); if strcmp(mainonly,'off') inputfile = which( files{index}); try, copyfile( inputfile, [ DEST files{index} ]); % asuming the file is in the path catch, fprintf('Cannot copy file %s\n', inputfile); end; end; else fprintf('Skipping %s\n', files{index}); cd(DEST); com = help2html( files{index}, [], options{:}, ... 'outputonly','on'); fprintf( fo, '%s', com); cd(tmpdir); end end; fprintf(fo, '
' ); end; return; % ------------------------------ Function to pop-out a Matlab help window -------- function makehelpmatlab( filename, directory, titlewindow); fo = fopen( filename, 'w'); fprintf(fo, '%%%s() - Help file for EEGLAB\n\n', filename); fprintf(fo, 'function noname();\n\n'); fprintf(fo, 'command = { ...\n'); for index = 1:length(directory) fprintf(fo, '''pophelp(''''%s'''');'' ...\n', directory{index}); end; fprintf(fo, '};\n'); fprintf(fo, 'text = { ...\n'); for index = 1:length(directory) fprintf(fo, '''%s'' ...\n', directory{index}); end; fprintf(fo, '};\n'); fprintf(fo, ['textgui( text, command,' ... '''fontsize'', 15, ''fontname'', ''times'', ''linesperpage'', 18, ', ... '''title'',strvcat( ''%s'', ''(Click on blue text for help)''));\n'], titlewindow); fprintf(fo, 'icadefs; set(gcf, ''COLOR'', BACKCOLOR);'); fprintf(fo, 'h = findobj(''parent'', gcf, ''style'', ''slider'');'); fprintf(fo, 'set(h, ''backgroundcolor'', GUIBACKCOLOR);'); fprintf(fo, 'return;\n'); fclose( fo ); return % convert spaces for .html function strout = space2html(strin, linkb, linke) strout = []; index = 1; while strin(index) == ' ' strout = [ strout '  ']; index = index+1; end; if nargin == 3 strout = [strout linkb strin(index:end) linke]; else strout = [strout strin(index:end)]; end;