interesting metrics (idea by KrimZon) to maybe sort players in the
[divverent/nexuiz.git] / data / merge-settings-into-cfg.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my ($in, $out) = @ARGV;
7
8 my %changes = ();
9 while(<STDIN>)
10 {
11         chomp;
12         /^(?:seta?\s)?\s*(\S+)\s+(.*)/
13                 or next;
14         $changes{$1} = $2;
15 }
16
17 my %changes_unapplied = %changes;
18 my $result = "";
19 open my $fh, "<", $in
20         or die "<$in: $!";
21 while(<$fh>)
22 {
23         chomp;
24         /^(seta?\s?\s*)(\S+)(\s+)(.*)/
25                 or do { $result .= "$_\n"; next; };
26         my $v = exists($changes{$2}) ? $changes{$2} : $4;
27         $result .= "$1$2$3$v\n";
28         delete $changes_unapplied{$2};
29 }
30 close $fh;
31 open $fh, ">", $out
32         or die ">$out: $!";
33 print $fh $result;
34 print $fh "set $_ $changes_unapplied{$_}\n" for keys %changes_unapplied;
35 close $fh;