]> Creatis software - CreaPhase.git/blob - octave_packages/missing-functions-1.0.2/__missingmatlab2txt__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / missing-functions-1.0.2 / __missingmatlab2txt__.m
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} {} __missingmatlab2txt__ (@var{funlist}, @var{funloc}, @var{funstat}, @var{catlist}, @var{catloc}, @var{catlvl}, @var{outformat})
19 ## Convert the function and category information into text.  The
20 ## @var{outformat} can be one of "wiki" or "html".
21 ## @end deftypefn
22
23 function output = __missingmatlab2txt__ (funlist, funloc, funstat, catlist, catloc, catlvl, outformat = "wiki")
24
25   ## this will be to keep track of what we are currently looking at,
26   ## functions will be considered at category level 99.
27   funlvl = 99;
28   statstr = {"Not Checked" "Missing" "Present"};
29
30   allloc = [catloc(:);funloc(:)];
31   [alloc, sidx] = sort (allloc);
32   allname = [catlist(:);funlist(:)](sidx);
33   allstat = [zeros(numel(catlist), 1);funstat(:)](sidx);
34   alllvl = [catlvl(:);funlvl*ones(numel(funlist), 1)](sidx);
35
36   switch lower (outformat)
37     case "wiki"
38       output = __towiki__ (alllvl, allname, allstat, funlvl, statstr);
39     case "html"
40       output = __tohtml__ (alllvl, allname, allstat, funlvl, statstr);
41     otherwise
42       error ("missingmatlab2txt: invalid outformat (%s)", outformat);
43   endswitch
44
45 endfunction
46
47 function output = __towiki__ (alllvl, allname, allstat, funlvl, statstr)
48
49   output = cell (size (allname));
50   for i = 1:numel (alllvl)
51     if (alllvl(i) == funlvl)
52       output{i} = sprintf ("||%s||%s||\n", allname{i}, statstr{allstat(i)+2});
53     else
54       hstring = char ("="*ones (1, alllvl(i)));
55       output{i} = sprintf ("\n%s%s%s\n", hstring, allname{i}, hstring)
56     endif
57   endfor
58
59 endfunction
60
61 function output = __tohtml__ (alllvl, allname, allstat, funlvl, statstr)
62
63   output = cell (size (allname));
64
65   lastwasfun = false ();
66   idx = 1;
67   output{idx} = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Matlab Functions Missing from Octave</title><link rel=\"stylesheet\" type=\"text/css\" href=\"missingmatlab.css\"/></head><body>\n";
68
69   for i = 1:numel (alllvl)
70     if (alllvl(i) == funlvl)
71       if (! lastwasfun)
72         output{++idx} = "<table>\n";
73       endif
74
75       thisclass = statstr{allstat(i)+2};
76       thisclass(isspace (thisclass)) = [];
77       output{++idx} = sprintf ("<tr class=\"%s\"><td class=\"funname\">%s</td><td class=\"funstatus\">%s</td></tr>\n",
78                                thisclass, allname{i}, statstr{allstat(i)+2});
79       lastwasfun = true ();
80     else
81       if lastwasfun
82         output{++idx} = "</table>\n";
83       endif
84       hstring = sprintf ("h%d", alllvl(i));
85       output{++idx} = sprintf ("\n<%s>%s</%s>\n", hstring, allname{i}, hstring);
86       lastwasfun = false ();
87     endif
88   endfor
89
90   if lastwasfun
91     output{++idx} = "</table>\n";
92   endif
93   output{++idx} = "</body></html>";
94
95 endfunction
96