#!/usr/bin/perl
# generate_edit_html.pl - Don Yang (uguu.org)
#
# Generate HTML replay text with bookmarks. You need to have "homura"
# in your $PATH for this to work, get the package here:
# http://uguu.org/arc_homura.html
#
# ./generate_edit_html.pl > edit.html
#
# 11/06/11
use strict;
# Collect timestamps for all phases before the final phase
my @log_files = qw{
schierke0.log
schierke1.log
schierke2.log
schierke3.log
schierke4.log
schierke5.log
schierke6.log
};
my $input;
my @times = ();
foreach my $file (@log_files)
{
$input .= " $file";
my $text = join '', `cat $input | homura`;
$text =~ /max_time=(\d+)/ or die;
push @times, $1;
}
# Generate bookmark controls
my $bookmarks = " Bookmarks:";
for(my $i = 0; $i <= $#times; $i++)
{
$bookmarks .= ' ';
}
my $func =
"function Bookmark(position){" .
"InputSeek(position);" .
"UpdateProgress();" .
"}";
# Generate raw HTML for everything including the last phase
$input .= " schierke7.log";
my $output = join '', `cat $input | homura`;
# Splice in bookmark functions
$output =~ s/^(.*onclick="Rewind\(\)">)(.*)$/$1$bookmarks$2/so;
$output =~ s/^(.*function UpdateProgress\(\)\{[^\{\}]*\})(.*)$/$1$func$2/so;
# Output to stdout
print $output;