# -*-perl-*-

# Makes listing files for the various flavors.

# $Id: grdoc_indexers,v 1.25 1996/04/19 15:30:14 pwalker Exp $

sub
routine_listing
{
    open (OUT, "> $opt_o/Routines.html") || 
	die "Cannot open $opt_o/Routines.html";
    &html_head("$opt_c Alphabetical Routine Listing");

    print OUT "<h1 align=center>$opt_c</h1>\n";
    print OUT "<h2 align=center>Alphabetical Routine Listing</h2>\n";
    &navigation("./");
    print OUT "<hr>\n<table width=100% cellpadding=0 cellspacing=0>\n";
    foreach $ROUTINE (sort cialph keys %routine_home) {
	print OUT "<tr valign>";
	print OUT "<td width=40%>";
	&localnav($ROUTINE, "brief");
	print OUT "</td>\n";
	if ($routine_home{$ROUTINE}) {
	    print OUT "<td>In ";
	    &localnav($routine_home{$ROUTINE}, "brief");
	    print OUT " </td>\n";
	} else {
	    print OUT "<td></td>\n";
	}
	print OUT "</tr>\n";
    }
    print OUT "</table>\n";
    print OUT "<hr>\n";
    &navigation("./");
    &html_foot("$opt_c Alphabetical Routine Listing");
}

sub
atAts_db
{
    open (DB, ">$opt_o/atAts_db");
    foreach $ROUTINE (sort cialph keys %routine_home) {
	$tmp = &resolve_XRefs("\@seeroutine $ROUTINE", "norich");
	$tmp =~ s:<a href=\"([^\"]+)\".*$:\1:;
	$tmp =~ s:GRDOCREPLACEWITHRELATIVEXREF/::g;
	print DB "\@seeroutine:$ROUTINE:$tmp\n";
    }
    foreach $FILE (sort cialph @allfiles) {
	$tmp = &resolve_XRefs("\@seefile $FILE", "norich");
	$tmp =~ s:<a href=\"([^\"]+)\".*$:\1:;
	$tmp =~ s:GRDOCREPLACEWITHRELATIVEXREF/::g;
	print DB "\@seefile:$FILE:$tmp\n";
    }

    close DB;
}


sub
file_listing
{
    open (OUT, "> $opt_o/Files.html") || 
	die "Cannot open $opt_o/Files.html";
    &html_head("$opt_c Alphabetical File Listing");

    print OUT "<h1 align=center>$opt_c</h1>\n";
    print OUT "<h2 align=center>Alphabetical File Listing</h2>\n";
    &navigation("./");
    &file_table_def();
    foreach $FILE (sort cialph @allfiles) {
	&file_list_line($FILE);
    }
    &file_table_undef();
    &navigation("./");
    &html_foot("$opt_c Alphabetical File Listing");
}


sub
NotYet
{
    local ($dd) = @_[0];
    local ($d);
    $d = &make_dotdot("$dd/");
    open (OUT, "> $dd/NotYet.html") || die "$opt_o/NotYet.html: $!\n";
    &html_head("Link Not Available");
    print OUT "<h1 align=center>Link not Available</h1>\n";
    &navigation("$d");
    print OUT <<EOM;
<hr>
This link is not yet available.  This is because either the
cross reference in the source was mistyped, or the file has not
been introduced to the documenting system at this time.
<p>
If you think this is a mistake, you should contact the author of
the file which generated the document which led you here.  Phew!
<hr>
EOM
    &navigation("$d");
    &html_foot("Link Not Available");

}

sub
dir_listing
# This routine actually constructs the separate index.html's (ecept int
# the root, where it makes dirlisting.html).
{
    local (@dothese);
    @dothese = ("", sort cialph keys %dirs);
    foreach $DIR (@dothese) {
	if ($DIR =~ m:^$:) {
	    $outfile = "$opt_o/dirlisting.html";
	    $pdir = "src/";
	} else {
	    $outfile = "$opt_o/$DIR/index.html";
	    $pdir = "src/$DIR/";
	}
	open (OUT, ">$outfile") || die "DL: $outfile: $!\n";
	&html_head("Listing for $pdir");

	print OUT "<h1 align=center>Listing for $pdir</h1>\n";
	&navigation(".");
	&insert_readme("$opt_i/$DIR/");
	&file_table_def();
	foreach $FILE (sort cialph @allfiles) {
	    &file_list_line($FILE) if ($mysubdir{$FILE} =~ m:^$DIR$:);
	}
	&file_table_undef();
	&navigation(".");
	&html_foot("Listing for $pdir");
    }
}

sub
dir_list_index
# This routine puts the hrefed index in a place into OUT.
{
    print OUT "<div align=right><table width=95% cellspacing=0 cellpadding=0>";
    print OUT "<tr><td>\n";
    print OUT "<a href=\"$opt_t/dirlisting.html\">src/</a><br>\n";
    foreach $SD (sort cialph keys %dirs) {
	next if (!($SD =~ m:\S:));
	$hr = "<a href=\"$SD/\">";
	$t = "src/$SD";
	$t =~ s:^(.*)/([^/]+):<font color=\"\#888888\">\1</font>$hr/\2/</a>:;;
	print OUT "$t<br>\n";
    }
    print OUT "</td></tr></table></div>\n";
}

