📄 help2html.m
字号:
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); else vartext = []; end; varname = []; else % not a title % ------------ % scan lines [tok1 strrm] = mystrtok( str ); [tok2 strrm] = strtok( strrm ); if ~isempty(tok2) & ( tok2 == '-' | tok2 == '=') % new variable newvar = 1; oldvarname = varname; oldvartext = vartext; if ~maindescription varname = formatstr( tok1, g.refcall); else varname = tok1; end; strrm = deblank(strrm); % remove tail blanks strrm = deblank(strrm(end:-1:1)); % remove initial blanks strrm = formatstr( strrm(end:-1:1), g.refcall); 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 ); if isempty(vartext) vartext = str; else if ~isempty(varname) vartext = [ vartext ' ' str]; % espace if in array else if all(vartext( end-2:end) == '.') vartext = [ deblank2(vartext(1:end-3)) ' ' str]; % espace if '...' else vartext = [ vartext '<BR>' 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, [ '</tr>' g.normrow g.normcol1 g.var '</td>\n' ], oldvarname); fprintf( fo, [ g.normcol2 g.vartext '</td></tr>\n' ], finalformat(oldvartext)); else if ~isempty(oldvartext) fprintf( fo, [ g.normcol2 g.text '</td></tr>\n' ], finalformat(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; % generate the output command % --------------------------- try, g.outputtext; catch, g.outputtext = ''; end; if isempty(g.outputtext), g.outputtext = filename(1:indexdot(end)-1); end; linktext = sprintf( g.outputlink, g.outputtext, filename(1:indexdot(end)-1), maintext ); if strcmp(g.outputonly, 'on') return; end; maindescription = 0; functioname = oldvarname( 1:findstr( oldvarname, '()' )-1); fprintf( fo, [g.normrow g.normcol1 g.functionname '</td>\n'],upper(functioname)); fprintf( fo, [g.normcol2 g.description '</td></tr>\n'], [ upper(oldvartext(1)) oldvartext(2:end) ]); % INSERT IMAGE IF PRESENT imagename = []; imagename1 = [ htmlfile( 1:findstr( htmlfile, functioname )-1) functioname '.jpg' ]; imagename2 = [ htmlfile( 1:findstr( htmlfile, functioname )-1) functioname '.gif' ]; if exist( imagename2 ), imagename = imagename2; end; if exist( imagename1 ), imagename = imagename1; end; if ~isempty(imagename) % do not make link if the file does not exist imageinfo = imfinfo(imagename); if imageinfo.Width < 600 fprintf(fo, [ g.normrow g.doublecol ... '<CENTER><BR><A HREF="' imagename '" target="_blank"><img SRC=' imagename ... '></A></CENTER></td></tr>' ]); else fprintf(fo, [ g.normrow g.doublecol ... '<CENTER><BR><A HREF="' imagename '" target="_blank"><img SRC=' imagename ... ' width=600></A></CENTER></td></tr>' ]); end; end; end; elseif ~isempty(oldvarname) allvars{indexout} = oldvarname; alltext{indexout} = oldvartext; indexout = indexout + 1; fprintf( fo, [ '</tr>' g.normrow g.normcol1 g.var '</td>\n' ], oldvarname); fprintf( fo, [ g.normcol2 g.vartext '</td></tr>\n' ], finalformat(oldvartext)); else if ~isempty(oldvartext) fprintf( fo, [ g.normcol2 g.text '</td></tr>\n' ], finalformat(oldvartext)); end; end; end; % print title % ----------- if newtitle fprintf( fo, [ g.normrow g.doublecol '<BR></td></tr>' g.normrow g.normcol1 g.title '</td>\n' ], tilehtml); if str(1) ~= '%' % last input fprintf( fo, [ g.normcol2 g.text '</td></tr>\n' ], vartext); end; oldvarname = []; oldvartext = []; end; else str = fgets( fid ); end;end;fprintf( fo, [ '</table>\n<BR>' g.seefile '%s</BODY></HTML>'], lower(filename), filename, g.footer);fclose( fid );fclose( fo );return;% -----------------% sub-functions% -----------------function str = deblank2( str ); % deblank two ways str = deblank(str(end:-1:1)); % remove initial blanks str = deblank(str(end:-1:1)); % remove tail blanks return;function strout = formatstr( str, refcall ); [tok1 strrm] = strtok( str ); strout = []; while ~isempty(tok1) tokout = functionformat( tok1, refcall ); if isempty( strout) strout = tokout; else strout = [strout ' ' tokout ]; end; [tok1 strrm] = strtok( strrm ); end;return; % final formatingfunction str = finalformat(str); % bold text in bracket if just in the beginning tmploc = sort(union(find(str == '['), find(str == ']'))); if ~isempty(tmploc) & str(1) == '[' if mod(length(tmploc),2) ~= 0, str, error('Opening but no closing bracket'); end; tmploc = tmploc(1:2); str = [ str(1:tmploc(1)) '<b>' str(tmploc(1)+1:tmploc(2)-1) '</b>' str(tmploc(2):end) ]; end; %tmploc = find(str == '"'); %if ~isempty(tmploc) % if mod(length(tmploc),2) ~= 0, str, error('Opening but no closing parenthesis'); end; % for index = length(tmploc):-2:1 % str = [ str(1:tmploc(index-1)-1) '<b>' str(tmploc(index-1)+1:tmploc(index)-1) '</b>' str(tmploc(index)+1:end) ]; % end; %end; function tokout = functionformat( tokin, refcall ); tokout = tokin; % default [test, realtokin, tail, beg] = testfunc1( tokin ); if ~test, [test, realtokin, tail] = testfunc2( tokin ); end; if test i1 = findstr( refcall, '%s'); i2 = findstr( refcall(i1(1):end), ''''); if isempty(i2) i2 = length( refcall(i1(1):end) )+1; end; filename = [ realtokin refcall(i1+2:i1+i2-2)]; % concatenate filename and extension %disp(filename) if exist( filename ) % do not make link if the file does not exist tokout = sprintf( [ beg '<A HREF="' refcall '">%s</A>' tail ' ' ], realtokin, realtokin ); end; end; return;function [test, realtokin, tail, beg] = testfunc1( tokin ) % test if is string is 'function()[,]' test = 0; realtokin = ''; tail = ''; beg = ''; if ~isempty( findstr( tokin, '()' ) ) if length(tokin)<3, return; end; realtokin = tokin( 1:findstr( tokin, '()' )-1); if length(realtokin) < (length(tokin)-2) tail = tokin(end); else tail = []; end; test = 1; if realtokin(1) == '(', realtokin = realtokin(2:end); beg = '('; end; if realtokin(1) == ',', realtokin = realtokin(2:end); beg = ','; end; end;return;function [test, realtokin, tail] = testfunc2( tokin ) % test if is string is 'FUNCTION[,]' test = 0; realtokin = ''; tail = ''; if all( upper(tokin) == tokin) if tokin(end) == ',' realtokin = tokin(1:end-1); tail = ','; else realtokin = tokin; end; testokin = realtokin; testokin(findstr(testokin, '_')) = 'A'; testokin(findstr(testokin, '2')) = 'A'; if all(double(testokin) > 64) & all(double(testokin) < 91) test = 1; end; realtokin = lower(realtokin); end;return; function [tok, str] = mystrtok(str) [tok str] = strtok(str); if tok(1) == '"' while tok(end) ~= '"' [tok2 str] = strtok(str); if isempty(tok2), tok, error('can not find closing quote ''"'' in previous text'); end; tok = [tok ' ' tok2]; end; end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -