To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / extra / soundsoftware / matlab-docs.pl @ 381:2dc8163e9150

History | View | Annotate | Download (62.2 KB)

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