# Things for the file listing
sub
file_table_def
{
    $filetable_l = 0;  $filetable_g = 0; # Line totalers
    print OUT "<p><table width=100% border>";
    print OUT "<tr><td width=35% bgcolor=\"$toprowHL\"><b>File</b></td>";
    print OUT "<td width=15% bgcolor=\"$toprowHL\"><b>Subdir</b></td>";
    print OUT "<td width=12% bgcolor=\"$toprowHL\"><b>Lines</b></td>";
    print OUT "<td bgcolor=\"$toprowHL\"><b>Contains Routines</b></td></tr>\n";
}

sub
file_table_undef
{
    print OUT "<tr><td colspan=2 bgcolor=\"$toprowHL\"><b>Total Lines</b></td>\n";
    print OUT "<td colspan=2 bgcolor=\"$toprowHL\"><b>$filetable_l lines ($filetable_g grdoc";
    print OUT " lines)</b></td></tr>\n";
    print OUT "</table><p>\n";
}

sub
file_list_line
{
    local ($FILE) = @_;
    print OUT "<tr valign><td bgcolor=\"$srcrowHL\">";
    &localnav($FILE, "brief");
    print OUT "</td>\n";
    print OUT "<td bgcolor=\"$blahrowHL\"><a href=\"$opt_t/$mysubdir{$FILE}/\">";
    print OUT "<font size=-1>src/$mysubdir{$FILE}</a></font></td>\n";
    print OUT "<td bgcolor=\"$blahrowHL\"><font size=-1>";
    print OUT "$totallines{$FILE} ($totalgrdlines{$FILE})</font></td>\n";
    $filetable_l += $totallines{$FILE};
    $filetable_g += $totalgrdlines{$FILE};
    $didrouts = 0;
    $rco = "";
    print OUT "<td bgcolor=\"$lastrowHL\">";
    foreach $ROUTINE (sort cialph keys %routine_home) {
	if ($routine_home{$ROUTINE} =~ m/^$FILE$/) {
	    print OUT "$rco";
	    &localnav($ROUTINE, "brief");
	    $rco = "<br>";
	}
    }
    print OUT "&nbsp;</td>";
}

sub
grdoc_printable
{
    # Creates the printable listing.
    
    # First the files
    open (OUT, "> $opt_o/Files_Print.html") || die "PR: $opt_o/FP $!\n";
    &html_head("List of all Files");
    &insert_header ($opt_i);
    print OUT "<h2 align=center>List of all Files</h2>\n";
    foreach $FILE (sort cialph @allfiles) {
	$msd = $mysubdir{$FILE};
	if ($msd =~ m:\S:) {
	    $msd = "src/$msd/";
	} else {
	    $msd = "src/";
	}
	print OUT "<hr><h2>$FILE (in $msd)</h2>\n";
	$urlfile = $FILE;
	$urlfile =~ s:\.:_:g;
	open (FD, "< $opt_o/$mysubdir{$FILE}/${urlfile}_File_Doc.html")
	    || warn "PRSUB: ${urlfile}_File_Doc.html  $!\n";
	while (<FD>) {
	    last if /<!-- BEGIN -->/;
	}
	while (<FD>) {
	    print OUT;
	    last if /<!-- END -->/;
	}
    }
    &html_foot("List of all Files");
    close OUT;

    # Now the routines
    open (OUT, "> $opt_o/Routines_Print.html") || die "PR: $opt_o/RP $!\n";
    &html_head("List of all Routines");
    &insert_header ($opt_i);
    print OUT "<h2 align=center>List of all Routines</h2>\n";
    foreach $ROUTINE (sort cialph (keys %routine_home)) {
	print OUT "<hr>\n";
	$msd = $mysubdir{$routine_home{$ROUTINE}};
	if ($msd =~ m:\S:) {
	    $msd = "src/$msd";
	} else {
	    $msd = "src";
	}

	print OUT "<h2>$ROUTINE (from $msd/$routine_home{$ROUTINE})</h2>\n";
	$urlfile = $ROUTINE;
	$urlfile =~ s:\.:_:g;
	open (FD, "< $opt_o/$mysubdir{$routine_home{$ROUTINE}}/${urlfile}_Routine_Doc.html")
	    || warn "PRSUB: ${urlfile}_Routine_Doc.html  $!\n";
	while (<FD>) {
	    last if /<!-- BEGIN -->/;
	}
	while (<FD>) {
	    print OUT;
	    last if /<!-- END -->/;
	}

    }
    &html_foot("List of all Routines");
    close OUT;
    # Thats all!
}

sub
cialph
{
    $foo = $a;  $bar = $b;
    $foo =~ tr:[A-Z]:[a-z]:;
    $bar =~ tr:[A-Z]:[a-z]:;
    $foo cmp $bar;
}

1;
