# -*-perl-*-

#/*@@
#  @file      grdoc_varindex
#  @date      Sun Apr 21 12:33:19 1996
#  @author    Paul Walker
#  @desc 
# Makes the variable and parameter index.  Assumes that the associate
# arrays %[vp](type|file) have been correctly constructed.
# <p>
# These arrays need a little explanation.  type is obvious.  But
# file contains a space delimited list of the files and or routines
# in which the parameter and or header was used.  This will get parsed
# out with resolve_XRef (see grdoc_parse) and turned into a comma separated
# list.  All this happens in makeVPTable
#  @enddesc 
# @comment
# <code>$Id: grdoc_varindex,v 1.6 1996/04/21 17:55:38 pwalker Exp $</code>
# @endcomment
#@@*/


#/*@@
#  @routine    grdoc_varindex
#  @date       Sun Apr 21 12:52:36 1996
#  @author     Paul Walker
#  @desc 
#  Makes the variable description page and parameter description
#  page.  A future improvement would to be not to make V or P
#  if there were no V or P's, but that would be a change to 
#  @seeroutine navigation also.
#  @enddesc 
#  @calls     html_head, navigation, makeVPTable, html_foot
#  @calledby   main
#@@*/


sub
grdoc_varindex
{
    $grdocoutflag = "";
    $grdocoutflag = "<font color=\"#ff0000\">+</font>" if $opt_O;

    open (OUT, "> $opt_o/Vars.html") || die "$opt_o/Vars.html: $!\n";
    &html_head("Variable Listing");
    print OUT "<h1 align=center>$opt_c</h1>\n";
    print OUT "<h2 align=center>Variable Listing</h2>";
    &navigation("./");
    print OUT "<p>";
    print OUT "<table width=100% border>\n";
    print OUT "<tr><th width=20% bgcolor=\"$toprowHL\">Variable</th>";
    print OUT "<th width=15% bgcolor=\"$toprowHL\">Type</th>";
    print OUT "<th width=65% bgcolor=\"$toprowHL\">File/Routine</th></tr>\n";

    &makeVPTable("v");
    if ($opt_O) {
	print OUT "<b>Note:</b> $grdocoutflag indicates routines which ";
	print OUT "update (or output or return) the variable in question<p>";
    }
    print OUT "</table>\n";
    print OUT "<p>";
    &navigation("./");
    &html_foot("Variable Listing");
    close OUT;

    open (OUT, "> $opt_o/Pars.html") || die "$opt_o/Pars.html: $!\n";
    &html_head("Parameter Listing");
    print OUT "<h1 align=center>$opt_c</h1>\n";
    print OUT "<h2 align=center>Parameter Listing</h2>";
    &navigation("./");
    print OUT "<p>";
    print OUT "<table width=100% border>\n";
    print OUT "<tr><th width=20% bgcolor=\"$toprowHL\">Parameter</th>";
    print OUT "<th width=15% bgcolor=\"$toprowHL\">Type</th>";
    print OUT "<th width=65% bgcolor=\"$toprowHL\">File/Routine</th></tr>\n";

    &makeVPTable("p");

    print OUT "</table>\n";
    print OUT "<p>";
    &navigation("./");
    &html_foot("Parameter Listing");
    close OUT;

}

#/*@@
#  @routine    makeVPTable
#  @date       Sun Apr 21 12:54:07 1996
#  @author     Paul Walker
#  @desc 
#  Makes a table of variables or parameters based on which vars or pars
#  were read in pass2.  Note the eval early on to select which one
#  we do.
#  @enddesc 
#  @calls     resolve_XRefs
#  @calledby  grdoc_varindex

#  @var     which
#  @vdesc   "v" means use variables, "p" means use params.
#  @vtype   char
#  @vio     in
#  @endvar 

#@@*/


sub
makeVPTable
{
    local ($which) = @_[0];
    local (%xtype, %xfile);
    eval "\%xtype = \%${which}type";
    eval "\%xfile = \%${which}file";

    foreach $X (sort cialph keys %xtype) {
	print OUT "<tr><td bgcolor=\"$pvrowHL\">$X</td><td>$xtype{$X}&nbsp;</td>";
	print OUT "<td>";
	$rco = "";
	$hl = "";
	foreach $XR (sort cialph split(' ',$xfile{$X})) {
	    if ($XR =~ m:GRDOCVARISOUT:) {
		$hl = $grdocoutflag;
	    } else {
		print OUT "$rco$hl";
		print OUT &resolve_XRefs("\@seefile $XR", "norich");
		$hl = "";
		$rco = ", ";
	    }
	}
	print OUT "&nbsp;</td></tr>\n";
    }
}

1;
