Chris@381
|
1 @rem = '--*-Perl-*--';
|
Chris@381
|
2 @rem = '
|
Chris@381
|
3 @echo off
|
Chris@381
|
4 perl -w -S %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
|
Chris@381
|
5 goto endofperl
|
Chris@381
|
6 @rem ';
|
Chris@381
|
7 # perl -w -S %0.bat "$@"
|
Chris@382
|
8 #!/usr/bin/perl
|
Chris@381
|
9 #
|
Chris@381
|
10 # mtree2html_2000 - produce html files from Matlab m-files.
|
Chris@381
|
11 # use configuration file for flexibility
|
Chris@381
|
12 # can process tree of directories
|
Chris@381
|
13 #
|
Chris@381
|
14 # Copyright (C) 1996-2000 Hartmut Pohlheim. All rights reserved.
|
Chris@381
|
15 # includes small parts of m2html from Jeffrey C. Kantor 1995
|
Chris@381
|
16 #
|
Chris@381
|
17 # Author: Hartmut Pohlheim
|
Chris@381
|
18 # History: 06.03.1996 file created
|
Chris@381
|
19 # 07.03.1996 first working version
|
Chris@381
|
20 # 08.03.1996 modularized, help text only once included
|
Chris@381
|
21 # 11.03.1996 clean up, some functions rwritten
|
Chris@381
|
22 # 18.04.1996 silent output with writing in one line only
|
Chris@381
|
23 # version 0.20 fixed
|
Chris@381
|
24 # 14.05.1996 start of adding tree structure, could create tree
|
Chris@381
|
25 # 15.05.1996 creating of index files for every directory
|
Chris@381
|
26 # 17.05.1996 first working version except compact A-Z index
|
Chris@381
|
27 # 20.05.1996 cleanup of actual version, more variables and
|
Chris@381
|
28 # configurable settings
|
Chris@381
|
29 # 21.05.1996 reading, update and creation of contents.m added
|
Chris@381
|
30 # 22.05.1996 creation of short index started
|
Chris@381
|
31 # 28.05.1996 jump letters for short index,
|
Chris@381
|
32 # 3 different directory indexes (short/long/contents)
|
Chris@381
|
33 # 29.05.1996 major cleanup, short and long index created from one function
|
Chris@381
|
34 # links for HTML and Indexes from 1 function,
|
Chris@381
|
35 # version 0.9
|
Chris@381
|
36 # 30.05.1996 contents.m changed to Contents.m (because unix likes it)
|
Chris@381
|
37 # function definition can be in first line of m file before comments
|
Chris@381
|
38 # version 0.91 fixed
|
Chris@381
|
39 # 03.06.1996 contents file can be written as wanted, the links will be correct
|
Chris@381
|
40 # cross references in help block of m-file will be found and
|
Chris@381
|
41 # converted, even if the name of the function is written upper case
|
Chris@381
|
42 # version 0.92 fixed
|
Chris@381
|
43 # 05.06.1996 construction of dependency matrix changed, is able now to process
|
Chris@381
|
44 # even the whole matlab tree (previous version needed to much memory)
|
Chris@381
|
45 # removed warning for contents files in different directories
|
Chris@381
|
46 # version 0.94 fixed
|
Chris@381
|
47 # 06.06.1996 new link name matrices for ConstructHTMLFile created,
|
Chris@381
|
48 # everything is done in ConstructDependencyMatrix,
|
Chris@381
|
49 # both dependencies (calls and called) and matrix
|
Chris@381
|
50 # with all mentioned names in this m-file, thus, much
|
Chris@381
|
51 # less scanning in html construction
|
Chris@381
|
52 # script is now (nearly) linear scalable, thus, matlab-toolbox
|
Chris@381
|
53 # tree takes less than 1 hour on a Pentium120, with source
|
Chris@381
|
54 # version 0.96 fixed
|
Chris@381
|
55 # 10.06.1996 order of creation changed, first all indexes (includes
|
Chris@381
|
56 # update/creation of contents.m) and then ConstructDepency
|
Chris@381
|
57 # thus, AutoAdd section will be linked as well
|
Chris@381
|
58 # excludenames extended, some more common word function names added
|
Chris@381
|
59 # version 0.97 fixed
|
Chris@381
|
60 # 17.02.1998 writecontentsm as command line parameter added
|
Chris@381
|
61 # error of file not found will even appear when silent
|
Chris@381
|
62 # version 1.02
|
Chris@381
|
63 # 21.05.2000 mark comments in source code specially (no fully correct,
|
Chris@381
|
64 # can't handle % in strings)
|
Chris@381
|
65 # version 1.11
|
Chris@381
|
66 # 05.11.2000 link also to upper and mixed case m-files
|
Chris@381
|
67 # searching for .m files now really works (doesn't find grep.com any longer)
|
Chris@381
|
68 # file renamed to mtree2html2001
|
Chris@381
|
69 # generated html code now all lower case
|
Chris@381
|
70 # inclusion of meta-description and meta-keywords in html files
|
Chris@381
|
71 # HTML4 compliance done (should be strict HTML4.0, quite near XHTML)
|
Chris@381
|
72 # version 1.23
|
Chris@381
|
73 #
|
Chris@383
|
74 # 29.03.2011 (Chris Cannam) add frames option.
|
Chris@381
|
75
|
Chris@381
|
76 $VERSION = '1.23';
|
Chris@381
|
77 ($PROGRAM = $0) =~ s@.*/@@; $PROGRAM = "\U$PROGRAM\E";
|
chris@411
|
78 $debug = 1;
|
Chris@381
|
79
|
Chris@381
|
80 #------------------------------------------------------------------------
|
Chris@381
|
81 # Define platform specific things
|
Chris@381
|
82 #------------------------------------------------------------------------
|
Chris@381
|
83 # suffix for files to search is defined twice
|
Chris@381
|
84 # the first ($suffix) is for string creation and contains the . as well
|
Chris@381
|
85 # the second ($suffixforsearch) is for regular expression, handling of . is quite special
|
Chris@381
|
86 $suffix = ".m";
|
Chris@381
|
87 $suffixforsearch = "m";
|
Chris@381
|
88 # the directory separator
|
Chris@381
|
89 $dirsep = "/";
|
Chris@381
|
90 # what is the current directory
|
Chris@381
|
91 $diract = ".";
|
Chris@381
|
92
|
Chris@381
|
93 #------------------------------------------------------------------------
|
Chris@382
|
94 # Define all variables and their standard settings
|
Chris@381
|
95 # documentation of variables is contained in accompanying rc file
|
Chris@381
|
96 #------------------------------------------------------------------------
|
Chris@381
|
97 %var =
|
Chris@381
|
98 (
|
Chris@381
|
99 'authorfile', '',
|
Chris@381
|
100 'codebodyfiles', '',
|
Chris@381
|
101 'codebodyindex', '',
|
Chris@381
|
102 'codeheadmeta', '<meta name="author of conversion perl script" content="Hartmut Pohlheim" />',
|
Chris@381
|
103 'codehr', '<hr size="3" noshade="noshade" />',
|
Chris@381
|
104 'codeheader', '',
|
Chris@383
|
105 'configfile', 'matlab-docs.conf',
|
Chris@381
|
106 'csslink', '',
|
Chris@381
|
107 'dirmfiles', $diract,
|
Chris@381
|
108 'dirhtml', $diract,
|
Chris@381
|
109 'exthtml', '.html',
|
Chris@382
|
110 'frames', 'yes',
|
Chris@381
|
111 'filenametopframe', 'index',
|
Chris@381
|
112 'filenameindexlongglobal', 'indexlg',
|
Chris@381
|
113 'filenameindexlonglocal', 'indexll',
|
Chris@381
|
114 'filenameindexshortglobal', 'indexsg',
|
Chris@381
|
115 'filenameindexshortlocal', 'indexsl',
|
Chris@381
|
116 'filenameextensionframe', 'f',
|
Chris@381
|
117 'filenameextensionindex', 'i',
|
Chris@381
|
118 'filenameextensionjump', 'j',
|
Chris@381
|
119 'filenamedirshort', 'dirtops',
|
Chris@381
|
120 'filenamedirlong', 'dirtopl',
|
Chris@381
|
121 'filenamedircontents', 'dirtopc',
|
Chris@381
|
122 'includesource', 'yes',
|
Chris@381
|
123 'links2filescase', 'all',
|
Chris@381
|
124 'processtree', 'yes',
|
Chris@381
|
125 'producetree', 'yes',
|
Chris@381
|
126 'textjumpindexlocal', 'Local Index',
|
Chris@381
|
127 'textjumpindexglobal', 'Global Index',
|
Chris@381
|
128 'texttitleframelayout', 'Documentation of Matlab Files',
|
Chris@381
|
129 'texttitleindexalldirs', 'Index of Directories',
|
Chris@381
|
130 'textheaderindexalldirs', 'Index of Directories',
|
Chris@381
|
131 'texttitleindex', '',
|
Chris@381
|
132 'textheaderindex', '',
|
Chris@381
|
133 'texttitlefiles', 'Documentation of ',
|
Chris@381
|
134 'textheaderfiles', 'Documentation of ',
|
Chris@381
|
135 'usecontentsm', 'yes',
|
Chris@381
|
136 'writecontentsm', 'no'
|
Chris@381
|
137 );
|
Chris@381
|
138
|
Chris@381
|
139
|
Chris@381
|
140 # define all m-file names, that should be excluded from linking
|
Chris@381
|
141 # however, files will still be converted
|
Chris@381
|
142 @excludenames = ( 'all','ans','any','are',
|
Chris@381
|
143 'cs',
|
Chris@381
|
144 'demo','dos',
|
Chris@381
|
145 'echo','edit','else','elseif','end','exist',
|
Chris@381
|
146 'flag','for','function',
|
Chris@381
|
147 'global',
|
Chris@381
|
148 'help',
|
Chris@381
|
149 'i','if','inf','info',
|
Chris@381
|
150 'j',
|
Chris@381
|
151 'more',
|
Chris@381
|
152 'null',
|
Chris@381
|
153 'return',
|
Chris@381
|
154 'script','strings',
|
Chris@381
|
155 'what','which','while','who','whos','why',
|
Chris@381
|
156 );
|
Chris@381
|
157
|
Chris@381
|
158 # Text for inclusion in created HTML/Frame files: Doctype and Charset
|
Chris@381
|
159 $TextDocTypeHTML = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">';
|
Chris@381
|
160 $TextDocTypeFrame = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">';
|
Chris@381
|
161 $TextMetaCharset = '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />';
|
Chris@381
|
162
|
Chris@381
|
163 #------------------------------------------------------------------------
|
Chris@381
|
164 # Read the command line arguments
|
Chris@381
|
165 #------------------------------------------------------------------------
|
Chris@381
|
166 if (@ARGV == 0) {
|
Chris@381
|
167 &DisplayHelp() if &CheckFileName($var{'configfile'}, 'configuration file');
|
Chris@381
|
168 }
|
Chris@381
|
169
|
Chris@381
|
170 # Print provided command line arguments on screen
|
Chris@381
|
171 foreach (@ARGV) { print " $_\n "; }
|
Chris@381
|
172
|
Chris@381
|
173 # Get the options
|
Chris@381
|
174 use Getopt::Long;
|
Chris@381
|
175 @options = ('help|h', 'todo|t', 'version|v',
|
Chris@381
|
176 'authorfile|a=s', 'configfile|c=s', 'dirhtml|html|d=s',
|
Chris@381
|
177 'dirmfiles|mfiles|m=s', 'includesource|i=s',
|
Chris@381
|
178 'processtree|r=s', 'producetree|p=s',
|
Chris@381
|
179 'silent|quiet|q', 'writecontentsm|w=s');
|
Chris@381
|
180 &GetOptions(@options) || die "use -h switch to display help statement\n";
|
Chris@381
|
181
|
Chris@381
|
182
|
Chris@381
|
183 # Display help or todo list, when requested
|
Chris@381
|
184 &DisplayHelp() if $opt_help;
|
Chris@381
|
185 &DisplayTodo() if $opt_todo;
|
Chris@381
|
186 die "$PROGRAM v$VERSION\n" if $opt_version;
|
Chris@381
|
187
|
Chris@381
|
188 $exit_status = 0;
|
Chris@381
|
189
|
Chris@381
|
190 #------------------------------------------------------------------------
|
Chris@381
|
191 # Read the config file
|
Chris@381
|
192 #------------------------------------------------------------------------
|
Chris@381
|
193 $var{'configfile'} = $opt_configfile if $opt_configfile;
|
Chris@381
|
194 &GetConfigFile($var{'configfile'});
|
Chris@381
|
195
|
Chris@381
|
196
|
Chris@381
|
197 #------------------------------------------------------------------------
|
Chris@381
|
198 # Process/Check the command line otions
|
Chris@381
|
199 #------------------------------------------------------------------------
|
Chris@381
|
200 $var{'dirhtml'} = $opt_dirhtml if $opt_dirhtml;
|
Chris@381
|
201 if (!(substr($var{'dirhtml'}, -1, 1) eq $dirsep)) { $var{'dirhtml'} = $var{'dirhtml'}.$dirsep; }
|
Chris@381
|
202 $var{'dirmfiles'} = $opt_dirmfiles if $opt_dirmfiles;
|
Chris@381
|
203 if (!(substr($var{'dirmfiles'}, -1, 1) eq $dirsep)) { $var{'dirmfiles'} = $var{'dirmfiles'}.$dirsep; }
|
Chris@381
|
204
|
Chris@381
|
205 $var{'authorfile'} = $opt_author if $opt_author;
|
Chris@381
|
206 $var{'includesource'} = $opt_includesource if $opt_includesource;
|
Chris@381
|
207 if ($var{'includesource'} ne 'no') { $var{'includesource'} = 'yes'; }
|
Chris@381
|
208 $var{'processtree'} = $opt_processtree if $opt_processtree;
|
Chris@381
|
209 if ($var{'processtree'} ne 'no') { $var{'processtree'} = 'yes'; }
|
Chris@381
|
210 $var{'producetree'} = $opt_producetree if $opt_producetree;
|
Chris@381
|
211 if ($var{'producetree'} ne 'no') { $var{'producetree'} = 'yes'; }
|
Chris@381
|
212 if ($var{'processtree'} eq 'no') { $var{'producetree'} = 'no'; }
|
Chris@382
|
213 if ($var{'frames'} ne 'no') { $var{'frames'} = 'yes'; }
|
Chris@381
|
214 # if (($var{'processtree'} eq 'yes') && ($var{'producetree'} eq 'no')) { $var{'usecontentsm'} = 'no'; }
|
Chris@381
|
215
|
Chris@381
|
216 $var{'writecontentsm'} = $opt_writecontentsm if $opt_writecontentsm;
|
Chris@381
|
217
|
Chris@381
|
218 #------------------------------------------------------------------------
|
Chris@381
|
219 # Do the real stuff
|
Chris@381
|
220 #------------------------------------------------------------------------
|
Chris@381
|
221
|
Chris@381
|
222 # Print variables on screen, when not silent
|
Chris@381
|
223 &ListVariables if !$opt_silent;
|
Chris@381
|
224
|
Chris@381
|
225 # Check the author file
|
Chris@381
|
226 if ($var{'authorfile'} ne '') {
|
chris@410
|
227 if (!($var{'authorfile'} =~ m,^/,)) {
|
chris@410
|
228 # relative path: treat as relative to config file
|
chris@410
|
229 my $cfd = $var{'configfile'};
|
chris@410
|
230 $cfd =~ s,/[^/]*$,/,;
|
chris@410
|
231 $cfd =~ s,^[^/]*$,.,;
|
chris@410
|
232 $var{'authorfile'} = "$cfd/" . $var{'authorfile'};
|
chris@410
|
233 }
|
chris@410
|
234 if (&CheckFileName($var{'authorfile'}, 'author file')) {
|
chris@410
|
235 $var{'authorfile'} = '';
|
chris@410
|
236 if (!$opt_silent) { print " Proceeding without author information!\n"; }
|
chris@410
|
237 }
|
Chris@381
|
238 }
|
Chris@381
|
239
|
Chris@381
|
240 # Call the function doing all the real work
|
Chris@381
|
241 &ConstructNameMatrix;
|
Chris@381
|
242
|
Chris@381
|
243 &ConstructDependencyMatrix;
|
Chris@381
|
244
|
Chris@381
|
245 &ConstructAllIndexFiles;
|
Chris@381
|
246
|
Chris@381
|
247 &ConstructHTMLFiles;
|
Chris@381
|
248
|
Chris@381
|
249 exit $exit_status;
|
Chris@381
|
250
|
Chris@381
|
251 #------------------------------------------------------------------------
|
Chris@381
|
252 # Construct list of all mfile names and initialize various data arrays.
|
Chris@381
|
253 #------------------------------------------------------------------------
|
Chris@381
|
254 sub ConstructNameMatrix
|
Chris@381
|
255 {
|
Chris@381
|
256 local(*MFILE);
|
Chris@381
|
257 local($file, $dirname);
|
Chris@381
|
258 local(@newdirectories);
|
Chris@381
|
259 local(%localnames);
|
Chris@381
|
260
|
Chris@381
|
261 $RecDeep = 0;
|
Chris@381
|
262 &ParseTreeReadFiles($var{'dirmfiles'}, $RecDeep);
|
Chris@381
|
263
|
Chris@381
|
264 foreach $dirname (@directories) {
|
Chris@381
|
265 if ($dirnumbermfiles{$dirname} > 0) {
|
Chris@381
|
266 push(@newdirectories, $dirname);
|
Chris@381
|
267 if (! defined($contentsname{$dirname})) {
|
Chris@381
|
268 $contentsname{$dirname} = 'Contents';
|
Chris@381
|
269 if (($var{'writecontentsm'} eq 'no') && ($var{'usecontentsm'} eq 'yes')) {
|
Chris@381
|
270 print "\r ParseTree - for directory $dirname no contents file found!\n";
|
Chris@381
|
271 print " create one or enable writing of contents file (writecontentsm = yes)!\n";
|
Chris@381
|
272 }
|
Chris@381
|
273 }
|
Chris@381
|
274 }
|
Chris@381
|
275 }
|
Chris@381
|
276 @alldirectories = @directories;
|
Chris@381
|
277 @directories = @newdirectories;
|
Chris@381
|
278
|
Chris@381
|
279 foreach $dirname (@directories) {
|
Chris@381
|
280 if ($debug > 0) { print "Dir: $dirname \t\t $dirnumbermfiles{$dirname} \t$contentsname{$dirname}\n"; }
|
Chris@381
|
281 }
|
Chris@381
|
282
|
Chris@381
|
283 @names = sort(keys %mfile);
|
Chris@381
|
284
|
Chris@381
|
285 # check, if name of directory is identical to name of file
|
Chris@381
|
286 @dirsinglenames = values(%dirnamesingle);
|
Chris@381
|
287 grep($localnames{$_}++, @dirsinglenames);
|
Chris@381
|
288 @dirandfilename = grep($localnames{$_}, @names);
|
Chris@381
|
289 if (@dirandfilename) {
|
Chris@381
|
290 print "\r Name clash between directory and file name: @dirandfilename\n";
|
Chris@381
|
291 print " These files will be excluded from linking!\n";
|
Chris@381
|
292 push(@excludenames, @dirandfilename);
|
Chris@381
|
293 }
|
Chris@381
|
294
|
Chris@381
|
295 # construct names matrix for help text linking
|
Chris@381
|
296 # exclude some common words (and at the same time m-functions) from linking in help text
|
Chris@381
|
297 grep($localnames{$_}++, @excludenames);
|
Chris@381
|
298 @linknames = grep(!$localnames{$_}, @names);
|
Chris@381
|
299
|
Chris@381
|
300 if ($debug > 2) { print "linknames (names of found m-files):\n @linknames\n"; }
|
Chris@381
|
301
|
Chris@381
|
302 }
|
Chris@381
|
303
|
Chris@381
|
304 #------------------------------------------------------------------------
|
Chris@381
|
305 # Parse tree and collect all Files
|
Chris@381
|
306 #------------------------------------------------------------------------
|
Chris@381
|
307 sub ParseTreeReadFiles
|
Chris@381
|
308 {
|
Chris@381
|
309 local($dirname, $localRecDeep) = @_;
|
Chris@381
|
310 local($file, $name, $filewosuffix);
|
Chris@381
|
311 local($dirhtmlname, $dirmode);
|
Chris@381
|
312 local($relpath, $relpathtoindex, $replacevardir);
|
Chris@381
|
313 local(*CHECKDIR, *AKTDIR);
|
Chris@381
|
314 local(@ALLEFILES);
|
Chris@381
|
315
|
Chris@381
|
316 opendir(AKTDIR, $dirname) || die "ParseTree - Can't open directory $dirname: $!";
|
Chris@381
|
317 if ($debug > 1) { print "\nDirectory: $dirname\n"; }
|
Chris@381
|
318
|
Chris@381
|
319 # create relative path
|
Chris@381
|
320 $_ = $dirname; $replacevardir = $var{'dirmfiles'};
|
Chris@381
|
321 s/$replacevardir//; $relpath = $_;
|
Chris@381
|
322 s/[^\/]+/../g; $relpathtoindex = $_;
|
Chris@381
|
323
|
Chris@381
|
324 # producetree no
|
Chris@381
|
325 if ($var{'producetree'} eq 'no') { $relpath = ''; $relpathtoindex = ''; }
|
Chris@381
|
326
|
Chris@381
|
327 # names of directories (top-level and below top-level m-file-directory)
|
Chris@381
|
328 push(@directories, $dirname);
|
Chris@381
|
329 $dirnumbermfiles{$dirname} = 0; # set number of m-files for this dir to zero
|
Chris@381
|
330 # relative path from top-level directory, depends on directory name
|
Chris@381
|
331 $dirnamerelpath{$dirname} = $relpath;
|
Chris@381
|
332 # relative path from actual directory to top-level directory, depends on directory name
|
Chris@381
|
333 $dirnamerelpathtoindex{$dirname} = $relpathtoindex;
|
Chris@381
|
334 # recursion level for directory, depends on directory name
|
Chris@381
|
335 $dirnamerecdeep{$dirname} = $localRecDeep;
|
Chris@381
|
336
|
Chris@381
|
337 # only the name of the directory, without path
|
Chris@381
|
338 $rindexprint = rindex($dirname, $dirsep, length($dirname)-2);
|
Chris@381
|
339 $rindsub = substr($dirname, $rindexprint+1, length($dirname)-$rindexprint-2);
|
Chris@381
|
340 $dirnamesingle{$dirname} = $rindsub;
|
Chris@381
|
341
|
Chris@381
|
342 # create name of html-directories
|
Chris@381
|
343 $_ = $dirname;
|
Chris@381
|
344 s/$var{'dirmfiles'}/$var{'dirhtml'}/;
|
Chris@381
|
345 $dirhtmlname = $_;
|
Chris@381
|
346 if ($var{'producetree'} eq 'no') { $dirhtmlname = $var{'dirhtml'}; }
|
Chris@381
|
347 # try to open html directory, if error, then create directory,
|
Chris@381
|
348 # use same mode as for corresponding m-file directory
|
Chris@381
|
349 opendir(CHECKDIR,"$dirhtmlname") || do {
|
Chris@381
|
350 $dirmode = (stat($dirname))[2]; # print "$dirmode\n";
|
Chris@381
|
351 mkdir("$dirhtmlname", $dirmode) || die ("Cannot create directory $dirhtmlname: $! !");
|
Chris@381
|
352 };
|
Chris@381
|
353 closedir(CHECKDIR);
|
Chris@381
|
354
|
Chris@381
|
355
|
Chris@381
|
356 # read everything from this directory and process them
|
Chris@381
|
357 @ALLEFILES = readdir(AKTDIR);
|
Chris@381
|
358
|
Chris@381
|
359 foreach $file (@ALLEFILES) {
|
Chris@381
|
360 # exclude . and .. directories
|
Chris@381
|
361 next if $file eq '.'; next if $file eq '..';
|
Chris@381
|
362
|
Chris@381
|
363 # test for existense of entry (redundant, used for debugging)
|
Chris@381
|
364 if (-e $dirname.$file) {
|
Chris@381
|
365 # if it's a directory, call this function recursively
|
Chris@381
|
366 if (-d $dirname.$file) {
|
Chris@381
|
367 if ($var{'processtree'} eq 'yes') {
|
Chris@381
|
368 &ParseTreeReadFiles($dirname.$file.$dirsep, $localRecDeep+1);
|
Chris@381
|
369 }
|
Chris@381
|
370 }
|
Chris@381
|
371 # if it's a file - test for m-file, save name and create some arrays
|
Chris@381
|
372 elsif (-f $dirname.$file) {
|
Chris@381
|
373 if ($file =~ /\.$suffixforsearch$/i) {
|
Chris@381
|
374 # Remove the file suffix to establish the matlab identifiers
|
Chris@381
|
375 $filewosuffix = $file;
|
Chris@381
|
376 $filewosuffix =~ s/\.$suffixforsearch$//i;
|
Chris@381
|
377 # $filename = $name;
|
Chris@381
|
378
|
Chris@381
|
379 # Contents file in unix must start with a capital letter (Contents.m)
|
Chris@381
|
380 # ensure, that m-file name is lower case, except the contents file
|
Chris@381
|
381 if (! ($filewosuffix =~ /^contents$/i)) {
|
chris@388
|
382 # if ($var{'links2filescase'} eq 'low') { $filewosuffix = "\L$filewosuffix\E"; }
|
Chris@381
|
383 $filewosuffixlow = "\L$filewosuffix\E";
|
Chris@381
|
384 }
|
Chris@381
|
385 else { $contentsname{$dirname} = $filewosuffix; }
|
Chris@381
|
386
|
Chris@381
|
387 # internal handle name is always lower case
|
Chris@381
|
388 $name = $filewosuffixlow;
|
Chris@381
|
389 # file name is not lower case
|
Chris@381
|
390 $filename = $filewosuffix;
|
Chris@381
|
391
|
Chris@381
|
392 # if don't use C|contents.m, then forget all C|contents.m
|
Chris@381
|
393 if ($var{'usecontentsm'} eq 'no') { if ($name =~ /contents/i) { next; } }
|
Chris@381
|
394
|
Chris@381
|
395 # if m-file with this name already exists, use directory and name for name
|
Chris@381
|
396 # only the first occurence of name will be used for links
|
Chris@381
|
397 if (defined $mfile{$name}) {
|
Chris@381
|
398 if (! ($name =~ /^contents$/i) ) {
|
Chris@381
|
399 print "\r ParseTree - Name conflict: $name in $dirname already exists: $mfile{$name} !\n";
|
Chris@381
|
400 print " $mfile{$name} will be used for links!\n";
|
Chris@381
|
401 }
|
Chris@381
|
402 $name = $dirname.$name;
|
Chris@381
|
403 }
|
Chris@381
|
404 # mfile name with path
|
Chris@381
|
405 $mfile{$name} = $dirname.$file;
|
Chris@381
|
406 # mfile name (without path)
|
Chris@381
|
407 $mfilename{$name} = $filename;
|
Chris@381
|
408 # mfile directory
|
Chris@381
|
409 $mfiledir{$name} = $dirname;
|
Chris@381
|
410
|
Chris@381
|
411 # html file name and full path, special extension of Contents files
|
Chris@381
|
412 if ($name =~ /contents/i) { $extrahtmlfilename = $dirnamesingle{$dirname}; }
|
Chris@381
|
413 else { $extrahtmlfilename = ''; }
|
Chris@381
|
414 $hfile{$name} = $dirhtmlname.$mfilename{$name}.$extrahtmlfilename.$var{'exthtml'};
|
Chris@381
|
415
|
Chris@381
|
416 # save relative html path
|
Chris@381
|
417 # if ($var{'producetree'} eq 'yes') {
|
Chris@381
|
418 $hfilerelpath{$name} = $relpath;
|
Chris@381
|
419 # } else { # if no tree to produce, relative path is empty
|
Chris@381
|
420 # $hfilerelpath{$name} = '';
|
Chris@381
|
421 # }
|
Chris@381
|
422
|
Chris@381
|
423 # create relative path from html file to directory with global index file
|
Chris@381
|
424 $hfileindexpath{$name} = $relpathtoindex;
|
Chris@381
|
425
|
Chris@381
|
426 # Function declaration, if one exists, set default to script
|
Chris@381
|
427 $synopsis{$name} = "";
|
Chris@381
|
428 $mtype{$name} = "script";
|
Chris@381
|
429
|
Chris@381
|
430 # First comment line
|
Chris@381
|
431 $apropos{$name} = "";
|
Chris@381
|
432
|
Chris@381
|
433 # count number of m-files in directories
|
Chris@381
|
434 $dirnumbermfiles{$dirname}++;
|
Chris@381
|
435
|
Chris@381
|
436 if ($debug > 1) {
|
Chris@381
|
437 if ($opt_silent) { print "\r"; }
|
Chris@381
|
438 print " ParseTree: $name \t\t $mfile{$name} \t\t $hfile{$name}\t\t";
|
Chris@381
|
439 if (!$opt_silent) { print "\n"; }
|
Chris@381
|
440 }
|
Chris@381
|
441 }
|
Chris@381
|
442 }
|
Chris@381
|
443 else {
|
Chris@381
|
444 print "Unknown type of file in $dirname: $file\n";
|
Chris@381
|
445 }
|
Chris@381
|
446 }
|
Chris@381
|
447 else { print "Error: Not existing file in $dirname: $file\n"; }
|
Chris@381
|
448 }
|
Chris@381
|
449
|
Chris@381
|
450 closedir(AKTDIR)
|
Chris@381
|
451
|
Chris@381
|
452 }
|
Chris@381
|
453
|
Chris@381
|
454 #------------------------------------------------------------------------
|
Chris@381
|
455 # Construct Dependency matrix
|
Chris@381
|
456 # $dep{$x,$y} > 0 if $x includes a reference to $y.
|
Chris@381
|
457 #------------------------------------------------------------------------
|
Chris@381
|
458 sub ConstructDependencyMatrix
|
Chris@381
|
459 {
|
Chris@381
|
460 &ConstructDependencyMatrixReadFiles('all');
|
Chris@381
|
461 &ConstructDependencyMatrixReally;
|
Chris@381
|
462 }
|
Chris@381
|
463
|
Chris@381
|
464
|
Chris@381
|
465 #------------------------------------------------------------------------
|
Chris@381
|
466 # Construct Dependency matrix
|
Chris@381
|
467 # $dep{$x,$y} > 0 if $x includes a reference to $y.
|
Chris@381
|
468 #------------------------------------------------------------------------
|
Chris@381
|
469 sub ConstructDependencyMatrixReadFiles
|
Chris@381
|
470 {
|
Chris@381
|
471 local($whatstring) = @_;
|
Chris@381
|
472 local(*MFILE);
|
Chris@381
|
473 local($name, $inames);
|
Chris@381
|
474 local(%symbolsdep, %symbolsall);
|
Chris@381
|
475
|
Chris@381
|
476 # Initialize as all zeros.
|
Chris@381
|
477 # foreach $name (@names) { grep($dep{$name,$_}=0,@names); if ($debug > 0) { print "\r DepMatrix anlegen: $name\t$#names\t"; } }
|
Chris@381
|
478
|
Chris@381
|
479 # Compute the dependency matrix
|
Chris@381
|
480 $inames = -1;
|
Chris@381
|
481 foreach $name (@names) {
|
Chris@381
|
482 # Read each file and tabulate the distinct alphanumeric identifiers in
|
Chris@381
|
483 # an array of symbols. Also scan for:
|
Chris@381
|
484 # synopsis: The function declaration line
|
Chris@381
|
485 # apropos: The first line of the help text
|
Chris@381
|
486
|
Chris@381
|
487 # look for whatstring, if all: process every file, if contents: process only contents files
|
Chris@381
|
488 if ($whatstring eq 'contents') { if (! ($name =~ /contents$/i) ) { next; } }
|
Chris@381
|
489 elsif ($whatstring eq 'all') { } # do nothing
|
Chris@381
|
490 else { print "\r ConstructDependency: Unknown parameter whatstring: $whatstring \n"; }
|
Chris@381
|
491
|
Chris@381
|
492 undef %symbolsall; undef %symbolsdep;
|
Chris@381
|
493 open(MFILE,"<$mfile{$name}") || die("Can't open $mfile{$name}: $!\n");
|
Chris@381
|
494 while (<MFILE>) {
|
Chris@381
|
495 chop;
|
Chris@381
|
496
|
Chris@381
|
497 # Split on nonalphanumerics, then look for all words, used for links later
|
Chris@381
|
498 # this one for all references
|
Chris@381
|
499 @wordsall = grep(/[a-zA-Z]\w*/, split('\W',$_));
|
Chris@381
|
500 # set all words to lower case for link checking
|
Chris@381
|
501 undef @wordsall2;
|
Chris@381
|
502 # do case conversion not, case checking is done later
|
Chris@381
|
503 foreach (@wordsall) { push(@wordsall2, "\L$_\E"); }
|
Chris@381
|
504 # @wordsall2 = @wordsall;
|
Chris@381
|
505 grep($symbolsall{$_}++, @wordsall2);
|
Chris@381
|
506
|
Chris@381
|
507 # Store first comment line, skip all others.
|
Chris@381
|
508 if (/^\s*%/) {
|
Chris@381
|
509 if (!$apropos{$name}) {
|
Chris@381
|
510 s/^\s*%\s*//; # remove % and leading white spaces on line
|
Chris@381
|
511 $_ = &SubstituteHTMLEntities($_);
|
Chris@381
|
512 $apropos{$name} = $_;
|
Chris@381
|
513 }
|
Chris@381
|
514 next;
|
Chris@381
|
515 }
|
Chris@381
|
516
|
Chris@381
|
517 # If it's the function declaration line, then store it and skip
|
Chris@381
|
518 # but only, when first function definition (multiple function lines when private subfunctions in file
|
Chris@381
|
519 if ($synopsis{$name} eq '') {
|
Chris@381
|
520 if (/^\s*function/) {
|
Chris@381
|
521 s/^\s*function\s*//;
|
Chris@381
|
522 $synopsis{$name} = $_;
|
Chris@381
|
523 $mtype{$name} = "function";
|
Chris@381
|
524 next;
|
Chris@381
|
525 }
|
Chris@381
|
526 }
|
Chris@381
|
527
|
Chris@381
|
528 # Split off any trailing comments
|
Chris@381
|
529 if ($_ ne '') {
|
Chris@381
|
530 # this one for references in program code only
|
Chris@381
|
531 # when syntax parsing, here is a working place
|
Chris@381
|
532 ($statement) = split('%',$_,1);
|
Chris@381
|
533 @wordsdep = grep(/[a-zA-Z]\w*/,split('\W',$statement));
|
Chris@381
|
534 # do case conversion not, case checking is done later
|
Chris@381
|
535 undef @wordsdep2;
|
Chris@381
|
536 foreach (@wordsdep) { push(@wordsdep2, "\L$_\E"); }
|
Chris@381
|
537 grep($symbolsdep{$_}++, @wordsdep2);
|
Chris@381
|
538 }
|
Chris@381
|
539 }
|
Chris@381
|
540 close MFILE;
|
Chris@381
|
541
|
Chris@381
|
542 # compute intersection between %symbolsall and @linknames
|
Chris@381
|
543 delete($symbolsall{$name});
|
Chris@381
|
544 # foreach $localsumall ($symbolsall) {
|
Chris@381
|
545 # $localsumall = "\L$localsumall\E";
|
Chris@381
|
546 # }
|
Chris@381
|
547 @{'all'.$name} = grep($symbolsall{$_}, @linknames);
|
Chris@381
|
548
|
Chris@381
|
549 # compute intersection between %symbolsdep and @linknames
|
Chris@381
|
550 delete($symbolsdep{$name});
|
Chris@381
|
551 @{'depcalls'.$name} = grep($symbolsdep{$_}, @linknames);
|
Chris@381
|
552
|
Chris@381
|
553 $inames++; print "\r DepCallsMatrix: $inames/$#names\t $name\t";
|
Chris@381
|
554 if ($debug > 2) { print "\n depnames: @{'depcalls'.$name}\n all: @{'all'.$name}\n"; }
|
Chris@381
|
555 }
|
Chris@381
|
556 }
|
Chris@381
|
557
|
Chris@381
|
558
|
Chris@381
|
559 #------------------------------------------------------------------------
|
Chris@381
|
560 # Construct Dependency matrix
|
Chris@381
|
561 # $dep{$x,$y} > 0 if $x includes a reference to $y.
|
Chris@381
|
562 #------------------------------------------------------------------------
|
Chris@381
|
563 sub ConstructDependencyMatrixReally
|
Chris@381
|
564 {
|
Chris@381
|
565 local($inames, $name);
|
Chris@381
|
566
|
Chris@381
|
567 $inames = -1;
|
Chris@381
|
568 foreach $name (@names) { undef %{'depint'.$name}; }
|
Chris@381
|
569 foreach $name (@names) {
|
Chris@381
|
570 grep(${'depint'.$_}{$name}++, @{'depcalls'.$name});
|
Chris@381
|
571 $inames++; print "\r DepCalledMatrix1: $inames/$#names\t $name\t";
|
Chris@381
|
572 }
|
Chris@381
|
573 $inames = -1;
|
Chris@381
|
574 foreach $name (@names) {
|
Chris@381
|
575 # compute intersection between %depint.name{$_} and @linknames
|
Chris@381
|
576 if (defined (%{'depint'.$name})) { @{'depcalled'.$name} = grep(${'depint'.$name}{$_}, @linknames); }
|
Chris@381
|
577 $inames++; print "\r DepCalledMatrix2: $inames/$#names\t $name\t";
|
Chris@381
|
578 if ($debug > 2) { print "\n depcalled: @{'depcalled'.$name}\n"; }
|
Chris@381
|
579 }
|
Chris@381
|
580
|
Chris@381
|
581 }
|
Chris@381
|
582
|
Chris@381
|
583
|
Chris@381
|
584 #========================================================================
|
Chris@381
|
585 # Construct all index files
|
Chris@381
|
586 #========================================================================
|
Chris@381
|
587 sub ConstructAllIndexFiles
|
Chris@381
|
588 {
|
Chris@381
|
589 local(@localnames);
|
Chris@381
|
590 local($ActDir);
|
Chris@381
|
591 local($name);
|
Chris@381
|
592
|
Chris@381
|
593 # define variables and names for frame target
|
Chris@381
|
594 $GlobalNameFrameMainLeft = 'Cont_Main';
|
Chris@381
|
595 $GlobalNameFrameMainRight = 'Cont_Lower';
|
Chris@381
|
596 $GlobalNameFrameAZIndexsmall = 'IndexAZindex';
|
Chris@381
|
597 $GlobalNameFrameAZIndexjump = 'IndexAZjump';
|
Chris@381
|
598
|
Chris@381
|
599 $indexcreated = 0;
|
Chris@381
|
600
|
Chris@381
|
601 &ConstructHighestIndexFile;
|
Chris@381
|
602 $indexcreated++;
|
Chris@381
|
603
|
Chris@381
|
604 # if ($var{'producetree'} eq 'yes') {
|
Chris@381
|
605 # moved next 2 lines out of if for producetree no
|
Chris@381
|
606 # &ConstructHighestIndexFile;
|
Chris@381
|
607 # $indexcreated++;
|
Chris@381
|
608
|
Chris@381
|
609 foreach $ActDir (@directories) {
|
Chris@381
|
610 undef @localnames;
|
Chris@381
|
611 foreach $name (@names) {
|
Chris@381
|
612 local($pathsubstr) = substr($mfile{$name}, 0, rindex($mfile{$name}, "/")+1);
|
Chris@381
|
613 if ($ActDir eq $pathsubstr) {
|
Chris@381
|
614 if ($debug > 1) { print "IndexFile: $pathsubstr ActDir: $ActDir Hfilerelpath: $hfilerelpath{$name}\n"; }
|
Chris@381
|
615 push(@localnames, $name);
|
Chris@381
|
616 }
|
Chris@381
|
617 }
|
Chris@381
|
618 if ($debug > 2) { print "localnames: @localnames\n"; }
|
Chris@381
|
619 # create contents file and short|long index of files in local directory
|
Chris@381
|
620 &ConstructContentsmFile($ActDir, @localnames);
|
Chris@381
|
621 &ConstructAZIndexFile($ActDir, 'short', 'local', @localnames);
|
Chris@381
|
622 &ConstructAZIndexFile($ActDir, 'long', 'local', @localnames);
|
Chris@381
|
623 $indexcreated+=2;
|
Chris@381
|
624 }
|
Chris@381
|
625 # } else {
|
Chris@381
|
626 # &ConstructContentsmFile($var{'dirmfiles'}, @names);
|
Chris@381
|
627 # }
|
Chris@381
|
628
|
Chris@381
|
629 # create short|long index of files in all directory
|
Chris@381
|
630 &ConstructAZIndexFile($var{'dirmfiles'}, 'short', 'global', @names);
|
Chris@381
|
631 &ConstructAZIndexFile($var{'dirmfiles'}, 'long', 'global', @names);
|
Chris@381
|
632 $indexcreated+=2;
|
Chris@381
|
633
|
Chris@381
|
634 # if contents.m were created or updated, the dependency matrices should
|
Chris@381
|
635 # be updated as well
|
Chris@381
|
636 if ($var{'writecontentsm'} eq 'yes') { &ConstructDependencyMatrixReadFiles('contents');; }
|
Chris@381
|
637 }
|
Chris@381
|
638
|
Chris@381
|
639
|
Chris@381
|
640 #========================================================================
|
Chris@381
|
641 # Construct the highest level index file
|
Chris@381
|
642 #========================================================================
|
Chris@381
|
643 sub ConstructHighestIndexFile
|
Chris@381
|
644 {
|
Chris@381
|
645 local(*IFILE);
|
Chris@381
|
646 local($indexfile, $filename);
|
Chris@381
|
647
|
Chris@381
|
648 # Build the frame layout file, this files includes the layout of the frames
|
Chris@381
|
649 # Build the frame layout file name (highest one)
|
Chris@381
|
650 $indexfile = $var{'dirhtml'}.$var{'filenametopframe'}.$var{'exthtml'};
|
Chris@381
|
651
|
Chris@382
|
652 if ($var{'frames'} eq 'yes') {
|
Chris@381
|
653
|
Chris@382
|
654 open(IFILE,">$indexfile") || die("Cannot open frame layout file $indexfile\n");
|
Chris@381
|
655
|
Chris@382
|
656 # Write the header of frame file
|
Chris@382
|
657 print IFILE "$TextDocTypeFrame\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n";
|
Chris@382
|
658 print IFILE " <title>$var{'texttitleframelayout'}</title>\n";
|
Chris@382
|
659 print IFILE "</head>\n";
|
Chris@381
|
660
|
Chris@382
|
661 # definition of 2 frames, left the tree of directories,
|
Chris@382
|
662 # right the index of that directory or the docu of a file
|
Chris@382
|
663 print IFILE "<frameset cols=\"25%,75%\">\n";
|
Chris@382
|
664 print IFILE " <frame src=\"$var{'filenamedirshort'}$var{'exthtml'}\" name=\"$GlobalNameFrameMainLeft\" />\n";
|
Chris@382
|
665 print IFILE " <frame src=\"$var{'filenameindexshortglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\" name=\"$GlobalNameFrameMainRight\" />\n"; print IFILE "</frameset>\n";
|
Chris@381
|
666
|
Chris@382
|
667 print IFILE "</html>\n";
|
Chris@382
|
668
|
Chris@382
|
669 close(IFILE);
|
Chris@382
|
670
|
Chris@382
|
671 if ($opt_silent) { print "\r"; }
|
Chris@382
|
672 print " Frame layout file created: $indexfile\t";
|
Chris@382
|
673 if (!$opt_silent) { print "\n"; }
|
Chris@382
|
674 }
|
Chris@381
|
675
|
Chris@381
|
676 for($irun=0; $irun <= 2; $irun++) {
|
Chris@381
|
677 # Build the top directory index file, these files include the directory tree
|
Chris@381
|
678 # Build the directory tree index file name
|
Chris@381
|
679
|
Chris@381
|
680 # Create no directory file for contents, when no contents to use
|
Chris@381
|
681 if (($irun == 2) && ($var{'usecontentsm'} eq 'no')) { next; }
|
Chris@381
|
682
|
Chris@381
|
683 # Assign the correct index file name
|
Chris@381
|
684 if ($irun == 0) { $filename = $var{'filenamedirshort'}; }
|
Chris@381
|
685 elsif ($irun == 1) { $filename = $var{'filenamedirlong'}; }
|
Chris@381
|
686 elsif ($irun == 2) { $filename = $var{'filenamedircontents'}; }
|
Chris@381
|
687
|
Chris@381
|
688 $indexfile = $var{'dirhtml'}.$filename.$var{'exthtml'};
|
Chris@381
|
689
|
Chris@381
|
690 open(IFILE,">$indexfile") || die("Cannot open directory tree index file $indexfile\n");
|
Chris@381
|
691 # Write header of HTML file
|
Chris@381
|
692 print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
Chris@381
|
693
|
Chris@381
|
694 if ($var{'texttitleindexalldirs'} eq '') {
|
Chris@381
|
695 print IFILE "<title>Index of Directories of $var{'dirmfiles'}</title>\n";
|
Chris@381
|
696 } else {
|
Chris@381
|
697 print IFILE "<title>$var{'texttitleindexalldirs'}</title>\n";
|
Chris@381
|
698 }
|
Chris@382
|
699
|
Chris@382
|
700 if ($var{'frames'} eq 'yes') {
|
Chris@382
|
701 print IFILE "<base target=\"$GlobalNameFrameMainRight\" />\n";
|
Chris@382
|
702 }
|
Chris@382
|
703
|
Chris@381
|
704 print IFILE "</head>\n";
|
Chris@381
|
705 print IFILE "<body $var{'codebodyindex'}>\n";
|
chris@410
|
706 print IFILE "<div id=\"matlabdoc\">\n";
|
Chris@381
|
707 if ($var{'textheaderindexalldirs'} eq '') {
|
Chris@381
|
708 print IFILE "<h1 $var{'codeheader'}>Index of Directories of <em>$var{'dirmfiles'}</em></h1>\n";
|
Chris@381
|
709 } else {
|
Chris@381
|
710 print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindexalldirs'}</h1>\n";
|
Chris@381
|
711 }
|
chris@389
|
712 print IFILE "<p>\n";
|
Chris@382
|
713
|
Chris@382
|
714 if ($var{'frames'} eq 'yes') {
|
Chris@382
|
715 if ($irun == 0) { print IFILE "<strong>short</strong>\n"; }
|
Chris@382
|
716 else { print IFILE "<a href=\"$var{'filenamedirshort'}$var{'exthtml'}\" target=\"$GlobalNameFrameMainLeft\">short</a>\n"; }
|
Chris@382
|
717 if ($irun == 1) { print IFILE " | <strong>long</strong>\n"; }
|
Chris@382
|
718 else { print IFILE " | <a href=\"$var{'filenamedirlong'}$var{'exthtml'}\" target=\"$GlobalNameFrameMainLeft\">long</a>\n"; }
|
Chris@382
|
719 if ($var{'usecontentsm'} eq 'yes') {
|
Chris@382
|
720 if ($irun == 2) { print IFILE " | <strong>contents</strong>\n"; }
|
Chris@382
|
721 else { print IFILE " | <a href=\"$var{'filenamedircontents'}$var{'exthtml'}\" target=\"$GlobalNameFrameMainLeft\">contents</a>\n"; }
|
Chris@382
|
722 }
|
Chris@382
|
723 } else {
|
Chris@382
|
724 if ($irun == 0) { print IFILE "<strong>short</strong>\n"; }
|
Chris@382
|
725 else { print IFILE "<a href=\"$var{'filenamedirshort'}$var{'exthtml'}\">short</a>\n"; }
|
Chris@382
|
726 if ($irun == 1) { print IFILE " | <strong>long</strong>\n"; }
|
Chris@382
|
727 else { print IFILE " | <a href=\"$var{'filenamedirlong'}$var{'exthtml'}\">long</a>\n"; }
|
Chris@382
|
728 if ($var{'usecontentsm'} eq 'yes') {
|
Chris@382
|
729 if ($irun == 2) { print IFILE " | <strong>contents</strong>\n"; }
|
Chris@382
|
730 else { print IFILE " | <a href=\"$var{'filenamedircontents'}$var{'exthtml'}\">contents</a>\n"; }
|
Chris@382
|
731 }
|
Chris@381
|
732 }
|
Chris@381
|
733
|
Chris@381
|
734 print IFILE "</p><br />\n\n";
|
Chris@381
|
735 print IFILE "<ul>\n";
|
Chris@381
|
736
|
Chris@381
|
737 # go through all directories and create a list entry for each one,
|
Chris@381
|
738 # depending on recursion level create sublists
|
Chris@381
|
739 $prevrecdeeplevel = 0;
|
Chris@381
|
740 foreach $name (@alldirectories) {
|
Chris@381
|
741 $actrecdeeplevel = $dirnamerecdeep{$name};
|
Chris@381
|
742 for( ; $prevrecdeeplevel < $actrecdeeplevel; $prevrecdeeplevel++ ) { print IFILE "<ul>\n"; }
|
Chris@381
|
743 for( ; $prevrecdeeplevel > $actrecdeeplevel; $prevrecdeeplevel-- ) { print IFILE "</ul>\n"; }
|
Chris@381
|
744 if ($irun == 0) { $indexfilenameused = $var{'filenameindexshortlocal'}.$var{'filenameextensionframe'}; }
|
Chris@381
|
745 elsif ($irun == 1) { $indexfilenameused = $var{'filenameindexlonglocal'}.$var{'filenameextensionframe'}; }
|
Chris@381
|
746 elsif ($irun == 2) { $indexfilenameused = $contentsname{$name}; }
|
Chris@381
|
747 else { die "ConstructHighestIndexFile: Unknown value of irun"; }
|
Chris@381
|
748 if ($dirnumbermfiles{$name} > 0) {
|
Chris@381
|
749 # producetree no
|
Chris@381
|
750 # if ($var{'producetree'} eq 'no') { $dirnamehere = ''; }
|
Chris@381
|
751 # else { $dirnamehere = '$dirnamerelpath{$name}'; }
|
Chris@381
|
752 # print IFILE "<LI><A HREF=\"$dirnamehere$indexfilenameused_$dirnamesingle{$name}$var{'exthtml'}\">$dirnamesingle{$name}</A>\n";
|
Chris@381
|
753 print IFILE "<li><a href=\"$dirnamerelpath{$name}$indexfilenameused$dirnamesingle{$name}$var{'exthtml'}\">$dirnamesingle{$name}</a></li>\n";
|
Chris@381
|
754 } else {
|
Chris@381
|
755 # print directories with no m-files inside not
|
Chris@381
|
756 # print IFILE "<li>$dirnamesingle{$name}</li>\n";
|
Chris@381
|
757 }
|
Chris@381
|
758 }
|
Chris@381
|
759 $actrecdeeplevel = 0;
|
Chris@381
|
760 for( ; $prevrecdeeplevel > $actrecdeeplevel; $prevrecdeeplevel-- ) { print IFILE "</ul>\n"; }
|
Chris@381
|
761 print IFILE "</ul>\n<br />$var{'codehr'}\n";
|
Chris@381
|
762
|
Chris@381
|
763 # Include info about author from authorfile
|
Chris@381
|
764 &WriteFile2Handle($var{'authorfile'}, IFILE);
|
Chris@381
|
765
|
Chris@381
|
766 print IFILE "<!--navigate-->\n";
|
Chris@381
|
767 print IFILE "<!--copyright-->\n";
|
chris@410
|
768 print IFILE "</div>\n</body>\n</html>\n";
|
Chris@381
|
769
|
Chris@381
|
770 close(IFILE);
|
Chris@381
|
771
|
Chris@381
|
772 if ($opt_silent) { print "\r"; }
|
Chris@381
|
773 print " Directory - Indexfile created: $indexfile\t";
|
Chris@381
|
774 if (!$opt_silent) { print "\n"; }
|
Chris@381
|
775 }
|
Chris@381
|
776 }
|
Chris@381
|
777
|
Chris@381
|
778
|
Chris@381
|
779 #========================================================================
|
Chris@381
|
780 # Construct the A-Z index file (global/local and/or short/long)
|
Chris@381
|
781 #========================================================================
|
Chris@381
|
782 sub ConstructAZIndexFile
|
Chris@381
|
783 {
|
Chris@381
|
784 local($LocalActDir, $LocalShortLong, $LocalGlobalLocal, @localnames) = @_;
|
Chris@381
|
785 local(*IFILE);
|
Chris@381
|
786 local($name, $indexfilename, $dirpath);
|
Chris@381
|
787 local($firstletter, $firstone);
|
Chris@381
|
788
|
Chris@381
|
789 if ($debug > 2) { print "localnames in AZ small: @localnames\n"; print " ActDir in A-Z: $LocalActDir\n"; }
|
Chris@381
|
790
|
Chris@381
|
791 # extract filename of index file from parameters of function
|
Chris@381
|
792 if ($LocalShortLong eq 'short') {
|
Chris@381
|
793 if ($LocalGlobalLocal eq 'global') { $indexfilename = $var{'filenameindexshortglobal'}; }
|
Chris@381
|
794 elsif ($LocalGlobalLocal eq 'local') { $indexfilename = $var{'filenameindexshortlocal'}; }
|
Chris@381
|
795 else { die "wrong parameter for LocalGlobalLocal in ConstructAZIndexFile: $LocalGlobalLocal."; }
|
Chris@381
|
796 } elsif ($LocalShortLong eq 'long') {
|
Chris@381
|
797 if ($LocalGlobalLocal eq 'global') { $indexfilename = $var{'filenameindexlongglobal'}; }
|
Chris@381
|
798 elsif ($LocalGlobalLocal eq 'local') { $indexfilename = $var{'filenameindexlonglocal'}; }
|
Chris@381
|
799 else { die "wrong parameter for LocalGlobalLocal in ConstructAZIndexFile: $LocalGlobalLocal."; }
|
Chris@381
|
800 } else { die "wrong parameter for LocalShortLong in ConstructAZIndexFile: $LocalShortLong."; }
|
Chris@381
|
801
|
Chris@381
|
802 # producetree no
|
Chris@381
|
803 # if ($var{'producetree'} eq 'no') { $dirnamehere = ''; }
|
Chris@381
|
804 # else { $dirnamehere = '$dirnamerelpath{$LocalActDir}'; }
|
Chris@381
|
805 # Build the index file name
|
Chris@381
|
806 # handle the global index file case separately (no extra directory name in file)
|
Chris@381
|
807 # the local index file name must be extended by the name of the directory
|
Chris@381
|
808 if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
|
Chris@381
|
809 else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
|
Chris@381
|
810 $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionindex'}.$extradirfilename.$var{'exthtml'};
|
Chris@382
|
811
|
chris@401
|
812 if ($LocalShortLong eq 'short' and $extradirfilename eq '' and $var{'frames'} ne 'yes') {
|
chris@401
|
813 # With no frames and no subdir path, this must go in the
|
chris@401
|
814 # top-level index file instead
|
Chris@382
|
815 $indexfile = $var{'dirhtml'}.$var{'filenametopframe'}.$var{'exthtml'};
|
Chris@382
|
816 }
|
Chris@382
|
817
|
Chris@381
|
818 if ($debug > 2) { print " indexfilename (a-z small): $indexfile\n"; }
|
Chris@381
|
819
|
Chris@381
|
820 open(IFILE,">$indexfile") || die("Cannot open index file $indexfile: $!\n");
|
Chris@381
|
821
|
Chris@381
|
822 # Write the header of HTML file
|
Chris@381
|
823 print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
Chris@381
|
824
|
chris@410
|
825 my $dirToPrint = $LocalActDir;
|
chris@410
|
826 $dirToPrint =~ s,^./,,;
|
chris@410
|
827
|
Chris@381
|
828 if ($var{'texttitleindex'} eq '') {
|
chris@410
|
829 print IFILE "<title>Index of Matlab Files in Directory $dirToPrint</title>\n";
|
Chris@381
|
830 } else {
|
Chris@381
|
831 if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
|
chris@410
|
832 else { print IFILE "<title>$var{'texttitleindex'} in Directory $dirToPrint</title>\n"; }
|
Chris@381
|
833 }
|
Chris@382
|
834
|
Chris@382
|
835 if ($var{'frames'} eq 'yes') {
|
Chris@382
|
836 print IFILE "<base target=\"$GlobalNameFrameMainRight\" />\n";
|
Chris@382
|
837 }
|
Chris@381
|
838 print IFILE "</head>\n";
|
Chris@382
|
839
|
Chris@381
|
840 print IFILE "<body $var{'codebodyindex'}>\n";
|
chris@410
|
841 print IFILE "<div id=\"matlabdoc\">\n";
|
Chris@381
|
842 if ($var{'textheaderindex'} eq '') {
|
chris@410
|
843 print IFILE "<h1 $var{'codeheader'}>Index of Matlab Files in Directory $dirToPrint</h1>\n";
|
Chris@381
|
844 } else {
|
Chris@381
|
845 if ($LocalGlobalLocal eq 'global') { print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindex'}</h1>\n"; }
|
chris@410
|
846 else { print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindex'} in Directory $dirToPrint</h1>\n"; }
|
Chris@381
|
847 }
|
Chris@381
|
848
|
Chris@381
|
849 # include links to indexes
|
Chris@381
|
850 &ConstructLinks2Index(IFILE, $dirnamerelpathtoindex{$LocalActDir}, $LocalActDir, $LocalGlobalLocal);
|
Chris@381
|
851
|
Chris@381
|
852 # Collect the starting letters of m files in this directory or all m-files
|
Chris@381
|
853 for('a'..'z') { undef @{$_}; }
|
Chris@381
|
854 foreach $name (@localnames) {
|
Chris@381
|
855 if (! ($mfilename{$name} =~ /contents/i)) {
|
Chris@381
|
856 $firstletter = substr($mfilename{$name}, 0, 1);
|
Chris@381
|
857 # convert first letter always to lower case
|
Chris@381
|
858 # needed for reference to lower and upper case m-files
|
Chris@381
|
859 $firstletter = "\L$firstletter\E";
|
Chris@381
|
860 push(@{$firstletter}, $name);
|
Chris@381
|
861 }
|
Chris@381
|
862 }
|
Chris@381
|
863
|
Chris@381
|
864 if ($LocalShortLong eq 'short') {
|
Chris@381
|
865 # begin create short index
|
Chris@381
|
866 print IFILE "<table width=\"100%\">\n";
|
Chris@381
|
867
|
Chris@381
|
868 for('a'..'z') {
|
Chris@381
|
869 # print " $_: @{$_}\n";
|
Chris@381
|
870 $numberofletter = $#{$_}+1;
|
chris@410
|
871 $cols = 3;
|
Chris@381
|
872 if ($numberofletter > 0) {
|
chris@410
|
873 print IFILE "\n<tr><td><br/><strong><a name=\"\U$_\E$_\"></a><span class=\"an\">\U$_\E</span></strong></td></tr>\n";
|
chris@410
|
874 for ($count = 0; $count < $numberofletter; $count++) {
|
chris@410
|
875 if (($count % $cols) == 0) {
|
chris@410
|
876 if ($count > 0) {
|
chris@410
|
877 print IFILE "</tr><tr>\n";
|
chris@410
|
878 }
|
chris@410
|
879 print IFILE "<tr><td></td>";
|
chris@410
|
880 }
|
chris@410
|
881 $name = @{$_}[$count];
|
chris@410
|
882 if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
|
chris@410
|
883 print IFILE "<td><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td>";
|
chris@410
|
884 }
|
chris@410
|
885
|
chris@410
|
886 print IFILE "</tr>\n";
|
chris@410
|
887
|
chris@410
|
888 # $numberhalf = ($numberofletter + 1 - (($numberofletter+1) % 2))/2;
|
chris@410
|
889 # if ($debug > 2) { print " $_: @{$_} \t $numberhalf \t $numberofletter\n"; }
|
chris@410
|
890 # for($count = 0; $count < $numberhalf; $count++) {
|
chris@410
|
891 # $name = @{$_}[$count];
|
chris@410
|
892 # if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
|
chris@410
|
893 # print IFILE "<tr><td width=\"50%\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td>";
|
chris@410
|
894 # if (($count + $numberhalf) < $numberofletter) {
|
chris@410
|
895 # $name = @{$_}[$count + $numberhalf];
|
chris@410
|
896 # if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
|
chris@410
|
897 # print IFILE "<td width=\"50%\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td></tr>\n";
|
chris@410
|
898 # } else {
|
chris@410
|
899 # print IFILE "<td width=\"50%\"></td></tr>\n";
|
chris@410
|
900 # }
|
chris@410
|
901 # }
|
Chris@381
|
902 }
|
Chris@381
|
903 }
|
Chris@381
|
904 print IFILE "</table>\n<br />$var{'codehr'}\n";
|
Chris@381
|
905
|
Chris@381
|
906 } elsif ($LocalShortLong eq 'long') {
|
Chris@381
|
907 # begin create long index
|
chris@410
|
908 print IFILE "<table width=\"100%\">\n";
|
chris@401
|
909 print IFILE "<tr><th>Name</th><th>Synopsis</th></tr>\n";
|
Chris@381
|
910
|
Chris@381
|
911 for('a'..'z') {
|
Chris@381
|
912 # print " $_: @{$_}\n";
|
Chris@381
|
913 $numberofletter = $#{$_}+1;
|
Chris@381
|
914 if ($numberofletter > 0) {
|
Chris@381
|
915 $firstone = 1;
|
Chris@381
|
916 foreach $name (@{$_}) {
|
Chris@381
|
917 if ($debug > 1) { print " AZinforeach1: $name \t\t $hfilerelpath{$name} \t\t $dirnamerelpath{$LocalActDir}\n"; }
|
Chris@381
|
918 if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
|
Chris@381
|
919 if (! ($mfilename{$name} =~ /contents/i)) {
|
chris@400
|
920 if ($firstone == 1) { print IFILE "\n<tr><td colspan=\"2\"><br /><strong><a name=\"\U$_\E$_\"></a><span class=\"an\">\U$_\E</span></strong></td></tr>\n"; $firstone = 0; }
|
Chris@381
|
921 print IFILE "<tr><td valign=\"top\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td><td>$apropos{$name}</td></tr>\n";
|
Chris@381
|
922 }
|
Chris@381
|
923 }
|
Chris@381
|
924 }
|
Chris@381
|
925 }
|
Chris@381
|
926 print IFILE "</table>\n<br />$var{'codehr'}\n";
|
Chris@381
|
927 } else { die "wrong parameter for LocalShortLong in ConstructAZIndexFile: $LocalShortLong."; }
|
Chris@381
|
928
|
Chris@381
|
929 # Include info about author from authorfile
|
Chris@381
|
930 &WriteFile2Handle($var{'authorfile'}, IFILE);
|
Chris@381
|
931
|
Chris@381
|
932 print IFILE "<!--navigate-->\n";
|
Chris@381
|
933 print IFILE "<!--copyright-->\n";
|
chris@410
|
934 print IFILE "</div>\n</body>\n</html>\n";
|
Chris@381
|
935
|
Chris@381
|
936 close(IFILE);
|
Chris@381
|
937
|
Chris@381
|
938 if ($opt_silent) { print "\r"; }
|
Chris@381
|
939 print " Indexfile small (A-Z) created: $indexfile\t";
|
Chris@381
|
940 if (!$opt_silent) { print "\n"; }
|
Chris@381
|
941
|
Chris@381
|
942
|
Chris@381
|
943 # Build the A-Z jump index file name
|
Chris@381
|
944 # handle the global index file case separately (no extra directory name in file)
|
Chris@381
|
945 if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
|
Chris@381
|
946 else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
|
Chris@381
|
947
|
Chris@382
|
948 if ($var{'frames'} eq 'yes') {
|
Chris@382
|
949
|
Chris@382
|
950 $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionjump'}.$extradirfilename.$var{'exthtml'};
|
Chris@382
|
951 if ($debug > 2) { print " indexfilename (a-z jump): $indexfile\n"; }
|
Chris@382
|
952 open(IFILE,">$indexfile") || die("Cannot open jump index file $indexfile: $!\n");
|
Chris@382
|
953
|
Chris@382
|
954 # Write the header of HTML file
|
Chris@382
|
955 print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
Chris@382
|
956
|
Chris@382
|
957 if ($var{'texttitleindex'} eq '') {
|
chris@410
|
958 print IFILE "<title>A-Z jump index in directory $dirToPrint</title>\n";
|
Chris@382
|
959 } else {
|
Chris@382
|
960 if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
|
chris@410
|
961 else { print IFILE "<title>$var{'texttitleindex'} in Directory $dirToPrint</title>\n"; }
|
Chris@382
|
962 }
|
Chris@382
|
963
|
Chris@382
|
964 if ($var{'frames'} eq 'yes') {
|
Chris@382
|
965 print IFILE "<base target=\"$GlobalNameFrameAZIndexsmall\" />\n";
|
Chris@382
|
966 }
|
Chris@382
|
967 print IFILE "</head>\n";
|
Chris@382
|
968 print IFILE "<body $var{'codebodyindex'}>\n";
|
chris@410
|
969 print IFILE "<div id=\"matlabdoc\">\n";
|
Chris@382
|
970
|
Chris@382
|
971 # Write the A-Z jump line, generate link for letters with files starting with this letter
|
Chris@382
|
972 # and only letters for no files starting with this letter
|
Chris@382
|
973 # use previously generated arrays with names of files sorted by starting letter
|
Chris@382
|
974 for('a'..'z') {
|
Chris@382
|
975 $numberofletter = $#{$_}+1;
|
Chris@382
|
976 if ($numberofletter > 0) {
|
Chris@382
|
977 print IFILE "<strong><a href=\"$indexfilename$var{'filenameextensionindex'}$extradirfilename$var{'exthtml'}#\U$_\E$_\">\U$_\E</a> </strong>\n";
|
Chris@382
|
978 } else {
|
Chris@382
|
979 print IFILE "\U$_\E \n";
|
Chris@382
|
980 }
|
Chris@382
|
981 }
|
Chris@382
|
982
|
chris@410
|
983 print IFILE "</div></body>\n</html>\n";
|
Chris@382
|
984
|
Chris@382
|
985 close(IFILE);
|
Chris@382
|
986
|
Chris@382
|
987 if ($opt_silent) { print "\r"; }
|
Chris@382
|
988 print " Indexfile small (A-Z jump) created: $indexfile\t";
|
Chris@382
|
989 if (!$opt_silent) { print "\n"; }
|
Chris@381
|
990 }
|
Chris@381
|
991
|
Chris@381
|
992
|
Chris@381
|
993 # Build the frame layout file, this file includes the layout of the frames
|
Chris@381
|
994 # Build the frame layout file name (for small/compact A-Z index)
|
Chris@381
|
995 # handle the global index file case separately (no extra directory name in file)
|
Chris@381
|
996 if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
|
Chris@381
|
997 else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
|
Chris@381
|
998
|
Chris@382
|
999 if ($var{'frames'} eq 'yes') {
|
Chris@381
|
1000
|
Chris@382
|
1001 $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionframe'}.$extradirfilename.$var{'exthtml'};
|
Chris@382
|
1002 if ($debug > 2) { print " indexfilename (a-z frame): $indexfile\n"; }
|
Chris@381
|
1003
|
Chris@382
|
1004 open(IFILE,">$indexfile") || die("Cannot open jump index frame file $indexfile: $!\n");
|
Chris@382
|
1005
|
Chris@382
|
1006 # Write the header of Frame file
|
Chris@382
|
1007 print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
Chris@382
|
1008
|
Chris@382
|
1009 if ($var{'texttitleindex'} eq '') {
|
chris@410
|
1010 print IFILE "<title>Index of Matlab Files in Directory $dirToPrint</title>\n";
|
Chris@382
|
1011 } else {
|
Chris@382
|
1012 if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
|
chris@410
|
1013 else { print IFILE "<title>$var{'texttitleindex'} in Directory $dirToPrint</title>\n"; }
|
Chris@382
|
1014 }
|
Chris@382
|
1015 print IFILE "</head>\n";
|
Chris@382
|
1016
|
Chris@382
|
1017 # definition of 2 frames, top the A-Z index, below the jump letter line
|
Chris@382
|
1018 print IFILE "<frameset rows=\"90%,10%\">\n";
|
Chris@382
|
1019 print IFILE " <frame src=\"$indexfilename$var{'filenameextensionindex'}$extradirfilename$var{'exthtml'}\" name=\"$GlobalNameFrameAZIndexsmall\" />\n";
|
Chris@382
|
1020 print IFILE " <frame src=\"$indexfilename$var{'filenameextensionjump'}$extradirfilename$var{'exthtml'}\" name=\"$GlobalNameFrameAZIndexjump\" />\n";
|
Chris@382
|
1021 print IFILE "</frameset>\n";
|
Chris@382
|
1022
|
Chris@382
|
1023 print IFILE "</html>\n";
|
Chris@382
|
1024
|
Chris@382
|
1025 close(IFILE);
|
Chris@382
|
1026
|
Chris@382
|
1027 if ($opt_silent) { print "\r"; }
|
Chris@382
|
1028 print " Frame layout file created: $indexfile\t";
|
Chris@382
|
1029 if (!$opt_silent) { print "\n"; }
|
Chris@381
|
1030 }
|
Chris@381
|
1031 }
|
Chris@382
|
1032
|
Chris@381
|
1033
|
Chris@381
|
1034 #========================================================================
|
Chris@381
|
1035 # Construct the links to all indexes
|
Chris@381
|
1036 #========================================================================
|
Chris@381
|
1037 sub ConstructLinks2Index
|
Chris@381
|
1038 {
|
Chris@381
|
1039 local(*WRITEFILE, $LocalPath2Index, $PathContents, $LocalGlobalLocal) = @_;
|
Chris@381
|
1040
|
Chris@381
|
1041 # include links to short/long - local/global index and C|contents.m
|
chris@389
|
1042 print WRITEFILE "\n<p>";
|
chris@389
|
1043 print WRITEFILE "$var{'textjumpindexglobal'} ";
|
Chris@382
|
1044
|
Chris@382
|
1045 if ($var{'frames'} eq 'yes') {
|
Chris@382
|
1046 print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexshortglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\">short</a> | ";
|
chris@389
|
1047 print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexlongglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\">long</a>\n";
|
Chris@382
|
1048 } else {
|
Chris@387
|
1049 print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenametopframe'}$var{'exthtml'}\">short</a> | ";
|
chris@389
|
1050 print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexlongglobal'}$var{'filenameextensionindex'}$var{'exthtml'}\">long</a>\n";
|
Chris@382
|
1051 }
|
Chris@382
|
1052
|
Chris@381
|
1053 if ($LocalGlobalLocal eq 'local') {
|
Chris@381
|
1054 if ($var{'usecontentsm'} eq 'yes') {
|
Chris@381
|
1055 print WRITEFILE " | <a href=\"$contentsname{$PathContents}$dirnamesingle{$PathContents}$var{'exthtml'}\">Local contents</a>\n";
|
Chris@381
|
1056 }
|
chris@389
|
1057 if ($var{'frames'} eq 'yes') {
|
chris@389
|
1058 print WRITEFILE " | $var{'textjumpindexlocal'} ";
|
Chris@382
|
1059 print WRITEFILE "<a href=\"$var{'filenameindexshortlocal'}$var{'filenameextensionframe'}$dirnamesingle{$PathContents}$var{'exthtml'}\">short</a> | ";
|
chris@389
|
1060 print WRITEFILE "<a href=\"$var{'filenameindexlonglocal'}$var{'filenameextensionframe'}$dirnamesingle{$PathContents}$var{'exthtml'}\">long</a>\n";
|
chris@389
|
1061 } else {
|
chris@389
|
1062 print WRITEFILE " | $var{'textjumpindexlocal'} ";
|
chris@389
|
1063 print WRITEFILE "<a href=\"$var{'filenameindexshortlocal'}$var{'filenameextensionindex'}$dirnamesingle{$PathContents}$var{'exthtml'}\">short</a> | ";
|
chris@389
|
1064 print WRITEFILE "<a href=\"$var{'filenameindexlonglocal'}$var{'filenameextensionindex'}$dirnamesingle{$PathContents}$var{'exthtml'}\">long</a>\n";
|
chris@389
|
1065 }
|
Chris@381
|
1066 }
|
Chris@381
|
1067 print WRITEFILE "</p>\n\n";
|
Chris@381
|
1068 print WRITEFILE "$var{'codehr'}\n";
|
Chris@381
|
1069 }
|
Chris@381
|
1070
|
Chris@381
|
1071
|
Chris@381
|
1072 #========================================================================
|
Chris@381
|
1073 # Construct the contents.m files or update
|
Chris@381
|
1074 #========================================================================
|
Chris@381
|
1075 sub ConstructContentsmFile
|
Chris@381
|
1076 {
|
Chris@381
|
1077 local($LocalActDir, @localnames) = @_;
|
Chris@381
|
1078 local(*CFILE, $name,$newline);
|
Chris@381
|
1079 local($contentsfile, $isincontentsonly);
|
Chris@381
|
1080 local(@lines, @autoaddlines, @emptylines);
|
Chris@381
|
1081 local($autoadd) = 'AutoAdd';
|
Chris@381
|
1082 local($autoaddsection) = 0;
|
Chris@381
|
1083 local($emptylineflag) = 0;
|
Chris@381
|
1084 local(%nameincontents);
|
Chris@381
|
1085
|
Chris@381
|
1086 # Build the contents file name
|
Chris@381
|
1087 $contentsfile = $LocalActDir.$contentsname{$LocalActDir}.$suffix;
|
Chris@381
|
1088
|
Chris@381
|
1089 if (-e $contentsfile) {
|
Chris@381
|
1090 open(CFILE,"<$contentsfile") || die("Cannot open contents file $contentsfile: $!\n");
|
Chris@381
|
1091 while (<CFILE>) {
|
Chris@381
|
1092 # Search for the specified string pattern
|
Chris@381
|
1093 @words = split;
|
Chris@381
|
1094 if ((@words >= 3) && ($words[2] eq '-')) {
|
Chris@381
|
1095 $isincontentsonly = 0;
|
Chris@381
|
1096 foreach $name (@localnames) {
|
Chris@381
|
1097 if ($name eq $words[1]) { # old
|
Chris@381
|
1098 # if ($mfilename{$name} eq $words[1]) {
|
Chris@381
|
1099 $isincontentsonly = 1;
|
Chris@381
|
1100 $nameincontents{$name} = 1;
|
Chris@381
|
1101 $newline = sprintf("%% %-13s - %s\n", $mfilename{$name}, $apropos{$name});
|
Chris@381
|
1102 push(@lines, $newline);
|
Chris@381
|
1103 }
|
Chris@381
|
1104 }
|
Chris@381
|
1105 # issue a warning, if file is in contents, but not as file in the directory
|
Chris@381
|
1106 if ($isincontentsonly == 0) {
|
Chris@381
|
1107 print "\rConstructContents: Obsolete entry $words[1] in $contentsfile ! Entry not used.\n";
|
Chris@381
|
1108 }
|
Chris@381
|
1109 } else {
|
Chris@381
|
1110 # look for the AutoAdd section, should be the second word
|
Chris@381
|
1111 if ((@words >= 2) && ($words[1] eq $autoadd)) { $autoaddsection = 1; }
|
Chris@381
|
1112 # push the red line in an array
|
Chris@381
|
1113 push(@lines, $_);
|
Chris@381
|
1114 }
|
Chris@381
|
1115 }
|
Chris@381
|
1116 close(CFILE);
|
Chris@381
|
1117 } else {
|
Chris@381
|
1118 $newline = "% MATLAB Files in directory $LocalActDir\n%\n";
|
Chris@381
|
1119 push(@lines, $newline);
|
Chris@381
|
1120
|
Chris@381
|
1121 }
|
Chris@381
|
1122
|
Chris@381
|
1123 # collect the file names, that were not included in original C|contents.m
|
Chris@381
|
1124 foreach $name (@localnames) {
|
Chris@381
|
1125 if (! defined $nameincontents{$name}) {
|
Chris@381
|
1126 if (! ($mfilename{$name} =~ /contents/i)) {
|
Chris@381
|
1127 $newline = sprintf("%% %-13s - %s\n", $mfilename{$name}, $apropos{$name});
|
Chris@381
|
1128 push(@autoaddlines, $newline);
|
Chris@381
|
1129 }
|
Chris@381
|
1130 }
|
Chris@381
|
1131 }
|
Chris@381
|
1132
|
Chris@381
|
1133 # write/update C|contents.m only if variable is set
|
Chris@381
|
1134 if ($var{'writecontentsm'} eq 'yes') {
|
Chris@381
|
1135 unlink($contentsfile);
|
Chris@381
|
1136 open(CFILE,">$contentsfile") || die("Cannot open contents file $contentsfile: $!\n");
|
Chris@381
|
1137 # write old C|contents.m or header of new file, as long as comment lines
|
Chris@381
|
1138 foreach $line (@lines) {
|
Chris@381
|
1139 if ($emptylineflag == 0) {
|
Chris@381
|
1140 if ($line =~ /^\s*%/) { print CFILE $line; }
|
Chris@381
|
1141 else { $emptylineflag = 1; push(@emptylines, $line); }
|
Chris@381
|
1142 } else { push(@emptylines, $line); }
|
Chris@381
|
1143 }
|
Chris@381
|
1144 # add header of AutoAdd section
|
Chris@381
|
1145 if (($autoaddsection == 0) && (@autoaddlines > 0)) { print CFILE "%\n% $autoadd\n"; }
|
Chris@381
|
1146 # add autoadd section lines (previously undocumented files
|
Chris@381
|
1147 foreach $line (@autoaddlines) { print CFILE $line; }
|
Chris@381
|
1148 # add tail of original C|contents.m (everything behind first non-comment line)
|
Chris@381
|
1149 foreach $line (@emptylines) { print CFILE $line; }
|
Chris@381
|
1150 print CFILE "\n";
|
Chris@381
|
1151 close CFILE;
|
Chris@381
|
1152 if ($opt_silent) { print "\r"; }
|
Chris@381
|
1153 print " Contents file created/updated: $contentsfile\t";
|
Chris@381
|
1154 if (!$opt_silent) { print "\n"; }
|
Chris@381
|
1155 }
|
Chris@381
|
1156 }
|
Chris@381
|
1157
|
Chris@381
|
1158
|
Chris@381
|
1159 #========================================================================
|
Chris@381
|
1160 # Replace found special characters with their HTMl Entities
|
Chris@381
|
1161 #========================================================================
|
Chris@381
|
1162 sub SubstituteHTMLEntities {
|
Chris@381
|
1163 local($_) = @_;
|
Chris@381
|
1164
|
Chris@381
|
1165 # Replace & <-> & < <-> < > <-> > " <-> "
|
Chris@381
|
1166 s/&/&/g; s/\</</g; s/\>/>/g; s/\"/"/g;
|
Chris@381
|
1167 return $_;
|
Chris@381
|
1168 }
|
Chris@381
|
1169
|
Chris@381
|
1170 #========================================================================
|
Chris@381
|
1171 # Replace found m-filenamestring with full link.
|
Chris@381
|
1172 #========================================================================
|
Chris@381
|
1173 sub SubstituteName2Link {
|
Chris@381
|
1174 local($_, $funname) = @_;
|
Chris@381
|
1175 local($refstr1, $refstr2, $reffound);
|
Chris@381
|
1176
|
Chris@381
|
1177 # Look for something matching in the line
|
Chris@381
|
1178 if ( /(\W+)($funname)(\W+)/i ) {
|
Chris@381
|
1179 $reffound = $2;
|
chris@388
|
1180 $refstr1 = "<a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$funname}$mfilename{$funname}$var{'exthtml'}\">";
|
Chris@381
|
1181 $refstr2 = "<\/a>";
|
Chris@381
|
1182 # Do links only for exact case match
|
Chris@381
|
1183 if ( ($var{'links2filescase'} eq 'exact') || ($var{'links2filescase'} eq 'exactvery') ) {
|
Chris@381
|
1184 if ( /(\W+)($funname)(\W+)/g ) {
|
Chris@381
|
1185 s/(\W+)($funname)(\W+)/$1$refstr1$funname$refstr2$3/g;
|
Chris@381
|
1186 }
|
Chris@381
|
1187 else {
|
Chris@381
|
1188 # Print info for not matching case in references, good for check up of files
|
Chris@381
|
1189 if ( ($var{'links2filescase'} eq 'exactvery') ) {
|
Chris@381
|
1190 print "Diff in case found: $funname (case of file name) <-> $reffound (case in source code)\n";
|
Chris@381
|
1191 print " (source line) $_ \n";
|
Chris@381
|
1192 }
|
Chris@381
|
1193 }
|
Chris@381
|
1194 }
|
Chris@381
|
1195 # Do links for exact match and additionally for all upper case (often used in original matlab help text)
|
Chris@381
|
1196 elsif ( ($var{'links2filescase'} eq 'exactupper') ) {
|
Chris@381
|
1197 s/(\W+)($funname)(\W+)/$1$refstr1$2$refstr2$3/g;
|
Chris@381
|
1198 $funname2 = "\U$funname\E";
|
Chris@381
|
1199 s/(\W+)($funname2)(\W+)/$1$refstr1$2$refstr2$3/g;
|
Chris@381
|
1200 }
|
Chris@381
|
1201 # Do links for all case mixes, this calls for trouble under LINUX/UNIX
|
Chris@381
|
1202 else { #elsif ( ($var{'links2filescase'} eq 'all') )
|
Chris@381
|
1203 s/(\W+)($funname)(\W+)/$1$refstr1$2$refstr2$3/ig;
|
Chris@381
|
1204 }
|
Chris@381
|
1205 }
|
Chris@381
|
1206
|
Chris@381
|
1207 return $_;
|
Chris@381
|
1208 }
|
Chris@381
|
1209
|
Chris@381
|
1210 #========================================================================
|
Chris@381
|
1211 # Construct the html files for each matlab file.
|
Chris@381
|
1212 # Need to reread each matlab file to find the help text.
|
Chris@381
|
1213 # Note that we can't do this in a single loop because sometimes
|
Chris@381
|
1214 # the help text maybe before the function declaration.
|
Chris@381
|
1215 #========================================================================
|
Chris@381
|
1216 sub ConstructHTMLFiles
|
Chris@381
|
1217 {
|
Chris@381
|
1218 local(*MFILE);
|
Chris@381
|
1219 local(*HFILE);
|
Chris@381
|
1220
|
Chris@381
|
1221 local($filescreated) = 0;
|
Chris@381
|
1222 local($functionline);
|
Chris@381
|
1223
|
Chris@381
|
1224 foreach $name (@names) {
|
Chris@381
|
1225 # Create cross reference information already here, used for keywords as well
|
Chris@381
|
1226 # Construct list of referenced functions
|
Chris@381
|
1227 @xref = @{'depcalls'.$name}; # the functions, that this m-file calls
|
Chris@381
|
1228 @yref = @{'depcalled'.$name}; # the functions, that this m-file is called from
|
Chris@381
|
1229 # print " depcalls: @{'depcalls'.$name}\n depcalled: @{'depcalled'.$name}\n";
|
Chris@381
|
1230 # foreach $cname (@names) { next if $cname eq $name; push(@yref,$cname) if grep(/$name/,@{'depcalls'.$cname}); }
|
Chris@381
|
1231
|
Chris@381
|
1232
|
Chris@381
|
1233 # Open m-file and html-file
|
Chris@381
|
1234 open(MFILE,"<$mfile{$name}");
|
Chris@381
|
1235 open(HFILE,">$hfile{$name}");
|
Chris@381
|
1236
|
Chris@381
|
1237 # Write the header of HTML file
|
Chris@381
|
1238 print HFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
Chris@381
|
1239
|
Chris@381
|
1240 # Write meta tags: use apropos (one line function description) for description
|
Chris@381
|
1241 # and cross reference function names for keywords (any better ideas?)
|
Chris@381
|
1242 print HFILE "<meta name=\"description\" content=\" $apropos{$name} \" />\n";
|
Chris@381
|
1243 print HFILE "<meta name=\"keywords\" content=\" @xref @yref \" />\n";
|
Chris@381
|
1244
|
Chris@381
|
1245 # Write Title and start body of html-file
|
Chris@381
|
1246 print HFILE "<title>$var{'texttitlefiles'} $mfilename{$name}</title>\n</head>\n";
|
Chris@381
|
1247 print HFILE "<body $var{'codebodyfiles'}>\n";
|
chris@410
|
1248 print HFILE "<div id=\"matlabdoc\">\n";
|
Chris@381
|
1249 print HFILE "<h1 $var{'codeheader'}>$var{'textheaderfiles'} $mfilename{$name}</h1>\n";
|
chris@401
|
1250
|
chris@401
|
1251 # http://test.soundsoftware.ac.uk/cannam/projects/smallbox/repository/annotate/DL/RLS-DLA/SolveFISTA.m
|
chris@410
|
1252 # print HFILE "<a href=\"" . $hfileindexpath{$name} . "../../projects/smallbox/repository/annotate/" . $mfiledir{$name} . $mfilename{$name} . ".m\">View in repository</a>\n";
|
chris@401
|
1253
|
Chris@381
|
1254 print HFILE "$var{'codehr'}\n";
|
Chris@381
|
1255
|
Chris@381
|
1256 # include links to short/long - local/global index and C|contents.m
|
Chris@381
|
1257 &ConstructLinks2Index(HFILE, $hfileindexpath{$name}, $mfiledir{$name}, 'local');
|
Chris@381
|
1258
|
Chris@381
|
1259 # If this is a function, then write out the first line as a synopsis
|
Chris@381
|
1260 if ($mtype{$name} eq "function") {
|
Chris@381
|
1261 print HFILE "<h2 $var{'codeheader'}>Function Synopsis</h2>\n";
|
Chris@381
|
1262 print HFILE "<pre>$synopsis{$name}</pre>\n$var{'codehr'}\n";
|
Chris@381
|
1263 }
|
Chris@381
|
1264
|
Chris@381
|
1265 # Look for the matlab help text block
|
Chris@381
|
1266 $functionline = "\n";
|
Chris@381
|
1267 do {
|
Chris@381
|
1268 $_ = <MFILE>;
|
Chris@381
|
1269 # remember functionline, if before help text block
|
Chris@381
|
1270 if (/^\s*function/) { $functionline = $_; }
|
Chris@381
|
1271 } until (/^\s*%/ || eof);
|
Chris@381
|
1272 if (! (eof(MFILE))) {
|
Chris@381
|
1273 print HFILE "<h2 $var{'codeheader'}>Help text</h2>\n";
|
Chris@381
|
1274 print HFILE "<pre>\n";
|
Chris@381
|
1275 while (/^\s*%/) {
|
Chris@381
|
1276 # First remove leading % and white space, then Substitute special characlers
|
Chris@381
|
1277 s/^\s*%//;
|
Chris@381
|
1278 $_ = &SubstituteHTMLEntities($_);
|
Chris@381
|
1279
|
Chris@381
|
1280 # check/create cross references
|
Chris@381
|
1281 foreach $funname (@{'all'.$name}) {
|
Chris@381
|
1282 if ($funname =~ /simulink/) { print "\n Simulink - Filename: $name; scanname: $funname\n"; }
|
Chris@381
|
1283 next if $funname eq $name;
|
Chris@381
|
1284 $_ = &SubstituteName2Link($_, $funname);
|
Chris@381
|
1285 }
|
Chris@381
|
1286 print HFILE $_;
|
Chris@381
|
1287 if (! eof) { $_ = <MFILE>; }
|
Chris@381
|
1288 }
|
Chris@381
|
1289 print HFILE "</pre>\n$var{'codehr'}\n";
|
Chris@381
|
1290 }
|
Chris@381
|
1291
|
Chris@381
|
1292 # Write the cross reference information
|
Chris@381
|
1293 if (@xref || @yref) {
|
Chris@381
|
1294 print HFILE "<h2 $var{'codeheader'}>Cross-Reference Information</H2>\n";
|
Chris@381
|
1295 print HFILE "<table border=\"0\" width=\"100%\">\n<tr align=\"left\">\n<th width=\"50%\">";
|
Chris@381
|
1296 if (@xref) {
|
Chris@381
|
1297 print HFILE "This $mtype{$name} calls";
|
Chris@381
|
1298 }
|
Chris@381
|
1299 print HFILE "</th>\n<th width=\"50%\">";
|
Chris@381
|
1300 if (@yref) {
|
Chris@381
|
1301 print HFILE "This $mtype{$name} is called by";
|
Chris@381
|
1302 }
|
Chris@381
|
1303 print HFILE "</th>\n</tr>\n<tr valign=\"top\"><td>";
|
Chris@381
|
1304 if (@xref) {
|
Chris@381
|
1305 print HFILE "\n<ul>\n";
|
Chris@381
|
1306 foreach $cname (sort @xref) {
|
Chris@381
|
1307 print HFILE "<li><a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$cname}$mfilename{$cname}$var{'exthtml'}\">$mfilename{$cname}</a></li>\n";
|
Chris@381
|
1308 }
|
Chris@381
|
1309 print HFILE "</ul>\n";
|
Chris@381
|
1310 }
|
Chris@381
|
1311 print HFILE "</td><td>";
|
Chris@381
|
1312 if (@yref) {
|
Chris@381
|
1313 print HFILE "\n<ul>\n";
|
Chris@381
|
1314 foreach $cname (sort @yref) {
|
Chris@381
|
1315 print HFILE "<li><a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$cname}$mfilename{$cname}$var{'exthtml'}\">$mfilename{$cname}</a></li>\n";
|
Chris@381
|
1316 }
|
Chris@381
|
1317 print HFILE "</ul>\n";
|
Chris@381
|
1318 }
|
Chris@381
|
1319 print HFILE "</td>\n</tr>\n</table>\n";
|
Chris@381
|
1320 print HFILE "$var{'codehr'}\n";
|
Chris@381
|
1321 }
|
Chris@381
|
1322
|
Chris@381
|
1323 # Include source text if requested
|
Chris@381
|
1324 if (($var{'includesource'} eq 'yes') && (! ($mfilename{$name} =~ /^contents$/i))) {
|
Chris@381
|
1325 print HFILE "<h2 $var{'codeheader'}>Listing of $mtype{$name} $mfilename{$name}</h2>\n";
|
Chris@381
|
1326 seek(MFILE,0,0);
|
Chris@381
|
1327 print HFILE "<pre>\n";
|
Chris@381
|
1328 $IsStillHelp = 2;
|
Chris@381
|
1329 print HFILE $functionline; # functionline from scanning of help
|
Chris@381
|
1330 while (<MFILE>) {
|
Chris@381
|
1331 if ($IsStillHelp == 2) {
|
Chris@381
|
1332 next if (/^\s*$/);
|
Chris@381
|
1333 next if (/^\s*function/);
|
Chris@381
|
1334 if (/^\s*%/) { $IsStillHelp = 1; next; }
|
Chris@381
|
1335 } elsif ($IsStillHelp == 1) {
|
Chris@381
|
1336 next if (/^\s*%/);
|
Chris@381
|
1337 $IsStillHelp = 0;
|
Chris@381
|
1338 }
|
Chris@381
|
1339
|
Chris@381
|
1340 # Substritute special characters
|
Chris@381
|
1341 $_ = &SubstituteHTMLEntities($_);
|
Chris@381
|
1342
|
Chris@381
|
1343 # check for comment in line and format with css em
|
chris@400
|
1344 s/^(.*)%(.*?)([\s\r\n]+)$/$1<em class=\"mcom\">%$2<\/em>$3/;
|
Chris@381
|
1345
|
Chris@381
|
1346 # check/create cross references
|
Chris@381
|
1347 foreach $funname (@{'all'.$name}) {
|
Chris@381
|
1348 next if $funname eq $name;
|
Chris@381
|
1349 $_ = &SubstituteName2Link($_, $funname);
|
Chris@381
|
1350 }
|
Chris@381
|
1351 print HFILE $_;
|
Chris@381
|
1352 }
|
Chris@381
|
1353 print HFILE "</pre>\n$var{'codehr'}\n";
|
Chris@381
|
1354 }
|
Chris@381
|
1355
|
Chris@381
|
1356 # Include info about author from authorfile
|
Chris@381
|
1357 &WriteFile2Handle($var{'authorfile'}, HFILE) ;
|
Chris@381
|
1358
|
Chris@381
|
1359 print HFILE "<!--navigate-->\n";
|
Chris@381
|
1360 print HFILE "<!--copyright-->\n";
|
chris@410
|
1361 print HFILE "</div>\n</body>\n</html>\n";
|
Chris@381
|
1362 close(MFILE);
|
Chris@381
|
1363 close(HFILE);
|
Chris@381
|
1364
|
Chris@381
|
1365 # Print name of finished file
|
Chris@381
|
1366 if ($opt_silent) { print "\r"; }
|
Chris@381
|
1367 print " HTML-File created: $hfile{$name}\t";
|
Chris@381
|
1368 if (!$opt_silent) { print "\n"; }
|
Chris@381
|
1369 $filescreated++;
|
Chris@381
|
1370 }
|
Chris@381
|
1371
|
Chris@381
|
1372 print "\n$PROGRAM: $indexcreated index and $filescreated files created.\n";
|
Chris@381
|
1373 }
|
Chris@381
|
1374
|
Chris@381
|
1375 #========================================================================
|
Chris@381
|
1376 # Function: CheckFileName
|
Chris@381
|
1377 # Purpose: .
|
Chris@381
|
1378 #========================================================================
|
Chris@381
|
1379 sub CheckFileName {
|
Chris@381
|
1380 local($filename, $description) = @_;
|
Chris@381
|
1381 local(*CHECKFILE);
|
Chris@381
|
1382
|
Chris@381
|
1383 open(CHECKFILE,"<$filename") || do {
|
Chris@381
|
1384 if ($description eq '') {$description = 'file';}
|
Chris@381
|
1385 # if (!$opt_silent) { print "Cannot open $description $filename: $!\n"; }
|
Chris@381
|
1386 print "Cannot open $description $filename: $!\n";
|
Chris@381
|
1387 return 1;
|
Chris@381
|
1388 };
|
Chris@381
|
1389 close(CHECKFILE);
|
Chris@381
|
1390 return 0;
|
Chris@381
|
1391
|
Chris@381
|
1392 }
|
Chris@381
|
1393
|
Chris@381
|
1394 #========================================================================
|
Chris@381
|
1395 # Function: CheckDirName
|
Chris@381
|
1396 # Purpose: .
|
Chris@381
|
1397 #========================================================================
|
Chris@381
|
1398 sub CheckDirName {
|
Chris@381
|
1399 local($dirname, $description) = @_;
|
Chris@381
|
1400 local(*CHECKDIR);
|
Chris@381
|
1401
|
Chris@381
|
1402 opendir(CHECKDIR,"$dirname") || die ("Cannot open $description directory $dirname: $!\n");
|
Chris@381
|
1403 closedir(CHECKDIR);
|
Chris@381
|
1404 }
|
Chris@381
|
1405
|
Chris@381
|
1406 #========================================================================
|
Chris@381
|
1407 # Function: WriteFile2Handle
|
Chris@381
|
1408 # Purpose: .
|
Chris@381
|
1409 #========================================================================
|
Chris@381
|
1410 sub WriteFile2Handle {
|
Chris@381
|
1411 local($filename, *WRITEFILE) = @_;
|
Chris@381
|
1412 local(*READFILE);
|
Chris@381
|
1413
|
Chris@381
|
1414 if ($filename ne '') {
|
Chris@381
|
1415 open(READFILE,"<$filename");
|
Chris@381
|
1416 @filecontents = <READFILE>;
|
Chris@381
|
1417 close(READFILE);
|
Chris@381
|
1418 print WRITEFILE "@filecontents\n";
|
Chris@381
|
1419 # if (!$opt_silent) {print " Contents of $filename added\n"};
|
Chris@381
|
1420 }
|
Chris@381
|
1421 }
|
Chris@381
|
1422
|
Chris@381
|
1423
|
Chris@381
|
1424 #========================================================================
|
Chris@381
|
1425 # Function: GetConfigFile
|
Chris@381
|
1426 # Purpose: Read user's configuration file, if such exists.
|
Chris@381
|
1427 #========================================================================
|
Chris@381
|
1428 sub GetConfigFile
|
Chris@381
|
1429 {
|
Chris@381
|
1430 local($filename) = @_;
|
Chris@381
|
1431 local(*CONFIG);
|
Chris@381
|
1432 local($value);
|
Chris@381
|
1433
|
Chris@381
|
1434 if (&CheckFileName($filename, 'configuration file')) {
|
Chris@381
|
1435 # if (!$opt_silent) { print " Proceeding using built-in defaults for configuration.\n"; }
|
Chris@381
|
1436 print " Proceeding using built-in defaults for configuration.\n";
|
Chris@381
|
1437 return 0;
|
Chris@381
|
1438 };
|
Chris@381
|
1439
|
Chris@381
|
1440 open(CONFIG,"< $filename");
|
Chris@381
|
1441 while (<CONFIG>) {
|
Chris@381
|
1442 s/#.*$//;
|
Chris@381
|
1443 next if /^\s*$/o;
|
Chris@381
|
1444
|
Chris@381
|
1445 # match keyword: process one or more arguments
|
Chris@381
|
1446 # keyword set
|
Chris@381
|
1447 if (/^\s*set\s+(\S+)\s*=\s*(.*)/) {
|
Chris@381
|
1448 # setting a configuration variable
|
Chris@381
|
1449 if (defined $var{$1}) {
|
Chris@381
|
1450 $var{$1} = $2;
|
Chris@381
|
1451 if ($debug > 3) { print "$1: $var{$1}\n"; }
|
Chris@381
|
1452 }
|
Chris@381
|
1453 else {
|
Chris@381
|
1454 print "$PROGRAM: unknown variable `$1' in configuration file\n"
|
Chris@381
|
1455 }
|
Chris@381
|
1456 } else {
|
Chris@381
|
1457 chop($_);
|
Chris@381
|
1458 print "$PROGRAM: unknown keyword in configuration file in line: `$_'\n"
|
Chris@381
|
1459 }
|
Chris@381
|
1460 }
|
Chris@381
|
1461 close CONFIG;
|
Chris@381
|
1462 1;
|
Chris@381
|
1463 }
|
Chris@381
|
1464
|
Chris@381
|
1465
|
Chris@381
|
1466 #------------------------------------------------------------------------
|
Chris@381
|
1467 # DisplayHelp - display help text using -h or -help command-line switch
|
Chris@381
|
1468 #------------------------------------------------------------------------
|
Chris@381
|
1469 sub DisplayHelp
|
Chris@381
|
1470 {
|
Chris@381
|
1471 $help=<<EofHelp;
|
Chris@381
|
1472 $PROGRAM v$VERSION - generate html documentation from Matlab m-files
|
Chris@381
|
1473
|
Chris@381
|
1474 Usage: $PROGRAM [-h] [-c config_file] [-m|dirmfiles matlab_dir] [-d|dirhtml html_dir]
|
Chris@381
|
1475 [-i yes|no] [-r yes|no] [-p yes|no] [-quiet|q] [-a authorfile]
|
Chris@381
|
1476
|
Chris@381
|
1477 $PROGRAM is a perl script that reads each matlab .m file in a directory
|
Chris@381
|
1478 to produce a corresponding .html file of help documentation and cross
|
Chris@381
|
1479 reference information. An index file is written with links to all of
|
Chris@381
|
1480 the html files produced. The options are:
|
Chris@381
|
1481
|
Chris@381
|
1482 -quiet or -q : be silent, no status information during generation
|
Chris@381
|
1483 -help or -h : display this help message
|
Chris@381
|
1484 -todo or -t : print the todo list for $PROGRAM
|
Chris@381
|
1485 -version or -v : display version
|
Chris@381
|
1486
|
Chris@381
|
1487 -configfile or -c : name of configuration file (default to $var{'configfile'}).
|
Chris@381
|
1488 -dirmfiles or -m : top level directory containing matlab files to generate html for;
|
Chris@381
|
1489 default to actual directory.
|
Chris@381
|
1490 -dirhtml or -d : top level directory for generated html files;
|
Chris@381
|
1491 default to actual directory.
|
Chris@381
|
1492
|
Chris@381
|
1493 -includesource or -i : Include matlab source in the html documentation [yes|no]
|
Chris@381
|
1494 default to yes.
|
Chris@381
|
1495 -processtree or -r : create docu for m-file directory and all subdirectories [yes|no];
|
Chris@381
|
1496 default to yes.
|
Chris@381
|
1497 -producetree or -p : create multi-level docu identical to directory structure
|
Chris@381
|
1498 of m-files [yes|no]; default to yes.
|
Chris@381
|
1499 -writecontentsm or -w: update or write contents.m files into the matlab source
|
Chris@381
|
1500 directories [yes|no]; default to no.
|
Chris@381
|
1501
|
Chris@381
|
1502 -authorfile or -a : name of file including author information, last element in html;
|
Chris@381
|
1503 default to empty.
|
Chris@381
|
1504
|
Chris@381
|
1505 The command line setting overwrite all other settings (built-in and configuration file).
|
Chris@381
|
1506 The configuration file settings overwrite the built-in settings (and not the command
|
Chris@381
|
1507 line settings).
|
Chris@381
|
1508
|
Chris@381
|
1509 Typical usages are:
|
Chris@381
|
1510 $PROGRAM
|
Chris@381
|
1511 (use default parameters from perl script, if configuration
|
Chris@381
|
1512 file is found -> generation of docu, else display of help)
|
Chris@381
|
1513
|
Chris@381
|
1514 $PROGRAM -dirmfiles matlab -dirhtml html
|
Chris@381
|
1515 (generate html documentation for all m-files in directory matlab,
|
Chris@381
|
1516 place html files in directory html, use built-in defaults for
|
Chris@381
|
1517 all other parameters, this way all m-files in the directory
|
Chris@381
|
1518 matlab and below are converted and the generated html-files are
|
Chris@381
|
1519 placed in the directory html and below producing the same
|
Chris@381
|
1520 directory structure than below matlab)
|
Chris@381
|
1521
|
Chris@381
|
1522 $PROGRAM -quiet
|
Chris@381
|
1523 (use built-in parameters from perl script, if configuration
|
Chris@381
|
1524 file is found use these settings as well, do generation,
|
Chris@381
|
1525 no display except critical errors, status of conversion and result)
|
Chris@381
|
1526
|
Chris@381
|
1527 $PROGRAM -m toolbox -dirhtml doc/html -r yes -p no
|
Chris@381
|
1528 (convert all m-files in directory toolbox and below and place
|
Chris@381
|
1529 the generated html files in directory doc/html, read all m-files
|
Chris@381
|
1530 recursively, however, the generated html files are placed in one
|
Chris@381
|
1531 directory)
|
Chris@381
|
1532
|
Chris@381
|
1533 $PROGRAM -m toolbox -dirhtml doc/html -i no -r no
|
Chris@381
|
1534 (convert all m-files in directory toolbox and place
|
Chris@381
|
1535 the generated html files in directory doc/html, do not read m-files
|
Chris@381
|
1536 recursively, do not include source code in documentation)
|
Chris@381
|
1537
|
Chris@381
|
1538 EofHelp
|
Chris@381
|
1539
|
Chris@381
|
1540 die "$help";
|
Chris@381
|
1541 }
|
Chris@381
|
1542
|
Chris@381
|
1543 #------------------------------------------------------------------------
|
Chris@381
|
1544 # DisplayTodo - display ToDo list using -t or -todo command-line switch
|
Chris@381
|
1545 #------------------------------------------------------------------------
|
Chris@381
|
1546 sub DisplayTodo
|
Chris@381
|
1547 {
|
Chris@381
|
1548 $todo=<<EofToDo;
|
Chris@381
|
1549 $PROGRAM v$VERSION - ToDo list
|
Chris@381
|
1550
|
Chris@381
|
1551 o use more than one high level directory
|
Chris@381
|
1552
|
Chris@381
|
1553 o what should/could be done here???
|
Chris@381
|
1554
|
Chris@381
|
1555 EofToDo
|
Chris@381
|
1556
|
Chris@381
|
1557 die "$todo";
|
Chris@381
|
1558 }
|
Chris@381
|
1559
|
Chris@381
|
1560
|
Chris@381
|
1561 #------------------------------------------------------------------------
|
Chris@381
|
1562 # ListVariables - list all defined variables and their values
|
Chris@381
|
1563 #------------------------------------------------------------------------
|
Chris@381
|
1564 sub ListVariables
|
Chris@381
|
1565 {
|
Chris@381
|
1566 local($value);
|
Chris@381
|
1567
|
Chris@381
|
1568 if ($debug > 0) {
|
Chris@381
|
1569 print "List of all variables and their values\n";
|
Chris@381
|
1570 foreach (sort keys %var)
|
Chris@381
|
1571 {
|
Chris@381
|
1572 if ($var{$_} eq '') {
|
Chris@381
|
1573 $value = "empty";
|
Chris@381
|
1574 } else {
|
Chris@381
|
1575 $value = $var{$_};
|
Chris@381
|
1576 }
|
Chris@381
|
1577 print " $_\n $value\n";
|
Chris@381
|
1578 }
|
Chris@381
|
1579 print "\n\n";
|
Chris@381
|
1580 }
|
Chris@381
|
1581 }
|
Chris@381
|
1582
|
Chris@381
|
1583
|
Chris@381
|
1584 __END__
|
Chris@381
|
1585 :endofperl
|