From 52461c587563822939b238379bb1d72975e80b62 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 14 Apr 1998 16:03:45 +0000 Subject: New files --- doc/tools/src2html1.4a/src2html | 589 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 589 insertions(+) create mode 100644 doc/tools/src2html1.4a/src2html (limited to 'doc/tools/src2html1.4a/src2html') diff --git a/doc/tools/src2html1.4a/src2html b/doc/tools/src2html1.4a/src2html new file mode 100644 index 0000000000..df238ba76c --- /dev/null +++ b/doc/tools/src2html1.4a/src2html @@ -0,0 +1,589 @@ +#!/usr/local/bin/perl +# Src2html: Take a source tree and generate Html documents that have hyperlinks +# to the definition of structures, variables, functions, and preprocessor +# definitions. Read the manual page for details on how to use the program. +# +# Version 1.4-alpha. Written by Warren Toomey wkt@cs.adfa.oz.au +# +# 19th January 1996 +# + +if ($#ARGV <= 0 || $#ARGV > 4) { # Check arg count + print(STDERR "Usage: $0 [-na] [-nl] [-d num] input_description\n"); + print(STDERR " -na: Don't produce top-level category files\n"); + print(STDERR " -nl: Don't produce per-letter files\n"); + print(STDERR " -d: Set debugging to given number (0-3)\n"); + exit(1); +} + +# Set up default option values +$NoLetters= 0; +$NoAll= 0; +$Debug=0; +$Top= $ARGV[$#ARGV]; +$Top=~ s/\.s2h$//; + +# Parse the options +for ($i=0; $i<= $#ARGV; $i++) { + if ($ARGV[$i] eq "-na") { $NoAll= 1; next; } + if ($ARGV[$i] eq "-nl") { $NoLetters= 1; next; } + if ($ARGV[$i] eq "-d") { $i++; $Debug= $ARGV[$i]; next; } +} + +$Title{"m"}= "Macros"; +$Title{"d"}= "Defines"; +$Title{"f"}= "Functions"; +$Title{"v"}= "Variables"; +$Title{"s"}= "Structs"; +$Title{"u"}= "Unions"; +$Title{"t"}= "Typedefs"; +$Title{"e"}= "Enums"; +$Title{"g"}= "All symbols"; + +&get_s2h; # Read the description file +&make_dirs; # Make directories as needed +&make_ctags; # Generate ctags for all src +&parse_ctags; # Parse ctags, generate html ptr files +foreach $i (keys(%Dirinfo)) +{ &rewrite_src($i); } # Rewrite the src code +exit(0); # and exit + + +## get_s2h: Opens the source description file, reads it, and sets up some +## variables describing where some directories are, and the source directories +## to process. Variables used are: +## Srctree - The root of the source tree we are processing +## Htmlroot - The directory where all WWW documents are kept +## Htmldir - The directory under Htmlroot for this source tree +## Htmltree - The root of the destination tree for the Html code +## Newsrctree - The directory in Htmltree to store the new Htmlised code +## Headers - The directory where we keep information to prepend in some docs +## Formdir - The place to put the index searching script +## Dirinfo{} - The list of dirs and the info about the directory +## Dotdir{} - The directory name with /'s -> .'s + +sub get_s2h { + $Newsrctree= 'newsrc'; # Set up as default + $Headers= '.'; + + + ######################################################### + # make sure we dump out the last bit of the last file.... + + # Print out the remainder of the + # current file, incl. the buffered line + if ($In_file == 1) { + if ("$line" ne "") { print OUT $line; } + while () { + s/\&/&/g; s/\/>/g; print OUT; + } + print OUT "\n\n\n\n\n\n\n\n\n"; + close(IN); close(OUT); + } + ######################################################### + + open(S2H,$ARGV[$#ARGV]) # Open descript + || die "$0: can't open $ARGV[$#ARGV]: $!\n"; + + while() { # Read in input lines + next if /^#/; # Skip comments + if ( /^set\s+Srctree\s+(\S+)/ ) { + $Srctree = $1; next; # Set the variable + } + if ( /^set\s+Htmlroot\s+(\S+)/ ) { + $Htmlroot = $1; next; # Set the variable + } + if ( /^set\s+Htmldir\s+(\S+)/ ) { + $Htmldir = $1; next; # Set the variable + } + if ( /^set\s+Newsrctree\s+(\S+)/ ) { + $Newsrctree = $1; next; # Set the variable + } + if ( /^set\s+Headers\s+(\S+)/ ) { + $Headers = $1; next; # Set the variable + } + if ( /^set\s+Formdir\s+(\S+)/ ) { + $Formdir = $1; next; # Set the variable + } + if ( /^dir\s+(\S+)\s+(.*)/ ) { + $Dirinfo{$1}= $2; $Dotdir{$1}=$1; + $Dotdir{$1}=~ s/\//./g; + next; # Get dir commands + } + if ( /^\n/ ) { next; } # Ignore blank lines + # Bad input line, give warning + chop; print "$_: Bad line, ignoring\n"; next; + } + close(S2H); + if (!defined($Srctree)) { die "$0: Srctree undefined in $ARGV[$#ARGV]\n"; } + if (!defined($Htmlroot)) { die "$0: Htmlroot undefined in $ARGV[$#ARGV]\n"; } + if (!defined($Htmldir)) { die "$0: Htmldir undefined in $ARGV[$#ARGV]\n"; } + $Htmltree= "$Htmlroot/$Htmldir"; +} + +## make_dirs: Make the directories need to store the Html documents, and also +## check to make sure that the input directories exist. We depend upon mkdir(1) +## having the -p option to make intermediate directories as needed. + +sub make_dirs { + local($i); + + foreach $i (keys(%Dirinfo)) { # Check that the directories exist + if (! -e "$Srctree/$i") { + die "$0: Input dir $Srctree/$i doesn't exist\n"; + } + if (! -d "$Srctree/$i") { + die "$0: Input dir $Srctree/$i is not a directory\n"; + } + } + if (! -e "$Htmltree") { + system("mkdir -p $Htmltree") && die "$0: Can't mkdir $Htmltree\n"; + } + if (! -e "$Htmltree/$Newsrctree") { + system("mkdir -p $Htmltree/$Newsrctree") + && die "$0: Can't mkdir $Htmltree/$Newsrctree\n"; + } + if (! -e "$Htmltree/ctags") { + system("mkdir -p $Htmltree/ctags") && die "$0: Can't mkdir ctags\n"; + } + foreach $i (keys(%Dirinfo)) { + if (! -e "$Htmltree/$Newsrctree/$i") { + system("mkdir -p $Htmltree/$Newsrctree/$i") + && die "$0: Can't mkdir $Htmltree/$Newsrctree/$i\n"; + } + } +} + +## make_ctags: Process all the source code, creating the ctags files. +## The Ctagsfile{} array is set up to hold the name of the ctags files +## created. + +sub make_ctags { + local($i); + + foreach $i (keys(%Dirinfo)) { + $Ctagsfile{$i}= "$Htmltree/ctags/$Dotdir{$i}.ctags"; + if ($Debug > 0 ) { print "Generating ctags for $Ctagsfile{$i}\n"; } + system("(cd $Srctree; ctags-new -d -t -w -y $i/*) > $Ctagsfile{$i}") + && print "$0: ctags failed on $Srctree/$i\n"; + } +} + + +## parse_ctags: Parse the ctags file produced by make_ctags, creating several +## arrays of information. The arrays created are: +## Macro{} - The name of every macro and its name lowercased +## Def{} - The name of every define and its name lowercased +## Func{} - The name of every function and its name lowercased +## Var{} - The name of every variable and its name lowercased +## Struct{} - The name of every struct and its name lowercased +## Union{} - The name of every union and its name lowercased +## Type{} - The name of every typedef and its name lowercased +## Enum{} - The name of every enum and its name lowercased +## Nfile{} - The directory in which the symbol was found +## Nline{} - The line number where the symbol was found + +sub parse_ctags { + local($i); + local($low); + + foreach $i (keys(%Dirinfo)) { + open(CTAGS,$Ctagsfile{$i}) || die "$0: Can't open $Ctagsfile{$i}, $!\n"; + if ($Debug > 0) { print "Parsing $Ctagsfile{$i} to build ptr files\n"; } + while () { + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+Preprocessor macro/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Macro{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+Preprocessor define/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Def{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C struct/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Struct{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C union/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Union{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C typedef/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Type{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C enum/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Enum{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C function/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Func{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + if ( /^(\w+)\s+(\d+)\s+(\S+)\s+C variable/ ) { + ($low=$1)=~tr/A-Z_/a-z/d; $Var{$low}=$1; + $Nfile{$1}= $3; $Nline{$1}= $2; next; + } + print "$0: In Ctagsfile{$i}, don't recognise $_"; + } + close(CTAGS); + &make_dir_html($i); + undef %Macro; undef %Def; undef %Func; undef %Var; + undef %Struct; undef %Union; undef %Type; undef %Enum; + } + &make_top_html; +} + +## make_letters_html: Make the lowest HTML documents, i.e those per-directory +## per-type per-letter Htmls that point directly at the source code. +## Arguments are: Dir name, prefix, title, Name/dir list +## If the file is created, set $Exists(letter) positive, else to 0. + +sub make_letters_html { + local($dir)= $_[0]; + local($pref)= $_[1]; + local($title)= $_[2]; + local(*type)= $_[3]; + local($htmlfile); + local($let)="@"; + + foreach $i ( "a".."z" ) { $Exists{$i}=0; } + foreach $name (sort keys( %type )) { + if (substr($name,0,1) ne $let) { + if ($let ne "@") { + print HTML "\n"; + close(HTML); + $Exists{$let}= 1; + } + $let= substr($name, 0, 1); + $htmlfile= "$Htmltree/$Dotdir{$dir}.$pref$let.html"; + open(HTML, "> $htmlfile") || die "$0: Can't open $htmlfile, $!\n"; + + print HTML "\n$title starting with "; + print HTML "`$let' in $dir\n"; + print HTML "

