|
10 | 10 | %% |
11 | 11 | % Copyright (c) 2010 Thomas Grenfell Smith |
12 | 12 | % Copyright (c) 2015 Michael Walter |
13 | | -% Copyright (c) 2015-2017 Colin B. Macdonald |
| 13 | +% Copyright (c) 2015-2018 Colin B. Macdonald |
14 | 14 | % Copyright (c) 2015 Oliver Heimlich |
| 15 | +% Copyright (C) 2018 Mike Miller |
15 | 16 | % This is Free Software, BSD-3-Clause, see doctest.m for details. |
16 | 17 |
|
17 | 18 |
|
|
24 | 25 | [~, ~, ext] = fileparts(what); |
25 | 26 | if any(strcmpi(ext, {'.texinfo' '.texi' '.txi' '.tex'})) |
26 | 27 | type = 'texinfo'; |
| 28 | + elseif (strcmp (ext, '.oct') && exist (what) == 3) % .oct explicitly |
| 29 | + type = 'octfile'; |
| 30 | + elseif (exist (what) == 3) % .oct/.mex |
| 31 | + [~, what, ~] = fileparts (what); % strip extension if present |
| 32 | + type = 'function'; % then access like any function |
27 | 33 | elseif (exist(what, 'file') && ~exist(what, 'dir')) || exist(what, 'builtin'); |
28 | 34 | if (exist(['@' what], 'dir')) |
29 | 35 | % special case, e.g., @logical is class, logical is builtin |
|
109 | 115 | end |
110 | 116 | else |
111 | 117 | [~, ~, ext] = fileparts(f); |
112 | | - if (~ any(strcmpi(ext, {'.m' '.texinfo' '.texi' '.txi' '.tex'}))) |
| 118 | + if (~ any(strcmpi(ext, ... |
| 119 | + {'.m' '.texinfo' '.texi' '.txi' '.tex' '.oct' '.mex'}))) |
113 | 120 | %fprintf(fid, 'Debug: ignoring file "%s"\n', f) |
114 | 121 | continue |
115 | 122 | end |
|
135 | 142 | targets = [target]; |
136 | 143 | elseif strcmp(type, 'class') |
137 | 144 | targets = collect_targets_class(what, depth); |
| 145 | +elseif strcmp (type, 'octfile') |
| 146 | + targets = collect_targets_octfile (what, depth); |
138 | 147 | elseif strcmp(type, 'texinfo') |
139 | 148 | target = struct(); |
140 | 149 | target.name = what; |
|
283 | 292 | end |
284 | 293 |
|
285 | 294 |
|
| 295 | +function targets = collect_targets_octfile (file, depth) |
| 296 | + % first target is the name of the octfile (w/o extension) |
| 297 | + [~, basename, ext] = fileparts (file); |
| 298 | + assert (strcmp (ext, '.oct')) |
| 299 | + target = collect_targets_function (basename); |
| 300 | + target.name = file; |
| 301 | + target.depth = depth; |
| 302 | + targets = [target]; |
| 303 | + |
| 304 | + % octfile may have many fcns in it: find them using the autoload map |
| 305 | + autoloadmap = autoload (); |
| 306 | + len = numel (file); |
| 307 | + % matches both "/foo/bar.oct" and "/baz/bar.oct"; uncommon in practice |
| 308 | + pmatch = @(e) (numel (e.file) >= len) && strcmp (e.file(end-len+1:end), file); |
| 309 | + idx = find (arrayfun (pmatch, autoloadmap)); |
| 310 | + |
| 311 | + if (~ isempty (idx)) |
| 312 | + % indicate that octfile has other fcns, and indent those targets |
| 313 | + targets(1).name = [targets(1).name ':']; |
| 314 | + for i = 1:numel (idx) |
| 315 | + f = autoloadmap(idx(i)).function; |
| 316 | + target = collect_targets_function (f); |
| 317 | + target.depth = depth + 1; |
| 318 | + targets = [targets; target]; |
| 319 | + end |
| 320 | + end |
| 321 | +end |
| 322 | + |
| 323 | + |
286 | 324 | function [docstring, error] = extract_docstring(name) |
287 | 325 | if is_octave() |
288 | 326 | [docstring, format] = get_help_text(name); |
|
0 commit comments