@@ -130,32 +130,21 @@ sub parse_expr {
my $mod_plus = shift;
my $arg = $arg[$$pos++];
+ my %ops = (
+ '&' => [\&config_and, undef],
+ '+' => [\&config_add, 0],
+ 'm+' => [\&config_add, 1],
+ '>' => [\&config_diff, 0],
+ '>+' => [\&config_diff, 1],
+ '-' => [\&config_sub, undef],
+ );
+
die "Parse error" if (!$arg);
- if ($arg eq '&') {
- my $arg1 = parse_expr($pos);
- my $arg2 = parse_expr($pos);
- return config_and($arg1, $arg2, undef);
- } elsif ($arg =~ /^\+/) {
- my $arg1 = parse_expr($pos);
- my $arg2 = parse_expr($pos);
- return config_add($arg1, $arg2, 0);
- } elsif ($arg =~ /^m\+/) {
- my $arg1 = parse_expr($pos);
- my $arg2 = parse_expr($pos, 1);
- return config_add($arg1, $arg2, 1);
- } elsif ($arg eq '>') {
- my $arg1 = parse_expr($pos);
- my $arg2 = parse_expr($pos);
- return config_diff($arg1, $arg2, 0);
- } elsif ($arg eq '>+') {
- my $arg1 = parse_expr($pos);
- my $arg2 = parse_expr($pos);
- return config_diff($arg1, $arg2, 1);
- } elsif ($arg eq '-') {
+ if (exists($ops{$arg})) {
my $arg1 = parse_expr($pos);
- my $arg2 = parse_expr($pos);
- return config_sub($arg1, $arg2, undef);
+ my $arg2 = parse_expr($pos, ($arg eq 'm+') ? 1 : 0);
+ return &{$ops{$arg}->[0]}($arg1, $arg2, $ops{$arg}->[1]);
} else {
return load_config($arg, $mod_plus);
}
Ah, the wonders of pointers. Simplifies the configuration parsing as all these cases are otherwise identical. Signed-off-by: Elliott Mitchell <ehem+openwrt@m5p.com> --- Oy vey. I only spotted passing the second arg to parse_expr() *just* before I was initially planning to send this. That is quite the boody trap lurking there. --- scripts/kconfig.pl | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-)