#!/usr/bin/perl
use strict;
use warnings;

use File::Path;
use File::Basename;
use lib ( dirname($0) );
use Qtopia::Paths;
use Qtopia::Vars;
use Qtopia::File;

Qtopia::Paths::get_paths();

# Windows depot builds use the perl scripts directly rather than the compiled code
if ( $isWindows ) {
    check_script($0, "$depotpath/src/qtopiadesktop/build/bin", $ARGV[0]);
}


use constant OUTPUT => 0;
use constant DEBUG => 0;

my %rules;

while ( @ARGV ) {
    my $bit = shift @ARGV;
    DEBUG and print "bit $bit\n";
    if ( index($bit, "=") == -1 ) {
        unshift(@ARGV, $bit);
        last;
    }
    my ( $before, $after ) = split(/=/, $bit);
    $rules{$before} = $after;
}
my $input = shift @ARGV;
my $output = shift @ARGV;

open IN, $input or die "Can't read $input";
my @data = <IN>;
close IN;

for ( @data ) {
    for my $before ( keys %rules ) {
        my $after = $rules{$before};
        s/$before/$after/;
    }
}

open OUT, ">$output" or die "Can't write $output";
print OUT @data;
close OUT;

exit 0;

