annotate extra/soundsoftware/matlab-docs.pl @ 382:baff1c482d98 feature_113

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