#! /usr/local/bin/perl

# This script edits the html files produced by javadoc in an attempt
# to modify references to Java API documentation so that they point to
# the master copy at www.javasoft.com, rather than to a (nonexistent)
# local copy in the current directory.

# usage: fixhrefs FILE [...]

$JAVA_API_URL="http://www.javasoft.com/products/JDK/CurrentRelease/api";
$JAVA_API_REGEXP="href\s*=\s*\"java\.([^.]+)\.([^.]+)\.html(#[^#\"]+)?\"\s*>";

@files = @ARGV;

foreach $file (@files) {
    open(IN, "<$file");
    $found = 0;
    while (<IN>) {
	if (/$JAVA_API_REGEXP/) {
	    $found = 1;
	}
    }
    close(IN);
    if ($found) {
	rename("$file", "$file~");
	open(IN, "<$file~");
	open(OUT, ">$file");
	while (<IN>) {
	    s/$JAVA_API_REGEXP/href=\"$JAVA_API_URL\/java.$1.$2.html\">/g;
	    print OUT $_;
	}
	close(IN);
	close(OUT);
	printf("wrote $file\n");
    }
}
