Index: prextra/prhelp2html.m
===================================================================
--- prextra/prhelp2html.m	(revision 15)
+++ prextra/prhelp2html.m	(revision 29)
@@ -1,11 +1,15 @@
 %PRHELP2HTML Construct HTML file from help part of PRTools routine
 %
-%		S = PRHELP2HTML(COMMAND,RECREATE,SUBDIR)
+%		S = PRHELP2HTML(COMMAND,RECREATE,HTMLDIR)
+%		S = PRHELP2HTML(TOOLBOX,RECREATE,HTMLDIR)
 %
 % INPUT
 %   COMMAND    String with PRTools command, default: all prtools m-files
+%   TOOLBOX    Name of the toolbox to be handled, default PRTOOLS.
+%              Toolbox should be in the bath in in this call the last
+%              character should be a '/'.
 %   RECREATE   0/1 flag indicating whether non-existing references
 %              in the SEE ALSO section should be created as well
-%   SUBDIR     String with desired sub-directory in which the HTML
+%   HTMLDIR     String with desired directory in which the HTML
 %              file should be stored
 %
@@ -56,17 +60,46 @@
 
 
-
-
-function out = prhelp2html(name,recreate,subdir)
-
-if nargin < 3, subdir = []; end
-if nargin < 2 || isempty(recreate), recreate = 0; end
-if nargin < 1
-	run_all_files(mfilename); 
-	s = prcontent2html('prtools');
+% BEFORE YOU START TO DEBUG, READ THIS
+% This routine was original intended to work on the prtools dir only.
+% Later it was somewhat changed in order to handle files in prdatasets,
+% prdatafiles and possibly distools and dd_tools as well. Only for
+% prtools the subdir structure (with the @dataset, @datafile, @mapping
+% sub dirs) is recognized, and only if the first parameter, COMMAND, is
+% empty.
+%
+% The Contents files have a special layout. It is handled by prcontent2html
+% in case of PRTools, but for other toolboxes it most likely doesn't work.
+%
+% The formatting rules of the PRTools help are strict. Don't try to relax
+% them in the below code, but change the help-text if you are not satisfied
+% with the result. Especially avoid '  ' (double spaces) where they are not
+% needed as the conversion jumps into a table-mode as soon as they are
+% encountered.
+%
+% Bob Duin, April 2011
+
+function out = prhelp2html(name,recreate,htmldir)
+
+if nargin < 3, htmldir = cd; end
+if nargin < 2 | isempty(recreate), recreate = 0; end
+if nargin < 1 | isempty(name) % default is prtools
+	dirs = {'ldc','dataset','datafile','mapping'};
+	run_all_files(mfilename,dirs,htmldir); 
+	s = prcontent2html('prtools',[],htmldir);
 	if nargout > 0
 		out = s;
 	end
 	return; 
+else
+	if strcmp(name(end),'/') & exist(name(1:end-1),'dir') == 7
+		name = name(1:end-1);
+		dirs = {fullfile(name,'Contents.m')};
+		run_all_files(mfilename,dirs,htmldir); 
+		s = prcontent2html(name,[],htmldir); % does not work usually
+		if nargout > 0
+			out = s;
+		end
+		return
+	end
 end
 
@@ -78,12 +111,12 @@
 end
 %[pp,name] = fileparts(file);
-if isempty(subdir)
-	[xx,subdir] = fileparts(fileparts(file));
-end
-if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
-%	disp([name ' Not PRTools'])
-	out = [];
-	return
-end
+if isempty(htmldir)
+	[xx,htmldir] = fileparts(fileparts(file));
+end
+% if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
+% %	disp([name ' Not PRTools'])
+% 	out = [];
+% 	return
+% end
 
 disp(file)
@@ -295,10 +328,10 @@
 		state = 'seealso';
 		if ~single
-			s = [s commandrefs(posttok,recreate)];
+			s = [s commandrefs(posttok,recreate,htmldir)];
 		end
 	else % undefined lines
 		if examplestate
 			if length(u) > 3 && strcmpi(u(1:4),'see ')
