Skip to content

Commit 139a796

Browse files
committed
minor fix
0 parents  commit 139a796

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4155
-0
lines changed

.hgignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
relre:help/helpsearch
2+
relre:help/tmp
3+
relre:help/html
4+
relre:examples/html
5+
relre:examples/demos.xml
6+
relre:help/help.jar
7+
relre:help/helptoc.xml

@DocFile/DocFile.m

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
function file = DocFile(files,varargin)
2+
% constructor
3+
%
4+
%% Syntax
5+
% files = DocFile(path) - recusively adds all files in sub--dirs
6+
% files = DocFile({fname,fname,...}) - adds a given cell--array of full--fill names
7+
% files = DocFile('function') - add a single function which is on search path
8+
%
9+
%% See also
10+
% getFiles
11+
%
12+
%% Example
13+
% doc = DocFile(fullfile(docHelpPath,'help','docGuide'))
14+
%
15+
16+
if nargin < 1
17+
error('I need at least one file or path!')
18+
end
19+
20+
if ~iscell(files) && isdir(files)
21+
files = getFiles(files,'*.m',true);
22+
end
23+
24+
file = struct(...
25+
'sourceFile',reshape(files,1,[]),...
26+
'sourceInfo',struct(...
27+
'docName','',...
28+
'isFunction',false,...
29+
'Syntax','',...
30+
'name','',...
31+
'ext','',...
32+
'path',''),...
33+
'targetTemporary','');
34+
35+
%
36+
% outputDir = fullfile(cd,'help','html');
37+
% evalCode = false;
38+
% for k=1:2:numel(varargin)
39+
% switch lower(varargin{k})
40+
% case 'outputdir'
41+
% outputDir = varargin{k+1};
42+
% case 'evalcode'
43+
% evalCode = varargin{k+2};
44+
% otherwise
45+
% error(['unkown option: ' varargin{k}]);
46+
% end
47+
% end
48+
49+
% outputDir = get_option(varargin,'outputDir',fullfile(mtex_path,'help','html'));
50+
51+
52+
for k=1:numel(file)
53+
currentFile = file(k);
54+
sourceInfo = currentFile.sourceInfo;
55+
% if ~isempty(dir(currentFile.sourceFile))
56+
[sourceInfo.path,sourceInfo.name,sourceInfo.ext] = fileparts(currentFile.sourceFile);
57+
if isempty(sourceInfo.path)
58+
currentFile.sourceFile = which(currentFile.sourceFile);
59+
[sourceInfo.path,sourceInfo.name,sourceInfo.ext] = fileparts(currentFile.sourceFile);
60+
end
61+
62+
switch sourceInfo.ext
63+
case '.m'
64+
[currentFile, sourceInfo] = setupmfileInfo(currentFile,sourceInfo);
65+
otherwise
66+
% target = fullfile(outputDir,sourceInfo.name);
67+
currentFile.targetTemporary = [sourceInfo.name,sourceInfo.ext];
68+
end
69+
currentFile.sourceInfo = sourceInfo;
70+
% currentFile.outputDir = outputDir;
71+
file(k) = currentFile;
72+
% end
73+
end
74+
75+
file = class(file,'DocFile');
76+
77+
78+
79+
function [currentFile, sourceInfo] = setupmfileInfo(currentFile, sourceInfo)
80+
81+
pos = strfind(sourceInfo.path,'@');
82+
if ~isempty(pos)
83+
sourceInfo.docName = [sourceInfo.path(pos+1:end) '.' sourceInfo.name];
84+
else
85+
sourceInfo.docName = sourceInfo.name;
86+
end
87+
%
88+
% target = fullfile(outputDir,sourceInfo.docName);
89+
currentFile.targetTemporary = ['script_' regexprep(sourceInfo.docName,'\.','__'),sourceInfo.ext];
90+
% currentFile.targetFile = [target,'.html'];
91+
%
92+
% % eval or not?
93+
% [sourceInfo.isFunction,sourceInfo.Syntax] = isFunction(currentFile.sourceFile);
94+
% if sourceInfo.isFunction
95+
% currentFile.targetTemporary(end+1:end+3) = 'ref';
96+
% end
97+
%
98+
99+
100+
101+
102+
103+

@DocFile/copy.m

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function copy(docFile,destination)
2+
% copy all docFiles to the given destination folder
3+
4+
if isempty(dir(destination))
5+
mkdir(destination);
6+
end
7+
8+
for k=1:numel(docFile)
9+
copyfile(docFile(k).sourceFile,destination);
10+
end