$title starting with "; + print HTML "`$let' in $dir

\n"; + print HTML "

    \n"; + } + print HTML "
  • $type{$name} "; + print HTML "$Nfile{$type{$name}}:$Nline{$type{$name}}\n"; next; + } + print HTML "
\n"; + close(HTML); + $Exists{$let}= 1; +} + +## make_type_html: Make the type htmls. If there are <50 symbols for the +## directory, create the per-directory per-type html document only. Otherwise +## for every letter grep symbols, call make_lowest_letter_html, and +## finally create the per-directory per-type html document that points only +## at the letter files created. +## Arguments are: Dir name, prefix, title, Name/dir list + +sub make_type_html { + local($dir)= $_[0]; + local($pref)= $_[1]; + local($title)= $_[2]; + local(*type)= $_[3]; + local($i); + local($htmlfile); + local(@keys)= keys(%type); + local($name); + + $Exists{$title}=0; + if ( $#keys < 0 ) { return; } + if ($Debug > 0) { + $i= $#keys + 1; + print "The associative array for $dir $title has $i elements\n"; + } + if ( ($#keys < 50) || ($NoLetters == 1) ) { + $htmlfile= "$Htmltree/$Dotdir{$dir}.$pref.html"; + open(HTML, "> $htmlfile") || die "$0: Can't open $htmlfile, $!\n"; + print HTML "\n$title in $dir\n"; + print HTML "

$title in $dir

\n"; + print HTML "
    \n"; + foreach $name (sort keys( %type )) { + print HTML "
  • $type{$name} "; + print HTML "$Nfile{$type{$name}}:$Nline{$type{$name}}\n"; next; + } + print HTML "
\n"; + close(HTML); + $Exists{$title}=1; + } + else { + &make_letters_html($dir, $pref, $title, *type); + + open(HTML, "> $Htmltree/$Dotdir{$dir}.$pref.html") + || die "$0: Can't open $htmlfile.$pref.html, $!\n"; + print HTML "\n$title in $dir\n"; + print HTML "

$title in $dir

\n"; + print HTML "

    \n"; + + foreach $i ( "a".."z" ) { + if ($Exists{$i} > 0) { # A file exists + print HTML "
  • "; + print HTML "$i\n"; $Exists{$title}++; $Exists{$i}=0; + } + } + print HTML "
\n"; + close(HTML); + if ($Exists{$title} == 0) { unlink($htmlfile); } + } +} + +## asappend: Append the contents of the second associative array to the +## first. + +sub asappend { + local(*To)= $_[0]; + local(*From)= $_[1]; + local($i); + + foreach $i (keys(%From)) { $To{$i}= $From{$i} ; } +} + +## make_dir_html: Make the html document for the directory. Use the +## Exist{} array to determine what types to include on the document. +## Arguments are: Dir name + +sub make_dir_html { + local($dir)= $_[0]; + local($i); + local(@keys); + + if ($Debug > 1) { print"In makedir, dir is $dir\n"; } + &make_type_html($dir, "f", $Title{"f"}, *Func); + &make_type_html($dir, "m", $Title{"m"}, *Macro); + &make_type_html($dir, "d", $Title{"d"}, *Def); + &make_type_html($dir, "v", $Title{"v"}, *Var); + &make_type_html($dir, "s", $Title{"s"}, *Struct); + &make_type_html($dir, "u", $Title{"u"}, *Union); + &make_type_html($dir, "t", $Title{"t"}, *Type); + &make_type_html($dir, "e", $Title{"e"}, *Enum); + + if ($NoAll != 1) { + &asappend(*GFunc, *Func); + &asappend(*GMacro, *Macro); + &asappend(*GDef, *Def); + &asappend(*GVar, *Var); + &asappend(*GStruct, *Struct); + &asappend(*GUnion, *Union); + &asappend(*GType, *Type); + &asappend(*GEnum, *Enum); + } + + &asappend(*Alldir, *Func); + &asappend(*Alldir, *Macro); + &asappend(*Alldir, *Def); + &asappend(*Alldir, *Var); + &asappend(*Alldir, *Struct); + &asappend(*Alldir, *Union); + &asappend(*Alldir, *Type); + &asappend(*Alldir, *Enum); + if ($NoLetters != 1) { + &make_letters_html($dir, "g", $Title{"g"}, *Alldir); + } + undef %Alldir; + + open(HTML, "> $Htmltree/$Dotdir{$dir}.html") + || die "$0: Can't open $Htmltree/$Dotdir{$dir}.html, $!\n"; + print HTML "\nCross-references for $dir\n"; + print HTML "

Cross-references for $dir

\n"; + if (-f "$Headers/$Dotdir{$dir}.hdr" ) { + open(TOPHDR, "$Headers/$Dotdir{$dir}.hdr"); + while () { print HTML; } + close(TOPHDR); + } + + if (defined($Formdir)) { + print HTML "


\n"; + print HTML "\n"; + print HTML "\n"; + print HTML "Enter a symbol's name here to quickly find it.\n"; + print HTML "

\n"; + } + print HTML "

Cross-references for $dir by type

    \n"; + + foreach $i ( "f","m","d","v","s","u","t","e" ) { + if ($Exists{$Title{$i}} > 0) { # A type exists + print HTML "
  • "; + print HTML "$Title{$i}\n"; + $Exists{$dir}++; $Exists{$Title{$i}}=0; + } + } + print HTML "

\n"; + if ($NoLetters != 1) { + print HTML "

Cross-references for $dir by letter

    \n"; + foreach $i ( "a".."z" ) { + if ($Exists{$i} > 0) { # A letter exists + print HTML "
  • "; + print HTML "$i\n"; $Exists{$i}=0; + } + } + } + print HTML "
\n"; + close(HTML); +} + +## Make_top_html: Make the top html document by making the ones below +## it and then adding links to them. + +sub make_top_html { + local($i); + local(@keys); + + $Dotdir{$Top}=$Top; + &make_type_html($Top, "f", $Title{"f"}, *GFunc); + &make_type_html($Top, "m", $Title{"m"}, *GMacro); + &make_type_html($Top, "d", $Title{"d"}, *GDef); + &make_type_html($Top, "v", $Title{"v"}, *GVar); + &make_type_html($Top, "s", $Title{"s"}, *GStruct); + &make_type_html($Top, "u", $Title{"u"}, *GUnion); + &make_type_html($Top, "t", $Title{"t"}, *GType); + &make_type_html($Top, "e", $Title{"e"}, *GEnum); + + open(HTMLTOP, "> $Htmltree/$Top.html") + || die "$0: Can't open $Htmltree/$Top.html, $!\n"; + print HTMLTOP "\nCross-references for $Top\n"; + print HTMLTOP "

Cross-references for $Top

\n"; + + if (-f "$Headers/$Top.hdr" ) { + open(TOPHDR, "$Headers/$Top.hdr"); + while () { print HTMLTOP; } + close(TOPHDR); + } + + if (defined($Formdir)) { + print HTMLTOP "


\n"; + print HTMLTOP "\n"; + print HTMLTOP "\n"; + print HTMLTOP "Enter a symbol's name here to quickly find it.\n"; + print HTMLTOP "

\n"; + } + print HTMLTOP "

Cross-references by directory

\n"; + print HTMLTOP "

    \n"; + + foreach $i (sort keys(%Dirinfo)) { + if ($Exists{$i} > 0) { # A dir exists + print HTMLTOP "
  • "; + print HTMLTOP "$i $Dirinfo{$i}\n"; $Exists{$i}=0; + } + } + if ($NoAll != 1) { + print HTMLTOP "

Cross-references by type

    \n"; + foreach $i ( "f","m","d","v","s","u","t","e" ) { + if ($Exists{$Title{$i}} > 0) { # A type exists + print HTMLTOP "
  • "; + print HTMLTOP "$Title{$i}\n"; + } + } + if ($NoLetters != 1) { + print HTMLTOP "

All Cross-references for $Top"; + print HTMLTOP "

    \n"; + &asappend(*Alltop, *GFunc); + &asappend(*Alltop, *GMacro); + &asappend(*Alltop, *GDef); + &asappend(*Alltop, *GVar); + &asappend(*Alltop, *GStruct); + &asappend(*Alltop, *GUnion); + &asappend(*Alltop, *GType); + &asappend(*Alltop, *GEnum); + + if ($Debug > 0) { print "Making top letters\n"; } + &make_letters_html($Top, "g", $Title{"g"}, *Alltop); + if ($Debug > 0) { print "Making top letters, part 2\n"; } + foreach $i ( "a".."z" ) { + if ($Exists{$i} > 0) { + print HTMLTOP "
  • "; + print HTMLTOP "$i\n"; + } + } + } + } + print HTMLTOP "
\n"; + print HTMLTOP "
This source tree was made with "; + print HTMLTOP "src2html.\n"; + close(HTMLTOP); +} + + +## rewrite_src: Reread the ctags file for the given directory, and +## rewrite the source code, adding in anchor points and bolding symbols. +## This is messy as we can have multiple symbols on a single source line, +## therefore we must buffer each line while reading from the ctags file. +## +sub rewrite_src { + local($dir)= $_[0]; + local($i); + local($file)=""; + local($line)=""; + local($symb); + local($cnt); + local($nextcnt); + + $In_file=0; + open(CTAGS,"sort +2 -3 +1n -2 $Ctagsfile{$dir} |") + || die "$0: Can't open sorted $Ctagsfile{$dir}, $!\n"; + if ($Debug > 0) { print "Rewriting source in $dir\n"; } + while () { + # Get the next file, line, symbol + if (/^(\w+)\s+(\d+)\s+([A-Za-z0-9_\+\-\.\/]+)/) { + if ($Debug > 2) { print "Symb $1 at $2 in $3\n"; } + $nextcnt= $2; $symb=$1; + # If it's in a new file + if ("$file" ne "$3") { + # Print out the remainder of the + # current file, incl. the buffered line + if ($In_file == 1) { + if ("$line" ne "") { print OUT $line; } + while () { + s/\&/&/g; s/\/>/g; print OUT; + } + print OUT "\n\n\n\n\n\n\n\n\n\n\n"; + close(IN); close(OUT); + } + $file= "$3"; + # Open the new file & do the preamble + open(IN, "$Srctree/$file") || + print "Cannot open $Srctree/$file\n"; + open(OUT, "> $Htmltree/$Newsrctree/$file.html"); + $In_file=1; + print OUT "\n$file Source\n"; + print OUT "\n"; + print OUT "

Source to $file

\n"; + if (defined($Formdir)) { + print OUT "
\n"; + print OUT "\n"; + print OUT "\n"; + print OUT "Enter a symbol's name here to quickly find it.\n"; + print OUT "

\n"; + } + print OUT "
\n";
+					# Get the first line
+		$cnt=1; $line = ;
+	        $line=~ s/\&/&/g;
+	        $line=~ s/\/>/g;
+	    }
+	}
+					# Print all lines until one with a symb
+	while ($cnt < $nextcnt) {
+	    print OUT $line; $cnt++; $line= ;
+	    $line=~ s/\&/&/g;
+	    $line=~ s/\/>/g;
+	}
+						# Now rewrite the line
+	$line=~ s/$symb/$symb<\/b>/;
+	next;
+    }
+    close(CTAGS); close(IN); close(OUT);
+}
-- 
cgit v1.2.3