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 @ 383:47ae83ce8db8

History | View | Annotate | Download (63.7 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 382:baff1c482d98 Chris
#!/usr/bin/perl
9 381:2dc8163e9150 Chris
#
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 383:47ae83ce8db8 Chris
#	   29.03.2011  (Chris Cannam) add frames option.
75 381:2dc8163e9150 Chris
76
$VERSION  = '1.23';
77
($PROGRAM = $0) =~ s@.*/@@; $PROGRAM = "\U$PROGRAM\E";
78
$debug = 0;
79
80
#------------------------------------------------------------------------
81
# Define platform specific things
82
#------------------------------------------------------------------------
83
# suffix for files to search is defined twice
84
# the first ($suffix) is for string creation and contains the . as well
85
# the second ($suffixforsearch) is for regular expression, handling of . is quite special
86
$suffix = ".m";
87
$suffixforsearch = "m";
88
# the directory separator
89
$dirsep = "/";
90
# what is the current directory
91
$diract = ".";
92
93
#------------------------------------------------------------------------
94 382:baff1c482d98 Chris
#  Define all variables and their standard settings
95 381:2dc8163e9150 Chris
#  documentation of variables is contained in accompanying rc file
96
#------------------------------------------------------------------------
97
%var =
98
(
99
   'authorfile',                '',
100
   'codebodyfiles',             '',
101
   'codebodyindex',             '',
102
   'codeheadmeta',              '<meta name="author of conversion perl script" content="Hartmut Pohlheim" />',
103
   'codehr',                    '<hr size="3" noshade="noshade" />',
104
   'codeheader',                '',
105 383:47ae83ce8db8 Chris
   'configfile',                'matlab-docs.conf',
106 381:2dc8163e9150 Chris
   'csslink',                   '',
107
   'dirmfiles',                 $diract,
108
   'dirhtml',                   $diract,
109
   'exthtml',                   '.html',
110 382:baff1c482d98 Chris
   'frames',                    'yes',
111 381:2dc8163e9150 Chris
   'filenametopframe',          'index',
112
   'filenameindexlongglobal',   'indexlg',
113
   'filenameindexlonglocal',    'indexll',
114
   'filenameindexshortglobal',  'indexsg',
115
   'filenameindexshortlocal',   'indexsl',
116
   'filenameextensionframe',    'f',
117
   'filenameextensionindex',    'i',
118
   'filenameextensionjump',     'j',
119
   'filenamedirshort',          'dirtops',
120
   'filenamedirlong',           'dirtopl',
121
   'filenamedircontents',       'dirtopc',
122
   'includesource',             'yes',
123
   'links2filescase',           'all',
124
   'processtree',               'yes',
125
   'producetree',               'yes',
126
   'textjumpindexlocal',        'Local Index',
127
   'textjumpindexglobal',       'Global Index',
128
   'texttitleframelayout',      'Documentation of Matlab Files',
129
   'texttitleindexalldirs',     'Index of Directories',
130
   'textheaderindexalldirs',    'Index of Directories',
131
   'texttitleindex',            '',
132
   'textheaderindex',           '',
133
   'texttitlefiles',            'Documentation of ',
134
   'textheaderfiles',           'Documentation of ',
135
   'usecontentsm',              'yes',
136
   'writecontentsm',            'no'
137
);
138
139
140
# define all m-file names, that should be excluded from linking
141
# however, files will still be converted
142
@excludenames = ( 'all','ans','any','are',
143
                  'cs',
144
                  'demo','dos',
145
                  'echo','edit','else','elseif','end','exist',
146
                  'flag','for','function',
147
                  'global',
148
                  'help',
149
                  'i','if','inf','info',
150
                  'j',
151
                  'more',
152
                  'null',
153
                  'return',
154
                  'script','strings',
155
                  'what','which','while','who','whos','why',
156
                );
157
158
# Text for inclusion in created HTML/Frame files: Doctype and Charset
159
$TextDocTypeHTML  = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">';
160
$TextDocTypeFrame = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">';
161
$TextMetaCharset = '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />';
162
163
#------------------------------------------------------------------------
164
# Read the command line arguments
165
#------------------------------------------------------------------------
166
if (@ARGV == 0) {
167
   &DisplayHelp()  if &CheckFileName($var{'configfile'}, 'configuration file');
168
}
169
170
# Print provided command line arguments on screen
171
foreach (@ARGV) { print "   $_\n      "; }
172
173
# Get the options
174
use Getopt::Long;
175
@options = ('help|h', 'todo|t', 'version|v',
176
            'authorfile|a=s', 'configfile|c=s', 'dirhtml|html|d=s',
177
            'dirmfiles|mfiles|m=s', 'includesource|i=s',
178
            'processtree|r=s', 'producetree|p=s',
179
            'silent|quiet|q', 'writecontentsm|w=s');
180
&GetOptions(@options) || die "use -h switch to display help statement\n";
181
182
183
# Display help or todo list, when requested
184
&DisplayHelp()                         if $opt_help;
185
&DisplayTodo()                         if $opt_todo;
186
die "$PROGRAM v$VERSION\n"             if $opt_version;
187
188
$exit_status = 0;
189
190
#------------------------------------------------------------------------
191
# Read the config file
192
#------------------------------------------------------------------------
193
$var{'configfile'} = $opt_configfile         if $opt_configfile;
194
&GetConfigFile($var{'configfile'});
195
196
197
#------------------------------------------------------------------------
198
# Process/Check the command line otions
199
#------------------------------------------------------------------------
200
$var{'dirhtml'}   = $opt_dirhtml              if $opt_dirhtml;
201
if (!(substr($var{'dirhtml'}, -1, 1) eq $dirsep)) { $var{'dirhtml'} = $var{'dirhtml'}.$dirsep; }
202
$var{'dirmfiles'} = $opt_dirmfiles            if $opt_dirmfiles;
203
if (!(substr($var{'dirmfiles'}, -1, 1) eq $dirsep)) { $var{'dirmfiles'} = $var{'dirmfiles'}.$dirsep; }
204
205
$var{'authorfile'} = $opt_author              if $opt_author;
206
$var{'includesource'} = $opt_includesource    if $opt_includesource;
207
if ($var{'includesource'} ne 'no') { $var{'includesource'} = 'yes'; }
208
$var{'processtree'} = $opt_processtree        if $opt_processtree;
209
if ($var{'processtree'} ne 'no') { $var{'processtree'} = 'yes'; }
210
$var{'producetree'} = $opt_producetree        if $opt_producetree;
211
if ($var{'producetree'} ne 'no') { $var{'producetree'} = 'yes'; }
212
if ($var{'processtree'} eq 'no') { $var{'producetree'} = 'no'; }
213 382:baff1c482d98 Chris
if ($var{'frames'} ne 'no') { $var{'frames'} = 'yes'; }
214 381:2dc8163e9150 Chris
# 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 382:baff1c482d98 Chris
   if ($var{'frames'} eq 'yes') {
646 381:2dc8163e9150 Chris
647 382:baff1c482d98 Chris
       open(IFILE,">$indexfile") || die("Cannot open frame layout file $indexfile\n");
648 381:2dc8163e9150 Chris
649 382:baff1c482d98 Chris
       # Write the header of frame file
650
       print IFILE "$TextDocTypeFrame\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n";
651
       print IFILE "   <title>$var{'texttitleframelayout'}</title>\n";
652
       print IFILE "</head>\n";
653 381:2dc8163e9150 Chris
654 382:baff1c482d98 Chris
       # definition of 2 frames, left the tree of directories,
655
       # right the index of that directory or the docu of a file
656
       print IFILE "<frameset  cols=\"25%,75%\">\n";
657
       print IFILE "   <frame src=\"$var{'filenamedirshort'}$var{'exthtml'}\" name=\"$GlobalNameFrameMainLeft\" />\n";
658
       print IFILE "   <frame src=\"$var{'filenameindexshortglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\" name=\"$GlobalNameFrameMainRight\" />\n";   print IFILE "</frameset>\n";
659 381:2dc8163e9150 Chris
660 382:baff1c482d98 Chris
       print IFILE "</html>\n";
661
662
       close(IFILE);
663
664
       if ($opt_silent) { print "\r"; }
665
       print "   Frame layout file created: $indexfile\t";
666
       if (!$opt_silent) { print "\n"; }
667
   }
668 381:2dc8163e9150 Chris
669
   for($irun=0; $irun <= 2; $irun++) {
670
      # Build the top directory index file, these files include the directory tree
671
      # Build the directory tree index file name
672
673
      # Create no directory file for contents, when no contents to use
674
      if (($irun == 2) && ($var{'usecontentsm'} eq 'no')) { next; }
675
676
      # Assign the correct index file name
677
      if ($irun == 0) { $filename = $var{'filenamedirshort'}; }
678
      elsif ($irun == 1) { $filename = $var{'filenamedirlong'}; }
679
      elsif ($irun == 2) { $filename = $var{'filenamedircontents'}; }
680
681
      $indexfile = $var{'dirhtml'}.$filename.$var{'exthtml'};
682
683
      open(IFILE,">$indexfile") || die("Cannot open directory tree index file $indexfile\n");
684
      # Write header of HTML file
685
      print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
686
687
      if ($var{'texttitleindexalldirs'} eq '') {
688
         print IFILE "<title>Index of Directories of $var{'dirmfiles'}</title>\n";
689
      } else {
690
         print IFILE "<title>$var{'texttitleindexalldirs'}</title>\n";
691
      }
692 382:baff1c482d98 Chris
693
      if ($var{'frames'} eq 'yes') {
694
	  print IFILE "<base target=\"$GlobalNameFrameMainRight\" />\n";
695
      }
696
697 381:2dc8163e9150 Chris
      print IFILE "</head>\n";
698
      print IFILE "<body $var{'codebodyindex'}>\n";
699
      if ($var{'textheaderindexalldirs'} eq '') {
700
         print IFILE "<h1 $var{'codeheader'}>Index of Directories of <em>$var{'dirmfiles'}</em></h1>\n";
701
      } else {
702
         print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindexalldirs'}</h1>\n";
703
      }
704
      print IFILE "<p align=\"center\">\n";
705 382:baff1c482d98 Chris
706
      if ($var{'frames'} eq 'yes') {
707
	  if ($irun == 0) { print IFILE "<strong>short</strong>\n"; }
708
	  else { print IFILE "<a href=\"$var{'filenamedirshort'}$var{'exthtml'}\" target=\"$GlobalNameFrameMainLeft\">short</a>\n"; }
709
	  if ($irun == 1) { print IFILE " | <strong>long</strong>\n"; }
710
	  else { print IFILE " | <a href=\"$var{'filenamedirlong'}$var{'exthtml'}\" target=\"$GlobalNameFrameMainLeft\">long</a>\n"; }
711
	  if ($var{'usecontentsm'} eq 'yes') {
712
	      if ($irun == 2) { print IFILE " | <strong>contents</strong>\n"; }
713
	      else { print IFILE " | <a href=\"$var{'filenamedircontents'}$var{'exthtml'}\" target=\"$GlobalNameFrameMainLeft\">contents</a>\n"; }
714
	  }
715
      } else {
716
	  if ($irun == 0) { print IFILE "<strong>short</strong>\n"; }
717
	  else { print IFILE "<a href=\"$var{'filenamedirshort'}$var{'exthtml'}\">short</a>\n"; }
718
	  if ($irun == 1) { print IFILE " | <strong>long</strong>\n"; }
719
	  else { print IFILE " | <a href=\"$var{'filenamedirlong'}$var{'exthtml'}\">long</a>\n"; }
720
	  if ($var{'usecontentsm'} eq 'yes') {
721
	      if ($irun == 2) { print IFILE " | <strong>contents</strong>\n"; }
722
	      else { print IFILE " | <a href=\"$var{'filenamedircontents'}$var{'exthtml'}\">contents</a>\n"; }
723
	  }
724 381:2dc8163e9150 Chris
      }
725
726
      print IFILE "</p><br />\n\n";
727
      print IFILE "<ul>\n";
728
729
      # go through all directories and create a list entry for each one,
730
      # depending on recursion level create sublists
731
      $prevrecdeeplevel = 0;
732
      foreach $name (@alldirectories) {
733
         $actrecdeeplevel = $dirnamerecdeep{$name};
734
         for( ; $prevrecdeeplevel < $actrecdeeplevel; $prevrecdeeplevel++ ) { print IFILE "<ul>\n"; }
735
         for( ; $prevrecdeeplevel > $actrecdeeplevel; $prevrecdeeplevel-- ) { print IFILE "</ul>\n"; }
736
         if ($irun == 0) { $indexfilenameused = $var{'filenameindexshortlocal'}.$var{'filenameextensionframe'}; }
737
         elsif ($irun == 1) { $indexfilenameused = $var{'filenameindexlonglocal'}.$var{'filenameextensionframe'}; }
738
         elsif ($irun == 2) { $indexfilenameused = $contentsname{$name}; }
739
         else { die "ConstructHighestIndexFile: Unknown value of irun"; }
740
         if ($dirnumbermfiles{$name} > 0) {
741
            # producetree no
742
            # if ($var{'producetree'} eq 'no') { $dirnamehere = ''; }
743
            # else { $dirnamehere = '$dirnamerelpath{$name}'; }
744
            # print IFILE "<LI><A HREF=\"$dirnamehere$indexfilenameused_$dirnamesingle{$name}$var{'exthtml'}\">$dirnamesingle{$name}</A>\n";
745
            print IFILE "<li><a href=\"$dirnamerelpath{$name}$indexfilenameused$dirnamesingle{$name}$var{'exthtml'}\">$dirnamesingle{$name}</a></li>\n";
746
         } else {
747
            # print directories with no m-files inside not
748
            # print IFILE "<li>$dirnamesingle{$name}</li>\n";
749
         }
750
      }
751
      $actrecdeeplevel = 0;
752
      for( ; $prevrecdeeplevel > $actrecdeeplevel; $prevrecdeeplevel-- ) { print IFILE "</ul>\n"; }
753
      print IFILE "</ul>\n<br />$var{'codehr'}\n";
754
755
      # Include info about author from authorfile
756
      &WriteFile2Handle($var{'authorfile'}, IFILE);
757
758
      print IFILE "<!--navigate-->\n";
759
      print IFILE "<!--copyright-->\n";
760
      print IFILE "</body>\n</html>\n";
761
762
      close(IFILE);
763
764
      if ($opt_silent) { print "\r"; }
765
      print "   Directory - Indexfile created: $indexfile\t";
766
      if (!$opt_silent) { print "\n"; }
767
   }
768
}
769
770
771
#========================================================================
772
# Construct the A-Z index file (global/local and/or short/long)
773
#========================================================================
774
sub ConstructAZIndexFile
775
{
776
   local($LocalActDir, $LocalShortLong, $LocalGlobalLocal, @localnames) = @_;
777
   local(*IFILE);
778
   local($name, $indexfilename, $dirpath);
779
   local($firstletter, $firstone);
780
781
   if ($debug > 2) { print "localnames in AZ small: @localnames\n"; print "     ActDir in A-Z: $LocalActDir\n"; }
782
783
   # extract filename of index file from parameters of function
784
   if ($LocalShortLong eq 'short') {
785
      if ($LocalGlobalLocal eq 'global') { $indexfilename = $var{'filenameindexshortglobal'}; }
786
      elsif ($LocalGlobalLocal eq 'local') { $indexfilename = $var{'filenameindexshortlocal'}; }
787
      else { die "wrong parameter for LocalGlobalLocal in ConstructAZIndexFile: $LocalGlobalLocal."; }
788
   } elsif ($LocalShortLong eq 'long') {
789
      if ($LocalGlobalLocal eq 'global') { $indexfilename = $var{'filenameindexlongglobal'}; }
790
      elsif ($LocalGlobalLocal eq 'local') { $indexfilename = $var{'filenameindexlonglocal'}; }
791
      else { die "wrong parameter for LocalGlobalLocal in ConstructAZIndexFile: $LocalGlobalLocal."; }
792
   } else { die "wrong parameter for LocalShortLong in ConstructAZIndexFile: $LocalShortLong."; }
793
794
   # producetree no
795
   # if ($var{'producetree'} eq 'no') { $dirnamehere = ''; }
796
   # else { $dirnamehere = '$dirnamerelpath{$LocalActDir}'; }
797
   # Build the index file name
798
   # handle the global index file case separately (no extra directory name in file)
799
   #    the local index file name must be extended by the name of the directory
800
   if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
801
   else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
802
   $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionindex'}.$extradirfilename.$var{'exthtml'};
803 382:baff1c482d98 Chris
804
   if ($LocalShortLong eq 'short' and $var{'frames'} ne 'yes') {
805
       # With no frames, this must go in the top-level index file instead
806
       $indexfile = $var{'dirhtml'}.$var{'filenametopframe'}.$var{'exthtml'};
807
   }
808
809 381:2dc8163e9150 Chris
   if ($debug > 2) { print "   indexfilename (a-z small): $indexfile\n"; }
810
811
   open(IFILE,">$indexfile") || die("Cannot open index file $indexfile: $!\n");
812
813
   # Write the header of HTML file
814
   print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
815
816
   if ($var{'texttitleindex'} eq '') {
817
      print IFILE "<title>Index of Matlab Files in Directory $LocalActDir</title>\n";
818
   } else {
819
      if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
820
      else { print IFILE "<title>$var{'texttitleindex'} in Directory $LocalActDir</title>\n"; }
821
   }
822 382:baff1c482d98 Chris
823
   if ($var{'frames'} eq 'yes') {
824
       print IFILE "<base target=\"$GlobalNameFrameMainRight\" />\n";
825
   }
826 381:2dc8163e9150 Chris
   print IFILE "</head>\n";
827 382:baff1c482d98 Chris
828 381:2dc8163e9150 Chris
   print IFILE "<body $var{'codebodyindex'}>\n";
829
   if ($var{'textheaderindex'} eq '') {
830
      print IFILE "<h1 $var{'codeheader'}>Index of Matlab Files in Directory $LocalActDir</h1>\n";
831
   } else {
832
      if ($LocalGlobalLocal eq 'global') { print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindex'}</h1>\n"; }
833
      else { print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindex'} in Directory $LocalActDir</h1>\n"; }
834
   }
835
836
   # include links to indexes
837
   &ConstructLinks2Index(IFILE, $dirnamerelpathtoindex{$LocalActDir}, $LocalActDir, $LocalGlobalLocal);
838
839
   # Collect the starting letters of m files in this directory or all m-files
840
   for('a'..'z') { undef @{$_}; }
841
   foreach $name (@localnames) {
842
      if (! ($mfilename{$name} =~ /contents/i)) {
843
         $firstletter = substr($mfilename{$name}, 0, 1);
844
         # convert first letter always to lower case
845
         # needed for reference to lower and upper case m-files
846
         $firstletter = "\L$firstletter\E";
847
         push(@{$firstletter}, $name);
848
      }
849
   }
850
851
   if ($LocalShortLong eq 'short') {
852
      # begin create short index
853
      print IFILE "<table width=\"100%\">\n";
854
855
      for('a'..'z') {
856
         # print "   $_: @{$_}\n";
857
         $numberofletter = $#{$_}+1;
858
         if ($numberofletter > 0) {
859
            print IFILE "\n<tr><td colspan=\"2\"><br /><strong><a name=\"\U$_\E$_\" class=\"an\">\U$_\E</a></strong></td></tr>\n";
860
            $numberhalf = ($numberofletter + 1 - (($numberofletter+1) % 2))/2;
861
            if ($debug > 2) { print "   $_: @{$_} \t $numberhalf \t $numberofletter\n"; }
862
            for($count = 0; $count < $numberhalf; $count++) {
863
               $name = @{$_}[$count];
864
               if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
865
               print IFILE "<tr><td width=\"50%\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td>";
866
               if (($count + $numberhalf) < $numberofletter) {
867
                  $name = @{$_}[$count + $numberhalf];
868
                  if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
869
                  print IFILE "<td width=\"50%\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td></tr>\n";
870
               } else {
871
                  print IFILE "<td width=\"50%\"></td></tr>\n";
872
               }
873
            }
874
         }
875
      }
876
      print IFILE "</table>\n<br />$var{'codehr'}\n";
877
878
   } elsif ($LocalShortLong eq 'long') {
879
      # begin create long index
880
      print IFILE "<table border=\"5\" width=\"100%\" cellpadding=\"5\">\n";
881
      print IFILE "<tr align=\"center\"><th>Name</th><th>Description</th></tr>\n";
882
883
      for('a'..'z') {
884
         # print "   $_: @{$_}\n";
885
         $numberofletter = $#{$_}+1;
886
         if ($numberofletter > 0) {
887
            $firstone = 1;
888
            foreach $name (@{$_}) {
889
               if ($debug > 1) { print "   AZinforeach1: $name \t\t $hfilerelpath{$name} \t\t $dirnamerelpath{$LocalActDir}\n"; }
890
               if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
891
               if (! ($mfilename{$name} =~ /contents/i)) {
892
                  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; }
893
                  print IFILE "<tr><td valign=\"top\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td><td>$apropos{$name}</td></tr>\n";
894
               }
895
            }
896
         }
897
      }
898
      print IFILE "</table>\n<br />$var{'codehr'}\n";
899
   } else { die "wrong parameter for LocalShortLong in ConstructAZIndexFile: $LocalShortLong."; }
900
901
   # Include info about author from authorfile
902
   &WriteFile2Handle($var{'authorfile'}, IFILE);
903
904
   print IFILE "<!--navigate-->\n";
905
   print IFILE "<!--copyright-->\n";
906
   print IFILE "</body>\n</html>\n";
907
908
   close(IFILE);
909
910
   if ($opt_silent) { print "\r"; }
911
   print "   Indexfile small (A-Z) created: $indexfile\t";
912
   if (!$opt_silent) { print "\n"; }
913
914
915
   # Build the A-Z jump index file name
916
   # handle the global index file case separately (no extra directory name in file)
917
   if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
918
   else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
919
920 382:baff1c482d98 Chris
   if ($var{'frames'} eq 'yes') {
921
922
       $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionjump'}.$extradirfilename.$var{'exthtml'};
923
       if ($debug > 2) { print "   indexfilename (a-z jump): $indexfile\n"; }
924
       open(IFILE,">$indexfile") || die("Cannot open jump index file $indexfile: $!\n");
925
926
       # Write the header of HTML file
927
       print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
928
929
       if ($var{'texttitleindex'} eq '') {
930
	   print IFILE "<title>A-Z jump index in directory $LocalActDir</title>\n";
931
       } else {
932
	   if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
933
	   else { print IFILE "<title>$var{'texttitleindex'} in Directory $LocalActDir</title>\n"; }
934
       }
935
936
       if ($var{'frames'} eq 'yes') {
937
	   print IFILE "<base target=\"$GlobalNameFrameAZIndexsmall\" />\n";
938
       }
939
       print IFILE "</head>\n";
940
       print IFILE "<body $var{'codebodyindex'}>\n";
941
942
       # Write the A-Z jump line, generate link for letters with files starting with this letter
943
       # and only letters for no files starting with this letter
944
       # use previously generated arrays with names of files sorted by starting letter
945
       for('a'..'z') {
946
	   $numberofletter = $#{$_}+1;
947
	   if ($numberofletter > 0) {
948
	       print IFILE "<strong><a href=\"$indexfilename$var{'filenameextensionindex'}$extradirfilename$var{'exthtml'}#\U$_\E$_\">\U$_\E</a> </strong>\n";
949
	   } else {
950
	       print IFILE "\U$_\E \n";
951
	   }
952
       }
953
954
       print IFILE "</body>\n</html>\n";
955
956
       close(IFILE);
957
958
       if ($opt_silent) { print "\r"; }
959
       print "   Indexfile small (A-Z jump) created: $indexfile\t";
960
       if (!$opt_silent) { print "\n"; }
961 381:2dc8163e9150 Chris
   }
962
963
964
   # Build the frame layout file, this file includes the layout of the frames
965
   # Build the frame layout file name (for small/compact A-Z index)
966
   # handle the global index file case separately (no extra directory name in file)
967
   if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
968
   else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
969
970 382:baff1c482d98 Chris
   if ($var{'frames'} eq 'yes') {
971 381:2dc8163e9150 Chris
972 382:baff1c482d98 Chris
       $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionframe'}.$extradirfilename.$var{'exthtml'};
973
       if ($debug > 2) { print "   indexfilename (a-z frame): $indexfile\n"; }
974 381:2dc8163e9150 Chris
975 382:baff1c482d98 Chris
       open(IFILE,">$indexfile") || die("Cannot open jump index frame file $indexfile: $!\n");
976
977
       # Write the header of Frame file
978
       print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
979
980
       if ($var{'texttitleindex'} eq '') {
981
	   print IFILE "<title>Index of Matlab Files in Directory $LocalActDir</title>\n";
982
       } else {
983
	   if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
984
	   else { print IFILE "<title>$var{'texttitleindex'} in Directory $LocalActDir</title>\n"; }
985
       }
986
       print IFILE "</head>\n";
987
988
       # definition of 2 frames, top the A-Z index, below the jump letter line
989
       print IFILE "<frameset  rows=\"90%,10%\">\n";
990
       print IFILE "   <frame src=\"$indexfilename$var{'filenameextensionindex'}$extradirfilename$var{'exthtml'}\" name=\"$GlobalNameFrameAZIndexsmall\" />\n";
991
       print IFILE "   <frame src=\"$indexfilename$var{'filenameextensionjump'}$extradirfilename$var{'exthtml'}\" name=\"$GlobalNameFrameAZIndexjump\" />\n";
992
       print IFILE "</frameset>\n";
993
994
       print IFILE "</html>\n";
995
996
       close(IFILE);
997
998
       if ($opt_silent) { print "\r"; }
999
       print "   Frame layout file created: $indexfile\t";
1000
       if (!$opt_silent) { print "\n"; }
1001 381:2dc8163e9150 Chris
   }
1002
}
1003 382:baff1c482d98 Chris
1004 381:2dc8163e9150 Chris
1005
#========================================================================
1006
# Construct the links to all indexes
1007
#========================================================================
1008
sub ConstructLinks2Index
1009
{
1010
   local(*WRITEFILE, $LocalPath2Index, $PathContents, $LocalGlobalLocal) = @_;
1011
1012
   # include links to short/long - local/global index and C|contents.m
1013
   print WRITEFILE "\n<p align=\"center\">";
1014
   print WRITEFILE "$var{'textjumpindexglobal'} (";
1015 382:baff1c482d98 Chris
1016
   if ($var{'frames'} eq 'yes') {
1017
       print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexshortglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\">short</a> | ";
1018
   } else {
1019
       print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenametopframe'}.$var{'exthtml'}\">short</a> | ";
1020
   }
1021
1022
   print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexlongglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\">long</a>)\n";
1023 381:2dc8163e9150 Chris
   if ($LocalGlobalLocal eq 'local') {
1024
      if ($var{'usecontentsm'} eq 'yes') {
1025
         print WRITEFILE " | <a href=\"$contentsname{$PathContents}$dirnamesingle{$PathContents}$var{'exthtml'}\">Local contents</a>\n";
1026
      }
1027
      # if ($var{'producetree'} eq 'yes') {
1028
         print WRITEFILE " | $var{'textjumpindexlocal'} (";
1029 382:baff1c482d98 Chris
         print WRITEFILE "<a href=\"$var{'filenameindexshortlocal'}$var{'filenameextensionframe'}$dirnamesingle{$PathContents}$var{'exthtml'}\">short</a> | ";
1030
         print WRITEFILE "<a href=\"$var{'filenameindexlonglocal'}$var{'filenameextensionframe'}$dirnamesingle{$PathContents}$var{'exthtml'}\">long</a>)\n";
1031 381:2dc8163e9150 Chris
      # }
1032
   }
1033
   print WRITEFILE "</p>\n\n";
1034
   print WRITEFILE "$var{'codehr'}\n";
1035
}
1036
1037
1038
#========================================================================
1039
# Construct the contents.m files or update
1040
#========================================================================
1041
sub ConstructContentsmFile
1042
{
1043
   local($LocalActDir, @localnames) = @_;
1044
   local(*CFILE, $name,$newline);
1045
   local($contentsfile, $isincontentsonly);
1046
   local(@lines, @autoaddlines, @emptylines);
1047
   local($autoadd) = 'AutoAdd';
1048
   local($autoaddsection) = 0;
1049
   local($emptylineflag) = 0;
1050
   local(%nameincontents);
1051
1052
   # Build the contents file name
1053
   $contentsfile = $LocalActDir.$contentsname{$LocalActDir}.$suffix;
1054
1055
   if (-e $contentsfile) {
1056
      open(CFILE,"<$contentsfile") || die("Cannot open contents file $contentsfile: $!\n");
1057
      while (<CFILE>) {
1058
         # Search for the specified string pattern
1059
         @words = split;
1060
         if ((@words >= 3) && ($words[2] eq '-')) {
1061
            $isincontentsonly = 0;
1062
            foreach $name (@localnames) {
1063
               if ($name eq $words[1]) {    # old
1064
               # if ($mfilename{$name} eq $words[1]) {
1065
                  $isincontentsonly = 1;
1066
                  $nameincontents{$name} = 1;
1067
                  $newline = sprintf("%% %-13s - %s\n", $mfilename{$name}, $apropos{$name});
1068
                  push(@lines, $newline);
1069
               }
1070
            }
1071
            # issue a warning, if file is in contents, but not as file in the directory
1072
            if ($isincontentsonly == 0) {
1073
               print "\rConstructContents: Obsolete entry  $words[1]  in  $contentsfile ! Entry not used.\n";
1074
            }
1075
         } else {
1076
            # look for the AutoAdd section, should be the second word
1077
            if ((@words >= 2) && ($words[1] eq $autoadd)) { $autoaddsection = 1; }
1078
            # push the red line in an array
1079
            push(@lines, $_);
1080
         }
1081
      }
1082
      close(CFILE);
1083
   } else {
1084
      $newline = "% MATLAB Files in directory  $LocalActDir\n%\n";
1085
      push(@lines, $newline);
1086
1087
   }
1088
1089
   # collect the file names, that were not included in original C|contents.m
1090
   foreach $name (@localnames) {
1091
      if (! defined $nameincontents{$name}) {
1092
         if (! ($mfilename{$name} =~ /contents/i)) {
1093
            $newline = sprintf("%% %-13s - %s\n", $mfilename{$name}, $apropos{$name});
1094
            push(@autoaddlines, $newline);
1095
         }
1096
      }
1097
   }
1098
1099
   # write/update C|contents.m only if variable is set
1100
   if ($var{'writecontentsm'} eq 'yes') {
1101
      unlink($contentsfile);
1102
      open(CFILE,">$contentsfile") || die("Cannot open contents file $contentsfile: $!\n");
1103
      # write old C|contents.m or header of new file, as long as comment lines
1104
      foreach $line (@lines) {
1105
         if ($emptylineflag == 0) {
1106
            if ($line =~ /^\s*%/) { print CFILE $line; }
1107
            else { $emptylineflag = 1; push(@emptylines, $line); }
1108
         } else { push(@emptylines, $line); }
1109
      }
1110
      # add header of AutoAdd section
1111
      if (($autoaddsection == 0) && (@autoaddlines > 0)) { print CFILE "%\n% $autoadd\n"; }
1112
      # add autoadd section lines (previously undocumented files
1113
      foreach $line (@autoaddlines) { print CFILE $line; }
1114
      # add tail of original C|contents.m (everything behind first non-comment line)
1115
      foreach $line (@emptylines)   { print CFILE $line; }
1116
      print CFILE "\n";
1117
      close CFILE;
1118
      if ($opt_silent) { print "\r"; }
1119
      print "   Contents file created/updated: $contentsfile\t";
1120
      if (!$opt_silent) { print "\n"; }
1121
   }
1122
}
1123
1124
1125
#========================================================================
1126
# Replace found special characters with their HTMl Entities
1127
#========================================================================
1128
sub SubstituteHTMLEntities {
1129
   local($_) = @_;
1130
1131
   # Replace & <-> &amp;  < <-> &lt;  > <-> &gt;  " <-> &quot;
1132
   s/&/&amp;/g; s/\</&lt;/g; s/\>/&gt;/g; s/\"/&quot;/g;
1133
   return $_;
1134
}
1135
1136
#========================================================================
1137
# Replace found m-filenamestring with full link.
1138
#========================================================================
1139
sub SubstituteName2Link {
1140
   local($_, $funname) = @_;
1141
   local($refstr1, $refstr2, $reffound);
1142
1143
   # Look for something matching in the line
1144
   if ( /(\W+)($funname)(\W+)/i ) {
1145
      $reffound = $2;
1146
      $refstr1 = "<a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$funname}$funname$var{'exthtml'}\">";
1147
      $refstr2 = "<\/a>";
1148
      # Do links only for exact case match
1149
      if ( ($var{'links2filescase'}  eq 'exact') || ($var{'links2filescase'}  eq 'exactvery') ) {
1150
         if ( /(\W+)($funname)(\W+)/g ) {
1151
            s/(\W+)($funname)(\W+)/$1$refstr1$funname$refstr2$3/g;
1152
         }
1153
         else {
1154
            # Print info for not matching case in references, good for check up of files
1155
            if ( ($var{'links2filescase'}  eq 'exactvery') ) {
1156
               print "Diff in case found: $funname  (case of file name)   <->  $reffound  (case in source code)\n";
1157
               print "     (source line)  $_ \n";
1158
            }
1159
         }
1160
      }
1161
      # Do links for exact match and additionally for all upper case (often used in original matlab help text)
1162
      elsif ( ($var{'links2filescase'}  eq 'exactupper') ) {
1163
         s/(\W+)($funname)(\W+)/$1$refstr1$2$refstr2$3/g;
1164
         $funname2 = "\U$funname\E";
1165
         s/(\W+)($funname2)(\W+)/$1$refstr1$2$refstr2$3/g;
1166
      }
1167
      # Do links for all case mixes, this calls for trouble under LINUX/UNIX
1168
      else {  #elsif ( ($var{'links2filescase'}  eq 'all') )
1169
         s/(\W+)($funname)(\W+)/$1$refstr1$2$refstr2$3/ig;
1170
      }
1171
   }
1172
1173
   return $_;
1174
}
1175
1176
#========================================================================
1177
# Construct the html files for each matlab file.
1178
#    Need to reread each matlab file to find the help text.
1179
#    Note that we can't do this in a single loop because sometimes
1180
#    the help text maybe before the function declaration.
1181
#========================================================================
1182
sub ConstructHTMLFiles
1183
{
1184
   local(*MFILE);
1185
   local(*HFILE);
1186
1187
   local($filescreated) = 0;
1188
   local($functionline);
1189
1190
   foreach $name (@names) {
1191
      # Create cross reference information already here, used for keywords as well
1192
      # Construct list of referenced functions
1193
      @xref = @{'depcalls'.$name};    # the functions, that this m-file calls
1194
      @yref = @{'depcalled'.$name};   # the functions, that this m-file is called from
1195
      # print "   depcalls: @{'depcalls'.$name}\n   depcalled: @{'depcalled'.$name}\n";
1196
      # foreach $cname (@names) { next if $cname eq $name; push(@yref,$cname) if grep(/$name/,@{'depcalls'.$cname}); }
1197
1198
1199
      # Open m-file and html-file
1200
      open(MFILE,"<$mfile{$name}");
1201
      open(HFILE,">$hfile{$name}");
1202
1203
      # Write the header of HTML file
1204
      print HFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
1205
1206
      # Write meta tags: use apropos (one line function description) for description
1207
      # and cross reference function names for keywords (any better ideas?)
1208
      print HFILE "<meta name=\"description\" content=\" $apropos{$name} \" />\n";
1209
      print HFILE "<meta name=\"keywords\" content=\" @xref @yref \" />\n";
1210
1211
      # Write Title and start body of html-file
1212
      print HFILE "<title>$var{'texttitlefiles'} $mfilename{$name}</title>\n</head>\n";
1213
      print HFILE "<body $var{'codebodyfiles'}>\n";
1214
      print HFILE "<h1 $var{'codeheader'}>$var{'textheaderfiles'} $mfilename{$name}</h1>\n";
1215
      print HFILE "$var{'codehr'}\n";
1216
1217
      # include links to short/long - local/global index and C|contents.m
1218
      &ConstructLinks2Index(HFILE, $hfileindexpath{$name}, $mfiledir{$name}, 'local');
1219
1220
      # If this is a function, then write out the first line as a synopsis
1221
      if ($mtype{$name} eq "function") {
1222
         print HFILE "<h2 $var{'codeheader'}>Function Synopsis</h2>\n";
1223
         print HFILE "<pre>$synopsis{$name}</pre>\n$var{'codehr'}\n";
1224
      }
1225
1226
      # Look for the matlab help text block
1227
      $functionline = "\n";
1228
      do {
1229
         $_ = <MFILE>;
1230
         # remember functionline, if before help text block
1231
         if (/^\s*function/) { $functionline = $_; }
1232
      } until (/^\s*%/ || eof);
1233
      if (! (eof(MFILE))) {
1234
         print HFILE "<h2 $var{'codeheader'}>Help text</h2>\n";
1235
         print HFILE "<pre>\n";
1236
         while (/^\s*%/) {
1237
            # First remove leading % and white space, then Substitute special characlers
1238
            s/^\s*%//;
1239
            $_ = &SubstituteHTMLEntities($_);
1240
1241
            # check/create cross references
1242
            foreach $funname (@{'all'.$name}) {
1243
               if ($funname =~ /simulink/) { print "\n Simulink - Filename: $name;  scanname: $funname\n"; }
1244
               next if $funname eq $name;
1245
               $_ = &SubstituteName2Link($_, $funname);
1246
            }
1247
            print HFILE $_;
1248
            if (! eof) { $_ = <MFILE>; }
1249
         }
1250
         print HFILE "</pre>\n$var{'codehr'}\n";
1251
      }
1252
1253
      # Write the cross reference information
1254
      if (@xref || @yref) {
1255
         print HFILE "<h2 $var{'codeheader'}>Cross-Reference Information</H2>\n";
1256
         print HFILE "<table border=\"0\" width=\"100%\">\n<tr align=\"left\">\n<th width=\"50%\">";
1257
         if (@xref) {
1258
            print HFILE "This $mtype{$name} calls";
1259
         }
1260
         print HFILE "</th>\n<th width=\"50%\">";
1261
         if (@yref) {
1262
            print HFILE "This $mtype{$name} is called by";
1263
         }
1264
         print HFILE "</th>\n</tr>\n<tr valign=\"top\"><td>";
1265
         if (@xref) {
1266
            print HFILE "\n<ul>\n";
1267
            foreach $cname (sort @xref) {
1268
               print HFILE "<li><a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$cname}$mfilename{$cname}$var{'exthtml'}\">$mfilename{$cname}</a></li>\n";
1269
            }
1270
            print HFILE "</ul>\n";
1271
         }
1272
         print HFILE "</td><td>";
1273
         if (@yref) {
1274
            print HFILE "\n<ul>\n";
1275
            foreach $cname (sort @yref) {
1276
               print HFILE "<li><a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$cname}$mfilename{$cname}$var{'exthtml'}\">$mfilename{$cname}</a></li>\n";
1277
            }
1278
            print HFILE "</ul>\n";
1279
         }
1280
         print HFILE "</td>\n</tr>\n</table>\n";
1281
         print HFILE "$var{'codehr'}\n";
1282
      }
1283
1284
      # Include source text if requested
1285
      if (($var{'includesource'} eq 'yes') && (! ($mfilename{$name} =~ /^contents$/i))) {
1286
         print HFILE "<h2 $var{'codeheader'}>Listing of $mtype{$name} $mfilename{$name}</h2>\n";
1287
         seek(MFILE,0,0);
1288
         print HFILE "<pre>\n";
1289
         $IsStillHelp = 2;
1290
         print HFILE $functionline;    # functionline from scanning of help
1291
         while (<MFILE>) {
1292
            if ($IsStillHelp == 2) {
1293
               next     if (/^\s*$/);
1294
               next     if (/^\s*function/);
1295
               if (/^\s*%/) { $IsStillHelp = 1; next; }
1296
            } elsif ($IsStillHelp == 1) {
1297
               next     if (/^\s*%/);
1298
               $IsStillHelp = 0;
1299
            }
1300
1301
            # Substritute special characters
1302
            $_ = &SubstituteHTMLEntities($_);
1303
1304
            # check for comment in line and format with css em
1305
            s/(.*)%(.*)/$1<em class=\"mcom\">%$2<\/em>/;
1306
1307
            # check/create cross references
1308
            foreach $funname (@{'all'.$name}) {
1309
               next if $funname eq $name;
1310
               $_ = &SubstituteName2Link($_, $funname);
1311
            }
1312
            print HFILE $_;
1313
         }
1314
         print HFILE "</pre>\n$var{'codehr'}\n";
1315
      }
1316
1317
      # Include info about author from authorfile
1318
      &WriteFile2Handle($var{'authorfile'}, HFILE)   ;
1319
1320
      print HFILE "<!--navigate-->\n";
1321
      print HFILE "<!--copyright-->\n";
1322
      print HFILE "</body>\n</html>\n";
1323
      close(MFILE);
1324
      close(HFILE);
1325
1326
      # Print name of finished file
1327
      if ($opt_silent) { print "\r"; }
1328
      print "   HTML-File created: $hfile{$name}\t";
1329
      if (!$opt_silent) { print "\n"; }
1330
      $filescreated++;
1331
   }
1332
1333
   print "\n$PROGRAM: $indexcreated index and $filescreated files created.\n";
1334
}
1335
1336
#========================================================================
1337
# Function:	CheckFileName
1338
# Purpose:	.
1339
#========================================================================
1340
sub CheckFileName {
1341
   local($filename, $description) = @_;
1342
   local(*CHECKFILE);
1343
1344
   open(CHECKFILE,"<$filename") || do {
1345
      if ($description eq '') {$description = 'file';}
1346
      # if (!$opt_silent) { print "Cannot open $description $filename: $!\n"; }
1347
      print "Cannot open $description $filename: $!\n";
1348
      return 1;
1349
   };
1350
   close(CHECKFILE);
1351
   return 0;
1352
1353
}
1354
1355
#========================================================================
1356
# Function:	CheckDirName
1357
# Purpose:	.
1358
#========================================================================
1359
sub CheckDirName {
1360
   local($dirname, $description) = @_;
1361
   local(*CHECKDIR);
1362
1363
   opendir(CHECKDIR,"$dirname") || die ("Cannot open $description directory $dirname: $!\n");
1364
   closedir(CHECKDIR);
1365
}
1366
1367
#========================================================================
1368
# Function:	WriteFile2Handle
1369
# Purpose:	.
1370
#========================================================================
1371
sub WriteFile2Handle {
1372
   local($filename, *WRITEFILE) = @_;
1373
   local(*READFILE);
1374
1375
   if ($filename ne '') {
1376
      open(READFILE,"<$filename");
1377
      @filecontents = <READFILE>;
1378
      close(READFILE);
1379
      print WRITEFILE "@filecontents\n";
1380
      # if (!$opt_silent) {print "      Contents of $filename added\n"};
1381
   }
1382
}
1383
1384
1385
#========================================================================
1386
# Function:	GetConfigFile
1387
# Purpose:	Read user's configuration file, if such exists.
1388
#========================================================================
1389
sub GetConfigFile
1390
{
1391
   local($filename) = @_;
1392
   local(*CONFIG);
1393
   local($value);
1394
1395
   if (&CheckFileName($filename, 'configuration file')) {
1396
      # if (!$opt_silent) { print "   Proceeding using built-in defaults for configuration.\n"; }
1397
      print "   Proceeding using built-in defaults for configuration.\n";
1398
      return 0;
1399
   };
1400
1401
   open(CONFIG,"< $filename");
1402
   while (<CONFIG>) {
1403
      s/#.*$//;
1404
      next if /^\s*$/o;
1405
1406
      # match keyword: process one or more arguments
1407
      # keyword set
1408
      if (/^\s*set\s+(\S+)\s*=\s*(.*)/) {
1409
         # setting a configuration variable
1410
         if (defined $var{$1}) {
1411
            $var{$1} = $2;
1412
            if ($debug > 3) { print "$1:   $var{$1}\n"; }
1413
         }
1414
         else {
1415
            print "$PROGRAM: unknown variable `$1' in configuration file\n"
1416
         }
1417
      } else {
1418
         chop($_);
1419
         print "$PROGRAM: unknown keyword in configuration file in line: `$_'\n"
1420
      }
1421
   }
1422
   close CONFIG;
1423
   1;
1424
}
1425
1426
1427
#------------------------------------------------------------------------
1428
# DisplayHelp - display help text using -h or -help command-line switch
1429
#------------------------------------------------------------------------
1430
sub DisplayHelp
1431
{
1432
   $help=<<EofHelp;
1433
   $PROGRAM v$VERSION - generate html documentation from Matlab m-files
1434
1435
   Usage: $PROGRAM [-h] [-c config_file] [-m|dirmfiles matlab_dir] [-d|dirhtml html_dir]
1436
                   [-i yes|no] [-r yes|no] [-p yes|no] [-quiet|q] [-a authorfile]
1437
1438
   $PROGRAM is a perl script that reads each matlab .m file in a directory
1439
   to produce a corresponding .html file of help documentation and cross
1440
   reference information. An index file is written with links to all of
1441
   the html files produced. The options are:
1442
1443
      -quiet         or -q : be silent, no status information during generation
1444
      -help          or -h : display this help message
1445
      -todo          or -t : print the todo list for $PROGRAM
1446
      -version       or -v : display version
1447
1448
      -configfile    or -c : name of configuration file (default to $var{'configfile'}).
1449
      -dirmfiles     or -m : top level directory containing matlab files to generate html for;
1450
                             default to actual directory.
1451
      -dirhtml       or -d : top level directory for generated html files;
1452
                             default to actual directory.
1453
1454
      -includesource or -i : Include matlab source in the html documentation [yes|no]
1455
                             default to yes.
1456
      -processtree   or -r : create docu for m-file directory and all subdirectories [yes|no];
1457
                             default to yes.
1458
      -producetree   or -p : create multi-level docu identical to directory structure
1459
                             of m-files [yes|no]; default to yes.
1460
      -writecontentsm or -w: update or write contents.m files into the matlab source
1461
                             directories [yes|no]; default to no.
1462
1463
      -authorfile    or -a : name of file including author information, last element in html;
1464
                             default to empty.
1465
1466
   The command line setting overwrite all other settings (built-in and configuration file).
1467
   The configuration file settings overwrite the built-in settings (and not the command
1468
   line settings).
1469
1470
   Typical usages are:
1471
     $PROGRAM
1472
        (use default parameters from perl script, if configuration
1473
         file is found -> generation of docu, else display of help)
1474
1475
     $PROGRAM -dirmfiles matlab -dirhtml html
1476
        (generate html documentation for all m-files in directory matlab,
1477
         place html files in directory html, use built-in defaults for
1478
         all other parameters, this way all m-files in the directory
1479
         matlab and below are converted and the generated html-files are
1480
         placed in the directory html and below producing the same
1481
         directory structure than below matlab)
1482
1483
     $PROGRAM -quiet
1484
        (use built-in parameters from perl script, if configuration
1485
         file is found use these settings as well, do generation,
1486
         no display except critical errors, status of conversion and result)
1487
1488
     $PROGRAM -m toolbox -dirhtml doc/html -r yes -p no
1489
        (convert all m-files in directory toolbox and below and place
1490
         the generated html files in directory doc/html, read all m-files
1491
         recursively, however, the generated html files are placed in one
1492
         directory)
1493
1494
     $PROGRAM -m toolbox -dirhtml doc/html -i no -r no
1495
        (convert all m-files in directory toolbox and place
1496
         the generated html files in directory doc/html, do not read m-files
1497
         recursively, do not include source code in documentation)
1498
1499
EofHelp
1500
1501
   die "$help";
1502
}
1503
1504
#------------------------------------------------------------------------
1505
# DisplayTodo - display ToDo list using -t or -todo command-line switch
1506
#------------------------------------------------------------------------
1507
sub DisplayTodo
1508
{
1509
   $todo=<<EofToDo;
1510
      $PROGRAM v$VERSION - ToDo list
1511
1512
       o	use more than one high level directory
1513
1514
       o	what should/could be done here???
1515
1516
EofToDo
1517
1518
   die "$todo";
1519
}
1520
1521
1522
#------------------------------------------------------------------------
1523
# ListVariables - list all defined variables and their values
1524
#------------------------------------------------------------------------
1525
sub ListVariables
1526
{
1527
   local($value);
1528
1529
   if ($debug > 0) {
1530
      print "List of all variables and their values\n";
1531
      foreach (sort keys %var)
1532
      {
1533
         if ($var{$_} eq '') {
1534
            $value = "empty";
1535
         } else {
1536
            $value = $var{$_};
1537
         }
1538
         print "   $_\n      $value\n";
1539
      }
1540
      print "\n\n";
1541
   }
1542
}
1543
1544
1545
__END__
1546
:endofperl