@DocFile/deadlink.m

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
function deadlink(docFiles,outputDir)
2+
3+
% html_path = fullfile(mtex_path,'help','html');
4+
html_path = outputDir;
5+
files = dir(fullfile(html_path,'*.html'));
6+
% html_page = {files.name};
7+
8+
% ug_files = get_ug_files(fullfile(mtex_path,'help'));
9+
check = struct;
10+
for file=docFiles
11+
htmlFile = fullfile(outputDir,[file.sourceInfo.docName '.html']);
12+
13+
if exist(htmlFile)
14+
html = read(htmlFile);
15+
source = read(file);
16+
links = regexp(html,'(href=")(?<href>\S*?)(.html")','names');
17+
lineBreak = regexp(source,'\n');
18+
19+
for k=1:numel(links)
20+
found = strfind(source,[links(k).href '.html']);
21+
22+
if ~exist(fullfile(html_path,[links(k).href '.html']))
23+
for l=1:numel(found)
24+
check(end+1).reference = links(k).href;
25+
check(end).inFile = file.sourceFile;
26+
check(end).inFileShort = file.sourceInfo.name;
27+
check(end).inLine = sum(lineBreak<found(l))+1;
28+
end
29+
end
30+
end
31+
32+
33+
end
34+
% page
35+
% html_file = fullfile(html_path, page{:});
36+
% link = regexp(file2cell(html_file),'(href=")(?<href>\S*?)(.html")','names');
37+
% for line = find(~cellfun('isempty',link))
38+
% for href = {link{line}.href}
39+
% if ~any(~cellfun('isempty',strfind(html_page, href{1})))
40+
% p = regexprep(page{:},'.html','');
41+
% if ~exist(p,'file')
42+
% ug = get_ug_filebytopic(ug_files,'test');
43+
% if ~isempty(ug)
44+
% p = ug;
45+
% else
46+
% p = regexprep(p,'_','/');
47+
% end
48+
% end
49+
%
50+
% if isempty(href{1})
51+
% s = ['EMPTY LINK -> <a href="' html_file '">' page{:} ...
52+
% '</a> -> (<a href="matlab:edit ' p '">' p '.m</a>)' ];
53+
% else
54+
% s = ['<a href="' html_file '">' page{:} '</a> -> (<a href="matlab:edit ' p '">' p '.m</a>)' ...
55+
% ' -> link: ' href{1} ];
56+
% end
57+
% disp(s)
58+
% end
59+
% end
60+
% end
61+
end
62+
% check
63+
64+
65+
wzrd = figure('MenuBar','none',...
66+
'Resize','off',...
67+
'Name','DocFiles',... 'Resize','off',...
68+
'NumberTitle','off',...
69+
'tag','docFileViewer',...
70+
'Color',get(0,'defaultUicontrolBackgroundColor'),...
71+
'Position',[100 100 200 500]);
72+
73+
wrzd_list = uicontrol('parent',wzrd,...
74+
'style','listbox',...
75+
'position',[0 0 200 500],...
76+
'backgroundcolor','white',...
77+
'fontsize',10,...
78+
'max',2,...
79+
'tag','docFileList');
80+
81+
82+
for k=1:numel(check)
83+
list{k} = ['<HTML><FONT color="black">' check(k).inFileShort '</FONT> <FONT color="blue">' check(k).reference '</FONT></HTML>'];
84+
end
85+
86+
set(wrzd_list,'String',list)
87+
88+
89+
set(wrzd_list,'Callback',{@fileChanged,check})
90+
91+
92+
function fileChanged(src,evt,check)
93+
94+
pos = get(src,'value');
95+
96+
opentoline(check(pos).inFile,check(pos).inLine);
97+
98+
figure(gcbf);
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+

@DocFile/display.m

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
function display( files )
2+
% just display the DocFile object
3+
4+
5+
fprintf('\n%s = DocFiles ( %d files )\n', inputname(1), numel(files));
6+
7+
if numel(files) < 1
8+
fprintf('\tEmpty Set\n\n')
9+
return
10+
end
11+
12+
source = {files.sourceFile};
13+
[root,source] = relativeRoot(source);
14+
15+
if numel(files) > 20
16+
17+
info = [files.sourceInfo];
18+
ext = strcat( '*' ,unique({info.ext}));
19+
fprintf('\t(')
20+
fprintf(' %s |', ext{:});
21+
fprintf('\b)\n')
22+
23+
sep = regexptranslate('escape',filesep);
24+
source = regexprep(source, [sep '.*'],[sep '..']);
25+
source = unique(source);
26+
[a,ind] = sort(lower(source));
27+
source = source(ind);
28+
29+
end
30+
31+
fprintf('\n\t%s\n',root);
32+
fprintf('\t\t|-%s\n', source{:});
33+
fprintf('\n');
34+
35+
36+
37+
function [root,source] = relativeRoot(absoluteFilePathes)
38+
39+
[root,pos] = relativePos(absoluteFilePathes);
40+
source = cellfun(@(x) x(pos+1:end),absoluteFilePathes,'UniformOutput',false);
41+
42+
43+
function [root,pos] = relativePos(absoluteFilePathes)
44+
45+
rootPattern = absoluteFilePathes{1};
46+
stop = min(cellfun('prodofsize',absoluteFilePathes));
47+
48+
k = 0;
49+
match = true;
50+
while match && k < stop
51+
k = k+1;
52+
c = rootPattern(k);
53+
for l=1:numel(absoluteFilePathes)
54+
if c ~= absoluteFilePathes{l}(k)
55+
match = false;
56+
end
57+
end
58+
59+
end
60+
61+
pos = regexp(rootPattern,regexptranslate('escape',filesep));
62+
pos = pos(pos<=k);
63+
pos = pos(end);
64+
65+
root = rootPattern(1:pos);
66+
67+
68+
69+
70+

@DocFile/getFilesByName.m

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function [ tocFiles,inName ] = getFilesByName( docFiles, names )
2+
% find a specific docFile by calling its name
3+
%
4+
%% Input
5+
% docFiles - @docFiles
6+
% names - string or cell--array of strings
7+
%
8+
%% Output
9+
% tocFiles - the specific docFiles in order of |names|
10+
% inName - logical vector, true if |name| is in docFiles list
11+
%
12+
13+
docFileNames = cellfun(@(x) x.name, {docFiles.sourceInfo},'UniformOutput',false);
14+
15+
[inName order] = ismember(docFileNames,names);
16+
tocFiles = [];
17+
if any(inName)
18+
docFiles = docFiles(inName);
19+
[order ndx] = sort(order(inName));
20+
tocFiles = docFiles(ndx);
21+
end

0 commit comments

Comments
 (0)