Merge branch 'master' of git://git.xonotic.org/xonotic/xonotic
[xonotic/xonotic.git] / misc / tools / cfgapply.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my %cvar2line = ();
7 my @lines = ();
8
9 my $first = 1;
10 while(<>)
11 {
12         chomp;
13         s/\r//g;
14
15         if(/^\s*(?:set\s+|seta\s+)(\S+)/ or /^\s*(\S+_\S+)/)
16         {
17                 if(exists $cvar2line{$1})
18                 {
19                         $lines[$cvar2line{$1}] = $_;
20                 }
21                 else
22                 {
23                         $cvar2line{$1} = scalar @lines;
24                         push @lines, $_;
25                 }
26         }
27         elsif($first) # only take comments, empty lines from the first config
28         {
29                 push @lines, $_;
30         }
31         $first = 0
32                 if eof;
33 }
34
35 print "$_\n" for @lines;