#!/usr/local/bin/perl -w
# -----------------------------------------------------------------------------

use strict;

foreach my $srcfile (@ARGV) {
    my $dstfile = $srcfile;
    $dstfile =~ s/\.xhtml$/.shtml/;

    my $func = $srcfile;
    $func =~ s|^(.*/)?gnumeric-||;
    $func =~ s/\..*$//;

    local (*SRC, *DST);
    open (SRC, "<$srcfile") || die "Cannot read $srcfile: $!\n";
    open (DST, ">$dstfile") || die "Cannot write $dstfile: $!\n";

    print DST '<!--#set var="title" value="Gnumeric function ', $func, '" -->';
    print DST '<!--#set var="rootdir" value=".." -->';
    print DST '<!--#include virtual="../header-begin.shtml" -->', "\n";
    print DST '<link rel="stylesheet" href="../style/function.css" type="text/css"/>', "\n";
    print DST '<!--#include virtual="../header-end.shtml" -->', "\n";

    while (<SRC>) {
	if (m'<body>' ... m'</body>') {
	    s|^.*<body>||;
	    s|</body>.*$||;

	    if (s|(<div class="refnamediv")|<p>$1| .. m{</div>}) {
		s|</div>|</div></p>|;
	    }
	    s/<(span class="(function|parameter)")\s+style="font-family: monospace;\s*"\s*>/<$1>/g;
	    s/\&\#10;\s*//g;

	    s|<pre class="synopsis">(.*)</pre>|$1|;

	    s/(href=\".*\.)xhtml\"/$1shtml\"/g;

	    print DST;
	}
    }    

    print DST '<!--#include virtual="../footer.shtml" -->', "\n";

    close (DST);
    close (SRC);
}

# -----------------------------------------------------------------------------
