% gethelpvar() - convert a Matlab m-file help-message header % into out variables % Usage: % >> [vartext, varnames] = gethelpvar( filein, varlist); % % Inputs: % filein - input filename (with .m extension) % varlist - optional list of variable to return. If absent % retrun all variables. % % Outputs: % vartext - variable text % varnames - name of the varialbe returned; % % Notes: see help2html() for file format % % Example: >> gethelpvar( 'gethelpvar.m', 'filein') % % Author: Arnaud Delorme, Salk Institute 20 April 2002 % % See also: help2html() % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % % 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 function [alltext, allvars] = gethelpvar( filename, varlist ) if nargin < 1 help gethelpvar; return; end; % input file % ---------- fid = fopen( filename, 'r'); if fid == -1 error('File not found'); end; cont = 1; % scan file % ----------- str = fgets( fid ); % if first line is the name of the function, reload if str(1) ~= '%', str = fgets( fid ); end; % state variables % ----------- maindescription = 1; varname = []; oldvarname = []; vartext = []; newvar = 0; allvars = {}; alltext = {}; indexout = 1; while (str(1) == '%') str = deblank(str(2:end-1)); % --- DECODING INPUT newvar = 0; str = deblank2(str); if ~isempty(str) % find a title % ------------ i2d = findstr(str, ':'); newtitle = 0; if ~isempty(i2d) i2d = i2d(1); switch lower(str(1:i2d)) case { 'usage:' 'authors:' 'author:' 'notes:' 'note:' 'input:' ... 'inputs:' 'outputs:' 'output' 'example:' 'examples:' 'see also:' }, newtitle = 1; end; if (i2d == length(str)) & (str(1) ~= '%'), newtitle = 1; end; end; if newtitle tilehtml = str(1:i2d); newtitle = 1; oldvarname = varname; oldvartext = vartext; if i2d < length(str) %vartext = formatstr(str(i2d+1:end), g.refcall); vartext = str(i2d+1:end); else vartext = []; end; varname = []; else % not a title % ------------ % scan lines [tok1 strrm] = strtok( str ); [tok2 strrm] = strtok( strrm ); if ~isempty(tok2) & ( isequal(tok2,'-') | isequal(tok2,'=')) % new variable newvar = 1; oldvarname = varname; oldvartext = vartext; varname = tok1; strrm = deblank(strrm); % remove tail blanks strrm = deblank(strrm(end:-1:1)); % remove initial blanks %strrm = formatstr( strrm(end:-1:1), g.refcall); strrm = strrm(end:-1:1); vartext = strrm; else % continue current text str = deblank(str); % remove tail blanks str = deblank(str(end:-1:1)); % remove initial blanks %str = formatstr( str(end:-1:1), g.refcall ); str = str(end:-1:1); if isempty(vartext) vartext = str; else if ~isempty(varname) vartext = [ vartext 10 str]; % espace if in array else if length(vartext)>3 & all(vartext( end-2:end) == '.') vartext = [ deblank2(vartext(1:end-3)) 10 str]; % espace if '...' else vartext = [ vartext 10 str]; % CR otherwise end; end; end; end; newtitle = 0; end; % --- END OF DECODING str = fgets( fid ); % test if last entry % ------------------ if str(1) ~= '%' if ~newtitle if ~isempty(oldvarname) allvars{indexout} = oldvarname; alltext{indexout} = oldvartext; indexout = indexout + 1; %fprintf( fo, [ '' g.normrow g.normcol1 g.var '\n' ], oldvarname); %fprintf( fo, [ g.normcol2 g.vartext '\n' ], oldvartext); else if ~isempty(oldvartext) %fprintf( fo, [ g.normcol2 g.tabtext '\n' ], oldvartext); end; end; newvar = 1; oldvarname = varname; oldvartext = vartext; end; end; % test if new input for an array % ------------------------------ if newvar | newtitle if maindescription if ~isempty(oldvartext) % FUNCTION TITLE maintext = oldvartext; maindescription = 0; functioname = oldvarname( 1:findstr( oldvarname, '()' )-1); %fprintf( fo, [g.normrow g.normcol1 g.functionname '\n'],upper(functioname)); %fprintf( fo, [g.normcol2 g.description '\n'], [ upper(oldvartext(1)) oldvartext(2:end) ]); % INSERT IMAGE IF PRESENT %imagename = [ htmlfile( 1:findstr( htmlfile, functioname )-1) functioname '.jpg' ]; %if exist( imagename ) % do not make link if the file does not exist %fprintf(fo, [ g.normrow g.doublecol ... % '