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};
88 foreach my $config (keys %$cfg2) {
89 if (!defined($cfg1->{$config}) or $cfg1->{$config} ne $cfg2->{$config}) {
90 $config{$config} = $cfg2->{$config};
99 my %config = %{$cfg1};
101 foreach my $config (keys %$cfg2) {
102 delete $config{$config};
107 sub print_cfgline
($$) {
110 if ($val eq '#undef' or $val eq 'n') {
111 print "# $PREFIX$name is not set\n";
113 print "$PREFIX$name=$val\n";
120 die "argument error in dump_config" unless ($cfg);
122 foreach my $config (sort keys %config) {
123 print_cfgline
($config, $config{$config});
129 my $mod_plus = shift;
130 my $arg = $arg[$$pos++];
132 die "Parse error" if (!$arg);
135 my $arg1 = parse_expr
($pos);
136 my $arg2 = parse_expr
($pos);
137 return config_and
($arg1, $arg2);
138 } elsif ($arg =~ /^\+/) {
139 my $arg1 = parse_expr
($pos);
140 my $arg2 = parse_expr
($pos);
141 return config_add
($arg1, $arg2, 0);
142 } elsif ($arg =~ /^m\+/) {
143 my $arg1 = parse_expr
($pos);
144 my $arg2 = parse_expr
($pos, 1);
145 return config_add
($arg1, $arg2, 1);
146 } elsif ($arg eq '>') {
147 my $arg1 = parse_expr
($pos);
148 my $arg2 = parse_expr
($pos);
149 return config_diff
($arg1, $arg2);
150 } elsif ($arg eq '-') {
151 my $arg1 = parse_expr
($pos);
152 my $arg2 = parse_expr
($pos);
153 return config_sub
($arg1, $arg2);
155 return load_config
($arg, $mod_plus);
159 while (@ARGV > 0 and $ARGV[0] =~ /^-\w+$/) {
160 my $cmd = shift @ARGV;
161 if ($cmd =~ /^-n$/) {
163 } elsif ($cmd =~ /^-p$/) {
164 $PREFIX = shift @ARGV;
166 die "Invalid option: $cmd\n";
172 dump_config
(parse_expr
(\
$pos));
173 die "Parse error" if ($arg[$pos]);
This page took 0.058911 seconds and 5 git commands to generate.