To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / extra / soundsoftware / matlab-docs.pl @ 401:a0f6e994657f
History | View | Annotate | Download (64.5 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 | 389:0bc92382a86b | chris | $debug = 4; |
| 79 | 381:2dc8163e9150 | Chris | |
| 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 | 388:dad587ecb8d0 | chris | # if ($var{'links2filescase'} eq 'low') { $filewosuffix = "\L$filewosuffix\E"; }
|
| 376 | 381:2dc8163e9150 | Chris | $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 | 389:0bc92382a86b | chris | print IFILE "<p>\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 | 401:a0f6e994657f | chris | if ($LocalShortLong eq 'short' and $extradirfilename eq '' and $var{'frames'} ne 'yes') {
|
| 805 | # With no frames and no subdir path, this must go in the |
||
| 806 | # top-level index file instead |
||
| 807 | 382:baff1c482d98 | Chris | $indexfile = $var{'dirhtml'}.$var{'filenametopframe'}.$var{'exthtml'};
|
| 808 | } |
||
| 809 | |||
| 810 | 381:2dc8163e9150 | Chris | if ($debug > 2) { print " indexfilename (a-z small): $indexfile\n"; }
|
| 811 | |||
| 812 | open(IFILE,">$indexfile") || die("Cannot open index file $indexfile: $!\n");
|
||
| 813 | |||
| 814 | # Write the header of HTML file |
||
| 815 | print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
||
| 816 | |||
| 817 | if ($var{'texttitleindex'} eq '') {
|
||
| 818 | print IFILE "<title>Index of Matlab Files in Directory $LocalActDir</title>\n"; |
||
| 819 | } else {
|
||
| 820 | if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
|
||
| 821 | else { print IFILE "<title>$var{'texttitleindex'} in Directory $LocalActDir</title>\n"; }
|
||
| 822 | } |
||
| 823 | 382:baff1c482d98 | Chris | |
| 824 | if ($var{'frames'} eq 'yes') {
|
||
| 825 | print IFILE "<base target=\"$GlobalNameFrameMainRight\" />\n"; |
||
| 826 | } |
||
| 827 | 381:2dc8163e9150 | Chris | print IFILE "</head>\n"; |
| 828 | 382:baff1c482d98 | Chris | |
| 829 | 381:2dc8163e9150 | Chris | print IFILE "<body $var{'codebodyindex'}>\n";
|
| 830 | if ($var{'textheaderindex'} eq '') {
|
||
| 831 | print IFILE "<h1 $var{'codeheader'}>Index of Matlab Files in Directory $LocalActDir</h1>\n";
|
||
| 832 | } else {
|
||
| 833 | if ($LocalGlobalLocal eq 'global') { print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindex'}</h1>\n"; }
|
||
| 834 | else { print IFILE "<h1 $var{'codeheader'}>$var{'textheaderindex'} in Directory $LocalActDir</h1>\n"; }
|
||
| 835 | } |
||
| 836 | |||
| 837 | # include links to indexes |
||
| 838 | &ConstructLinks2Index(IFILE, $dirnamerelpathtoindex{$LocalActDir}, $LocalActDir, $LocalGlobalLocal);
|
||
| 839 | |||
| 840 | # Collect the starting letters of m files in this directory or all m-files |
||
| 841 | for('a'..'z') { undef @{$_}; }
|
||
| 842 | foreach $name (@localnames) {
|
||
| 843 | if (! ($mfilename{$name} =~ /contents/i)) {
|
||
| 844 | $firstletter = substr($mfilename{$name}, 0, 1);
|
||
| 845 | # convert first letter always to lower case |
||
| 846 | # needed for reference to lower and upper case m-files |
||
| 847 | $firstletter = "\L$firstletter\E"; |
||
| 848 | push(@{$firstletter}, $name);
|
||
| 849 | } |
||
| 850 | } |
||
| 851 | |||
| 852 | if ($LocalShortLong eq 'short') {
|
||
| 853 | # begin create short index |
||
| 854 | print IFILE "<table width=\"100%\">\n"; |
||
| 855 | |||
| 856 | for('a'..'z') {
|
||
| 857 | # print " $_: @{$_}\n";
|
||
| 858 | $numberofletter = $#{$_}+1;
|
||
| 859 | if ($numberofletter > 0) {
|
||
| 860 | 400:4ad6499d7998 | chris | print IFILE "\n<tr><td colspan=\"2\"><br /><strong><a name=\"\U$_\E$_\"></a><span class=\"an\">\U$_\E</span></strong></td></tr>\n"; |
| 861 | 381:2dc8163e9150 | Chris | $numberhalf = ($numberofletter + 1 - (($numberofletter+1) % 2))/2; |
| 862 | if ($debug > 2) { print " $_: @{$_} \t $numberhalf \t $numberofletter\n"; }
|
||
| 863 | for($count = 0; $count < $numberhalf; $count++) {
|
||
| 864 | $name = @{$_}[$count];
|
||
| 865 | if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
|
||
| 866 | print IFILE "<tr><td width=\"50%\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td>";
|
||
| 867 | if (($count + $numberhalf) < $numberofletter) {
|
||
| 868 | $name = @{$_}[$count + $numberhalf];
|
||
| 869 | if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
|
||
| 870 | print IFILE "<td width=\"50%\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td></tr>\n";
|
||
| 871 | } else {
|
||
| 872 | print IFILE "<td width=\"50%\"></td></tr>\n"; |
||
| 873 | } |
||
| 874 | } |
||
| 875 | } |
||
| 876 | } |
||
| 877 | print IFILE "</table>\n<br />$var{'codehr'}\n";
|
||
| 878 | |||
| 879 | } elsif ($LocalShortLong eq 'long') {
|
||
| 880 | # begin create long index |
||
| 881 | print IFILE "<table border=\"5\" width=\"100%\" cellpadding=\"5\">\n"; |
||
| 882 | 401:a0f6e994657f | chris | print IFILE "<tr><th>Name</th><th>Synopsis</th></tr>\n"; |
| 883 | 381:2dc8163e9150 | Chris | |
| 884 | for('a'..'z') {
|
||
| 885 | # print " $_: @{$_}\n";
|
||
| 886 | $numberofletter = $#{$_}+1;
|
||
| 887 | if ($numberofletter > 0) {
|
||
| 888 | $firstone = 1; |
||
| 889 | foreach $name (@{$_}) {
|
||
| 890 | if ($debug > 1) { print " AZinforeach1: $name \t\t $hfilerelpath{$name} \t\t $dirnamerelpath{$LocalActDir}\n"; }
|
||
| 891 | if ($LocalGlobalLocal eq 'global') { $dirpath = $hfilerelpath{$name}; } else { $dirpath = ""; }
|
||
| 892 | if (! ($mfilename{$name} =~ /contents/i)) {
|
||
| 893 | 400:4ad6499d7998 | chris | if ($firstone == 1) { print IFILE "\n<tr><td colspan=\"2\"><br /><strong><a name=\"\U$_\E$_\"></a><span class=\"an\">\U$_\E</span></strong></td></tr>\n"; $firstone = 0; }
|
| 894 | 381:2dc8163e9150 | Chris | print IFILE "<tr><td valign=\"top\"><a href=\"$dirpath$mfilename{$name}$var{'exthtml'}\">$mfilename{$name}</a></td><td>$apropos{$name}</td></tr>\n";
|
| 895 | } |
||
| 896 | } |
||
| 897 | } |
||
| 898 | } |
||
| 899 | print IFILE "</table>\n<br />$var{'codehr'}\n";
|
||
| 900 | } else { die "wrong parameter for LocalShortLong in ConstructAZIndexFile: $LocalShortLong."; }
|
||
| 901 | |||
| 902 | # Include info about author from authorfile |
||
| 903 | &WriteFile2Handle($var{'authorfile'}, IFILE);
|
||
| 904 | |||
| 905 | print IFILE "<!--navigate-->\n"; |
||
| 906 | print IFILE "<!--copyright-->\n"; |
||
| 907 | print IFILE "</body>\n</html>\n"; |
||
| 908 | |||
| 909 | close(IFILE); |
||
| 910 | |||
| 911 | if ($opt_silent) { print "\r"; }
|
||
| 912 | print " Indexfile small (A-Z) created: $indexfile\t"; |
||
| 913 | if (!$opt_silent) { print "\n"; }
|
||
| 914 | |||
| 915 | |||
| 916 | # Build the A-Z jump index file name |
||
| 917 | # handle the global index file case separately (no extra directory name in file) |
||
| 918 | if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
|
||
| 919 | else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
|
||
| 920 | |||
| 921 | 382:baff1c482d98 | Chris | if ($var{'frames'} eq 'yes') {
|
| 922 | |||
| 923 | $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionjump'}.$extradirfilename.$var{'exthtml'};
|
||
| 924 | if ($debug > 2) { print " indexfilename (a-z jump): $indexfile\n"; }
|
||
| 925 | open(IFILE,">$indexfile") || die("Cannot open jump index file $indexfile: $!\n");
|
||
| 926 | |||
| 927 | # Write the header of HTML file |
||
| 928 | print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
||
| 929 | |||
| 930 | if ($var{'texttitleindex'} eq '') {
|
||
| 931 | print IFILE "<title>A-Z jump index in directory $LocalActDir</title>\n"; |
||
| 932 | } else {
|
||
| 933 | if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
|
||
| 934 | else { print IFILE "<title>$var{'texttitleindex'} in Directory $LocalActDir</title>\n"; }
|
||
| 935 | } |
||
| 936 | |||
| 937 | if ($var{'frames'} eq 'yes') {
|
||
| 938 | print IFILE "<base target=\"$GlobalNameFrameAZIndexsmall\" />\n"; |
||
| 939 | } |
||
| 940 | print IFILE "</head>\n"; |
||
| 941 | print IFILE "<body $var{'codebodyindex'}>\n";
|
||
| 942 | |||
| 943 | # Write the A-Z jump line, generate link for letters with files starting with this letter |
||
| 944 | # and only letters for no files starting with this letter |
||
| 945 | # use previously generated arrays with names of files sorted by starting letter |
||
| 946 | for('a'..'z') {
|
||
| 947 | $numberofletter = $#{$_}+1;
|
||
| 948 | if ($numberofletter > 0) {
|
||
| 949 | print IFILE "<strong><a href=\"$indexfilename$var{'filenameextensionindex'}$extradirfilename$var{'exthtml'}#\U$_\E$_\">\U$_\E</a> </strong>\n";
|
||
| 950 | } else {
|
||
| 951 | print IFILE "\U$_\E \n"; |
||
| 952 | } |
||
| 953 | } |
||
| 954 | |||
| 955 | print IFILE "</body>\n</html>\n"; |
||
| 956 | |||
| 957 | close(IFILE); |
||
| 958 | |||
| 959 | if ($opt_silent) { print "\r"; }
|
||
| 960 | print " Indexfile small (A-Z jump) created: $indexfile\t"; |
||
| 961 | if (!$opt_silent) { print "\n"; }
|
||
| 962 | 381:2dc8163e9150 | Chris | } |
| 963 | |||
| 964 | |||
| 965 | # Build the frame layout file, this file includes the layout of the frames |
||
| 966 | # Build the frame layout file name (for small/compact A-Z index) |
||
| 967 | # handle the global index file case separately (no extra directory name in file) |
||
| 968 | if ($LocalGlobalLocal eq 'global') { $extradirfilename = ''; }
|
||
| 969 | else { $extradirfilename = $dirnamesingle{$LocalActDir}; }
|
||
| 970 | |||
| 971 | 382:baff1c482d98 | Chris | if ($var{'frames'} eq 'yes') {
|
| 972 | 381:2dc8163e9150 | Chris | |
| 973 | 382:baff1c482d98 | Chris | $indexfile = $var{'dirhtml'}.$dirnamerelpath{$LocalActDir}.$indexfilename.$var{'filenameextensionframe'}.$extradirfilename.$var{'exthtml'};
|
| 974 | if ($debug > 2) { print " indexfilename (a-z frame): $indexfile\n"; }
|
||
| 975 | 381:2dc8163e9150 | Chris | |
| 976 | 382:baff1c482d98 | Chris | open(IFILE,">$indexfile") || die("Cannot open jump index frame file $indexfile: $!\n");
|
| 977 | |||
| 978 | # Write the header of Frame file |
||
| 979 | print IFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
||
| 980 | |||
| 981 | if ($var{'texttitleindex'} eq '') {
|
||
| 982 | print IFILE "<title>Index of Matlab Files in Directory $LocalActDir</title>\n"; |
||
| 983 | } else {
|
||
| 984 | if ($LocalGlobalLocal eq 'global') { print IFILE "<title>$var{'texttitleindex'}</title>\n"; }
|
||
| 985 | else { print IFILE "<title>$var{'texttitleindex'} in Directory $LocalActDir</title>\n"; }
|
||
| 986 | } |
||
| 987 | print IFILE "</head>\n"; |
||
| 988 | |||
| 989 | # definition of 2 frames, top the A-Z index, below the jump letter line |
||
| 990 | print IFILE "<frameset rows=\"90%,10%\">\n"; |
||
| 991 | print IFILE " <frame src=\"$indexfilename$var{'filenameextensionindex'}$extradirfilename$var{'exthtml'}\" name=\"$GlobalNameFrameAZIndexsmall\" />\n";
|
||
| 992 | print IFILE " <frame src=\"$indexfilename$var{'filenameextensionjump'}$extradirfilename$var{'exthtml'}\" name=\"$GlobalNameFrameAZIndexjump\" />\n";
|
||
| 993 | print IFILE "</frameset>\n"; |
||
| 994 | |||
| 995 | print IFILE "</html>\n"; |
||
| 996 | |||
| 997 | close(IFILE); |
||
| 998 | |||
| 999 | if ($opt_silent) { print "\r"; }
|
||
| 1000 | print " Frame layout file created: $indexfile\t"; |
||
| 1001 | if (!$opt_silent) { print "\n"; }
|
||
| 1002 | 381:2dc8163e9150 | Chris | } |
| 1003 | } |
||
| 1004 | 382:baff1c482d98 | Chris | |
| 1005 | 381:2dc8163e9150 | Chris | |
| 1006 | #======================================================================== |
||
| 1007 | # Construct the links to all indexes |
||
| 1008 | #======================================================================== |
||
| 1009 | sub ConstructLinks2Index |
||
| 1010 | {
|
||
| 1011 | local(*WRITEFILE, $LocalPath2Index, $PathContents, $LocalGlobalLocal) = @_; |
||
| 1012 | |||
| 1013 | # include links to short/long - local/global index and C|contents.m |
||
| 1014 | 389:0bc92382a86b | chris | print WRITEFILE "\n<p>"; |
| 1015 | print WRITEFILE "$var{'textjumpindexglobal'} ";
|
||
| 1016 | 382:baff1c482d98 | Chris | |
| 1017 | if ($var{'frames'} eq 'yes') {
|
||
| 1018 | print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexshortglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\">short</a> | ";
|
||
| 1019 | 389:0bc92382a86b | chris | print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexlongglobal'}$var{'filenameextensionframe'}$var{'exthtml'}\">long</a>\n";
|
| 1020 | 382:baff1c482d98 | Chris | } else {
|
| 1021 | 387:f89765996ef9 | Chris | print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenametopframe'}$var{'exthtml'}\">short</a> | ";
|
| 1022 | 389:0bc92382a86b | chris | print WRITEFILE "<a href=\"$LocalPath2Index$var{'filenameindexlongglobal'}$var{'filenameextensionindex'}$var{'exthtml'}\">long</a>\n";
|
| 1023 | 382:baff1c482d98 | Chris | } |
| 1024 | |||
| 1025 | 381:2dc8163e9150 | Chris | if ($LocalGlobalLocal eq 'local') {
|
| 1026 | if ($var{'usecontentsm'} eq 'yes') {
|
||
| 1027 | print WRITEFILE " | <a href=\"$contentsname{$PathContents}$dirnamesingle{$PathContents}$var{'exthtml'}\">Local contents</a>\n";
|
||
| 1028 | } |
||
| 1029 | 389:0bc92382a86b | chris | if ($var{'frames'} eq 'yes') {
|
| 1030 | print WRITEFILE " | $var{'textjumpindexlocal'} ";
|
||
| 1031 | 382:baff1c482d98 | Chris | print WRITEFILE "<a href=\"$var{'filenameindexshortlocal'}$var{'filenameextensionframe'}$dirnamesingle{$PathContents}$var{'exthtml'}\">short</a> | ";
|
| 1032 | 389:0bc92382a86b | chris | print WRITEFILE "<a href=\"$var{'filenameindexlonglocal'}$var{'filenameextensionframe'}$dirnamesingle{$PathContents}$var{'exthtml'}\">long</a>\n";
|
| 1033 | } else {
|
||
| 1034 | print WRITEFILE " | $var{'textjumpindexlocal'} ";
|
||
| 1035 | print WRITEFILE "<a href=\"$var{'filenameindexshortlocal'}$var{'filenameextensionindex'}$dirnamesingle{$PathContents}$var{'exthtml'}\">short</a> | ";
|
||
| 1036 | print WRITEFILE "<a href=\"$var{'filenameindexlonglocal'}$var{'filenameextensionindex'}$dirnamesingle{$PathContents}$var{'exthtml'}\">long</a>\n";
|
||
| 1037 | } |
||
| 1038 | 381:2dc8163e9150 | Chris | } |
| 1039 | print WRITEFILE "</p>\n\n"; |
||
| 1040 | print WRITEFILE "$var{'codehr'}\n";
|
||
| 1041 | } |
||
| 1042 | |||
| 1043 | |||
| 1044 | #======================================================================== |
||
| 1045 | # Construct the contents.m files or update |
||
| 1046 | #======================================================================== |
||
| 1047 | sub ConstructContentsmFile |
||
| 1048 | {
|
||
| 1049 | local($LocalActDir, @localnames) = @_; |
||
| 1050 | local(*CFILE, $name,$newline); |
||
| 1051 | local($contentsfile, $isincontentsonly); |
||
| 1052 | local(@lines, @autoaddlines, @emptylines); |
||
| 1053 | local($autoadd) = 'AutoAdd'; |
||
| 1054 | local($autoaddsection) = 0; |
||
| 1055 | local($emptylineflag) = 0; |
||
| 1056 | local(%nameincontents); |
||
| 1057 | |||
| 1058 | # Build the contents file name |
||
| 1059 | $contentsfile = $LocalActDir.$contentsname{$LocalActDir}.$suffix;
|
||
| 1060 | |||
| 1061 | if (-e $contentsfile) {
|
||
| 1062 | open(CFILE,"<$contentsfile") || die("Cannot open contents file $contentsfile: $!\n");
|
||
| 1063 | while (<CFILE>) {
|
||
| 1064 | # Search for the specified string pattern |
||
| 1065 | @words = split; |
||
| 1066 | if ((@words >= 3) && ($words[2] eq '-')) {
|
||
| 1067 | $isincontentsonly = 0; |
||
| 1068 | foreach $name (@localnames) {
|
||
| 1069 | if ($name eq $words[1]) { # old
|
||
| 1070 | # if ($mfilename{$name} eq $words[1]) {
|
||
| 1071 | $isincontentsonly = 1; |
||
| 1072 | $nameincontents{$name} = 1;
|
||
| 1073 | $newline = sprintf("%% %-13s - %s\n", $mfilename{$name}, $apropos{$name});
|
||
| 1074 | push(@lines, $newline); |
||
| 1075 | } |
||
| 1076 | } |
||
| 1077 | # issue a warning, if file is in contents, but not as file in the directory |
||
| 1078 | if ($isincontentsonly == 0) {
|
||
| 1079 | print "\rConstructContents: Obsolete entry $words[1] in $contentsfile ! Entry not used.\n"; |
||
| 1080 | } |
||
| 1081 | } else {
|
||
| 1082 | # look for the AutoAdd section, should be the second word |
||
| 1083 | if ((@words >= 2) && ($words[1] eq $autoadd)) { $autoaddsection = 1; }
|
||
| 1084 | # push the red line in an array |
||
| 1085 | push(@lines, $_); |
||
| 1086 | } |
||
| 1087 | } |
||
| 1088 | close(CFILE); |
||
| 1089 | } else {
|
||
| 1090 | $newline = "% MATLAB Files in directory $LocalActDir\n%\n"; |
||
| 1091 | push(@lines, $newline); |
||
| 1092 | |||
| 1093 | } |
||
| 1094 | |||
| 1095 | # collect the file names, that were not included in original C|contents.m |
||
| 1096 | foreach $name (@localnames) {
|
||
| 1097 | if (! defined $nameincontents{$name}) {
|
||
| 1098 | if (! ($mfilename{$name} =~ /contents/i)) {
|
||
| 1099 | $newline = sprintf("%% %-13s - %s\n", $mfilename{$name}, $apropos{$name});
|
||
| 1100 | push(@autoaddlines, $newline); |
||
| 1101 | } |
||
| 1102 | } |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | # write/update C|contents.m only if variable is set |
||
| 1106 | if ($var{'writecontentsm'} eq 'yes') {
|
||
| 1107 | unlink($contentsfile); |
||
| 1108 | open(CFILE,">$contentsfile") || die("Cannot open contents file $contentsfile: $!\n");
|
||
| 1109 | # write old C|contents.m or header of new file, as long as comment lines |
||
| 1110 | foreach $line (@lines) {
|
||
| 1111 | if ($emptylineflag == 0) {
|
||
| 1112 | if ($line =~ /^\s*%/) { print CFILE $line; }
|
||
| 1113 | else { $emptylineflag = 1; push(@emptylines, $line); }
|
||
| 1114 | } else { push(@emptylines, $line); }
|
||
| 1115 | } |
||
| 1116 | # add header of AutoAdd section |
||
| 1117 | if (($autoaddsection == 0) && (@autoaddlines > 0)) { print CFILE "%\n% $autoadd\n"; }
|
||
| 1118 | # add autoadd section lines (previously undocumented files |
||
| 1119 | foreach $line (@autoaddlines) { print CFILE $line; }
|
||
| 1120 | # add tail of original C|contents.m (everything behind first non-comment line) |
||
| 1121 | foreach $line (@emptylines) { print CFILE $line; }
|
||
| 1122 | print CFILE "\n"; |
||
| 1123 | close CFILE; |
||
| 1124 | if ($opt_silent) { print "\r"; }
|
||
| 1125 | print " Contents file created/updated: $contentsfile\t"; |
||
| 1126 | if (!$opt_silent) { print "\n"; }
|
||
| 1127 | } |
||
| 1128 | } |
||
| 1129 | |||
| 1130 | |||
| 1131 | #======================================================================== |
||
| 1132 | # Replace found special characters with their HTMl Entities |
||
| 1133 | #======================================================================== |
||
| 1134 | sub SubstituteHTMLEntities {
|
||
| 1135 | local($_) = @_; |
||
| 1136 | |||
| 1137 | # Replace & <-> & < <-> < > <-> > " <-> " |
||
| 1138 | s/&/&/g; s/\</</g; s/\>/>/g; s/\"/"/g; |
||
| 1139 | return $_; |
||
| 1140 | } |
||
| 1141 | |||
| 1142 | #======================================================================== |
||
| 1143 | # Replace found m-filenamestring with full link. |
||
| 1144 | #======================================================================== |
||
| 1145 | sub SubstituteName2Link {
|
||
| 1146 | local($_, $funname) = @_; |
||
| 1147 | local($refstr1, $refstr2, $reffound); |
||
| 1148 | |||
| 1149 | # Look for something matching in the line |
||
| 1150 | if ( /(\W+)($funname)(\W+)/i ) {
|
||
| 1151 | $reffound = $2; |
||
| 1152 | 388:dad587ecb8d0 | chris | $refstr1 = "<a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$funname}$mfilename{$funname}$var{'exthtml'}\">";
|
| 1153 | 381:2dc8163e9150 | Chris | $refstr2 = "<\/a>"; |
| 1154 | # Do links only for exact case match |
||
| 1155 | if ( ($var{'links2filescase'} eq 'exact') || ($var{'links2filescase'} eq 'exactvery') ) {
|
||
| 1156 | if ( /(\W+)($funname)(\W+)/g ) {
|
||
| 1157 | s/(\W+)($funname)(\W+)/$1$refstr1$funname$refstr2$3/g; |
||
| 1158 | } |
||
| 1159 | else {
|
||
| 1160 | # Print info for not matching case in references, good for check up of files |
||
| 1161 | if ( ($var{'links2filescase'} eq 'exactvery') ) {
|
||
| 1162 | print "Diff in case found: $funname (case of file name) <-> $reffound (case in source code)\n"; |
||
| 1163 | print " (source line) $_ \n"; |
||
| 1164 | } |
||
| 1165 | } |
||
| 1166 | } |
||
| 1167 | # Do links for exact match and additionally for all upper case (often used in original matlab help text) |
||
| 1168 | elsif ( ($var{'links2filescase'} eq 'exactupper') ) {
|
||
| 1169 | s/(\W+)($funname)(\W+)/$1$refstr1$2$refstr2$3/g; |
||
| 1170 | $funname2 = "\U$funname\E"; |
||
| 1171 | s/(\W+)($funname2)(\W+)/$1$refstr1$2$refstr2$3/g; |
||
| 1172 | } |
||
| 1173 | # Do links for all case mixes, this calls for trouble under LINUX/UNIX |
||
| 1174 | else { #elsif ( ($var{'links2filescase'} eq 'all') )
|
||
| 1175 | s/(\W+)($funname)(\W+)/$1$refstr1$2$refstr2$3/ig; |
||
| 1176 | } |
||
| 1177 | } |
||
| 1178 | |||
| 1179 | return $_; |
||
| 1180 | } |
||
| 1181 | |||
| 1182 | #======================================================================== |
||
| 1183 | # Construct the html files for each matlab file. |
||
| 1184 | # Need to reread each matlab file to find the help text. |
||
| 1185 | # Note that we can't do this in a single loop because sometimes |
||
| 1186 | # the help text maybe before the function declaration. |
||
| 1187 | #======================================================================== |
||
| 1188 | sub ConstructHTMLFiles |
||
| 1189 | {
|
||
| 1190 | local(*MFILE); |
||
| 1191 | local(*HFILE); |
||
| 1192 | |||
| 1193 | local($filescreated) = 0; |
||
| 1194 | local($functionline); |
||
| 1195 | |||
| 1196 | foreach $name (@names) {
|
||
| 1197 | # Create cross reference information already here, used for keywords as well |
||
| 1198 | # Construct list of referenced functions |
||
| 1199 | @xref = @{'depcalls'.$name}; # the functions, that this m-file calls
|
||
| 1200 | @yref = @{'depcalled'.$name}; # the functions, that this m-file is called from
|
||
| 1201 | # print " depcalls: @{'depcalls'.$name}\n depcalled: @{'depcalled'.$name}\n";
|
||
| 1202 | # foreach $cname (@names) { next if $cname eq $name; push(@yref,$cname) if grep(/$name/,@{'depcalls'.$cname}); }
|
||
| 1203 | |||
| 1204 | |||
| 1205 | # Open m-file and html-file |
||
| 1206 | open(MFILE,"<$mfile{$name}");
|
||
| 1207 | open(HFILE,">$hfile{$name}");
|
||
| 1208 | |||
| 1209 | # Write the header of HTML file |
||
| 1210 | print HFILE "$TextDocTypeHTML\n<html>\n<head>\n$var{'codeheadmeta'}\n$TextMetaCharset\n$var{'csslink'}\n";
|
||
| 1211 | |||
| 1212 | # Write meta tags: use apropos (one line function description) for description |
||
| 1213 | # and cross reference function names for keywords (any better ideas?) |
||
| 1214 | print HFILE "<meta name=\"description\" content=\" $apropos{$name} \" />\n";
|
||
| 1215 | print HFILE "<meta name=\"keywords\" content=\" @xref @yref \" />\n"; |
||
| 1216 | |||
| 1217 | # Write Title and start body of html-file |
||
| 1218 | print HFILE "<title>$var{'texttitlefiles'} $mfilename{$name}</title>\n</head>\n";
|
||
| 1219 | print HFILE "<body $var{'codebodyfiles'}>\n";
|
||
| 1220 | print HFILE "<h1 $var{'codeheader'}>$var{'textheaderfiles'} $mfilename{$name}</h1>\n";
|
||
| 1221 | 401:a0f6e994657f | chris | |
| 1222 | # http://test.soundsoftware.ac.uk/cannam/projects/smallbox/repository/annotate/DL/RLS-DLA/SolveFISTA.m |
||
| 1223 | |||
| 1224 | print HFILE "<a href=\"" . $hfileindexpath{$name} . "../../projects/smallbox/repository/annotate/" . $mfiledir{$name} . $mfilename{$name} . ".m\">View in repository</a>\n";
|
||
| 1225 | |||
| 1226 | 381:2dc8163e9150 | Chris | print HFILE "$var{'codehr'}\n";
|
| 1227 | |||
| 1228 | # include links to short/long - local/global index and C|contents.m |
||
| 1229 | &ConstructLinks2Index(HFILE, $hfileindexpath{$name}, $mfiledir{$name}, 'local');
|
||
| 1230 | |||
| 1231 | # If this is a function, then write out the first line as a synopsis |
||
| 1232 | if ($mtype{$name} eq "function") {
|
||
| 1233 | print HFILE "<h2 $var{'codeheader'}>Function Synopsis</h2>\n";
|
||
| 1234 | print HFILE "<pre>$synopsis{$name}</pre>\n$var{'codehr'}\n";
|
||
| 1235 | } |
||
| 1236 | |||
| 1237 | # Look for the matlab help text block |
||
| 1238 | $functionline = "\n"; |
||
| 1239 | do {
|
||
| 1240 | $_ = <MFILE>; |
||
| 1241 | # remember functionline, if before help text block |
||
| 1242 | if (/^\s*function/) { $functionline = $_; }
|
||
| 1243 | } until (/^\s*%/ || eof); |
||
| 1244 | if (! (eof(MFILE))) {
|
||
| 1245 | print HFILE "<h2 $var{'codeheader'}>Help text</h2>\n";
|
||
| 1246 | print HFILE "<pre>\n"; |
||
| 1247 | while (/^\s*%/) {
|
||
| 1248 | # First remove leading % and white space, then Substitute special characlers |
||
| 1249 | s/^\s*%//; |
||
| 1250 | $_ = &SubstituteHTMLEntities($_); |
||
| 1251 | |||
| 1252 | # check/create cross references |
||
| 1253 | foreach $funname (@{'all'.$name}) {
|
||
| 1254 | if ($funname =~ /simulink/) { print "\n Simulink - Filename: $name; scanname: $funname\n"; }
|
||
| 1255 | next if $funname eq $name; |
||
| 1256 | $_ = &SubstituteName2Link($_, $funname); |
||
| 1257 | } |
||
| 1258 | print HFILE $_; |
||
| 1259 | if (! eof) { $_ = <MFILE>; }
|
||
| 1260 | } |
||
| 1261 | print HFILE "</pre>\n$var{'codehr'}\n";
|
||
| 1262 | } |
||
| 1263 | |||
| 1264 | # Write the cross reference information |
||
| 1265 | if (@xref || @yref) {
|
||
| 1266 | print HFILE "<h2 $var{'codeheader'}>Cross-Reference Information</H2>\n";
|
||
| 1267 | print HFILE "<table border=\"0\" width=\"100%\">\n<tr align=\"left\">\n<th width=\"50%\">"; |
||
| 1268 | if (@xref) {
|
||
| 1269 | print HFILE "This $mtype{$name} calls";
|
||
| 1270 | } |
||
| 1271 | print HFILE "</th>\n<th width=\"50%\">"; |
||
| 1272 | if (@yref) {
|
||
| 1273 | print HFILE "This $mtype{$name} is called by";
|
||
| 1274 | } |
||
| 1275 | print HFILE "</th>\n</tr>\n<tr valign=\"top\"><td>"; |
||
| 1276 | if (@xref) {
|
||
| 1277 | print HFILE "\n<ul>\n"; |
||
| 1278 | foreach $cname (sort @xref) {
|
||
| 1279 | print HFILE "<li><a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$cname}$mfilename{$cname}$var{'exthtml'}\">$mfilename{$cname}</a></li>\n";
|
||
| 1280 | } |
||
| 1281 | print HFILE "</ul>\n"; |
||
| 1282 | } |
||
| 1283 | print HFILE "</td><td>"; |
||
| 1284 | if (@yref) {
|
||
| 1285 | print HFILE "\n<ul>\n"; |
||
| 1286 | foreach $cname (sort @yref) {
|
||
| 1287 | print HFILE "<li><a class=\"mfun\" href=\"$hfileindexpath{$name}$hfilerelpath{$cname}$mfilename{$cname}$var{'exthtml'}\">$mfilename{$cname}</a></li>\n";
|
||
| 1288 | } |
||
| 1289 | print HFILE "</ul>\n"; |
||
| 1290 | } |
||
| 1291 | print HFILE "</td>\n</tr>\n</table>\n"; |
||
| 1292 | print HFILE "$var{'codehr'}\n";
|
||
| 1293 | } |
||
| 1294 | |||
| 1295 | # Include source text if requested |
||
| 1296 | if (($var{'includesource'} eq 'yes') && (! ($mfilename{$name} =~ /^contents$/i))) {
|
||
| 1297 | print HFILE "<h2 $var{'codeheader'}>Listing of $mtype{$name} $mfilename{$name}</h2>\n";
|
||
| 1298 | seek(MFILE,0,0); |
||
| 1299 | print HFILE "<pre>\n"; |
||
| 1300 | $IsStillHelp = 2; |
||
| 1301 | print HFILE $functionline; # functionline from scanning of help |
||
| 1302 | while (<MFILE>) {
|
||
| 1303 | if ($IsStillHelp == 2) {
|
||
| 1304 | next if (/^\s*$/); |
||
| 1305 | next if (/^\s*function/); |
||
| 1306 | if (/^\s*%/) { $IsStillHelp = 1; next; }
|
||
| 1307 | } elsif ($IsStillHelp == 1) {
|
||
| 1308 | next if (/^\s*%/); |
||
| 1309 | $IsStillHelp = 0; |
||
| 1310 | } |
||
| 1311 | |||
| 1312 | # Substritute special characters |
||
| 1313 | $_ = &SubstituteHTMLEntities($_); |
||
| 1314 | |||
| 1315 | # check for comment in line and format with css em |
||
| 1316 | 400:4ad6499d7998 | chris | s/^(.*)%(.*?)([\s\r\n]+)$/$1<em class=\"mcom\">%$2<\/em>$3/; |
| 1317 | 381:2dc8163e9150 | Chris | |
| 1318 | # check/create cross references |
||
| 1319 | foreach $funname (@{'all'.$name}) {
|
||
| 1320 | next if $funname eq $name; |
||
| 1321 | $_ = &SubstituteName2Link($_, $funname); |
||
| 1322 | } |
||
| 1323 | print HFILE $_; |
||
| 1324 | } |
||
| 1325 | print HFILE "</pre>\n$var{'codehr'}\n";
|
||
| 1326 | } |
||
| 1327 | |||
| 1328 | # Include info about author from authorfile |
||
| 1329 | &WriteFile2Handle($var{'authorfile'}, HFILE) ;
|
||
| 1330 | |||
| 1331 | print HFILE "<!--navigate-->\n"; |
||
| 1332 | print HFILE "<!--copyright-->\n"; |
||
| 1333 | print HFILE "</body>\n</html>\n"; |
||
| 1334 | close(MFILE); |
||
| 1335 | close(HFILE); |
||
| 1336 | |||
| 1337 | # Print name of finished file |
||
| 1338 | if ($opt_silent) { print "\r"; }
|
||
| 1339 | print " HTML-File created: $hfile{$name}\t";
|
||
| 1340 | if (!$opt_silent) { print "\n"; }
|
||
| 1341 | $filescreated++; |
||
| 1342 | } |
||
| 1343 | |||
| 1344 | print "\n$PROGRAM: $indexcreated index and $filescreated files created.\n"; |
||
| 1345 | } |
||
| 1346 | |||
| 1347 | #======================================================================== |
||
| 1348 | # Function: CheckFileName |
||
| 1349 | # Purpose: . |
||
| 1350 | #======================================================================== |
||
| 1351 | sub CheckFileName {
|
||
| 1352 | local($filename, $description) = @_; |
||
| 1353 | local(*CHECKFILE); |
||
| 1354 | |||
| 1355 | open(CHECKFILE,"<$filename") || do {
|
||
| 1356 | if ($description eq '') {$description = 'file';}
|
||
| 1357 | # if (!$opt_silent) { print "Cannot open $description $filename: $!\n"; }
|
||
| 1358 | print "Cannot open $description $filename: $!\n"; |
||
| 1359 | return 1; |
||
| 1360 | }; |
||
| 1361 | close(CHECKFILE); |
||
| 1362 | return 0; |
||
| 1363 | |||
| 1364 | } |
||
| 1365 | |||
| 1366 | #======================================================================== |
||
| 1367 | # Function: CheckDirName |
||
| 1368 | # Purpose: . |
||
| 1369 | #======================================================================== |
||
| 1370 | sub CheckDirName {
|
||
| 1371 | local($dirname, $description) = @_; |
||
| 1372 | local(*CHECKDIR); |
||
| 1373 | |||
| 1374 | opendir(CHECKDIR,"$dirname") || die ("Cannot open $description directory $dirname: $!\n");
|
||
| 1375 | closedir(CHECKDIR); |
||
| 1376 | } |
||
| 1377 | |||
| 1378 | #======================================================================== |
||
| 1379 | # Function: WriteFile2Handle |
||
| 1380 | # Purpose: . |
||
| 1381 | #======================================================================== |
||
| 1382 | sub WriteFile2Handle {
|
||
| 1383 | local($filename, *WRITEFILE) = @_; |
||
| 1384 | local(*READFILE); |
||
| 1385 | |||
| 1386 | if ($filename ne '') {
|
||
| 1387 | open(READFILE,"<$filename"); |
||
| 1388 | @filecontents = <READFILE>; |
||
| 1389 | close(READFILE); |
||
| 1390 | print WRITEFILE "@filecontents\n"; |
||
| 1391 | # if (!$opt_silent) {print " Contents of $filename added\n"};
|
||
| 1392 | } |
||
| 1393 | } |
||
| 1394 | |||
| 1395 | |||
| 1396 | #======================================================================== |
||
| 1397 | # Function: GetConfigFile |
||
| 1398 | # Purpose: Read user's configuration file, if such exists. |
||
| 1399 | #======================================================================== |
||
| 1400 | sub GetConfigFile |
||
| 1401 | {
|
||
| 1402 | local($filename) = @_; |
||
| 1403 | local(*CONFIG); |
||
| 1404 | local($value); |
||
| 1405 | |||
| 1406 | if (&CheckFileName($filename, 'configuration file')) {
|
||
| 1407 | # if (!$opt_silent) { print " Proceeding using built-in defaults for configuration.\n"; }
|
||
| 1408 | print " Proceeding using built-in defaults for configuration.\n"; |
||
| 1409 | return 0; |
||
| 1410 | }; |
||
| 1411 | |||
| 1412 | open(CONFIG,"< $filename"); |
||
| 1413 | while (<CONFIG>) {
|
||
| 1414 | s/#.*$//; |
||
| 1415 | next if /^\s*$/o; |
||
| 1416 | |||
| 1417 | # match keyword: process one or more arguments |
||
| 1418 | # keyword set |
||
| 1419 | if (/^\s*set\s+(\S+)\s*=\s*(.*)/) {
|
||
| 1420 | # setting a configuration variable |
||
| 1421 | if (defined $var{$1}) {
|
||
| 1422 | $var{$1} = $2;
|
||
| 1423 | if ($debug > 3) { print "$1: $var{$1}\n"; }
|
||
| 1424 | } |
||
| 1425 | else {
|
||
| 1426 | print "$PROGRAM: unknown variable `$1' in configuration file\n" |
||
| 1427 | } |
||
| 1428 | } else {
|
||
| 1429 | chop($_); |
||
| 1430 | print "$PROGRAM: unknown keyword in configuration file in line: `$_'\n" |
||
| 1431 | } |
||
| 1432 | } |
||
| 1433 | close CONFIG; |
||
| 1434 | 1; |
||
| 1435 | } |
||
| 1436 | |||
| 1437 | |||
| 1438 | #------------------------------------------------------------------------ |
||
| 1439 | # DisplayHelp - display help text using -h or -help command-line switch |
||
| 1440 | #------------------------------------------------------------------------ |
||
| 1441 | sub DisplayHelp |
||
| 1442 | {
|
||
| 1443 | $help=<<EofHelp; |
||
| 1444 | $PROGRAM v$VERSION - generate html documentation from Matlab m-files |
||
| 1445 | |||
| 1446 | Usage: $PROGRAM [-h] [-c config_file] [-m|dirmfiles matlab_dir] [-d|dirhtml html_dir] |
||
| 1447 | [-i yes|no] [-r yes|no] [-p yes|no] [-quiet|q] [-a authorfile] |
||
| 1448 | |||
| 1449 | $PROGRAM is a perl script that reads each matlab .m file in a directory |
||
| 1450 | to produce a corresponding .html file of help documentation and cross |
||
| 1451 | reference information. An index file is written with links to all of |
||
| 1452 | the html files produced. The options are: |
||
| 1453 | |||
| 1454 | -quiet or -q : be silent, no status information during generation |
||
| 1455 | -help or -h : display this help message |
||
| 1456 | -todo or -t : print the todo list for $PROGRAM |
||
| 1457 | -version or -v : display version |
||
| 1458 | |||
| 1459 | -configfile or -c : name of configuration file (default to $var{'configfile'}).
|
||
| 1460 | -dirmfiles or -m : top level directory containing matlab files to generate html for; |
||
| 1461 | default to actual directory. |
||
| 1462 | -dirhtml or -d : top level directory for generated html files; |
||
| 1463 | default to actual directory. |
||
| 1464 | |||
| 1465 | -includesource or -i : Include matlab source in the html documentation [yes|no] |
||
| 1466 | default to yes. |
||
| 1467 | -processtree or -r : create docu for m-file directory and all subdirectories [yes|no]; |
||
| 1468 | default to yes. |
||
| 1469 | -producetree or -p : create multi-level docu identical to directory structure |
||
| 1470 | of m-files [yes|no]; default to yes. |
||
| 1471 | -writecontentsm or -w: update or write contents.m files into the matlab source |
||
| 1472 | directories [yes|no]; default to no. |
||
| 1473 | |||
| 1474 | -authorfile or -a : name of file including author information, last element in html; |
||
| 1475 | default to empty. |
||
| 1476 | |||
| 1477 | The command line setting overwrite all other settings (built-in and configuration file). |
||
| 1478 | The configuration file settings overwrite the built-in settings (and not the command |
||
| 1479 | line settings). |
||
| 1480 | |||
| 1481 | Typical usages are: |
||
| 1482 | $PROGRAM |
||
| 1483 | (use default parameters from perl script, if configuration |
||
| 1484 | file is found -> generation of docu, else display of help) |
||
| 1485 | |||
| 1486 | $PROGRAM -dirmfiles matlab -dirhtml html |
||
| 1487 | (generate html documentation for all m-files in directory matlab, |
||
| 1488 | place html files in directory html, use built-in defaults for |
||
| 1489 | all other parameters, this way all m-files in the directory |
||
| 1490 | matlab and below are converted and the generated html-files are |
||
| 1491 | placed in the directory html and below producing the same |
||
| 1492 | directory structure than below matlab) |
||
| 1493 | |||
| 1494 | $PROGRAM -quiet |
||
| 1495 | (use built-in parameters from perl script, if configuration |
||
| 1496 | file is found use these settings as well, do generation, |
||
| 1497 | no display except critical errors, status of conversion and result) |
||
| 1498 | |||
| 1499 | $PROGRAM -m toolbox -dirhtml doc/html -r yes -p no |
||
| 1500 | (convert all m-files in directory toolbox and below and place |
||
| 1501 | the generated html files in directory doc/html, read all m-files |
||
| 1502 | recursively, however, the generated html files are placed in one |
||
| 1503 | directory) |
||
| 1504 | |||
| 1505 | $PROGRAM -m toolbox -dirhtml doc/html -i no -r no |
||
| 1506 | (convert all m-files in directory toolbox and place |
||
| 1507 | the generated html files in directory doc/html, do not read m-files |
||
| 1508 | recursively, do not include source code in documentation) |
||
| 1509 | |||
| 1510 | EofHelp |
||
| 1511 | |||
| 1512 | die "$help"; |
||
| 1513 | } |
||
| 1514 | |||
| 1515 | #------------------------------------------------------------------------ |
||
| 1516 | # DisplayTodo - display ToDo list using -t or -todo command-line switch |
||
| 1517 | #------------------------------------------------------------------------ |
||
| 1518 | sub DisplayTodo |
||
| 1519 | {
|
||
| 1520 | $todo=<<EofToDo; |
||
| 1521 | $PROGRAM v$VERSION - ToDo list |
||
| 1522 | |||
| 1523 | o use more than one high level directory |
||
| 1524 | |||
| 1525 | o what should/could be done here??? |
||
| 1526 | |||
| 1527 | EofToDo |
||
| 1528 | |||
| 1529 | die "$todo"; |
||
| 1530 | } |
||
| 1531 | |||
| 1532 | |||
| 1533 | #------------------------------------------------------------------------ |
||
| 1534 | # ListVariables - list all defined variables and their values |
||
| 1535 | #------------------------------------------------------------------------ |
||
| 1536 | sub ListVariables |
||
| 1537 | {
|
||
| 1538 | local($value); |
||
| 1539 | |||
| 1540 | if ($debug > 0) {
|
||
| 1541 | print "List of all variables and their values\n"; |
||
| 1542 | foreach (sort keys %var) |
||
| 1543 | {
|
||
| 1544 | if ($var{$_} eq '') {
|
||
| 1545 | $value = "empty"; |
||
| 1546 | } else {
|
||
| 1547 | $value = $var{$_};
|
||
| 1548 | } |
||
| 1549 | print " $_\n $value\n"; |
||
| 1550 | } |
||
| 1551 | print "\n\n"; |
||
| 1552 | } |
||
| 1553 | } |
||
| 1554 | |||
| 1555 | |||
| 1556 | __END__ |
||
| 1557 | :endofperl |