#!/usr/bin/env perl
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************


# This perl script is used to find any directories in the condor src
# tree that have an html subdirectory, and an "index.html" file in
# that html directory.  These files are created by doc_target()
# entries in the Imakefile, which creates an HTML version of all Doc++
# comments in the specified header files.  When this script is run, it
# copies all the html from each module into subdirectories of the
# directory specified in $target below.  Then, it creates an
# "index.html" file that just contains a sorted list links to each of
# these subdirectories.
#
# Written on 2/2/99 by Derek Wright <wright@cs.wisc.edu>

$target="htmldocs";
$title="Condor Doc++ Entries";
$gifsrc="/p/condor/public/html/CondorTitle.gif";

# See if we want to copy in the html or just recreate the index.html file. 
$_ = shift;
$copy = ! /^-n.*$/;

umask 022;

opendir( DIR, ".." ) || die "Can't opendir \"..\": $!\n";

# Grab all the entries in the parent directory, except . and .. 
@alldirs = grep !/^\.\.?$/, readdir(DIR);
closedir DIR;

if( $copy ) {
    `rm -rf $target`;
    mkdir( $target, 0777 );
    `cp howto.html $target`;
    `cp $gifsrc $target`;
}

# For each entry, see if the html/index.html file exists, and if so,
# stuff it in a hashtable.
foreach $dir (@alldirs) {
    if( -f "../$dir/html/index.html" ) {
	if( $copy ) {
	    mkdir( "$target/$dir", 0777 );
	    `cp ../$dir/html/* $target/$dir`;
	}
	$html_files{$dir} = "$dir/index.html";
    }
}


# Finally, print out our top-level html index of all doc++ stuff. 
open( OUT, ">$target/index.html" ) || die "Can't open index.html: $!\n";

print OUT "<HTML>\n";
print OUT "<HEAD>\n";
print OUT "<TITLE>$title</TITLE>\n";
print OUT "</HEAD>\n";
print OUT "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" alink=\"#ff0000\">\n";
print OUT "<A HREF=\"http://www.cs.wisc.edu/condor\">\n";
print OUT "<CENTER>\n";
print OUT "<IMG SRC=\"CondorTitle.gif\" border=0 ></a>\n";
print OUT "</CENTER>\n";
print OUT "<HR NOSHADE>\n";

print OUT "<H2>$title</H2>\n\n";
print OUT "<UL>\n";

foreach $dir ( sort(keys %html_files) ) {
    print OUT "<LI><A HREF=\"$html_files{$dir}\">$dir</a>\n";
}

print OUT "</UL>\n";

print OUT "\n<HR NOSHADE>\n";

print OUT "<P>If you want to know more about how this page and \n";
print OUT "the doc++ pages have been made, check out the \n";
print OUT "<a href=\"howto.html\">howto</a> document.\n\n";

print OUT "<P><em>This page generated automatically.</em>\n\n";

print OUT "</BODY>\n";
print OUT "</HTML>\n";

# We're done, clean up.
close OUT;