-				s = [s '</p>' commandrefs(u(5:end),recreate) '<p>'];
+				s = [s '</p>' commandrefs(u(5:end),recreate,fileparts(htmldir)) '<p>'];
 			else
 				s = [s strrep(code(strrep(r,' ','#$!'),0,3),'#$!','&nbsp;') '<br>'];
@@ -316,5 +349,5 @@
 				s = [s '<strong><font size="4">' findmakecode(u(3:end)) '</font></strong><br>'];
 			else
-				s = [s commandrefs(u,recreate)];		
+				s = [s commandrefs(u,recreate,htmldir)];		
 			end
 		elseif tabstartspace && tabstate && (colpos1 > colpos0) ...
@@ -377,8 +410,19 @@
 s = [s '</p>' content_manual '</body></html>'];
 [qq,name] = fileparts(name); % allows for names like dataset/show
-if exist(['./' subdir],'file') ~= 7
-	mkdir(subdir);
-end
-writf([fullfile(subdir,name) '.html'],s);
+% if exist(fullfile(htmldir,name),'file') == 2
+% 	htmlname = fullfile(htmldir,name);
+% else
+% 	%htmlname = [tok '.html'];
+% 	file = which(name);
+% 	pp = fileparts(file);
+% 	[qq,subdir] = fileparts(pp);
+% 	htmldir = fullfile(fileparts(htmldir),subdir);
+% 	htmlname = fullfile(htmldir,name);
+% end
+	
+if exist([htmldir],'file') ~= 7
+	mkdir(htmldir);
+end
+writf([fullfile(htmldir,name) '.html'],s);
 disp([int2str(recreate) ' ' name ' html created'])
 if nargout > 0
@@ -456,6 +500,7 @@
 end
 
-function s = commandrefs(r,recreate)
-	if nargin < 2, recreate = 0; end
+function s = commandrefs(r,recreate,htmldir)
+	if nargin < 3, htmldir = cd; end
+	if nargin < 2 | isempty(recreate), recreate = 0; end
 	s = [];
 	r_debug = r;
@@ -467,7 +512,11 @@
 		pp = fileparts(file);
 		[qq,subdir] = fileparts(pp);
-		htmlname = fullfile(subdir,htmlname);
-		if exist(htmlname,'file') == 2
-			s = [s '<a href="../' htmlname '">' tok '</a>, '];
+%		htmlname = fullfile(subdir,htmlname);
+		htmlfullname1 = fullfile(htmldir,htmlname);
+		htmlfullname2 = fullfile(fullfile(fileparts(htmldir),subdir),htmlname);
+		if exist(htmlfullname1,'file') == 2  % check whether command is in htmldir
+			s = [s '<a href="./' htmlname '">' tok '</a>, '];
+		elseif exist(htmlfullname2,'file') == 2 % exists elsewhere?
+			s = [s '<a href="../' fullfile(subdir,htmlname) '">' tok '</a>, '];
 		elseif isempty(tok) || ~isempty(regexp(tok,'^ *', 'once' ))
 			;
@@ -554,7 +603,7 @@
 return
 
-function run_all_files(command)
-
-dirs = {'ldc','dataset','datafile','mapping'};
+function run_all_files(command,dirs,subdir)
+
+%dirs = {'ldc','dataset','datafile','mapping'};
 for n=1:length(dirs)
 	prtools_dir = fileparts(which(dirs{n}));
@@ -564,7 +613,7 @@
 		[qq,name] = fileparts(ff{j});
 		if n==1
-			feval(command,name); % prtools main commands
+			feval(command,name,[],fullfile(subdir,prtools_dirname)); % prtools main commands
 		else
-			feval(command,fullfile(prtools_dirname,name)); % subdir commands
+			feval(command,fullfile(prtools_dirname,name),[],fullfile(subdir,prtools_dirname)); % subdir commands
 		end
 	end
