#!/usr/bin/perl -n
next unless /^[\d]/;
chomp;
@line = split /\t/;
$lineno++;
$startraw = $line[1];
$endraw = $line[2];
$dialogue = $line[3];
if (($dialogue eq '\\N') or ($dialogue eq 'NULL')) {
	$dialogue = "Replace this line with line number $lineno of dialogue";
} elsif ($dialogue =~ /\\$/) {
	$dialogue =~ s/\\$//;
	$nextline = <STDIN>;
	chomp($nextline);
	$dialogue .= "\n$nextline";
} elsif ($dialogue =~ /\r/) {
	$dialogue =~ s/\r/\n/g;
}
if ($dialogue =~ /\\n/) {
	$dialogue =~ s/\\n//g;
}
$startraw += .01;
$start = &raw_to_minsec($startraw);
$end = &raw_to_minsec($endraw);

print "$lineno\n";
print "$start --> $end\n";
print "$dialogue\n";
print "\n";

sub raw_to_minsec {
	my($input) = @_;
	my($intpart) = int($input);
	my($secpart) = sprintf("%03d", 1000*($input - $intpart));
	my($sec) = sprintf("%02d", $intpart % 60);
	my($min) = sprintf("%02d", (($intpart - $sec)/60) % 60);
	my($hr) = sprintf("%02d", ((($intpart - $sec)/60) - $min) / 60);
	return("$hr:$min:$sec,$secpart");
}

