#!/usr/bin/perl

use lib "."; use lib "uxmon"; use lib "platforms"; 		#inslib
chdir( "doc" ) || die "ooops - where are we?";
open( OUT, ">disp.cfg" );
select OUT;
print OUT <<END
%skin default white_bg frames bsdoc
END
;

my $pwd = `pwd`;
chomp $pwd;

mkdir( "www", 0700 );
system( "ln -s ../../skins www" );
system( "ln -s .. bin" );
mkdir( "www/logs", 0700 );

@file = ();
foreach $file (sort `ls -1 ..`) {
    chomp $file;
    next unless( $file =~ /[A-Z+]{2,}/ );
    push( @file, $file );
    system( "ln -s ../$file ." );
    print "%Page $file.html $file\n";
    print "%include $pwd/$file.h\n";
}
print "%Frameset index README.html Big_Sister_Documentation\n";
close OUT;
select STDOUT;

open( OUT, ">bsm.cfg" );
chomp( $pwd=`pwd` );
print OUT <<END
DisplayCFG file=$pwd/disp.cfg
Display
grouping
END
;
close OUT;

system( "../contrib/webize.pl", @file );
symlink( "../common.pm", "../BigSister/common.pm" );
system( "echo ../bsmonitor/bsmon.pl -I.. -I../platforms -b $pwd -f bsm.cfg -D 3" );
if( ($pid = fork()) == 0 ) {
    exec( "perl -I$pwd/.. -I$pwd/../platforms -I $pwd/../bsmonitor -I$pwd/../tools $pwd/../bsmonitor/bsmon.pl -b $pwd -f $pwd/bsm.cfg -D 3" );
    exit(1);
}

while( ! -f "www/index.html" ) { sleep 1; }
sleep 2;
kill "TERM", $pid;

foreach $file (`ls -1 www`) {
    chomp $file;
    next unless( $file =~ /\.html/ );
    print STDERR $file."\n";
    rename( "www/$file", $file );
}
foreach $file (@file) {
    unlink $file;
    unlink $file.".h";
}

system( "rm -rf www" );
unlink( "disp.cfg", "bin", "bsm.cfg" );
