Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • prextra/prhelp2html.m

    r29 r15  
    11%PRHELP2HTML Construct HTML file from help part of PRTools routine
    22%
    3 %               S = PRHELP2HTML(COMMAND,RECREATE,HTMLDIR)
    4 %               S = PRHELP2HTML(TOOLBOX,RECREATE,HTMLDIR)
     3%               S = PRHELP2HTML(COMMAND,RECREATE,SUBDIR)
    54%
    65% INPUT
    76%   COMMAND    String with PRTools command, default: all prtools m-files
    8 %   TOOLBOX    Name of the toolbox to be handled, default PRTOOLS.
    9 %              Toolbox should be in the bath in in this call the last
    10 %              character should be a '/'.
    117%   RECREATE   0/1 flag indicating whether non-existing references
    128%              in the SEE ALSO section should be created as well
    13 %   HTMLDIR     String with desired directory in which the HTML
     9%   SUBDIR     String with desired sub-directory in which the HTML
    1410%              file should be stored
    1511%
     
    6056
    6157
    62 % BEFORE YOU START TO DEBUG, READ THIS
    63 % This routine was original intended to work on the prtools dir only.
    64 % Later it was somewhat changed in order to handle files in prdatasets,
    65 % prdatafiles and possibly distools and dd_tools as well. Only for
    66 % prtools the subdir structure (with the @dataset, @datafile, @mapping
    67 % sub dirs) is recognized, and only if the first parameter, COMMAND, is
    68 % empty.
    69 %
    70 % The Contents files have a special layout. It is handled by prcontent2html
    71 % in case of PRTools, but for other toolboxes it most likely doesn't work.
    72 %
    73 % The formatting rules of the PRTools help are strict. Don't try to relax
    74 % them in the below code, but change the help-text if you are not satisfied
    75 % with the result. Especially avoid '  ' (double spaces) where they are not
    76 % needed as the conversion jumps into a table-mode as soon as they are
    77 % encountered.
    78 %
    79 % Bob Duin, April 2011
    80 
    81 function out = prhelp2html(name,recreate,htmldir)
    82 
    83 if nargin < 3, htmldir = cd; end
    84 if nargin < 2 | isempty(recreate), recreate = 0; end
    85 if nargin < 1 | isempty(name) % default is prtools
    86         dirs = {'ldc','dataset','datafile','mapping'};
    87         run_all_files(mfilename,dirs,htmldir);
    88         s = prcontent2html('prtools',[],htmldir);
     58
     59
     60function out = prhelp2html(name,recreate,subdir)
     61
     62if nargin < 3, subdir = []; end
     63if nargin < 2 || isempty(recreate), recreate = 0; end
     64if nargin < 1
     65        run_all_files(mfilename);
     66        s = prcontent2html('prtools');
    8967        if nargout > 0
    9068                out = s;
    9169        end
    9270        return;
    93 else
    94         if strcmp(name(end),'/') & exist(name(1:end-1),'dir') == 7
    95                 name = name(1:end-1);
    96                 dirs = {fullfile(name,'Contents.m')};
    97                 run_all_files(mfilename,dirs,htmldir);
    98                 s = prcontent2html(name,[],htmldir); % does not work usually
    99                 if nargout > 0
    100                         out = s;
    101                 end
    102                 return
    103         end
    10471end
    10572
     
    11178end
    11279%[pp,name] = fileparts(file);
    113 if isempty(htmldir)
    114         [xx,htmldir] = fileparts(fileparts(file));
    115 end
    116 % if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
    117 % %     disp([name ' Not PRTools'])
    118 %       out = [];
    119 %       return
    120 % end
     80if isempty(subdir)
     81        [xx,subdir] = fileparts(fileparts(file));
     82end
     83if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
     84%       disp([name ' Not PRTools'])
     85        out = [];
     86        return
     87end
    12188
    12289disp(file)
     
    328295                state = 'seealso';
    329296                if ~single
    330                         s = [s commandrefs(posttok,recreate,htmldir)];
     297                        s = [s commandrefs(posttok,recreate)];
    331298                end
    332299        else % undefined lines
    333300                if examplestate
    334301                        if length(u) > 3 && strcmpi(u(1:4),'see ')
    335                                 s = [s '</p>' commandrefs(u(5:end),recreate,fileparts(htmldir)) '<p>'];
     302                                s = [s '</p>' commandrefs(u(5:end),recreate) '<p>'];
    336303                        else
    337304                                s = [s strrep(code(strrep(r,' ','#$!'),0,3),'#$!','&nbsp;') '<br>'];
     
    349316                                s = [s '<strong><font size="4">' findmakecode(u(3:end)) '</font></strong><br>'];
    350317                        else
    351                                 s = [s commandrefs(u,recreate,htmldir)];               
     318                                s = [s commandrefs(u,recreate)];               
    352319                        end
    353320                elseif tabstartspace && tabstate && (colpos1 > colpos0) ...
     
    410377s = [s '</p>' content_manual '</body></html>'];
    411378[qq,name] = fileparts(name); % allows for names like dataset/show
    412 % if exist(fullfile(htmldir,name),'file') == 2
    413 %       htmlname = fullfile(htmldir,name);
    414 % else
    415 %       %htmlname = [tok '.html'];
    416 %       file = which(name);
    417 %       pp = fileparts(file);
    418 %       [qq,subdir] = fileparts(pp);
    419 %       htmldir = fullfile(fileparts(htmldir),subdir);
    420 %       htmlname = fullfile(htmldir,name);
    421 % end
    422        
    423 if exist([htmldir],'file') ~= 7
    424         mkdir(htmldir);
    425 end
    426 writf([fullfile(htmldir,name) '.html'],s);
     379if exist(['./' subdir],'file') ~= 7
     380        mkdir(subdir);
     381end
     382writf([fullfile(subdir,name) '.html'],s);
    427383disp([int2str(recreate) ' ' name ' html created'])
    428384if nargout > 0
     
    500456end
    501457
    502 function s = commandrefs(r,recreate,htmldir)
    503         if nargin < 3, htmldir = cd; end
    504         if nargin < 2 | isempty(recreate), recreate = 0; end
     458function s = commandrefs(r,recreate)
     459        if nargin < 2, recreate = 0; end
    505460        s = [];
    506461        r_debug = r;
     
    512467                pp = fileparts(file);
    513468                [qq,subdir] = fileparts(pp);
    514 %               htmlname = fullfile(subdir,htmlname);
    515                 htmlfullname1 = fullfile(htmldir,htmlname);
    516                 htmlfullname2 = fullfile(fullfile(fileparts(htmldir),subdir),htmlname);
    517                 if exist(htmlfullname1,'file') == 2  % check whether command is in htmldir
    518                         s = [s '<a href="./' htmlname '">' tok '</a>, '];
    519                 elseif exist(htmlfullname2,'file') == 2 % exists elsewhere?
    520                         s = [s '<a href="../' fullfile(subdir,htmlname) '">' tok '</a>, '];
     469                htmlname = fullfile(subdir,htmlname);
     470                if exist(htmlname,'file') == 2
     471                        s = [s '<a href="../' htmlname '">' tok '</a>, '];
    521472                elseif isempty(tok) || ~isempty(regexp(tok,'^ *', 'once' ))
    522473                        ;
     
    603554return
    604555
    605 function run_all_files(command,dirs,subdir)
    606 
    607 %dirs = {'ldc','dataset','datafile','mapping'};
     556function run_all_files(command)
     557
     558dirs = {'ldc','dataset','datafile','mapping'};
    608559for n=1:length(dirs)
    609560        prtools_dir = fileparts(which(dirs{n}));
     
    613564                [qq,name] = fileparts(ff{j});
    614565                if n==1
    615                         feval(command,name,[],fullfile(subdir,prtools_dirname)); % prtools main commands
     566                        feval(command,name); % prtools main commands
    616567                else
    617                         feval(command,fullfile(prtools_dirname,name),[],fullfile(subdir,prtools_dirname)); % subdir commands
     568                        feval(command,fullfile(prtools_dirname,name)); % subdir commands
    618569                end
    619570        end
Note: See TracChangeset for help on using the changeset viewer.