]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/cfgapply.pl
cfgapply: also handle non-set commands
[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         s/\/\/.*//;
15
16         if(/^\s*(?:set\s+|seta\s+|)(\S+)/)
17         {
18                 if(exists $cvar2line{$1})
19                 {
20                         $lines[$cvar2line{$1}] = $_;
21                 }
22                 else
23                 {
24                         $cvar2line{$1} = scalar @lines;
25                         push @lines, $_;
26                 }
27         }
28         elsif($first) # only take comments, empty lines from the first config
29         {
30                 push @lines, $_;
31         }
32         $first = 0
33                 if eof;
34 }
35
36 print "$_\n" for @lines;