[49c6428] | 1 | #!/usr/bin/perl |
---|
[52461c5] | 2 | # Src2html: Take a source tree and generate Html documents that have hyperlinks |
---|
| 3 | # to the definition of structures, variables, functions, and preprocessor |
---|
| 4 | # definitions. Read the manual page for details on how to use the program. |
---|
| 5 | # |
---|
| 6 | # Version 1.4-alpha. Written by Warren Toomey wkt@cs.adfa.oz.au |
---|
| 7 | # |
---|
| 8 | # 19th January 1996 |
---|
| 9 | # |
---|
[49c6428] | 10 | # $Id$ |
---|
| 11 | # |
---|
[52461c5] | 12 | |
---|
| 13 | if ($#ARGV <= 0 || $#ARGV > 4) { # Check arg count |
---|
| 14 | print(STDERR "Usage: $0 [-na] [-nl] [-d num] input_description\n"); |
---|
| 15 | print(STDERR " -na: Don't produce top-level category files\n"); |
---|
| 16 | print(STDERR " -nl: Don't produce per-letter files\n"); |
---|
| 17 | print(STDERR " -d: Set debugging to given number (0-3)\n"); |
---|
| 18 | exit(1); |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | # Set up default option values |
---|
| 22 | $NoLetters= 0; |
---|
| 23 | $NoAll= 0; |
---|
| 24 | $Debug=0; |
---|
| 25 | $Top= $ARGV[$#ARGV]; |
---|
| 26 | $Top=~ s/\.s2h$//; |
---|
| 27 | |
---|
| 28 | # Parse the options |
---|
| 29 | for ($i=0; $i<= $#ARGV; $i++) { |
---|
| 30 | if ($ARGV[$i] eq "-na") { $NoAll= 1; next; } |
---|
| 31 | if ($ARGV[$i] eq "-nl") { $NoLetters= 1; next; } |
---|
| 32 | if ($ARGV[$i] eq "-d") { $i++; $Debug= $ARGV[$i]; next; } |
---|
| 33 | } |
---|
| 34 | |
---|
[49c6428] | 35 | $Title{"m"}= "C Macros"; |
---|
| 36 | $Title{"d"}= "C Defines"; |
---|
| 37 | $Title{"f"}= "C Functions"; |
---|
| 38 | $Title{"v"}= "C Variables"; |
---|
| 39 | $Title{"s"}= "C Structs"; |
---|
| 40 | $Title{"u"}= "C Unions"; |
---|
| 41 | $Title{"t"}= "C Typedefs"; |
---|
| 42 | $Title{"e"}= "C Enums"; |
---|
| 43 | $Title{"AdaType"}= "Ada Types"; |
---|
| 44 | $Title{"AdaProcedure"}= "Ada Procedures"; |
---|
| 45 | $Title{"AdaFunction"}= "Ada Functions"; |
---|
| 46 | $Title{"AdaPackage"}= "Ada Packages"; |
---|
| 47 | $Title{"AdaTask"}= "Ada Tasks"; |
---|
[52461c5] | 48 | $Title{"g"}= "All symbols"; |
---|
| 49 | |
---|
| 50 | &get_s2h; # Read the description file |
---|
| 51 | &make_dirs; # Make directories as needed |
---|
| 52 | &make_ctags; # Generate ctags for all src |
---|
| 53 | &parse_ctags; # Parse ctags, generate html ptr files |
---|
| 54 | foreach $i (keys(%Dirinfo)) |
---|
| 55 | { &rewrite_src($i); } # Rewrite the src code |
---|
| 56 | exit(0); # and exit |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | ## get_s2h: Opens the source description file, reads it, and sets up some |
---|
| 60 | ## variables describing where some directories are, and the source directories |
---|
| 61 | ## to process. Variables used are: |
---|
| 62 | ## Srctree - The root of the source tree we are processing |
---|
| 63 | ## Htmlroot - The directory where all WWW documents are kept |
---|
| 64 | ## Htmldir - The directory under Htmlroot for this source tree |
---|
| 65 | ## Htmltree - The root of the destination tree for the Html code |
---|
| 66 | ## Newsrctree - The directory in Htmltree to store the new Htmlised code |
---|
| 67 | ## Headers - The directory where we keep information to prepend in some docs |
---|
| 68 | ## Formdir - The place to put the index searching script |
---|
| 69 | ## Dirinfo{} - The list of dirs and the info about the directory |
---|
| 70 | ## Dotdir{} - The directory name with /'s -> .'s |
---|
| 71 | |
---|
| 72 | sub get_s2h { |
---|
| 73 | $Newsrctree= 'newsrc'; # Set up as default |
---|
| 74 | $Headers= '.'; |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | ######################################################### |
---|
| 78 | # make sure we dump out the last bit of the last file.... |
---|
| 79 | |
---|
| 80 | # Print out the remainder of the |
---|
| 81 | # current file, incl. the buffered line |
---|
| 82 | if ($In_file == 1) { |
---|
| 83 | if ("$line" ne "") { print OUT $line; } |
---|
| 84 | while (<IN>) { |
---|
| 85 | s/\&/&/g; s/\</</g; s/\>/>/g; print OUT; |
---|
| 86 | } |
---|
| 87 | print OUT "\n\n\n\n\n\n\n\n</pre></body>\n"; |
---|
| 88 | close(IN); close(OUT); |
---|
| 89 | } |
---|
| 90 | ######################################################### |
---|
| 91 | |
---|
| 92 | open(S2H,$ARGV[$#ARGV]) # Open descript |
---|
| 93 | || die "$0: can't open $ARGV[$#ARGV]: $!\n"; |
---|
| 94 | |
---|
| 95 | while(<S2H>) { # Read in input lines |
---|
| 96 | next if /^#/; # Skip comments |
---|
| 97 | if ( /^set\s+Srctree\s+(\S+)/ ) { |
---|
| 98 | $Srctree = $1; next; # Set the variable |
---|
| 99 | } |
---|
| 100 | if ( /^set\s+Htmlroot\s+(\S+)/ ) { |
---|
| 101 | $Htmlroot = $1; next; # Set the variable |
---|
| 102 | } |
---|
| 103 | if ( /^set\s+Htmldir\s+(\S+)/ ) { |
---|
| 104 | $Htmldir = $1; next; # Set the variable |
---|
| 105 | } |
---|
| 106 | if ( /^set\s+Newsrctree\s+(\S+)/ ) { |
---|
| 107 | $Newsrctree = $1; next; # Set the variable |
---|
| 108 | } |
---|
| 109 | if ( /^set\s+Headers\s+(\S+)/ ) { |
---|
| 110 | $Headers = $1; next; # Set the variable |
---|
| 111 | } |
---|
| 112 | if ( /^set\s+Formdir\s+(\S+)/ ) { |
---|
| 113 | $Formdir = $1; next; # Set the variable |
---|
| 114 | } |
---|
| 115 | if ( /^dir\s+(\S+)\s+(.*)/ ) { |
---|
| 116 | $Dirinfo{$1}= $2; $Dotdir{$1}=$1; |
---|
| 117 | $Dotdir{$1}=~ s/\//./g; |
---|
| 118 | next; # Get dir commands |
---|
| 119 | } |
---|
| 120 | if ( /^\n/ ) { next; } # Ignore blank lines |
---|
| 121 | # Bad input line, give warning |
---|
| 122 | chop; print "$_: Bad line, ignoring\n"; next; |
---|
| 123 | } |
---|
| 124 | close(S2H); |
---|
| 125 | if (!defined($Srctree)) { die "$0: Srctree undefined in $ARGV[$#ARGV]\n"; } |
---|
| 126 | if (!defined($Htmlroot)) { die "$0: Htmlroot undefined in $ARGV[$#ARGV]\n"; } |
---|
| 127 | if (!defined($Htmldir)) { die "$0: Htmldir undefined in $ARGV[$#ARGV]\n"; } |
---|
| 128 | $Htmltree= "$Htmlroot/$Htmldir"; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | ## make_dirs: Make the directories need to store the Html documents, and also |
---|
| 132 | ## check to make sure that the input directories exist. We depend upon mkdir(1) |
---|
| 133 | ## having the -p option to make intermediate directories as needed. |
---|
| 134 | |
---|
| 135 | sub make_dirs { |
---|
| 136 | local($i); |
---|
| 137 | |
---|
| 138 | foreach $i (keys(%Dirinfo)) { # Check that the directories exist |
---|
| 139 | if (! -e "$Srctree/$i") { |
---|
| 140 | die "$0: Input dir $Srctree/$i doesn't exist\n"; |
---|
| 141 | } |
---|
| 142 | if (! -d "$Srctree/$i") { |
---|
| 143 | die "$0: Input dir $Srctree/$i is not a directory\n"; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | if (! -e "$Htmltree") { |
---|
| 147 | system("mkdir -p $Htmltree") && die "$0: Can't mkdir $Htmltree\n"; |
---|
| 148 | } |
---|
| 149 | if (! -e "$Htmltree/$Newsrctree") { |
---|
| 150 | system("mkdir -p $Htmltree/$Newsrctree") |
---|
| 151 | && die "$0: Can't mkdir $Htmltree/$Newsrctree\n"; |
---|
| 152 | } |
---|
| 153 | if (! -e "$Htmltree/ctags") { |
---|
| 154 | system("mkdir -p $Htmltree/ctags") && die "$0: Can't mkdir ctags\n"; |
---|
| 155 | } |
---|
| 156 | foreach $i (keys(%Dirinfo)) { |
---|
| 157 | if (! -e "$Htmltree/$Newsrctree/$i") { |
---|
| 158 | system("mkdir -p $Htmltree/$Newsrctree/$i") |
---|
| 159 | && die "$0: Can't mkdir $Htmltree/$Newsrctree/$i\n"; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | ## make_ctags: Process all the source code, creating the ctags files. |
---|
| 165 | ## The Ctagsfile{} array is set up to hold the name of the ctags files |
---|
| 166 | ## created. |
---|
| 167 | |
---|
| 168 | sub make_ctags { |
---|
| 169 | local($i); |
---|
| 170 | |
---|
| 171 | foreach $i (keys(%Dirinfo)) { |
---|
| 172 | $Ctagsfile{$i}= "$Htmltree/ctags/$Dotdir{$i}.ctags"; |
---|
| 173 | if ($Debug > 0 ) { print "Generating ctags for $Ctagsfile{$i}\n"; } |
---|
[49c6428] | 174 | system("(cd $Srctree; /usr1/rtems/rtemsdoc-work/tools/src2html/ctags-wr $i) > $Ctagsfile{$i}") |
---|
[52461c5] | 175 | && print "$0: ctags failed on $Srctree/$i\n"; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | ## parse_ctags: Parse the ctags file produced by make_ctags, creating several |
---|
| 181 | ## arrays of information. The arrays created are: |
---|
| 182 | ## Macro{} - The name of every macro and its name lowercased |
---|
| 183 | ## Def{} - The name of every define and its name lowercased |
---|
| 184 | ## Func{} - The name of every function and its name lowercased |
---|
| 185 | ## Var{} - The name of every variable and its name lowercased |
---|
| 186 | ## Struct{} - The name of every struct and its name lowercased |
---|
| 187 | ## Union{} - The name of every union and its name lowercased |
---|
| 188 | ## Type{} - The name of every typedef and its name lowercased |
---|
| 189 | ## Enum{} - The name of every enum and its name lowercased |
---|
| 190 | ## Nfile{} - The directory in which the symbol was found |
---|
| 191 | ## Nline{} - The line number where the symbol was found |
---|
| 192 | |
---|
| 193 | sub parse_ctags { |
---|
| 194 | local($i); |
---|
| 195 | local($low); |
---|
[49c6428] | 196 | local($count); |
---|
| 197 | |
---|
| 198 | $count = 0; |
---|
[52461c5] | 199 | |
---|
| 200 | foreach $i (keys(%Dirinfo)) { |
---|
| 201 | open(CTAGS,$Ctagsfile{$i}) || die "$0: Can't open $Ctagsfile{$i}, $!\n"; |
---|
| 202 | if ($Debug > 0) { print "Parsing $Ctagsfile{$i} to build ptr files\n"; } |
---|
| 203 | while (<CTAGS>) { |
---|
[49c6428] | 204 | $count ++; |
---|
[52461c5] | 205 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+Preprocessor macro/ ) { |
---|
[49c6428] | 206 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 207 | $Macro{$k}=$1; $Nline{$k}= $2; |
---|
| 208 | $Nfile{$k}= $3; next; |
---|
[52461c5] | 209 | } |
---|
| 210 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+Preprocessor define/ ) { |
---|
[49c6428] | 211 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 212 | $Def{$k}=$1; $Nline{$k}= $2; |
---|
| 213 | $Nfile{$k}= $3; next; |
---|
[52461c5] | 214 | } |
---|
| 215 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C struct/ ) { |
---|
[49c6428] | 216 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 217 | $Struct{$k}=$1; $Nline{$k}= $2; |
---|
| 218 | $Nfile{$k}= $3; next; |
---|
[52461c5] | 219 | } |
---|
| 220 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C union/ ) { |
---|
[49c6428] | 221 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 222 | $Union{$k}=$1; $Nline{$k}= $2; |
---|
| 223 | $Nfile{$k}= $3; next; |
---|
[52461c5] | 224 | } |
---|
| 225 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C typedef/ ) { |
---|
[49c6428] | 226 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 227 | $Type{$k}=$1; $Nline{$k}= $2; |
---|
| 228 | $Nfile{$k}= $3; next; |
---|
[52461c5] | 229 | } |
---|
| 230 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C enum/ ) { |
---|
[49c6428] | 231 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 232 | $Enum{$k}=$1; $Nline{$k}= $2; |
---|
| 233 | $Nfile{$k}= $3; next; |
---|
[52461c5] | 234 | } |
---|
| 235 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C function/ ) { |
---|
[49c6428] | 236 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 237 | $Func{$k}=$1; $Nline{$k}= $2; |
---|
| 238 | $Nfile{$k}= $3; next; |
---|
[52461c5] | 239 | } |
---|
| 240 | if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C variable/ ) { |
---|
[49c6428] | 241 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 242 | $Var{$k}=$1; $Nline{$k}= $2; |
---|
| 243 | $Nfile{$k}= $3; next; |
---|
| 244 | } |
---|
| 245 | if ( /^(return)\/.\s+(\d+)\s+(\S+)\s+.*/ ) { |
---|
| 246 | next; |
---|
| 247 | # Code like the following line results in "return" as ctag |
---|
| 248 | # "type Action is access function return Boolean; |
---|
| 249 | } |
---|
| 250 | if ( /^(\w+)\/.\s+(\d+)\s+(\S+)\s+use .*/ ) { |
---|
| 251 | next; |
---|
| 252 | # throw away lines like "use type System" |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | if ( /^(\w+)\/.\s+(\d+)\s+(\S+)\s+type .*/ ) { |
---|
| 256 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 257 | $AdaType{$k}=$1; $Nline{$k}= $2; |
---|
| 258 | $Nfile{$k}= $3; next; |
---|
| 259 | } |
---|
| 260 | if ( /^(\w+)\/.+\s+(\d+)\s+(\S+)\s+procedure .*/ ) { |
---|
| 261 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 262 | $AdaProcedure{$k}=$1; $Nline{$k}= $2; |
---|
| 263 | $Nfile{$k}= $3; next; |
---|
| 264 | } |
---|
| 265 | if ( /^(\w+)\/.+\s+(\d+)\s+(\S+)\s+function .*/ ) { |
---|
| 266 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 267 | $AdaFunction{$k}=$1; $Nline{$k}= $2; |
---|
| 268 | $Nfile{$k}= $3; next; |
---|
| 269 | } |
---|
| 270 | if ( /^(\".+)\/.+\s+(\d+)\s+(\S+)\s+function .*/ ) { |
---|
| 271 | next; |
---|
| 272 | # throw away functions like "*" |
---|
| 273 | } |
---|
| 274 | if ( /^(\w+)\/.\s+(\d+)\s+(\S+)\s+package .*/ ) { |
---|
| 275 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 276 | $AdaPackage{$k}=$1; $Nline{$k}= $2; |
---|
| 277 | $Nfile{$k}= $3; next; |
---|
| 278 | } |
---|
| 279 | if ( /^(\w+)\/.\s+(\d+)\s+(\S+)\s+task .*/ ) { |
---|
| 280 | ($low=$1)=~tr/A-Z_/a-z/d; $k="$low$count"; |
---|
| 281 | $AdaTask{$k}=$1; $Nline{$k}= $2; |
---|
| 282 | $Nfile{$k}= $3; next; |
---|
| 283 | } |
---|
| 284 | if ( /^([\w\/]+)\s+(\d+)\s+(\S+)\s+use type .*/ ) { |
---|
| 285 | next; |
---|
| 286 | } |
---|
| 287 | if ( /^([\w\/\(]+)\s+(\d+)\s+(\S+)\s+type .*/ ) { |
---|
| 288 | next; |
---|
| 289 | } |
---|
| 290 | if ( /^;([\w\/\(]+)\s+(\d+)\s+(\S+)\s+type .*/ ) { |
---|
| 291 | next; |
---|
| 292 | } |
---|
| 293 | if ( /^\(([\w\/\(]+)\s+(\d+)\s+(\S+)\s+procedure .*/ ) { |
---|
| 294 | next; |
---|
[52461c5] | 295 | } |
---|
| 296 | print "$0: In Ctagsfile{$i}, don't recognise $_"; |
---|
| 297 | } |
---|
| 298 | close(CTAGS); |
---|
| 299 | &make_dir_html($i); |
---|
| 300 | undef %Macro; undef %Def; undef %Func; undef %Var; |
---|
| 301 | undef %Struct; undef %Union; undef %Type; undef %Enum; |
---|
[49c6428] | 302 | undef %AdaType; undef %AdaProcedure; undef %AdaFunction; |
---|
| 303 | undef %AdaPackage; undef %AdaTask; |
---|
[52461c5] | 304 | } |
---|
| 305 | &make_top_html; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | ## make_letters_html: Make the lowest HTML documents, i.e those per-directory |
---|
| 309 | ## per-type per-letter Htmls that point directly at the source code. |
---|
| 310 | ## Arguments are: Dir name, prefix, title, Name/dir list |
---|
| 311 | ## If the file is created, set $Exists(letter) positive, else to 0. |
---|
| 312 | |
---|
| 313 | sub make_letters_html { |
---|
| 314 | local($dir)= $_[0]; |
---|
| 315 | local($pref)= $_[1]; |
---|
| 316 | local($title)= $_[2]; |
---|
| 317 | local(*type)= $_[3]; |
---|
| 318 | local($htmlfile); |
---|
| 319 | local($let)="@"; |
---|
| 320 | |
---|
[49c6428] | 321 | foreach $i ( "a".."z", |
---|
| 322 | "AdaType", "AdaProcedure", "AdaFunction", "AdaPackage", "AdaTask" ) { |
---|
| 323 | $Exists{$i}=0; |
---|
| 324 | } |
---|
[52461c5] | 325 | foreach $name (sort keys( %type )) { |
---|
| 326 | if (substr($name,0,1) ne $let) { |
---|
| 327 | if ($let ne "@") { |
---|
| 328 | print HTML "</ul></body>\n"; |
---|
| 329 | close(HTML); |
---|
| 330 | $Exists{$let}= 1; |
---|
| 331 | } |
---|
| 332 | $let= substr($name, 0, 1); |
---|
| 333 | $htmlfile= "$Htmltree/$Dotdir{$dir}.$pref$let.html"; |
---|
| 334 | open(HTML, "> $htmlfile") || die "$0: Can't open $htmlfile, $!\n"; |
---|
| 335 | |
---|
| 336 | print HTML "<head>\n<title>$title starting with "; |
---|
| 337 | print HTML "`$let' in $dir</title>\n"; |
---|
| 338 | print HTML "</head><body><h1>$title starting with "; |
---|
| 339 | print HTML "`$let' in $dir</h1><p>\n"; |
---|
| 340 | print HTML "<ul>\n"; |
---|
| 341 | } |
---|
[49c6428] | 342 | # print HTML "<li><a href=\"$Newsrctree/$Nfile{$type{$name}}"; |
---|
| 343 | # print HTML ".html#$type{$name}\">$type{$name}</a> "; |
---|
| 344 | # print HTML "$Nfile{$type{$name}}:$Nline{$type{$name}}\n"; next; |
---|
| 345 | |
---|
| 346 | print HTML "<li><a href=\"$Newsrctree/$Nfile{$name}"; |
---|
[52461c5] | 347 | print HTML ".html#$type{$name}\">$type{$name}</a> "; |
---|
[49c6428] | 348 | print HTML "$Nfile{$name}:$Nline{$name}\n"; next; |
---|
[52461c5] | 349 | } |
---|
| 350 | print HTML "</ul></body>\n"; |
---|
| 351 | close(HTML); |
---|
| 352 | $Exists{$let}= 1; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | ## make_type_html: Make the type htmls. If there are <50 symbols for the |
---|
| 356 | ## directory, create the per-directory per-type html document only. Otherwise |
---|
| 357 | ## for every letter grep symbols, call make_lowest_letter_html, and |
---|
| 358 | ## finally create the per-directory per-type html document that points only |
---|
| 359 | ## at the letter files created. |
---|
| 360 | ## Arguments are: Dir name, prefix, title, Name/dir list |
---|
| 361 | |
---|
| 362 | sub make_type_html { |
---|
| 363 | local($dir)= $_[0]; |
---|
| 364 | local($pref)= $_[1]; |
---|
| 365 | local($title)= $_[2]; |
---|
| 366 | local(*type)= $_[3]; |
---|
| 367 | local($i); |
---|
| 368 | local($htmlfile); |
---|
| 369 | local(@keys)= keys(%type); |
---|
| 370 | local($name); |
---|
| 371 | |
---|
| 372 | $Exists{$title}=0; |
---|
| 373 | if ( $#keys < 0 ) { return; } |
---|
| 374 | if ($Debug > 0) { |
---|
| 375 | $i= $#keys + 1; |
---|
| 376 | print "The associative array for $dir $title has $i elements\n"; |
---|
| 377 | } |
---|
| 378 | if ( ($#keys < 50) || ($NoLetters == 1) ) { |
---|
| 379 | $htmlfile= "$Htmltree/$Dotdir{$dir}.$pref.html"; |
---|
| 380 | open(HTML, "> $htmlfile") || die "$0: Can't open $htmlfile, $!\n"; |
---|
| 381 | print HTML "<head>\n<title>$title in $dir</title>\n"; |
---|
| 382 | print HTML "</head><body><h1>$title in $dir</h1>\n"; |
---|
| 383 | print HTML "<ul>\n"; |
---|
| 384 | foreach $name (sort keys( %type )) { |
---|
[49c6428] | 385 | # print HTML "<li><a href=\"$Newsrctree/$Nfile{$type{$name}}"; |
---|
| 386 | # print HTML ".html#$type{$name}\">$type{$name}</a> "; |
---|
| 387 | # print HTML "$Nfile{$type{$name}}:$Nline{$type{$name}}\n"; next; |
---|
| 388 | |
---|
| 389 | print HTML "<li><a href=\"$Newsrctree/$Nfile{$name}"; |
---|
| 390 | print HTML ".html#$type{$name}\">$type{$name}</a> "; |
---|
| 391 | print HTML "$Nfile{$name}:$Nline{$name}\n"; next; |
---|
[52461c5] | 392 | } |
---|
| 393 | print HTML "</ul></body>\n"; |
---|
| 394 | close(HTML); |
---|
| 395 | $Exists{$title}=1; |
---|
| 396 | } |
---|
| 397 | else { |
---|
| 398 | &make_letters_html($dir, $pref, $title, *type); |
---|
| 399 | |
---|
| 400 | open(HTML, "> $Htmltree/$Dotdir{$dir}.$pref.html") |
---|
| 401 | || die "$0: Can't open $htmlfile.$pref.html, $!\n"; |
---|
| 402 | print HTML "<head>\n<title>$title in $dir</title>\n"; |
---|
| 403 | print HTML "</head><body><h1>$title in $dir</h1><p>\n"; |
---|
| 404 | print HTML "<ul>\n"; |
---|
| 405 | |
---|
[49c6428] | 406 | foreach $i ( "a".."z", |
---|
| 407 | "AdaType", "AdaProcedure", "AdaFunction", "AdaPackage", "AdaTask" ) { |
---|
[52461c5] | 408 | if ($Exists{$i} > 0) { # A file exists |
---|
| 409 | print HTML "<li><a href=\"$Dotdir{$dir}.$pref$i.html\">"; |
---|
| 410 | print HTML "$i</a>\n"; $Exists{$title}++; $Exists{$i}=0; |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | print HTML "</ul></body>\n"; |
---|
| 414 | close(HTML); |
---|
| 415 | if ($Exists{$title} == 0) { unlink($htmlfile); } |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | ## asappend: Append the contents of the second associative array to the |
---|
| 420 | ## first. |
---|
| 421 | |
---|
| 422 | sub asappend { |
---|
| 423 | local(*To)= $_[0]; |
---|
| 424 | local(*From)= $_[1]; |
---|
| 425 | local($i); |
---|
| 426 | |
---|
| 427 | foreach $i (keys(%From)) { $To{$i}= $From{$i} ; } |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | ## make_dir_html: Make the html document for the directory. Use the |
---|
| 431 | ## Exist{} array to determine what types to include on the document. |
---|
| 432 | ## Arguments are: Dir name |
---|
| 433 | |
---|
| 434 | sub make_dir_html { |
---|
| 435 | local($dir)= $_[0]; |
---|
| 436 | local($i); |
---|
| 437 | local(@keys); |
---|
| 438 | |
---|
| 439 | if ($Debug > 1) { print"In makedir, dir is $dir\n"; } |
---|
| 440 | &make_type_html($dir, "f", $Title{"f"}, *Func); |
---|
| 441 | &make_type_html($dir, "m", $Title{"m"}, *Macro); |
---|
| 442 | &make_type_html($dir, "d", $Title{"d"}, *Def); |
---|
| 443 | &make_type_html($dir, "v", $Title{"v"}, *Var); |
---|
| 444 | &make_type_html($dir, "s", $Title{"s"}, *Struct); |
---|
| 445 | &make_type_html($dir, "u", $Title{"u"}, *Union); |
---|
| 446 | &make_type_html($dir, "t", $Title{"t"}, *Type); |
---|
| 447 | &make_type_html($dir, "e", $Title{"e"}, *Enum); |
---|
[49c6428] | 448 | &make_type_html($dir, "AdaType", $Title{"AdaType"}, *AdaType); |
---|
| 449 | &make_type_html($dir, |
---|
| 450 | "AdaProcedure", $Title{"AdaProcedure"}, *AdaProcedure); |
---|
| 451 | &make_type_html($dir, "AdaFunction", $Title{"AdaFunction"}, *AdaFunction); |
---|
| 452 | &make_type_html($dir, "AdaPackage", $Title{"AdaPackage"}, *AdaPackage); |
---|
| 453 | &make_type_html($dir, "AdaTask", $Title{"AdaTask"}, *AdaTask); |
---|
[52461c5] | 454 | |
---|
| 455 | if ($NoAll != 1) { |
---|
| 456 | &asappend(*GFunc, *Func); |
---|
| 457 | &asappend(*GMacro, *Macro); |
---|
| 458 | &asappend(*GDef, *Def); |
---|
| 459 | &asappend(*GVar, *Var); |
---|
| 460 | &asappend(*GStruct, *Struct); |
---|
| 461 | &asappend(*GUnion, *Union); |
---|
| 462 | &asappend(*GType, *Type); |
---|
| 463 | &asappend(*GEnum, *Enum); |
---|
[49c6428] | 464 | &asappend(*GAdaType, *AdaType); |
---|
| 465 | &asappend(*GAdaProcedure, *AdaProcedure); |
---|
| 466 | &asappend(*GAdaFunction, *AdaFunction); |
---|
| 467 | &asappend(*GAdaPackage, *AdaPackage); |
---|
| 468 | &asappend(*GAdaTask, *AdaTask); |
---|
[52461c5] | 469 | } |
---|
| 470 | |
---|
| 471 | &asappend(*Alldir, *Func); |
---|
| 472 | &asappend(*Alldir, *Macro); |
---|
| 473 | &asappend(*Alldir, *Def); |
---|
| 474 | &asappend(*Alldir, *Var); |
---|
| 475 | &asappend(*Alldir, *Struct); |
---|
| 476 | &asappend(*Alldir, *Union); |
---|
| 477 | &asappend(*Alldir, *Type); |
---|
| 478 | &asappend(*Alldir, *Enum); |
---|
[49c6428] | 479 | &asappend(*Alldir, *AdaType); |
---|
| 480 | &asappend(*Alldir, *AdaProcedure); |
---|
| 481 | &asappend(*Alldir, *AdaFunction); |
---|
| 482 | &asappend(*Alldir, *AdaPackage); |
---|
| 483 | &asappend(*Alldir, *AdaTask); |
---|
| 484 | |
---|
[52461c5] | 485 | if ($NoLetters != 1) { |
---|
| 486 | &make_letters_html($dir, "g", $Title{"g"}, *Alldir); |
---|
| 487 | } |
---|
| 488 | undef %Alldir; |
---|
| 489 | |
---|
| 490 | open(HTML, "> $Htmltree/$Dotdir{$dir}.html") |
---|
| 491 | || die "$0: Can't open $Htmltree/$Dotdir{$dir}.html, $!\n"; |
---|
| 492 | print HTML "<head>\n<title>Cross-references for $dir</title>\n"; |
---|
| 493 | print HTML "</head><body><h1>Cross-references for $dir</h1><p>\n"; |
---|
| 494 | if (-f "$Headers/$Dotdir{$dir}.hdr" ) { |
---|
| 495 | open(TOPHDR, "$Headers/$Dotdir{$dir}.hdr"); |
---|
| 496 | while (<TOPHDR>) { print HTML; } |
---|
| 497 | close(TOPHDR); |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | if (defined($Formdir)) { |
---|
| 501 | print HTML "<hr><form action=\"$Formdir/src2html.cgi\" "; |
---|
| 502 | print HTML "method=\"POST\">\n"; |
---|
| 503 | print HTML "<input type=\"submit\" value=\"Search\">\n"; |
---|
| 504 | print HTML "<input type= \"text\" "; |
---|
| 505 | print HTML "name=\"$Htmldir/$Newsrctree\">\n"; |
---|
| 506 | print HTML "Enter a symbol's name here to quickly find it.\n"; |
---|
| 507 | print HTML "</form><hr>\n"; |
---|
| 508 | } |
---|
| 509 | print HTML "<h1>Cross-references for $dir by type</h1><p><ul>\n"; |
---|
| 510 | |
---|
[49c6428] | 511 | foreach $i ( "f","m","d","v","s","u","t","e", |
---|
| 512 | "AdaType", "AdaProcedure", "AdaFunction", "AdaPackage", "AdaTask" ) { |
---|
[52461c5] | 513 | if ($Exists{$Title{$i}} > 0) { # A type exists |
---|
| 514 | print HTML "<li><a href=\"$Dotdir{$dir}.$i.html\">"; |
---|
| 515 | print HTML "$Title{$i}</a>\n"; |
---|
| 516 | $Exists{$dir}++; $Exists{$Title{$i}}=0; |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | print HTML "</ul><p>\n"; |
---|
| 520 | if ($NoLetters != 1) { |
---|
| 521 | print HTML "<h1>Cross-references for $dir by letter</h1><p><ul>\n"; |
---|
| 522 | foreach $i ( "a".."z" ) { |
---|
| 523 | if ($Exists{$i} > 0) { # A letter exists |
---|
| 524 | print HTML "<li><a href=\"$Dotdir{$dir}.g$i.html\">"; |
---|
| 525 | print HTML "$i</a>\n"; $Exists{$i}=0; |
---|
| 526 | } |
---|
| 527 | } |
---|
| 528 | } |
---|
| 529 | print HTML "</ul></body>\n"; |
---|
| 530 | close(HTML); |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | ## Make_top_html: Make the top html document by making the ones below |
---|
| 534 | ## it and then adding links to them. |
---|
| 535 | |
---|
| 536 | sub make_top_html { |
---|
| 537 | local($i); |
---|
| 538 | local(@keys); |
---|
| 539 | |
---|
| 540 | $Dotdir{$Top}=$Top; |
---|
| 541 | &make_type_html($Top, "f", $Title{"f"}, *GFunc); |
---|
| 542 | &make_type_html($Top, "m", $Title{"m"}, *GMacro); |
---|
| 543 | &make_type_html($Top, "d", $Title{"d"}, *GDef); |
---|
| 544 | &make_type_html($Top, "v", $Title{"v"}, *GVar); |
---|
| 545 | &make_type_html($Top, "s", $Title{"s"}, *GStruct); |
---|
| 546 | &make_type_html($Top, "u", $Title{"u"}, *GUnion); |
---|
| 547 | &make_type_html($Top, "t", $Title{"t"}, *GType); |
---|
| 548 | &make_type_html($Top, "e", $Title{"e"}, *GEnum); |
---|
[49c6428] | 549 | &make_type_html($Top, "AdaType", $Title{"AdaType"}, *GAdaType); |
---|
| 550 | &make_type_html($Top, "AdaProcedure", $Title{"AdaProcedure"}, *GAdaProcedure); |
---|
| 551 | &make_type_html($Top, "AdaFunction", $Title{"AdaFunction"}, *GAdaFunction); |
---|
| 552 | &make_type_html($Top, "AdaPackage", $Title{"AdaPackage"}, *GAdaPackage); |
---|
| 553 | &make_type_html($Top, "AdaTask", $Title{"AdaTask"}, *GAdaTask); |
---|
[52461c5] | 554 | |
---|
| 555 | open(HTMLTOP, "> $Htmltree/$Top.html") |
---|
| 556 | || die "$0: Can't open $Htmltree/$Top.html, $!\n"; |
---|
| 557 | print HTMLTOP "<head>\n<title>Cross-references for $Top</title>\n"; |
---|
| 558 | print HTMLTOP "</head><body><h1>Cross-references for $Top</h1><p>\n"; |
---|
| 559 | |
---|
| 560 | if (-f "$Headers/$Top.hdr" ) { |
---|
| 561 | open(TOPHDR, "$Headers/$Top.hdr"); |
---|
| 562 | while (<TOPHDR>) { print HTMLTOP; } |
---|
| 563 | close(TOPHDR); |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | if (defined($Formdir)) { |
---|
| 567 | print HTMLTOP "<hr><form action=\"$Formdir/src2html.cgi\" "; |
---|
| 568 | print HTMLTOP "method=\"POST\">\n"; |
---|
| 569 | print HTMLTOP "<input type=\"submit\" value=\"Search\">\n"; |
---|
| 570 | print HTMLTOP "<input type= \"text\" "; |
---|
| 571 | print HTMLTOP "name=\"$Htmldir/$Newsrctree\">\n"; |
---|
| 572 | print HTMLTOP "Enter a symbol's name here to quickly find it.\n"; |
---|
| 573 | print HTMLTOP "</form><hr>\n"; |
---|
| 574 | } |
---|
| 575 | print HTMLTOP "<h2>Cross-references by directory</h2><p>\n"; |
---|
| 576 | print HTMLTOP "<ul>\n"; |
---|
| 577 | |
---|
| 578 | foreach $i (sort keys(%Dirinfo)) { |
---|
| 579 | if ($Exists{$i} > 0) { # A dir exists |
---|
| 580 | print HTMLTOP "<li><a href=\"$Dotdir{$i}.html\">"; |
---|
| 581 | print HTMLTOP "$i</a> $Dirinfo{$i}\n"; $Exists{$i}=0; |
---|
| 582 | } |
---|
| 583 | } |
---|
| 584 | if ($NoAll != 1) { |
---|
| 585 | print HTMLTOP "</ul><p><h2>Cross-references by type</h2><p><ul>\n"; |
---|
[49c6428] | 586 | foreach $i ( "f","m","d","v","s","u","t","e", |
---|
| 587 | "AdaType", "AdaProcedure", "AdaFunction", "AdaPackage", "AdaTask" ) { |
---|
[52461c5] | 588 | if ($Exists{$Title{$i}} > 0) { # A type exists |
---|
| 589 | print HTMLTOP "<li><a href=\"$Top.$i.html\">"; |
---|
| 590 | print HTMLTOP "$Title{$i}</a>\n"; |
---|
| 591 | } |
---|
| 592 | } |
---|
| 593 | if ($NoLetters != 1) { |
---|
| 594 | print HTMLTOP "</ul><p><h2>All Cross-references for $Top"; |
---|
| 595 | print HTMLTOP "</h2><p><ul>\n"; |
---|
| 596 | &asappend(*Alltop, *GFunc); |
---|
| 597 | &asappend(*Alltop, *GMacro); |
---|
| 598 | &asappend(*Alltop, *GDef); |
---|
| 599 | &asappend(*Alltop, *GVar); |
---|
| 600 | &asappend(*Alltop, *GStruct); |
---|
| 601 | &asappend(*Alltop, *GUnion); |
---|
| 602 | &asappend(*Alltop, *GType); |
---|
| 603 | &asappend(*Alltop, *GEnum); |
---|
[49c6428] | 604 | &asappend(*Alltop, *GAdaType); |
---|
| 605 | &asappend(*Alltop, *GAdaProcedure); |
---|
| 606 | &asappend(*Alltop, *GAdaFunction); |
---|
| 607 | &asappend(*Alltop, *GAdaPackage); |
---|
| 608 | &asappend(*Alltop, *GAdaTask); |
---|
[52461c5] | 609 | |
---|
| 610 | if ($Debug > 0) { print "Making top letters\n"; } |
---|
| 611 | &make_letters_html($Top, "g", $Title{"g"}, *Alltop); |
---|
| 612 | if ($Debug > 0) { print "Making top letters, part 2\n"; } |
---|
| 613 | foreach $i ( "a".."z" ) { |
---|
| 614 | if ($Exists{$i} > 0) { |
---|
| 615 | print HTMLTOP "<li><a href=\"$Dotdir{$Top}.g$i.html\">"; |
---|
| 616 | print HTMLTOP "$i</a>\n"; |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | print HTMLTOP "</ul>\n"; |
---|
| 622 | print HTMLTOP "<hr>This source tree was made with "; |
---|
| 623 | print HTMLTOP "<a href=\"http://minnie.cs.adfa.oz.au/Src2html/index.html"; |
---|
| 624 | print HTMLTOP "\">src2html</a>.</body>\n"; |
---|
| 625 | close(HTMLTOP); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | |
---|
| 629 | ## rewrite_src: Reread the ctags file for the given directory, and |
---|
| 630 | ## rewrite the source code, adding in anchor points and bolding symbols. |
---|
| 631 | ## This is messy as we can have multiple symbols on a single source line, |
---|
| 632 | ## therefore we must buffer each line while reading from the ctags file. |
---|
| 633 | ## |
---|
| 634 | sub rewrite_src { |
---|
| 635 | local($dir)= $_[0]; |
---|
| 636 | local($i); |
---|
| 637 | local($file)=""; |
---|
| 638 | local($line)=""; |
---|
| 639 | local($symb); |
---|
| 640 | local($cnt); |
---|
| 641 | local($nextcnt); |
---|
| 642 | |
---|
| 643 | $In_file=0; |
---|
| 644 | open(CTAGS,"sort +2 -3 +1n -2 $Ctagsfile{$dir} |") |
---|
| 645 | || die "$0: Can't open sorted $Ctagsfile{$dir}, $!\n"; |
---|
| 646 | if ($Debug > 0) { print "Rewriting source in $dir\n"; } |
---|
| 647 | while (<CTAGS>) { |
---|
| 648 | # Get the next file, line, symbol |
---|
[49c6428] | 649 | if (/^([\w\/]+)\s+(\d+)\s+([A-Za-z0-9_\+\-\.\/]+)/) { |
---|
[52461c5] | 650 | if ($Debug > 2) { print "Symb $1 at $2 in $3\n"; } |
---|
[49c6428] | 651 | $fname=$3; $nextcnt= $2; $symb=$1; |
---|
| 652 | $symb=~ s/\/.//g; |
---|
| 653 | |
---|
[52461c5] | 654 | # If it's in a new file |
---|
[49c6428] | 655 | if ("$file" ne "$fname") { |
---|
[52461c5] | 656 | # Print out the remainder of the |
---|
| 657 | # current file, incl. the buffered line |
---|
| 658 | if ($In_file == 1) { |
---|
| 659 | if ("$line" ne "") { print OUT $line; } |
---|
| 660 | while (<IN>) { |
---|
| 661 | s/\&/&/g; s/\</</g; s/\>/>/g; print OUT; |
---|
| 662 | } |
---|
| 663 | print OUT "\n\n\n\n\n\n\n\n\n\n</pre></body>\n"; |
---|
| 664 | close(IN); close(OUT); |
---|
| 665 | } |
---|
[49c6428] | 666 | $file= "$fname"; |
---|
[52461c5] | 667 | # Open the new file & do the preamble |
---|
| 668 | open(IN, "$Srctree/$file") || |
---|
| 669 | print "Cannot open $Srctree/$file\n"; |
---|
| 670 | open(OUT, "> $Htmltree/$Newsrctree/$file.html"); |
---|
| 671 | $In_file=1; |
---|
| 672 | print OUT "<head>\n<title>$file Source</title>\n"; |
---|
| 673 | print OUT "</head><body>\n"; |
---|
| 674 | print OUT "<h1>Source to $file</h1>\n"; |
---|
| 675 | if (defined($Formdir)) { |
---|
| 676 | print OUT "<hr><form action=\"$Formdir/src2html.cgi\" "; |
---|
| 677 | print OUT "method=\"POST\">\n"; |
---|
| 678 | print OUT "<input type=\"submit\" value=\"Search\">\n"; |
---|
| 679 | print OUT "<input type= \"text\" "; |
---|
| 680 | print OUT "name=\"$Htmldir/$Newsrctree\">\n"; |
---|
| 681 | print OUT "Enter a symbol's name here to quickly find it.\n"; |
---|
| 682 | print OUT "</form><hr>\n"; |
---|
| 683 | } |
---|
| 684 | print OUT "<pre>\n"; |
---|
| 685 | # Get the first line |
---|
| 686 | $cnt=1; $line = <IN>; |
---|
| 687 | $line=~ s/\&/&/g; |
---|
| 688 | $line=~ s/\</</g; |
---|
| 689 | $line=~ s/\>/>/g; |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | # Print all lines until one with a symb |
---|
| 693 | while ($cnt < $nextcnt) { |
---|
| 694 | print OUT $line; $cnt++; $line= <IN>; |
---|
| 695 | $line=~ s/\&/&/g; |
---|
| 696 | $line=~ s/\</</g; |
---|
| 697 | $line=~ s/\>/>/g; |
---|
| 698 | } |
---|
| 699 | # Now rewrite the line |
---|
[49c6428] | 700 | $line=~ s/\b$symb\b/<a name="$symb"<\/a><b>$symb<\/b>/; |
---|
[52461c5] | 701 | next; |
---|
| 702 | } |
---|
| 703 | close(CTAGS); close(IN); close(OUT); |
---|
| 704 | } |
---|