#!/usr/bin/perl

$script_in = $ARGV[0];
$_ = $script_in;
/(.*)\.js/;
$script_base = $1;
$script_out = $script_base . ".ssa";

$header = "[Script Info]
; This is a Sub Station Alpha v4 script.
; For Sub Station Alpha info and downloads,
; go to http://www.eswat.demon.co.uk/
; or email kotus@eswat.demon.co.uk
Title: 
Original Script: None
Original Timing: None
ScriptType: v4.00
Collisions: Normal
PlayResY: 480
PlayDepth: 0
Wav: 0, 0,C:\random_anime_soundtrack.wav
LastWav: 1
Timer: 100.0000

[V4 Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: Default,Trebuchet MS,28,65535,16744448,65280,-2147483640,-1,0,1,1,1,2,30,30,30,0,0

[Events]
Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
";

open INPUT,"$script_in" or die "can't find input: $!";
open OUTPUT,">$script_out" or die "can't open output file: $!";


print OUTPUT $header;

while (defined($_ = <INPUT>)) {

  if ($_ !~ /^\W*$/) {

    if ($_ =~ /^\#/) {
      print OUTPUT $_;
    } else {

      if ($_ =~ / ^([^\s]*)\s(.[^\s]*)\s .* \{(.*?)\}\s(.*)$ /x ) {
	print OUTPUT "Dialogue: Marked=0," . $1 . "," . $2 .",*Default," . $3 . ",0000,0000,0000,," . $4 . "\n";
      }
    }
  }
}
