~ubuntu-branches/ubuntu/utopic/octave-missing-functions/utopic

« back to all changes in this revision

Viewing changes to inst/__matlabfunctionlist__.m

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2008-05-21 09:08:52 UTC
  • Revision ID: james.westby@ubuntu.com-20080521090852-kmab4xonk38otmr1
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## Copyright (C) 2008 Bill Denney
 
2
##
 
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.
 
7
##
 
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.
 
12
##
 
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/>.
 
16
 
 
17
## -*- texinfo -*-
 
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.
 
25
## @end deftypefn
 
26
 
 
27
function [funlist, funloc, catlist, catloc, catlvl] = __matlabfunctionlist__ (url = "http://www.mathworks.com/access/helpdesk/help/techdoc/ref/f16-6011.html")
 
28
 
 
29
  [raw, success, message] = urlread(url);
 
30
  if (! success)
 
31
    warning ("__matlabfunctionlist__:url",
 
32
             "__matlabfunctionlist__: Could not read\n%s\n%s", url, message);
 
33
    funlist = {};
 
34
    funloc = [];
 
35
    catlist = {};
 
36
    catloc = [];
 
37
    catlvl = [];
 
38
    return
 
39
  endif
 
40
  ## Building up a really rough single-purpose XML parser
 
41
 
 
42
  ## Tags
 
43
  tagopen = find (raw == "<");
 
44
  tagclose = find (raw == ">");
 
45
  ## categories
 
46
  h2loc = findstr (raw, "<h2");
 
47
  ## sub-categories
 
48
  h3loc = findstr (raw, "<h3");
 
49
  ## sub-sub categories (optional)
 
50
  h4loc = findstr (raw, "<h4");
 
51
 
 
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);
 
56
 
 
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)];
 
62
 
 
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);
 
67
  idx = 0;
 
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, ", ");
 
75
    endif
 
76
    for j = 1:rows (tmpfunname)
 
77
      idx++;
 
78
      funlist{idx} = strtrim (tmpfunname(j,:));
 
79
      funloc(idx) = tmpfunloc(i);
 
80
    endfor
 
81
  endfor
 
82
 
 
83
endfunction
 
84
 
 
85
function name = getname (raw, loc, tagopen, tagclose)
 
86
 
 
87
  name = cell (size (loc));
 
88
  for i = 1:numel (loc)
 
89
    name{i} = raw(tagclose(find (tagclose > loc(i), 1))+1:tagopen(find (tagopen > loc(i), 1))-1);
 
90
  endfor
 
91
 
 
92
endfunction