#!/usr/bin/perl
# Usage: javadocTour -classpath  CLASSPATH
#                      -sourcepath SOURCPATH 
#                      -d          JAVADOCDIR
#
# Given a classpath and sourcepath, this shell will find all directories 
# that contain java files and generate corresponding javadoc html pages. 
#                                                                        
# The ClASSPATH and the SOURCPATH are defined by their directory names.
#
# You have to unzip the classes.zip file and the src.zip files.    
#
# For improvements, please edit the original in /homes/sep/matt/usr/srcAdm
# author: matthias schwab, 10jun397
#%

require "getopts.pl" ;

if ( $#ARGV < 0 ) {
  &usage ;
}

$classpath = "";
$sourcpath = "";
$documpath = "";
while ($arg = shift) {
  if    ($arg  =~ /\-classpath/)  {
    $classpath =  shift;
  }
  elsif ($arg  =~ /\-sourcepath/) {
    $sourcpath =  shift;
  }
  elsif ($arg  =~ /\-d/)          {
    $documpath =  shift;  
  }
}

if ($classpath eq "" || $sourcpath eq "" || $documpath eq "") { 
  &usage ;
}

#print "classpath:    $classpath\n";
#print "sourcepath:   $sourcpath\n";
#print "documentpath: $documpath\n";

#this makes a list of all available packages 
#split classpath into various rootdirectories 
#this requires the classes to be unzipped ... 

@classpath = split(":",$classpath); 
#print "classpath is @classpath\n"; 
while(scalar(@classpath) != 0) {
      $root = shift(@classpath); 
      #print "I AM HERE: $root \n"; 
      if ($root ne " ") {
	  # print "Working on $root \n"; 
	  # makeDocList requires perl 5.000 or better 
	  @dirlist = `makeDocList -c -d $root`;
	  # print "@dirlist \n"; 
	  if (scalar(@dirlist) != 0) {
	      while ($dir = shift(@dirlist)) {
		  chop($dir); 
		  $package =  $dir;
		  $package =~ s/$root//; 
		  $package =~ s/\//\./g; 
		  $package =~ s/\./ /;
		  push(@packagelist,$package);
	      }
	  }
      } 
  }

#print @packagelist;

`/usr/local/java/bin/javadoc -J-mx64m -classpath $classpath -sourcepath $sourcpath -d $documpath @packagelist`; 


sub usage {
  open( THIS, $0 ) ;

  while ( <THIS> ) {
       if ( $_ =~ /^\#/ ) {
         next if $_ =~ /^\#\!/ ;
         exit if $_ =~ /^\#\%/ ;

         print ;
         }
       }

  exit( 0 ) ;
  }

