3 # Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
13 my $PREFIX = "CONFIG_";
15 sub set_config
($$$$) {
21 if (!defined($config->{$idx}) or !$mod_plus or
22 $config->{$idx} eq '#undef' or $newval eq 'y') {
23 $config->{$idx} = $newval;
32 open FILE
, "$file" or die "can't open file";
35 /^$PREFIX(.+?)=(.+)/ and do {
36 set_config
(\
%config, $1, $2, $mod_plus);
39 /^# $PREFIX(.+?) is not set/ and do {
40 set_config
(\
%config, $1, "#undef", $mod_plus);
44 /^(.+)$/ and warn "WARNING: can't parse line: $1\n";
55 foreach my $config (keys %$cfg1) {
56 my $val1 = $cfg1->{$config};
57 my $val2 = $cfg2->{$config};
58 $val2 and ($val1 eq $val2) and do {
59 $config{$config} = $val1;
75 foreach my $config (keys %cfg) {
76 next if $mod_plus and $config{$config} and $config{$config} eq "y";
77 $config{$config} = $cfg{$config};
83 sub config_diff
($$$) {
89 foreach my $config (keys %$cfg2) {
90 if (!defined($cfg1->{$config}) or $cfg1->{$config} ne $cfg2->{$config}) {
91 next if $new_only and !defined($cfg1->{$config}) and $cfg2->{$config} eq '#undef';
92 $config{$config} = $cfg2->{$config};
101 my %config = %{$cfg1};
103 foreach my $config (keys %$cfg2) {
104 delete $config{$config};
109 sub print_cfgline
($$) {
112 if ($val eq '#undef' or $val eq 'n') {
113 print "# $PREFIX$name is not set\n";
115 print "$PREFIX$name=$val\n";
122 die "argument error in dump_config" unless ($cfg);
124 foreach my $config (sort keys %config) {
125 print_cfgline
($config, $config{$config});
131 my $mod_plus = shift;
132 my $arg = $arg[$$pos++];
134 die "Parse error" if (!$arg);
137 my $arg1 = parse_expr
($pos);
138 my $arg2 = parse_expr
($pos);
139 return config_and
($arg1, $arg2);
140 } elsif ($arg =~ /^\+/) {
141 my $arg1 = parse_expr
($pos);
142 my $arg2 = parse_expr
($pos);
143 return config_add
($arg1, $arg2, 0);
144 } elsif ($arg =~ /^m\+/) {
145 my $arg1 = parse_expr
($pos);
146 my $arg2 = parse_expr
($pos, 1);
147 return config_add
($arg1, $arg2, 1);
148 } elsif ($arg eq '>') {
149 my $arg1 = parse_expr
($pos);
150 my $arg2 = parse_expr
($pos);
151 return config_diff
($arg1, $arg2, 0);
152 } elsif ($arg eq '>+') {
153 my $arg1 = parse_expr
($pos);
154 my $arg2 = parse_expr
($pos);
155 return config_diff
($arg1, $arg2, 1);
156 } elsif ($arg eq '-') {
157 my $arg1 = parse_expr
($pos);
158 my $arg2 = parse_expr
($pos);
159 return config_sub
($arg1, $arg2);
161 return load_config
($arg, $mod_plus);
165 while (@ARGV > 0 and $ARGV[0] =~ /^-\w+$/) {
166 my $cmd = shift @ARGV;
167 if ($cmd =~ /^-n$/) {
169 } elsif ($cmd =~ /^-p$/) {
170 $PREFIX = shift @ARGV;
172 die "Invalid option: $cmd\n";
178 dump_config
(parse_expr
(\
$pos));
179 die "Parse error" if ($arg[$pos]);
This page took 0.058269 seconds and 5 git commands to generate.