#!/usr/bin/perl -w
if(scalar(@ARGV) == 0) {
        print "Usage: mkCallList <file generated by pod2html & htmlStrip>\n\n";
        exit -1;
}

print <<EOF
#define TITLE GLOD Documentation: Call List
#include header.inc
<center>
<table border=0 width=100%>

EOF
;

@files = @ARGV;
foreach $file (sort(@files)) {
    $_ = $file;
    next if(! (/glod(\w+)/));
    
    # open the file
    open(IN, "$file") || die($!);
    while(<IN>) {
        last if(/\<A NAME=\"name\"\>/);
    }
    $name = <IN>;
    chomp $name;
    while(! ($name =~ /\<\/P\>/)) {
        $t = <IN>; chomp $t;
        $t =~ /\s*(.+)\s*/;
        $name = $name . ' ' . $1;
    }
    
    
    while(<IN>) {
        last if(/\<A NAME=\"c specification\"\>/);
    }

    $spec = <IN>;
    chomp $spec;
    while(! ($spec =~ /\<\/P\>/)) {
        $t = <IN>; 
        chomp $t;
        $t =~ /\s*(.+)\s*/;
        $spec = $spec . ' '. $1;
    }
    
    if(! defined($name) || ! defined($spec)) {
        printf("$file doesn't have a C spec and a name! Fix this!\n");
        exit -1;
    }
    
    $name =~ /\<\/STRONG\> \- (.+)\<\/P\>$/;
    $descr = $1;

    unless($spec =~ /\<P\>(.+)\<\/P\>/) {
        print STDERR "Uhoh!\n";
        print STDERR "[$spec]\n";
        exit -1;
    }
    $cspec = $1;
    
    # add the hyperlinks
    $h = "./$file.html";
    $cspec =~ s/$file[ifv]*/\<a href=\"$h\">$file\<\/a\>/g;

    print <<EOF
        <HBAR>
        <tr valign="top">
            <td>$cspec</td>
            <td>$descr</td>
        </tr>
EOF
    ;

    print "\n";
    close(IN);
}

print <<EOF
</table>
</center>
#include footer.inc

EOF
;

exit 0;




