#!/usr/bin/perl

#- written by Guillaume Cottenceau, http://zarb.org/~gc/

#- from MDK::Common
sub cat_ { local *F; open F, $_[0] or return; my @l = <F>; wantarray() ? @l : join '', @l }
sub output { my $f = shift; local *F; open F, ">$f" or die "output in file $f failed: $!\n"; print F foreach @_; 1 }
  
if (@ARGV != 2) {
    die "Usage: rough-bat2sh.pl <input-batfile> <output-shfile>\n";
}
my @contents = cat_($ARGV[0]);

foreach my $line (@contents) {

    if ($line =~ /echo/
        || $line =~ /^\s*rem/) {
        $line = "\n";
    }

    #- \ -> /
    $line =~ s|\\|/|g;

    #- move -> mv
    $line =~ s/^\s*move\b/mv/;

    #- del -> rm
    $line =~ s/^\s*del\b/rm/;

    #- aacdec -> faad
    $line =~ s/^\s*aacdec\b/faad/;

    #- dos2unix
    $line =~ s/\r\n/\n/;

}

output $ARGV[1], @contents;

