Mercurial > hg > ltpda
comparison m-toolbox/mk_functions_by_category.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function mk_functions_by_category | |
2 | |
3 % Make a list of functions by category and write out | |
4 % to html_help/help/ug/bycatagory_content.html | |
5 % | |
6 | |
7 outfile = 'html_help/help/ug/bycategory_content.html'; | |
8 | |
9 % Make a list of categories | |
10 cats = utils.const.categories.list; | |
11 | |
12 % Start HTML header | |
13 fd = fopen(outfile, 'w+'); | |
14 | |
15 % Make table header | |
16 fprintf(fd, '<h2><a name="TOP">Categories</a></h2>\n'); | |
17 fprintf(fd, '<br>\n'); | |
18 fprintf(fd, '<p>\n'); | |
19 fprintf(fd, '<ul>\n'); | |
20 for jj=1:length(cats) | |
21 c = cats{jj}; | |
22 cns = strrep(c, ' ', '_'); | |
23 fprintf(fd, '\t<li><a href="bycategory.html#%s">%s</a></li>\n', cns, c); | |
24 end | |
25 fprintf(fd, '</ul>\n'); | |
26 fprintf(fd, '</p>\n'); | |
27 fprintf(fd, '<br>\n'); | |
28 | |
29 % Get functions for each category | |
30 infos = getAllMethods(); | |
31 for jj=1:length(cats) | |
32 | |
33 c = cats{jj}; | |
34 cns = strrep(c, ' ', '_'); | |
35 | |
36 disp(sprintf('*** Writing help for category %s', c)); | |
37 % Start new section | |
38 fprintf(fd, '<hr>\n'); | |
39 fprintf(fd, '<h4><a name="%s"></a>%s</h4>\n', cns, c); | |
40 fprintf(fd, '\n'); | |
41 | |
42 % start table | |
43 fprintf(fd, '<table cellspacing="0" class="body" cellpadding="4" border="2">\n'); | |
44 fprintf(fd, ' <colgroup>\n'); | |
45 fprintf(fd, ' <col width="20%%">\n'); | |
46 fprintf(fd, ' <col width="20%%">\n'); | |
47 fprintf(fd, ' <col width="60%%">\n'); | |
48 fprintf(fd, ' </colgroup>\n'); | |
49 fprintf(fd, ' <thead>\n'); | |
50 fprintf(fd, ' <tr valign="top">\n'); | |
51 fprintf(fd, ' <th bgcolor="#B2B2B2">Function name</th>\n'); | |
52 fprintf(fd, ' <th bgcolor="#B2B2B2">Class</th>\n'); | |
53 fprintf(fd, ' <th bgcolor="#B2B2B2">Description</th>\n'); | |
54 fprintf(fd, ' </tr>\n'); | |
55 fprintf(fd, ' </thead>\n'); | |
56 fprintf(fd, ' <tbody>\n'); | |
57 | |
58 % add each row | |
59 for kk=1:numel(infos) | |
60 ii = infos(kk); | |
61 if strcmpi(ii.mcategory, c) | |
62 | |
63 % This function | |
64 fcn = ii.mname; | |
65 | |
66 % Function description | |
67 fi = which([ii.mclass '/' fcn]); | |
68 desc = getDescription(fi); | |
69 | |
70 fprintf(fd, ' <!-- %s -->\n', fcn); | |
71 fprintf(fd, ' <tr valign="top">\n'); | |
72 fprintf(fd, ' <td bgcolor="#F2F2F2">\n'); | |
73 fprintf(fd, ' <p>%s</p>\n', fcn); | |
74 fprintf(fd, ' </td>\n'); | |
75 fprintf(fd, ' <td bgcolor="#F2F2F2">\n'); | |
76 fprintf(fd, ' <p>%s</p>\n', ii.mclass); | |
77 fprintf(fd, ' </td>\n'); | |
78 fprintf(fd, ' <td bgcolor="#F2F2F2">\n'); | |
79 fprintf(fd, ' <p>%s</p>\n', desc); | |
80 fprintf(fd, ' </td>\n'); | |
81 fprintf(fd, ' </tr>\n'); | |
82 | |
83 end | |
84 end | |
85 | |
86 % close table | |
87 fprintf(fd, ' </tbody>\n'); | |
88 fprintf(fd, '</table>\n'); | |
89 | |
90 % back to top link | |
91 fprintf(fd, '\n'); | |
92 fprintf(fd, '<a href="bycategory.html#TOP">Back to top</a>\n'); | |
93 | |
94 end | |
95 | |
96 fclose(fd); | |
97 end | |
98 | |
99 | |
100 function infos = getAllMethods() | |
101 | |
102 infos = []; | |
103 cls = utils.helper.ltpda_userclasses; | |
104 | |
105 for cc=1:numel(cls) | |
106 cl = cls{cc}; | |
107 infos = [infos getPublicMethods(cl)]; | |
108 end | |
109 end | |
110 | |
111 function infos = getPublicMethods(cl) | |
112 | |
113 mths = {}; | |
114 | |
115 % prefs = getappdata(0, 'LTPDApreferences'); | |
116 % vl = LTPDAprefs.verboseLevel; | |
117 % LTPDAprefs('display', 'verboseLevel', -1); | |
118 | |
119 cms = eval(['?' cl]); | |
120 infos = []; | |
121 for ll=1:numel(cms.Methods) | |
122 try | |
123 mt = cms.Methods{ll}; | |
124 if (~mt.Static && ... | |
125 strcmpi(mt.Access, 'public') && ... | |
126 ~strcmpi(cms.Methods{ll}.DefiningClass.Name, 'handle') && ... | |
127 ~mt.Hidden) | |
128 | |
129 cmd = sprintf('%s.getInfo(''%s'');', cl, mt.Name); | |
130 ii = eval(cmd); | |
131 ii.setMclass(cl); | |
132 | |
133 disp(sprintf('Added method: %s/%s', ii.mclass, ii.mname)); | |
134 mths = [mths {ii.mname}]; | |
135 infos = [infos ii]; | |
136 end | |
137 catch Me | |
138 fprintf(2, 'failed to add %s/%s\n', cl, mt.Name); | |
139 fprintf(2, '%s', Me.message); | |
140 end | |
141 end | |
142 | |
143 % LTPDAprefs('display', 'verboseLevel', vl); | |
144 | |
145 [mths,i,j] = unique(mths); | |
146 infos = infos(i); | |
147 end | |
148 | |
149 %-------------------------------------------------------------------------- | |
150 % Reads the first comment line from the file | |
151 function desc = getDescription(fname) | |
152 | |
153 try | |
154 fd = fopen(fname, 'r'); | |
155 | |
156 while ~feof(fd) | |
157 l = strtrim(fgetl(fd)); | |
158 % look for comments | |
159 if ~isempty(l) && l(1) == '%' | |
160 desc = l; | |
161 break | |
162 end | |
163 end | |
164 | |
165 fclose(fd); | |
166 catch | |
167 desc = ''; | |
168 end | |
169 end | |
170 | |
171 %-------------------------------------------------------------------------- | |
172 % Make a list of files and functions in ltpda | |
173 % | |
174 % | |
175 function cats = mkfilecatlist(versions) | |
176 | |
177 | |
178 cats = {}; | |
179 | |
180 % get categories | |
181 for j=1:length(versions) | |
182 c = versions(j,9); | |
183 if ~isempty(c{1}) | |
184 % check this is already in cats | |
185 if ~ismember(c, cats) | |
186 cats = [cats c]; | |
187 end | |
188 end | |
189 end | |
190 | |
191 end | |
192 | |
193 | |
194 |