1 ## Copyright (C) 2008 Bill Denney
3 ## This software is free software; you can redistribute it and/or modify it
4 ## under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or (at
6 ## your option) any later version.
8 ## This software is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this software; see the file COPYING. If not, see
15 ## <http://www.gnu.org/licenses/>.
18 ## @deftypefn {Function File} {[@var{funlist}, @var{funloc}, @var{catlist}, @var{catloc}, @var{catlvl}] =} __matlabfunctionlist__ (@var{url})
19 ## Return a list of matlab functions, @var{funlist}, from the @var{url}.
20 ## It will also return the list of locations of the functions within the
21 ## file, the categories in the url (@var{catlist}), the location of the
22 ## categories within the url (@var{catloc}), and the level of the
23 ## categories (@var{catlvl}, 2 = h2, 3 = h3, ...). Note, the locations
24 ## may not be sorted or unique.
27 function [funlist, funloc, catlist, catloc, catlvl] = __matlabfunctionlist__ (url = "http://www.mathworks.com/access/helpdesk/help/techdoc/ref/f16-6011.html")
29 [raw, success, message] = urlread(url);
31 warning ("__matlabfunctionlist__:url",
32 "__matlabfunctionlist__: Could not read\n%s\n%s", url, message);
40 ## Building up a really rough single-purpose XML parser
43 tagopen = find (raw == "<");
44 tagclose = find (raw == ">");
46 h2loc = findstr (raw, "<h2");
48 h3loc = findstr (raw, "<h3");
49 ## sub-sub categories (optional)
50 h4loc = findstr (raw, "<h4");
52 ## Find the names of each section
53 h2name = getname (raw, h2loc, tagopen, tagclose);
54 h3name = getname (raw, h3loc, tagopen, tagclose);
55 h4name = getname (raw, h4loc, tagopen, tagclose);
57 catlist = [h2name(:);h3name(:);h4name(:)];
58 catloc = [h2loc(:);h3loc(:);h4loc(:)];
59 catlvl = [2*ones(numel(h2name),1);
60 3*ones(numel(h3name),1);
61 4*ones(numel(h4name),1)];
63 tmpfunloc = findstr (raw, "<tr valign=\"top\"><td width=\"150\"><a");
64 ## this is not quite right, but it is the minimum size required.
65 funlist = cell (numel (tmpfunloc), 1);
66 funloc = zeros (numel (tmpfunloc), 1);
68 for i = 1:numel (tmpfunloc)
69 tmpfunname = raw(tagclose(find (tagclose > tmpfunloc(i), 3)(3))+1:
70 tagopen(find (tagopen > tmpfunloc(i), 3)(3))-1);
71 ## convert all whitespace to actual spaces
72 tmpfunname(isspace (tmpfunname)) = " ";
73 if (numel (tmpfunname) > 2)
74 tmpfunname = split (tmpfunname, ", ");
76 for j = 1:rows (tmpfunname)
78 funlist{idx} = strtrim (tmpfunname(j,:));
79 funloc(idx) = tmpfunloc(i);
85 function name = getname (raw, loc, tagopen, tagclose)
87 name = cell (size (loc));
89 name{i} = raw(tagclose(find (tagclose > loc(i), 1))+1:tagopen(find (tagopen > loc(i), 1))-1);