#!/usr/bin/perl
#
# makedoctree
#
# makes a directory of all documentation versions
#


## libraries
use strict;


### variables ###
our $baseurl = 'http://svn.netmrg.net';
our %docfiles = (
	"netmrg.sgml"   => "share/doc/netmrg.sgml",
	"netmrg.dsl"    => "share/doc/netmrg.dsl",
	"netmrgdoc.css" => "share/doc/netmrgdoc.css",
	"netmrg-logo-small.png"  => "share/doc/netmrg-logo-small.png",
	"netmrg-logo-medium.png" => "share/doc/netmrg-logo-medium.png",
);
our $updatever = "trunk";
my $docfolder = "/tmp";



### forward declairations ###


### main ###

# accept a new version via command line
$updatever = $ARGV[0] if ($ARGV[0] && $ARGV[0] ne "");


# figure out our pretty version (for directory name)
my $prettyver = $updatever;
if ($updatever eq "trunk")
{
	$prettyver = "Trunk";
} # end if trunk
elsif ($updatever =~ /netmrg-(\d+)_(\d+\w+?)(_(\d+\w+?))?/)
{
	$prettyver =~ s/netmrg/NetMRG/;
	$prettyver =~ s/_/\./g;
} # end if netmrg-(version)
else
{
	exit(1);
} # end if something else we don't recognize


# make sure our doc directory exists
my $docdir = "$docfolder/$prettyver";
`rm -rf $docdir` if ( -d $docdir);
mkdir ($docdir);


# co each doc file
for my $shortdocfile (keys(%docfiles))
{
	my $midurl = ($updatever eq "trunk" ? $updatever : "branches/$updatever");
	my $docfile = $docfiles{$shortdocfile};
	my $doccontents = `svn cat $baseurl/$midurl/$docfile 2> /dev/null`;
	open (DOC, ">$docdir/$shortdocfile");
	print DOC $doccontents;
	close (DOC);
} # end foreach file

# run docbook2html on the file
`docbook2html -d $docdir/netmrg.dsl#html $docdir/netmrg.sgml -o $docdir`;

